Action execution during backtracking

Skip to end of metadata
Go to start of metadata

ANTLR must parse ahead to see if something matches. If it fails, then ANTLR tries the next viable alt. Upon failure, it's pretty hard to undo actions in general so ANTLR gates actions out with something like this:

Labels are still defined, because semantic preds might need them:

AST actions are off during backtracking:

Upon success, antlr still rewinds the input and then does the same parse again "with feeling".

Clearly you don't want actions executed when that alt ultimately doesn't succeed. Similarly, when the alt does succeed, you do not want actions executed twice. This all makes sense.

The problem arises when you want actions to execute during backtracking so that semantic predicates make sense during backtracking. If you are combining backtracking (syntactic predicates) and semantic predicates for tough languages like C++ then you must execute actions during the backtrack but then avoid them during the parse.

To be finished when I know how to solve...

Labels:
faq_actions faq_actions Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.