[antlr-interest] ANTLR-2.7.6: how to catch an exception inside Lexer

Terence Parr parrt at cs.usfca.edu
Tue Mar 20 15:24:16 PDT 2007

On Mar 20, 2007, at 3:16 PM, ning dong wrote:

> Hi all,
>  Is there any way to catch an exception inside Lexer and do something
> (ie, catch the exception thrown by nextToken()). The online document
> only shows how to do it in parser.
>  What I really want to do is to rewind the CharBuffer and try new
> rules when something is wrong. Or Can anyone tell me how to do that?
> Seems the rewind() in Parser is to rewind the TokenStreamBuffer, not
> the CharBuffer.

Hi. don't do this manually.  Use filter=true option and then just  
list rules in order of precedence.  It will auto-backtrack across them.


More information about the antlr-interest mailing list