3 $Id: sc_lex.l 1647 2016-07-01 11:57:57Z coelho $
5 Copyright 1989-2016 MINES ParisTech
7 This file is part of Linear/C3 Library.
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
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.
18 See the GNU Lesser General Public License for more details.
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/>.
29 Grammaire lex necessaire pour l'analyse lexicale d'un systeme
30 d'assertions. Les tokens renvoyes sont commentes dans le fichier
37 #include <unistd.h> /* flex uses isatty */
40 #include "arithmetique.h"
45 #define RETURN(x) /* fprintf(stderr, "lex: %d\n", x); */ return x
47 char * sc_internal_symbol_table(char *);
48 extern int syst_error(char *);
53 <TEXT>"VAR" { RETURN(VAR); }
54 <TEXT>[.A-Za-z_]['A-Za-z0-9_:#.]* { syst_lval.Variable = (Variable) sc_internal_symbol_table(syst_text); /*'*/
56 <TEXT>\'[A-Za-z0-9_:#?. ]*\' { syst_lval.Variable = (Variable) sc_internal_symbol_table(syst_text); /*'*/
58 <TEXT>[0-9]*[.DEe][0-9DEe\-]* { syst_lval.Variable = (Variable) sc_internal_symbol_table(syst_text); /*'*/
60 <TEXT>[0-9]* { sscan_Value(syst_text,&syst_lval.Value);
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); }
74 <TEXT>"#" {BEGIN COMMENT;}
75 <COMMENT>\n {BEGIN TEXT;}
77 . { syst_error("unexpected character"); }
80 #define SYMBOLS_SIZE (10)
82 char * sc_internal_symbol_table(char * name)
85 static int index = 0; /* next available chunk */
86 static char ** symbols = NULL;
92 if (symbols) symbols = (char**) realloc(symbols, sizeof(char*) * size);
93 else symbols = (char**) malloc(sizeof(char*) * size);
96 for (i=0; i<index; i++)
97 if (!strcmp(name, symbols[i]))
100 /* not found, i==index */
101 symbols[index++] = strdup(name);
120 void sc_init_lex(void)
126 extern bool syst_syntax_error;
128 int syst_error(char *s)
130 /* procedure minimun de recouvrement d'erreurs */
133 (void) fprintf(stderr,"%s near %s\n",s,yytext);
134 /* while ((c = getchar()) != EOF)
137 syst_syntax_error = true;