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

Xie, Linlin linlin.xie at siemens.com
Mon May 11 02:41:03 PDT 2009


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.

Linlin

 

From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Xie, Linlin
Sent: 11 May 2009 10:19
To: Jim Idle
Cc: antlr-interest at antlr.org; Fitt, Andrew; Hamid, Nusrat
Subject: Re: [antlr-interest] How to pass the current node to the
action?

 

Hi Jim,

 

Thank you very much for your reply. I tried with the .tree solution you
suggested, but got errors like "error C2440: 'type cast' :  cannot
convert from 'p_return' to 'pANTLR3_COMMON_TOKEN'." I can see that you
are trying to use the common token structure, but the way to get the
common token of current node doesn't seem to work. 

 

Is there anything I did wrong? Do you have any idea why it's not
working? Thanks again.

Linlin

 

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

 

Xie, Linlin wrote: 

Sorry, I didn't give a subject to my last question. Below is the
details, can anybody help me out?

 

I presume that you mean:

p: r1 r2

In which case you need to use one of:
$tree
$p.tree
$p
$r1.tree
$r2.tree

But I can't tell you which from the code you show, but you should be
able to work that out. Also, don't forget the search on the ANTLR home
page, or the Wiki

Jim

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


More information about the antlr-interest mailing list