/*** Definition section ***/ %{ /* C code to be copied verbatim */ #include %} /* This tells flex to read only one input file */ %option noyywrap %% /*** Rules section ***/ /* [0-9]+ matches a string of one or more digits */ [0-9]+ { /* yytext is a string containing the matched text. */ printf("Saw an integer: %s\n", yytext); } [a-z][a-z|0-9]+ { /* yytext is a string containing the matched text. */ printf("Saw an identifier: %s\n", yytext); } [*|+|-|/] { /* yytext is a string containing the matched text. */ printf("Saw an operator: %s\n", yytext); } [=] { /* yytext is a string containing the matched text. */ printf("Saw an assignment: %s\n", yytext); } .|\n { /* Ignore all other characters. */ } %% /*** C Code section ***/ int main(void) { /* Call the lexer, then quit. */ yylex(); return 0; }