/* file name: calc4.l */ /* lexer for calculator with variable identifiers. */ /* flex specification */ %{ #include "symtab4.h" /* declaration of `symrec' */ #include "calc4.tab.h" %} DIGIT [0-9] LETTER [A-Za-z] %% {DIGIT}+("."{DIGIT}+)? { yylval.val = atof(yytext); return NUM; } [ \t] /* ignore whitespace */ {LETTER}({LETTER}|{DIGIT})* { symrec *sym; sym = getsym(yytext); if (sym == 0) sym = putsym(yytext); yylval.tptr = sym; return VAR; } <> yyterminate(); /* signal end of dialogue */ \n return yytext[0]; . return yytext[0]; %%