suppressing extraneous 'mismatched' messages?

8 views
Skip to first unread message

markmc....@gmail.com

unread,
Jul 18, 2016, 12:16:17 PM7/18/16
to antlr-discussion
I'm new to ANTLR after decades of using LALR parser generators ...

I have this rule:

dclobjects: dclobject (COMMA dclobject)* ';'

I'm getting these messages "mismatched input IF on line xxxx" ...

... when an IF statement follows one of these declarations.

BUT ... the parser then figures it out and correctly closes out the dclobjects  statement and then moves on to the IF statement.

This is the behavior I want; why the message on 'mismatch'?

Gerald Rosenberg

unread,
Jul 18, 2016, 2:51:09 PM7/18/16
to antlr-discussion
The default Antlr error recovery mechanism will skip tokens until it can resynchronize with the calling rule (TDAR 159). While it may be only one or a few tokens, they are still likely significant to a proper parse.

Best to resolve the source of the ambiguity rather than suppressing the error reports.  If the 'error' is truly acceptable, the solution is to apply a custom error handler to the parser. The handler can filter out the 'expected' errors.
Reply all
Reply to author
Forward
0 new messages