[antlr-interest] Error recovery during list assembly

Brent Yates brent.yates at gmail.com
Sat Jul 19 14:58:09 PDT 2008


For the following rule:

list
    :   BEGIN item* END
    ;

I would like to be able to recovery from tokens which are not valid items
and not the END literal in such a way that the item list assembly keeps
going.  From inspection of the currently generated code (3.1b2, C target)
the parser will check to see if the next token matches one of the expected
tokens for item.  If it does, it calls the item rule, if not, it drops out
of the item loop and tries to match the END literal.  If the end match fails
then a normal single token delete/insert recovery is tried.  The parser is
expecting the END literal though, not more items, and I don't
see a way to get back into the items loop.

It seems that I need the recovery to happen in the item rule function, but
the error is not detected in the item rule - it is detected in the check for
END.

Is there a way to structure the rule to help this situation or is there a
manual way to code via actions or overrides a way to recover from these
sorts of input errors?

Thanks!

Brent Yates
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080719/f97f3ac2/attachment.html 


More information about the antlr-interest mailing list