[antlr-interest] token stream resynching in custom exception handlers?

mzukowski at bco.com mzukowski at bco.com
Fri Nov 2 07:38:10 PST 2001


There is no way I know of to refer to the follow set from actions or
exception handlers.

The typical default error handler looks like this:

		catch (RecognitionException ex) {
			if (inputState.guessing==0) {
				reportError(ex);
				consume();
				consumeUntil(_tokenSet_5);
			} else {
			  throw ex;
			}

Maybe you can do what you need to in reportError()?  Can you pass all the
info you need wrapped in MyExceptionType?

More specifics on what you are trying to accomplish may help us figure out
alternatives for you.  

Monty

> -----Original Message-----
> From: Dennis Marsa [mailto:drm at xilinx.com]
> Sent: Friday, November 02, 2001 7:27 AM
> To: antlr-interest at yahoogroups.com
> Subject: [antlr-interest] token stream resynching in custom exception
> handlers?
> 
> 
> How can one write a custom exception handler for a rule in ANTLR
> that synchs the token stream to the follow set of the rule just
> as the default exception handler does?
> 
> For example:
> 
> foo
>     :    a
>     |    b  { throw MyExceptionType(...); }
>     |    c
>     ;
>     exception
>     catch [MyExceptionType& exc] {
>         // Do some custom work with exc
> 
>         // Attempt to resynch the token stream
>         consume();
>         consumeUntil(????);  // oops!
>     }
>     
> This doesn't seem possible since in the grammar file, there seems
> to be no way of referring to the rule's follow set for the call to
> consumeUntil().  Or is there?
> 
> Is there another strategy that I'm not seeing?
> 
> 
> Dennis Marsa
> 
>  
> 
> Your use of Yahoo! Groups is subject to 
http://docs.yahoo.com/info/terms/ 


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20011102/d2d17522/attachment.html


More information about the antlr-interest mailing list