PIPS
sc_lex.l
Go to the documentation of this file.
1 /*
2 
3  $Id: sc_lex.l 1647 2016-07-01 11:57:57Z coelho $
4 
5  Copyright 1989-2016 MINES ParisTech
6 
7  This file is part of Linear/C3 Library.
8 
9  Linear/C3 Library is free software: you can redistribute it and/or modify it
10  under the terms of the GNU Lesser General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  any later version.
13 
14  Linear/C3 Library is distributed in the hope that it will be useful, but WITHOUT ANY
15  WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  FITNESS FOR A PARTICULAR PURPOSE.
17 
18  See the GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with Linear/C3 Library. If not, see <http://www.gnu.org/licenses/>.
22 
23 */
24 
25 %option nounput
26 %START COMMENT TEXT
27 %{
28 /*
29  Grammaire lex necessaire pour l'analyse lexicale d'un systeme
30  d'assertions. Les tokens renvoyes sont commentes dans le fichier
31  "sc_gram.y".
32 */
33 
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <string.h>
37 #include <unistd.h> /* flex uses isatty */
38 
39 #include "boolean.h"
40 #include "arithmetique.h"
41 #include "vecteur.h"
42 
43 #include "sc_gram.h"
44 
45 #define RETURN(x) /* fprintf(stderr, "lex: %d\n", x); */ return x
46 
47 char * sc_internal_symbol_table(char *);
48 extern int syst_error(char *);
49 
50 %}
51 
52 %%
53 <TEXT>"VAR" { RETURN(VAR); }
54 <TEXT>[.A-Za-z_]['A-Za-z0-9_:#.]* { syst_lval.Variable = (Variable) sc_internal_symbol_table(syst_text); /*'*/
55  RETURN(IDENT); }
56 <TEXT>\'[A-Za-z0-9_:#?. ]*\' { syst_lval.Variable = (Variable) sc_internal_symbol_table(syst_text); /*'*/
57  RETURN(IDENT); }
58 <TEXT>[0-9]*[.DEe][0-9DEe\-]* { syst_lval.Variable = (Variable) sc_internal_symbol_table(syst_text); /*'*/
59  RETURN(IDENT); }
60 <TEXT>[0-9]* { sscan_Value(syst_text,&syst_lval.Value);
61  RETURN(CONSTANTE); }
62 <TEXT>"==" { RETURN(EGAL); }
63 <TEXT>"=" { RETURN(EGAL); }
64 <TEXT>"," { RETURN(VIRG); }
65 <TEXT>"+" { RETURN(PLUS); }
66 <TEXT>"-" { RETURN(MOINS); }
67 <TEXT>">" { RETURN(SUP); }
68 <TEXT>">=" { RETURN(SUPEGAL); }
69 <TEXT>"<" { RETURN(INF); }
70 <TEXT>"<=" { RETURN(INFEGAL); }
71 <TEXT>"{" { RETURN(ACCOUVR); }
72 <TEXT>"}" { RETURN(ACCFERM); }
73 <TEXT>[ \t\r\n]* ;
74 <TEXT>"#" {BEGIN COMMENT;}
75 <COMMENT>\n {BEGIN TEXT;}
76 <COMMENT>[^\n]* ;
77 . { syst_error("unexpected character"); }
78 %%
79 
80 #define SYMBOLS_SIZE (10)
81 
82 char * sc_internal_symbol_table(char * name)
83 {
84  static int size = 0;
85  static int index = 0; /* next available chunk */
86  static char ** symbols = NULL;
87 
88  int i;
89 
90  if (index==size) {
91  size += SYMBOLS_SIZE;
92  if (symbols) symbols = (char**) realloc(symbols, sizeof(char*) * size);
93  else symbols = (char**) malloc(sizeof(char*) * size);
94  }
95 
96  for (i=0; i<index; i++)
97  if (!strcmp(name, symbols[i]))
98  return symbols[i];
99 
100  /* not found, i==index */
101  symbols[index++] = strdup(name);
102  return symbols[i];
103 }
104 
105 #ifdef FLEX_SCANNER
106 int syst_input()
107 {
108  return( input()) ;
109 }
110 #endif
111 
112 int yywrap(void)
113 {
114 #ifdef FLEX_SCANNER
115  yy_init = 1 ;
116 #endif
117  return( 1 ) ;
118 }
119 
120 void sc_init_lex(void)
121 {
122  /*yyrestart(); */
123  BEGIN TEXT;
124 }
125 
126 extern bool syst_syntax_error;
127 
128 int syst_error(char *s)
129 {
130  /* procedure minimun de recouvrement d'erreurs */
131 /* int c;*/
132 
133  (void) fprintf(stderr,"%s near %s\n",s,yytext);
134 /* while ((c = getchar()) != EOF)
135  putchar(c);
136 */
137  syst_syntax_error = true;
138  return true;
139 }
140 
141 
142