[antlr-interest] Re: rooting a parser rule rather than a token

Eric Mahurin eric_mahurin at yahoo.com
Wed Aug 11 15:32:13 PDT 2004


--- In antlr-interest at yahoogroups.com, "lgcraymer" <lgc at m...> wrote:
> --- In antlr-interest at yahoogroups.com, "Eric Mahurin"
> <eric_mahurin at y...> wrote:
> > I'm not sure why, but antlr doesn't currently allow you to make a call
> > to a rule from another rule an AST root.  So, you can't do something
> > like this:
> > 
> > binary_expression : primary (binary_operator^ primary)* ;
> > 
> That's a feature, not a bug.  It prevents you from losing any children
> of the binary_operator root AST.  We did talk about this particular
> topic at the cabal, and ANTLR 3 may provide a different approach.
> 
> --Loring

In the code from the last message, no children should be lost.  Here
are a few examples of what it does:

x: A y^ E ;

y           equivalent-x
-----       ------------
B|C|D       A (B^|C^|D^) E
B C^ D      A B C^ D E
B C D       b C d ; b : A B^ ; d : E^ B

The current ANTLR seemed to be close to handling all but the last case
and that last one (rooting a rule where the root of that rule has
siblings) is probably not very useful.  I do find myself doing the
other two enough.

This seems like a natural definition for a rooted rule.  Do you see
anything wrong with it?

- Eric




 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
    antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



More information about the antlr-interest mailing list