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

Prashant Deva prashant.deva at gmail.com
Wed May 25 18:39:41 PDT 2005


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