for default JavaCC stops parsing after first exception (TokenMgrError) but is a way to parse all input until EOF?
I need that to list all errors instead of stoping at the first one.
Thanks.
for default JavaCC stops parsing after first exception (TokenMgrError) but is a way to parse all input until EOF?
I need that to list all errors instead of stoping at the first one.
Thanks.
In general you should avoid TokenMgeErrors. Usually this can be accomplished with a "catch all" rule -- see the FAQ for details.
Now you are left with a ParseException. You can deal with these using try-catch. See the JavaCC documentation for information on that.
You can use a method that skips all the tokens until the argument one:
void error_skipto(int kind){
ParseException e = generateParseException();
System.out.println(e.toString());
Token t;
do {
t = getNextToken();
} while (t.kind != kind);
}
and then call it in a non-terminal method:
void block(): {}
{
try{
< START > [code()] < END >
}catch ( ParseException e ) {
error_skipto(SEMICOLON);
System.out.println( "Captured by: block()" );
}
}