%option nounput noinput %{ #ifdef FLEXALONE /* Mode flex seul */ #define ENTIER 1001 #define FLOTTANT 1002 #else /* couplage flex/bison */ #include "yyparse.h" #endif #include "proto-color.h" void echo(char *lex_cat) { // fprintf(stderr,GREEN("[%s:%s]"), lex_cat, yytext); } void echonl() { // fprintf(stderr,GREEN("[\\n]")"\n"); } void PutValEntier() { sscanf( yytext, "%d", &yylval.entier ); } void PutValFlottant() { sscanf( yytext, "%f", &yylval.flottant ); } void PutValIndex() { yylval.index=yytext[0]-'A'; } %} DIGIT [0-9] %% [A-Z] { echo("VAR"); PutValIndex(); return(VAR); } {DIGIT}+ { echo("ENTIER"); PutValEntier(); return(ENTIER); } {DIGIT}+\.{DIGIT}* | {DIGIT}*\.{DIGIT}+ { echo("REEL"); PutValFlottant(); return(FLOTTANT); } [-+*/%()] { echo("Tokens"); return yytext[0]; } [=] { echo("Affect"); return yytext[0]; } [ \t] ; \n {echonl(); return yytext[0];} . echo("UNK"); %% int yywrap (void) {return 1;} #ifdef FLEXALONE int main(int argc, char *argv[]) { while (yylex()!=0) ; return 0; } #endif