import java_cup.runtime.*; import java.util.ArrayList; import java.util.List; terminal LPAREN, RPAREN; terminal SEMI, EQUALS; terminal PLUS, MINUS, TIMES, DIVIDE; terminal String IDENTIFIER; terminal Integer INTEGER_CONSTANT; non terminal List decl_list; non terminal Decl decl; non terminal Exp expression; precedence left PLUS, MINUS; precedence left TIMES, DIVIDE; decl_list ::= decl_list:l decl:d {: l.add (d); RESULT = l; :} | {: RESULT = new ArrayList (); :} ; decl ::= IDENTIFIER:id EQUALS expression:e SEMI {: RESULT = new Decl (id, e); :} ; expression ::= INTEGER_CONSTANT:i {: RESULT = new ExpInt (i.intValue ()); :} | IDENTIFIER:id {: RESULT = new ExpVar (id); :} | expression:e1 PLUS expression:e2 {: RESULT = new ExpBinOp (ExpBinOp.BinOp.PLUS, e1, e2); :} | expression:e1 MINUS expression:e2 {: RESULT = new ExpBinOp (ExpBinOp.BinOp.MINUS, e1, e2); :} | expression:e1 TIMES expression:e2 {: RESULT = new ExpBinOp (ExpBinOp.BinOp.TIMES, e1, e2); :} | expression:e1 DIVIDE expression:e2 {: RESULT = new ExpBinOp (ExpBinOp.BinOp.DIVIDE, e1, e2); :} | LPAREN expression:e RPAREN {: RESULT = e; :} ;