%{ #define ENDFILE 0 #define IDENT 1 #define INTEGER 2 #define REAL 3 #include #undef yywrap int yywrap(void) { return 1; } extern int line_count; extern int decimal_digit; extern float real_num; %} Digit [0-9] Letter [a-zA-Z] %% ("+"|"-")?{Digit}+"."{Digit}+("E"("+"|"-"|""){Digit}+)* { /* Real Constant */ real_num = atof(yytext); return REAL; } {Digit}+ { /* Decimal Integer */ decimal_digit = atoi(yytext); return INTEGER; } {Letter}({Letter}|{Digit}|_)* { /* Identifier */ return IDENT; } [ \t]+ { /* Skip blanks and tabs */ } "\n" { /* Count lines */ line_count++; } . { /* Skip all other characters */ } <> { /* End-of-file */ return ENDFILE; } %%