1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/* SI 413 Fall 2013
 * Lab 4
 * YOUR NAMES HERE!
 * Flex file specifying the calculator program scanner
 */
%{
#include "calc.tab.hpp"
#include <cstdlib> // for atoi
%}
 
/* This tells flex to quit when it reaches EOF */
%option noyywrap
 
%%
 
[0-9]+    { yylval.val = atoi(yytext); return NUM; }
[+-]      { yylval.sym = yytext[0]; return OPA; }
[*/]      { yylval.sym = yytext[0]; return OPM; }
"("       { return LP; }
")"       { return RP; }
";"       { return STOP; }
<<EOF>>   { return 0; }
[ \t\n]+  { }
.         { errout << "Unrecognized token starting with " << yytext[0] << endl; exit(1); }
%%