%option nounput noinput %{ #include "proto-color.h" void echo(char *lex_cat) { fprintf(stdout,GREEN("[%s:%s]"), lex_cat, yytext); } void echo2(char *lex_cat) { fprintf(stdout,RED("[%s:%s]"), lex_cat, yytext); } void echonl() { fprintf(stdout,GREEN("[\\n]")"\n"); } void echonl_DOS() { fprintf(stdout,GREEN("[\\r\\n]")"\n"); } void echonl_MAC() { fprintf(stdout,GREEN("[\\r]")"\n"); } %} %% [-+=%/] { echo("OP"); } \>|\< { echo("CMP");} [(){},;\[\]] { echo("SEP");} for | do | while { echo("KW"); } [a-zA-Z][a-zA-Z0-9]* { echo("SYMB"); } [0-9]+\.? | [0-9]*\.?[0-9]+ { echo("NUM"); } [ \t]* // { echo("Blanc"); } \n echonl(); \r echonl_MAC(); \r\n echonl_DOS(); . { echo2("Error"); } %% int yywrap(void) { return 1; } int main(int argc, char *argv[]) { while (yylex()!=0) ; return 0; }