%% %class scanner %unicode %line %column %byaccj %{ /* For more information, please see the jflex manual They have explanation as to why we need a reference to a parser object. We also will need a cross-reference back to the lexer object.*/ /* store a reference to the parser object */ private Parser yyparser; /* constructor taking an additional parser */ public scanner (java.io.Reader r, Parser yyparser) { this (r); this.yyparser = yyparser; } /* return the current line number. We need this because yyline is made private and we don't have a mechanism like extern in C. */ public int getLine() { return yyline; } %} %% "+" {return Parser.PLUS;} "*" {return Parser.TIMES;} "(" {return Parser.LPAREN;} ")" {return Parser.RPAREN;} \r|\n|\r\n {return Parser.CR;} [0-9]+ {yyparser.yylval = new ParserVal(Integer.parseInt(yytext()));return Parser.INT;} [ \t] {;}