2
votes

i have problems to recovery and reposting error with ANTLR v3. i follow this link http://www.antlr.org/blog/antlr3/error.handling.tml but i don't have that solutions. i want to make some reporting and recovery for example in the source program like this : student input code :

FOR(int a=0;a<10;a++){
 b=b*a;
}

and the program will report like this: Program : "are you meant the keyword FOR is for?" student answer:"yes" after that, the system recovery and modified the source code automatically. How to do like that with ANTLR v3?imposible to do with ANTLR? need help. thanks guys!

1
Is restarting the parse from scratch acceptable? It might simplify the implementation.sarnold

1 Answers

1
votes

I think you need to override org.antlr.runtime.BaseRecognizer.recoverFromMismatchedToken inside your generated parser class.

This function is called when ANTLR detects an invalid token. So in your own function you can asks the user whether recovery is needed.

If needed, then you can call BaseRecognizer.recoverFromMismatchedToken to perform the recovery. If not, you can throw an exception MismatchedTokenException.