[antlr-interest] (POST THIRD TIME) how to bail on MissingTokenException

Geoff hendrey geoff_hendrey at yahoo.com
Mon Nov 24 21:35:08 PST 2008


For some reason, I misread your suggestion as that I needed to override recoverFromMismatchedSet. 
After looking at the source for BaseRecognizer, and re-reading your suggestion, I realized my error.

I added this to my grammar:

protected Object recoverFromMismatchedToken(IntStream input, int ttype, BitSet follow) throws RecognitionException{
     throw new MissingTokenException(ttype, input, null);

}

I guess the Definitive Guide was written before MissingTokenException, because it only covers overriding recoverFromMismatchedSet...

I'm not sure if passing null into MissingTokenException could cause any problems, but this seems to work fine. I basically just want to make sure I throw some type of RecognitionException. Now AntlrWorks also terminates the parsing when I debug, as expect, rather than placing MissingTokenException into the parse tree. Thanks for your help.

 -geoff

"When I do good, I feel good. When I do bad, I feel bad. That's my religion."
-A. Lincoln




________________________________
From: Terence Parr <parrt at cs.usfca.edu>
To: Geoff hendrey <geoff_hendrey at yahoo.com>
Cc: antlr-interest at antlr.org
Sent: Thursday, October 30, 2008 10:55:51 AM
Subject: Re: [antlr-interest] (POST THIRD TIME) how to bail on MissingTokenException

Missing comes from the automatic in-line error recovery. You need to override

    protected Object recoverFromMismatchedToken(IntStream input, int ttype, BitSet follow)

just throw an exception. make sure you don't catch anything later... this should be in the book under how to make the parser bail on first exception.
Ter
On Oct 29, 2008, at 9:25 PM, Geoff hendrey wrote:

> Hi,
> 
> thanks for the response, I really appreciate it. Do you mean "mismatch" or "missing"? Just to be sure we are on the same page, I am getting a MissingTokenException, not MismatchedTokenException. My grammar file already deals with MismatchedTokenException, nd I have no problem with that. I need to find out how to abort parsing on MISSINGTokenException.
> 
> Thanks, and sorry for using caps and bold. Just wanted to make sure we are on the same page.
> 
> -geoff
> 
> 
> 
> From: Terence Parr <parrt at cs.usfca.edu>
> To: Geoff hendrey <geoff_hendrey at yahoo.com>
> Cc: antlr-interest at antlr.org
> Sent: Wednesday, October 29, 2008 12:58:28 PM
> Subject: Re: [antlr-interest] (POST THIRD TIME) how to bail on MissingTokenException
> 
> Hi Geoff, isn't there something in the source code that says " override me if you want to turn off automatic in-line error recovery for mismatch token"?
> Ter
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20081124/bb7c2a40/attachment.html 


More information about the antlr-interest mailing list