import java_cup.runtime.*; import adder.*; parser code {: /* these variables must be declared here: */ String intext; // concrete syntax typed in by user Yylex scanner; // scanner object :}; init with {: try { /* Get Input, form lexer: */ java.io.InputStreamReader lr = new java.io.InputStreamReader(System.in); java.io.BufferedReader lineinput = new java.io.BufferedReader(lr); /* didn't figure out how to pass in input from the main program: */ System.out.print("Enter arithmetic expression: "); intext = lineinput.readLine(); } catch (Exception ee) {} /* scanner needs an input stream */ scanner = new Yylex(new java.io.StringBufferInputStream(intext)); :}; scan with {: return scanner.next_token(); :}; terminal String CONST; terminal TIMES, PLUS, LPAREN, RPAREN; non terminal expr EXP; precedence left PLUS; precedence left TIMES; EXP ::= CONST:c1 {: RESULT = new constexp(c1); :} | EXP:e1 PLUS EXP:e2 {: RESULT = new sumexp("",e1,e2); :} | EXP:e1 TIMES EXP:e2 {: RESULT = new multexp("",e1,e2); :} | LPAREN EXP:e1 RPAREN {: RESULT = e1; :};