Skip to content

Commit

Permalink
Override error routines in parser
Browse files Browse the repository at this point in the history
  • Loading branch information
romildo committed Oct 9, 2016
1 parent b896b59 commit a5321a6
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/main/cup/parser.cup
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
package parse;

import error.ErrorManager;
import java_cup.runtime.Symbol;
import java_cup.runtime.ComplexSymbolFactory.ComplexSymbol;

parser code {:
/* override error routines */
private Loc locOfInfo(Object info) {
return info instanceof ComplexSymbol ?
Loc.loc((ComplexSymbol) info) :
info instanceof Symbol ?
Loc.loc((Symbol) info) :
Loc.loc(cur_token);
}
private String lexemeOfInfo(Object info) {
return info instanceof ComplexSymbol ?
" at '" + ((ComplexSymbol) info).getName() + "'" :
"";

}
public void report_fatal_error(String message, Object info) {
done_parsing();
ErrorManager.em.fatal(locOfInfo(info), message + lexemeOfInfo(info) + "\nCan't recover from previous error(s), giving up.");
}
public void report_error(String message, Object info) {
ErrorManager.em.error(locOfInfo(info), message + lexemeOfInfo(info));
}
:};

terminal LITNUM;
terminal PLUS, MINUS, TIMES, DIV;
terminal LPAREN, RPAREN;
Expand Down

0 comments on commit a5321a6

Please sign in to comment.