[antlr-interest] Tree construction with loops, children at same level

Jim Idle jimi at temporal-wave.com
Fri Apr 18 11:29:22 PDT 2008


Are you sure you want that? ;-)

 

unionFunction

@init

{

     boolean  multi = false;

}

 : b+=byFunction 

     (    (op=UnionOp b+=byFunction )+

 

                     -> ^($op $b+)

 

           |         -> $b

     )

;

 

Assuming that UnionOp generates only one node, that should work for all of them. 

 

JIm

 

From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Marko Simovic
Sent: Friday, April 18, 2008 10:26 AM
To: antlr-interest
Subject: [antlr-interest] Tree construction with loops, children at same level

 

So, given a rule like this:

unionFunction
: (byFunction -> byFunction)
(opNode=UnionOp b=byFunction -> ^(Function[$opNode] $unionFunction $b) )*;

the following input:

a union b union c

creates a tree which consists of a union node with two children, one of which is another union node (essentially "(a union b) union c").

what i want in such scenarios is to output a single union node with three children. how is this done?

Thanks,
Marko 

 

No virus found in this incoming message.
Checked by AVG.
Version: 7.5.524 / Virus Database: 269.23.1/1385 - Release Date: 4/18/2008 9:30 AM


No virus found in this outgoing message.
Checked by AVG. 
Version: 7.5.524 / Virus Database: 269.23.1/1385 - Release Date: 4/18/2008 9:30 AM
 


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080418/968a22d3/attachment-0001.html 


More information about the antlr-interest mailing list