exceptionjavaccparseexception

How to manipulate ParseException in Javacc


I have created a lexer and parser in javacc and I am trying to handle errors. I initially tried using try-catch blocks for each symbol that is missing in the parser but I read online something about catching the ParseException only once in the main block with a try-catch and manipulating it to get the last token read and next token and more similar things. I am trying to know more about it but I did not come across anything else as most places use try-catch blocks.

Till now, I know I can do : e.currentToken.image if I catch (ParseException e) and also e.getErrorOffset(), but would like to know if there are other methods that can be used to print a more human-readable and informative error. If anyone has any examples or could direct me to some document.Thanks in advance.


Solution

  • The best way to get better (or different) error messages may be to modify the ParseException class itself.