package edu.gac.max.mcs388.s2002.c3; import java_cup.runtime.Symbol; import edu.gac.max.mcs388.s2002.compiler_support.Identifier; %% %{ Symbol makeToken(int id, Object val){ // yychar and yychar+yylength() are the positions of left and right ends return new Symbol(id, yychar, yychar + yylength(), val); } Symbol makeToken(int id){ // as above but with no attribute value return new Symbol(id, yychar, yychar + yylength()); } %} %char %type Symbol %eofval{ return makeToken(sym.EOF); %eofval} %% "int" {return makeToken(sym.INT);} "main" {return makeToken(sym.MAIN);} "print_int" {return makeToken(sym.PRINT_INT);} [a-zA-Z_][a-zA-Z0-9_]* {return makeToken(sym.ID, Identifier.get(yytext()));} "/" {return makeToken(sym.DIVIDE);} [0-9]+ {return makeToken(sym.NUMBER, new Integer(Integer.parseInt(yytext())));} "," {return makeToken(sym.COMMA);} "=" {return makeToken(sym.ASSIGN);} "-" {return makeToken(sym.MINUS);} "*" {return makeToken(sym.TIMES);} "(" {return makeToken(sym.LPAREN);} ")" {return makeToken(sym.RPAREN);} "{" {return makeToken(sym.LBRACE);} "}" {return makeToken(sym.RBRACE);} ";" {return makeToken(sym.SEMI);} "%" {return makeToken(sym.MOD);} "+" {return makeToken(sym.PLUS);} " "|\n|\t {} "//".* {} . {return makeToken(sym.ILLEGAL_CHAR, yytext());}