%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 ); } %} DIGIT [0-9] %% {DIGIT}+ { echo("ENTIER"); PutValEntier(); return(ENTIER); } {DIGIT}+\.{DIGIT}* | {DIGIT}*\.{DIGIT}+ { echo("REEL"); PutValFlottant(); return(FLOTTANT); } [-+*/%()] { echo("Tokens"); 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