[antlr-interest] Error recovery during list assembly
Johannes Luber
jaluber at gmx.de
Sat Jul 19 15:25:08 PDT 2008
Brent Yates schrieb:
> 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
You are describing a situation which mention Ter on his blog once. IIRC
then ANTLR doesn't handle this situation itself. I don't know if you can
overwrite this behaviour yourself. :(
Johannes
More information about the antlr-interest
mailing list