[antlr-interest] How can I maintain the order in the tree?

Daniels, Troy (US SSA) troy.daniels at baesystems.com
Wed Mar 18 10:40:13 PDT 2009


I think something like this should work.

 

parent: child -> ^(Parent child);

 

child: (childA | childB | childC) child | /* nothing */ ;

 

Multiple calls to child will build up the tree in the right order.  You
probably also need something to put the term that matched into a tree,
but this is the basic idea.

 

Troy

 

  _____  

From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Gabriel Petrovay
Sent: Wednesday, March 18, 2009 1:03 PM
To: antlr-interest
Subject: [antlr-interest] How can I maintain the order in the tree?

 

Hi all,

Take this example:

tokens {
Parent;
}

parent : (childA | childB | childC)*
    -> ^(Parent childA* childB* childC*)
  ;

if I provide as input:
childB childC childA childB

the tree will order them as defined in the rule and return the following
tree:
^(Parent childA childB childB childC)

How can I define a tree that maintains this order?
e.g. I want to get: ^(Parent childB childC childA childB)


Thanks!

-- 
MSc Gabriel Petrovay
MCSA, MCDBA, MCAD
Mobile: +41(0)787978034

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


More information about the antlr-interest mailing list