Action execution during backtracking

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:

if ( backtracking==0 ) {
     SymbolTable.getPredefinedType("void"), symtab.getDefaultPkg());
}

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

packageDefinition1=packageDefinition();

AST actions are off during backtracking:

if ( backtracking==0 ) list_packageDefinition.add(packageDefinition1.tree);

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

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...