dcsimg
How can I get an n-ary tree for a logical operation rather than a nested binary tree (ANTLR v3)
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Krishnan_Anantheswaran
Posted On:   Tuesday, July 14, 2009 01:08 PM

Say I'm trying to match ANDed expressions: andExpr : notExpr (AND notExpr)*; I get that if I put a ^ next to the AND keyword as in: andExpr : notExpr (AND ^ notExpr)*; I will get a nested binary tree when there are multiple ANDs involved and a single node for the notExpr when no ANDs are present. What I want instead is (using tree construction rules only): 1. If no ANDs are involved I get the notExpr as a single node 2. if one or more ANDs are present I get a root node representing the AND and flat list of multiple children representing all the notExpr's involved. Thanks in advance. I'm   More>>

Say I'm trying to match ANDed expressions:

			
andExpr : notExpr (AND notExpr)*;


I get that if I put a ^ next to the AND keyword as in:

			
andExpr : notExpr (AND ^ notExpr)*;


I will get a nested binary tree when there are multiple ANDs involved and a single node for the notExpr when no ANDs are present.




What I want instead is (using tree construction rules only):




1. If no ANDs are involved I get the notExpr as a single node



2. if one or more ANDs are present I get a root node representing the AND and flat list of multiple children representing all the notExpr's involved.




Thanks in advance. I'm having a lot of fun learning ANTLR



Krishnan    <<Less
About | Sitemap | Contact