[antlr-interest] Re-Thinking Antlr's Error recovery

Terence Parr parrt at cs.usfca.edu
Wed May 25 19:58:51 PDT 2005


Hi Prashant.  You'll find that v3 has a much better error recovery  
scheme.  You get one error until you successfully resync and only  
then can you get another error.  It also computes the context- 
sensitive FOLLOw set so you get a very accurate recovery.

Ter
On May 25, 2005, at 6:39 PM, Prashant Deva wrote:

> I was just thinking a bit about the concept of antlr's error recovery.
> The current mechanism leads one error to several errors.
>
> Take for example this statement containing an error -
>
> int a = 20 adas dasd   sdf sdf adasd ;
>
> Now according to antlr's current error recovery mechanism, after
> reaching '20', the parser would try to apply some other rule to the
> flawed input ( which would again give an error).
>
> But that is not what we want. What we would really like is some way to
> tell the parser to consume until the ';' and then start parsing from
> next statement.
>
> So in essence, what we really want most of the time is NOT 'error
> recovery' but 'error containment', ie we want to 'contain' the error
> till the ';'.
>
> This can be applied almost everywhere, lets say we have -
>
> if (asdasd (asd ) { //missing bracket
> ........
> .....
>
> }
>
> again the best thing to do in this situation would be to consume until
> the '}', otherwise the single error of a missing bracket would lead to
> like 200 errors when it tries to look for it inside the opening '{'
> and recover there.
>
> So do we really need error 'recovery' or should it be error  
> 'containment'.
>
> PRASHANT
>



More information about the antlr-interest mailing list