[antlr-interest] FailedPredicateException leads to infinite loop - bug in the Lexer?

Ron Burk ronburk at gmail.com
Wed Mar 31 11:27:09 PDT 2010


> My question is then what is
> the appropriate way to construct the lexer such that it will recover
> gracefully from that invalid input and NOT go into the infinite loop state
> caused by the thrown exception?

Personally, I try to keep "modes" in the lexer and
out of the parser. I probably would have had the
lexer looking past any initial '<' to distinguish the
various types of things it presages (especially
since the XML spec seems to make that relatively
easy). So, for example, this:

> <Program><</Program>

would have returned a token stream like:

TK_START_TAG
TK_IDENT
TK_GT
TK_ILLEGAL
TK_END_TAG
TK_IDENT
TK_GT

I would keep modes like CDATA in the lexer.
YMMV, many ways to skin a cat, etc.


More information about the antlr-interest mailing list