/* icalc.l - a lex specification file for generating a lexical analyzer * for a simple integer calculator * * The lexical analyzer generated by this lex specification will recognize * simple operators, parenthesis, and integer constants as tokens and return * them to the syntax analyzer generated by the corresponding icalc.y file. */ %{ /* place C preprocessor and global/local variable declarations here */ #include #include "icalc.h" /* yylval is a global variable that lex uses to pass values to yacc */ extern int yylval; %} %% "+" { return PLUS; } "-" { return MINUS; } "*" { return MULT; } "/" { return DIV; } "(" { return LPAREN; } ")" { return RPAREN; } [0-9]+ { /* match a numeric string and convert to a binary int */ yylval = atoi(yytext); return NUM; } [ \t\f\v]+ { /* ignore all white space */ } [^0-9+\-*/()] { /* any other lexeme NOT one of the above is an error */ return yytext[0]; }