-2

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.

alvr
  • 391
  • 1
  • 3
  • 9

2 Answers2

1

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.

Theodore Norvell
  • 15,366
  • 6
  • 31
  • 45
0

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()" );
    }
}
Chris
  • 1,692
  • 2
  • 17
  • 21