[antlr-interest] HOW To catch error (no exception is thown)

jabon elekis at gmail.com
Mon Apr 21 21:56:58 PDT 2008


Guntis Ozols a écrit :
>> it's been 2 days, I try to catch error from the parser.
>>     
>
> To catch error, you need to throw it first.
> For some reason still unclear to me,
> antlr lexer does not throw error by default.
>
> The answer you are looking for is in FAQ.
> For some reason, not error handling FAQ but lexing FAQ instead.
>
> !The code there is version specific!
>
> It suggests you to override nextToken() with lots of code.
>
> I am just overriding reportError() with one line to throw
> RuntimeException from there, but then I can not use syntactic
> predicates for lexer rules.
>
> Perhaps there are other options, too.
>
> http://www.antlr.org/wiki/pages/viewpage.action?pageId=5341217.
>
>   
thanks a lot, that work .I ve just put

 public void reportError (RecognitionException re){
             throw new RuntimeException("Bailing out!");
        }

in member in parser.I have no information on the error  but i have an 
error (it still that).

PS: I use  antwork 1.1.7


a+++



More information about the antlr-interest mailing list