[antlr-interest] exceptions in the lexer

Adrian Herscu bmf1972 at fastmail.fm
Tue Aug 21 09:05:06 PDT 2007


Hi,

I have the same problem with antlr 2.7.6...
I have used this (ugly) workaround:

try {
   myParser.myStartRule();
} catch (final ANTLRException e) {
   if (e instanceof TokenStreamRecognitionException) {
     final TokenStreamRecognitionException tsre =
       (TokenStreamRecognitionException) e;
       myParser.reportError(tsre.recog);
   } else {
     throw new MyInternalError(e.getMessage());
   }
}

Anyone found a better approach?

Adrian.

P.S. I also think that it is somehow related to some syntactic predicate 
in my lexer...
I tried for an hour to understand why my lexer throws that exception and 
I am still wondering...

Terence Parr wrote:
> 
> On Dec 10, 2004, at 2:25 PM, Paul J. Lucas wrote:
>> On Fri, 10 Dec 2004, Terence Parr wrote:
>>
>>> Hm...perhaps I should just make it catch ANTLRException, the root,
>>> instead?
>> 	That would work also (and should fix the problem once and for
>> 	all).
> 
> Oh, I think I remember now.  Definitely had to do with 
> TokenRetryException.  I wanted to be able to blast out of the lexer 
> entirely on an exception to force the a token stream switch to flip to 
> another lexer and retry.  If I made that part of the same hierarchy 
> under RecognitionException then you couldn't do the retry.  I 
> specifically made it separate.  Hmm...seems like we need it.
> 
>  From the comment on the interface, "Anything that goes wrong while 
> generating a stream of tokens", I think I meant to be different than 
> recognition issues.  For the life of me though, I can't remember 
> expecting lexer *recognition* exceptions to make it to the parser.  
> Yet, that is what the code says.  Bizarre.  The lexer should just look 
> for another token.
> 
> Ok, i'll look into it.
> Ter
> --
> CS Professor & Grad Director, University of San Francisco
> Creator, ANTLR Parser Generator, http://www.antlr.org
> Cofounder, http://www.jguru.com
> Cofounder, http://www.knowspam.net enjoy email again!
> 
> 
> 
> 
> 
>  



More information about the antlr-interest mailing list