/* icalc.l - lex/flex specification file for the tokens used in a simple integer calculator */ %{ #include #include "icalc2.h" static int token; extern int yylval; %} %% [ \t\v\f]+ ; "=" return ASSIGN; "+=" return PASSGN; "-=" return SASSGN; "*=" return TASSGN; "/=" return DASSGN; "%=" return MASSGN; "||" return OR; "&&" return AND; "==" return EQ; "!=" return NE; "<" return LT; "<=" return LE; ">" return GT; ">=" return GE; "\?" return THEN; ":" return ELSE; "(" return LPAREN; ")" return RPAREN; "," return COMMA; "+" return PLUS; "-" return MINUS; "*" return MULT; "/" return DIV; "%" return MOD; "^" return POW; "++" return INCR; "--" return DECR; "MAXINT" return MAXINT; "MININT" return MININT; "abs" return ABS; "max" return MAX; "min" return MIN; "swap" return SWAP; [0-9]+ { /* match any digit and convert it to a binary int */ yylval = atoi(yytext); return DIGIT; } [a-z] { /* match a register letter and convert to array index in the range 0-25 */ token = yytext[0]; yylval = token - 'a'; return REG; } [^0-9a-z] { return yytext[0]; }