[antlr-interest] How to abort lexer when invalid token encountered?

Olivier Lefevre lefevrol at yahoo.com
Thu Mar 6 16:26:32 PST 2008


Karl Goldstein wrote:
> I'm writing a parser for a simple SQL-like query language.  If the lexer 
> encounters an invalid token (say for an unbalanced quote), I want to 
> abort parsing immediately (no recovery) and return the character 
> position of the invalid token  to the client.

You could check within an action and throw an exception that is *not* a
subclass of RecognitionException: ANTLR is "blind" to those, so it will
bubble up all the way to the top of the stack and your program will die.
That way you can dispense with all those overrides in the header.

-- O.L.



More information about the antlr-interest mailing list