[antlr-interest] [antlr-dev] actions in rules with backtracking

Terence Parr parrt at cs.usfca.edu
Thu Nov 30 19:28:43 PST 2006


Hi, as Kay points out the only way right now to execute actions  
during syntactic predicates speculative recognition is by specifying  
your own special action to gate actions in and out during speculation  
and by using the @init action.

I would really like to come up with a way to specify that an action  
should always execute so that, for example, people can update a  
symbol table.

Finally, please note that modifying the lexer from the parser usually  
won't work as you mentioned in your follow-up.

Ter
On Nov 30, 2006, at 1:08 PM, Kay Roepke wrote:

> Hi!
>
> On 30. Nov 2006, at 21:54 , Christopher D. Rickett wrote:
>
>> Is there a way to force actions that begin rules to always be
>> executed,
>> even if backtracking is enabled?  For example:
>>
>> A : {/* my action */;} B ;
>>
>> Is there a way to ensure that this action will be executed?
>
> Do you mean to execute the action 'while backtracking'?
> That's tricky. For synpreds you might be able to get away with the
> global
> @synpredgate { expression that replaces the 'backtracking == 0'
> check}, but
> that only works for syntactic predicates and affects all synpreds.
>
> OTOH:
> If you simply want to execute code at the beginning of a rule, use an
> @init action.
> Those are not protected with 'if (backtracking==0)':
>
> rule
> @init {
> 	// this is always executed, try the -trace option to see it in action
> }
> :	'foo' ;
>
> BTW, what do you want to achieve?
>
> HTH,
> -k
>
> P.S.: antlr-interest is a better list for those questions ;)
> -- 
> Kay Röpke
> http://classdump.org/
>
>
>
>
> _______________________________________________
> antlr-dev mailing list
> antlr-dev at antlr.org
> http://www.antlr.org/mailman/listinfo/antlr-dev



More information about the antlr-interest mailing list