[antlr-interest] action execution at the rule prediction stage

Sam Harwell sharwell at pixelminegames.com
Sat Apr 25 19:06:52 PDT 2009


Actions surrounded in double angle brackets are "always" run. This means
they run during backtracking, but they may or may not run during
prediction. If you're not careful, they may have unpredictable results.
Here is what they look like:

 

rule : subrule {{AlwaysRunMe();}} ;

 

You also have the @init and @after sections that are always run.

 

Sam

 

From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Xie, Linlin
Sent: Saturday, April 25, 2009 1:49 PM
To: antlr-interest at antlr.org
Subject: [antlr-interest] action execution at the rule prediction stage

 

Dear All,

 

I have a question about the time of execution of the actions put inside
or at the end of the rules. I can see from the generated lexer or parser
code that the actions (at the end of the rule) are inserted after the
match of the whole rule. But I would like to know if any actions (in the
middle or at the end) would be executed before the match of the rule?
i.e. at the Look Ahead (Prediction) stage, would the match of a part of
the rule trigger any actions of the subrule matched? 

 

For example:

 

Rule : Rule1| Rule2;

Rule1 : Rule3* Rule4;

Rule2 : ( Rule3 Rule3 )* Rule5;

Rule3 : AnyRule { AnyAction; };

Rule4 : xxx;

Rule5 : yyy;

 

When trying to find out if the input matches Rule1 or Rule2, will the
AnyAction be executed? Or if the action is in the middle of the rule,
will it be executed before the match of the full rule?

 

I haven't found out any theoretical confirmation from the book, so would
like to ask if anybody can confirm how it works.

 

Thanks.

Linlin

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090425/0366f613/attachment.html 


More information about the antlr-interest mailing list