%{ /* From Aho, Seti, Ullman, fig. 4.58, p. 265. */ #include "LexCalc.h" #define yylval calc_lval #include "LexCalc.tab.h" %} %option noyywrap digit [0-9] number {digit}+\.?|{digit}*\.{digit}+ identifier [a-zA-Z]+ %% [ ] { /* Skip blanks. */ } {number} { sscanf(yytext, "%lf", &yylval.value); return NUMBER; } "exit" { return EXIT; } {identifier} { yylval.name = yytext; yylval.length = yyleng; return IDENTIFIER; } \n|. { return yytext[0]; } %%