[antlr-interest] Rewriting to Flat Tree Nodes for Associative Multiary Operators

Randall R Schulz rschulz at sonic.net
Fri Oct 3 06:59:23 PDT 2008


On Friday 03 October 2008 03:02, Gavin Lambert wrote:
> At 11:04 3/10/2008, Randall R Schulz wrote:
>  >op790FormulaFlat
>  >
>  >    :   (op780FormulaFlat -> op780FormulaFlat)
>  >
>  >    (
>  >        ( Or rDisjuncts = op790FormulaFlat) + )
>  >    ->  ^(Or $op790FormulaFlat $rDisjuncts+)
>  >    ) ?
>  >    ;
>
> That's a completely different form from what Jim suggested (for
> starters, it uses recursion within an iterative loop, which can
> cause complications).
>
> Try this instead:
>
> op790FormulaFlat
>
>    :  (a=op780FormulaFlat -> op780FormulaFlat)
>
>       ( (Or b+=op780FormulaFlat)+ -> ^(Or $a $b+) )?
>    ;

Beautiful.

Thanks, Gavin and Jim.

Again, I knew there had to be a simple solution, but I just wasn't 
seeing it.

I'm such a dilettante when it comes to this stuff. As I said to someone 
off-list, I never get in deeper than I need to to get the next parser 
done and then I stop learning (and start forgetting, I think).


Randall Schulz


More information about the antlr-interest mailing list