[antlr-interest] Rewriting to Flat Tree Nodes for Associative Multiary Operators
John B. Brodie
jbb at acm.org
Thu Oct 2 14:59:42 PDT 2008
Greetings!
On Thursday 02 October 2008 05:23:09 pm Randall R Schulz wrote:
> How might I alter a rule such as this one:
>
> op790Formula
> : (op780Formula -> op780Formula)
> (
> Or rDisjunct = op790Formula
> -> ^(Or $op790Formula $rDisjunct)
> ) ?
> ;
>
> (parenthetically:
> op780Formula
> : ... // Next higher level of operator precedence (And)
> ;
> )
>
> which, when given input like this:
>
> p | q | r | s
>
> produces this sort of tree:
>
> (Or p (Or q (Or r s)))
>
> so that I instead get this:
>
> (Or p q r s)
have you tried:
op790Formula : op780Formula ( Or^ op790Formula )? ;
or without recursion:
op790Formula : op780Formula ( Or^ op780Formula )* ;
Hope this helps...
-jbb
More information about the antlr-interest
mailing list