import java_cup.runtime.*; action code {: // inicializações para código das acções semânticas :} ; parser code {: Yylex lexer; public void report_error(String message, Object error_info) { Symbol info = (Symbol) error_info; System.err.print("** " + message); System.err.println(" at `" + info.value + "' in position " + info.left); } public void report_fatal_error(String message, Object _) { System.err.println("** " + message); } :} ; init with {: // lê o standart input lexer = new Yylex(System.in); :} ; scan with {: // usa o tokeniser construído pelo jlex return lexer.yylex(); :} ; terminal MAIS, MENOS ; terminal String INTEIRO ; terminal ERRO ; non terminal Expressao expressao, parcela, factor ; non terminal Expressao expressao_atomica ; expressao ::= parcela:e {: RESULT = e; :} | expressao:e1 MAIS parcela:e2 {: /* ... */ :} | expressao:e1 MENOS parcela:e2 {: /* ... */ :} ; parcela ::= factor ; factor ::= expressao_atomica ; expressao_atomica ::= INTEIRO ;