[antlr-interest] Recovering from semantic errors

Iztok Kavkler iztok.kavkler at fmf.uni-lj.si
Wed Jun 17 08:28:05 PDT 2009


I have a problem that occurs in my tree parser. When I have the rule 
like the following:

statement: something1 { action1 } something2 { action2 } ;
	catch [Exception e] { printError(e); }

Then when action1 throws a (semantic) exception, I don't want to do 
anything (if everything went ok, the actions would emit some code, but 
since there was an exception I just print out the error message and do 
nothing).

However, the tokens that should be matched by something2 will be left in 
the tree token stream, which will break the parsing of subsequent 
statements. Is there a way to tell the tree parser to recover from this?


More information about the antlr-interest mailing list