[antlr-interest] Error recovery contortion

Terence Parr parrt at cs.usfca.edu
Tue Dec 7 11:26:53 PST 2004



On Dec 7, 2004, at 11:09 AM, Paul J. Lucas wrote:
>> The following code generates precisely the same output
>> for func() with and without the "defaultErrorHandler=false;".
>
> 	For *your* example code, it would work fine because your rule
> 	contains only tokens, not rules.

Ah.

>   If it contains a rule as mine
> 	does, *that* rule is auto-recovered from by ANTLR so, by the
> 	time it gets back to the current rule, it's too late.

Right.  I get it.  After the rule recovers, ANTLR tries to keep going 
in the invoking rule, but no tree is returned from the other rule.  
Hold on.  Sorry for being dense about this (I really should just try to 
build something myself).  Anyhoo, if I make it

func : ID another SEMI ;
exception
catch [ RecognitionException re ] {
                     ## = #([ERROR,"ERROR"]);
                         recover( re );
     }

another : STUFF ;

instead I see in func():

                         another();
                         astFactory.addASTChild(currentAST, returnAST);

but if I have a catch on another(), it does the recover.  Control will 
return normally from func() and add returnAST to the current tree, 
right?

Why can't you add a catch to the equiv of another()?  Perhaps using 
this example, we can tease out precisely the weakness so I can 
understand the problem.

>>> 	One slight problem: reportError() isn't declared to throw any
>>> 	exception.  Hence, I created the ANTLR_WorkaroundException class 
>>> that
>>> 	extends RuntimeException to work around this annoyance.
>>
>> Only an annoyance, mein herr, because you want reportError to do more
>> than it was meant to ;)
>
> 	Which is why I suggested modifying the auto-exception-recovery
> 	code that ANTLR emits to include a recover() method that is
> 	declared to throw an exception.

Yep, I believe the recover() method will do nicely and is a backward 
compatible change.

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!





 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
    antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 





More information about the antlr-interest mailing list