[antlr-interest] Tree construction with loops, children at same level
Jim Idle
jimi at temporal-wave.com
Fri Apr 18 12:40:50 PDT 2008
You can ignore the @init block. I was going to show that you could set that to true for more than one byFunction and use conditional rewrites, but I decided that that was not really a good way to do it when you didn't have to.
Jim
From: Marko Simovic [mailto:markobarko at gmail.com]
Sent: Friday, April 18, 2008 12:17 PM
To: Jim Idle
Cc: antlr-interest
Subject: Re: [antlr-interest] Tree construction with loops, children at same level
heheh...not really. client preference. unless you have compelling argument against?
thanks, that works. however, what does the @init block do?
-----Original Message-----
From: Jim Idle <HYPERLINK "mailto:Jim%20Idle%20%3cjimi at temporal-wave.com%3e"jimi at temporal-wave.com>
To: antlr-interest <HYPERLINK "mailto:antlr-interest%20%3cantlr-interest at antlr.org%3e"antlr-interest at antlr.org>
Subject: Re: [antlr-interest] Tree construction with loops, children at same level
Date: Fri, 18 Apr 2008 11:29:22 -0700
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
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/f7bb5cc3/attachment.html
More information about the antlr-interest
mailing list