[antlr-interest] expression tree question

Thomas Rolfs thomas.rolfs at cox.net
Thu Jan 13 22:21:46 PST 2005


This is a very simplified version of my expression grammar.

atom
  : ...
  ;

relationalExpression
  : atmo ((EQUALS^|NOT_EQUALS^|GT^|GTE^|LESS^|LTE^) atom)*
  ;

expression
  : relationalExpression ((AND^|OR^) relationalExpression)*
  ;


The expression:

 1 and 2 and 3 and 4

creates the tree:

 <and <and < and 1 2 > 3 > 4 >

but I would like to have:

 < and 1 < and 2 < and 3 < and 4>>>>
 
What is the best way to do this?

I can get the desired tree by changing the rule to:

expression
  : relationalExpression ((AND^|OR^) expression)*
  ;

but I'm guessing that operator precedence will be broken.

Thanks in advance.
-- 
Thomas Rolfs



More information about the antlr-interest mailing list