// File di specifica JavaCup per un valutatore di espressioni import java_cup.runtime.*; /* Simboli terminali (token restituiti dallo scanner). */ terminal PIU, MENO, PER, DIVISO; terminal UNARIO, TONDA_APERTA, TONDA_CHIUSA; terminal Integer NUMERO; /* Non terminali */ non terminal Integer expr; /* Precedenze e associativita' */ precedence left PIU, MENO; precedence left PER, DIVISO; precedence left UNARIO; /* Simbolo iniziale */ start with expr; /* Produzioni */ expr ::= expr:e1 PIU expr:e2 {: RESULT = new Integer(e1.intValue() + e2.intValue()); :} | expr:e1 MENO expr:e2 {: RESULT = new Integer(e1.intValue() - e2.intValue()); :} | expr:e1 PER expr:e2 {: RESULT = new Integer(e1.intValue() * e2.intValue()); :} | expr:e1 DIVISO expr:e2 {: RESULT = new Integer(e1.intValue() / e2.intValue()); :} | NUMERO:n {: RESULT = n; :} | MENO expr:e {: RESULT = new Integer(0 - e.intValue()); :} %prec UNARIO | PIU expr:e {: RESULT = e; :} %prec UNARIO | TONDA_APERTA expr:e TONDA_CHIUSA {: RESULT = e; :} ;