[antlr-interest] AST for repeated occurrences of binary operators
jimi at temporal-wave.com
Tue Nov 24 16:29:45 PST 2009
expr : ae+=andExpr (OR ae+=andExpr)* -> ^(OR $ae+) ;
But usually that isn't the best way to organize the tree and:
expr : andExpr (^OR andExpr)*;
Is what is needed. Then you walk the tree using the AST syntax I gave you before when I thought that that was what you were asking for.
> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of David-Sarah Hopwood
> Sent: Tuesday, November 24, 2009 4:22 PM
> To: antlr-interest at antlr.org
> Subject: Re: [antlr-interest] AST for repeated occurrences of binary
> Caetano Sauer wrote:
> >> On Nov 24, 2009 9:38 PM, "David-Sarah Hopwood"
> >> <david-sarah at jacaranda.org>
> >> wrote:
> >> expr : andExpr (^OR andExpr)*;
> > I am not sure if that's equivalent. In the a OR b OR c case, it would
> > generate the tree (OR a (OR b (OR c))).
> Actually it would produce (OR a (OR b c)).
> > What I want is (OR a b c).
> I think that will be produced by:
> orExpr : andExpr (^OR andExpr (OR! andExpr)*)?;
> David-Sarah Hopwood ⚥ http://davidsarah.livejournal.com
More information about the antlr-interest