[antlr-interest] How to pass the current node to the action?

Xie, Linlin linlin.xie at siemens.com
Wed May 13 08:10:38 PDT 2009


Hi Jim, 

 

Thanks for your previous replies. How does the fixation of the
conversion to common token bug go? As I can use labels for all the
sub-rules, but can't do it to the current rule, as the example shown:

 

P: r1=rule1 r2=rule2;

 

I can use labels for rule1 and rule2, but can't assign rule P to any
label and use the label to refer to the current rule. If you can fix
that as soon as possible, that'd be great!

 

Also this problem probably has some connection with the
ADAPTER->rulePostProcessing( ADAPTER, root_0 ) function. Though having
read the code for the function, I still couldn't get a consistent
picture of how it works. To me, sometimes the rulePostProcessing cuts
the root_0 node, and sometimes it doesn't for the same situation of
having a single child in a rule. So I wonder if you can explain to me
how exactly this function works? Or is there any signal or parameter
that I can use to switch off the cut off of the root_0 (i.e. the
prioritization of the tree)?  I suppose if the $tree can be used (i.e.
the bug above fixed), and I attach some user data to the user pointer of
the $tree, the rulePostProcessing has to do something to pass on the
data when it has to cut off the root_0, right?

 

I look forward to your reply. Thank you very much.

Regards,

Linlin

 

 

From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Jim Idle
Sent: 11 May 2009 18:04
Cc: antlr-interest at antlr.org
Subject: Re: [antlr-interest] How to pass the current node to the
action?

 

Xie, Linlin wrote: 

Hi Jim,

 

The weird thing is if I use the $rule1.tree directly, the generated code
would try to convert the rule1_return structure to common token type
first, but if I assign the rule to a variable, say P: r1=Rule1 Rule2;
then using $r1.tree would be completely fine, as the generated  code
would just keep the rule1_return structure, not trying to convert it at
all.

 

Can you see why it works this way? Thanks a lot.

Maybe a bug in code generation templates, I will take a look, but for
now, use labels :-)

Jim

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090513/3e39ad58/attachment.html 


More information about the antlr-interest mailing list