[antlr-interest] executing actions in backtracking mode

Terence Parr parrt at cs.usfca.edu
Sat Jun 10 16:21:12 PDT 2006


Ok, so I really need this now.  I need to gate most actions out  
during backtracking but I need a way to force execution of an action  
no matter what.  I think we could add the notion of an option to  
actions rather than a special character.  Or, perhaps the @ syntax.

Currently we use

rule
@init {
	int i=3;
}
@finally {
	System.out.println("on my way out of rule");
}
	:	...
	;

for init actions etc...  Note that init actions are always executed  
during backtracking, but currently '@finally' are not.

Perhaps we do likewise for forcing execution:

a : @force{always exec} BLORT {regular action gated by  
backtracking==0} ;

or, better yet, a more general solution:

@gate(any condition){}

That way you could do more than force exec, you could specify the  
gate condition.  You can put an IF in the action now, but all actions  
are gated with if ( backtracking==0 ) already.

Hmm...I'm wondering if I can fake this somehow for now...perhaps a  
global action that lets you indicate the gate:

@synpredgate {backtracking==0} // default

Ter


More information about the antlr-interest mailing list