/* * Lex/flex scanner for simple expression evaluator. * Modified to use C++. */ %{ #define UseCppImplementation #define YYSTYPE float extern YYSTYPE yylval; #include "calc2.tab.h" %} digit [0-9] number {digit}+ newline \n whitespace [ \t]+ %option noyywrap %option c++ %% "+" {return PLUS;} "-" {return MINUS;} "*" {return TIMES;} "/" {return DIVIDES;} "(" {return LPAREN;} ")" {return RPAREN;} {number} {yylval = atof(yytext); return NUMBER;} {newline} {return NEWLINE;} {whitespace} {/* skip whitespace */} . {return ERROR;} %%