[antlr-interest] Tree grammar for expression subrules?

Jim Idle jimi at temporal-wave.com
Sat Mar 5 10:34:16 PST 2011


You write expressions like that in the following way:

expression
 : ^(OR expression expression)
 | term
 ;

term
 : X
 | Y
 | Z
 ;

Then do not create the UPSILON as it will just mislead you. if you feel
you need it then add it to term, which although allowing ^(OR EPSILION
EPSILON) won't happen because you won't produce that tree. However, don't
generally make a token for something that isn't there.

Jim

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Bart Kiers
> Sent: Saturday, March 05, 2011 9:09 AM
> To: g4 at novadsp.com
> Cc: antlr-interest at antlr.org interest
> Subject: Re: [antlr-interest] Tree grammar for expression subrules?
>
> On Fri, Mar 4, 2011 at 11:23 PM, g4 at novadsp.com <g4 at novadsp.com> wrote:
>
> >
> > On 04/03/2011 19:13, Bart Kiers wrote:
> >
> >  I'd expect that to become the tree-grammar rule:
> >>>
> >>>    expression
> >>>       :  term
> >>>       |  ^(OR expression term)
> >>>       |  ^(OR expression EPSILON)
> >>>       ;
> >>>
> >>
> > Hello Bart
> >
> > Once again, extremely useful input. Thanks. My question though still
> > stands. Cannot discern any pattern in writing the tree rules as, for
> > example, this seems to violate cardinality ... or does it?
> >
> >
> >
> Hi, I'm starting to hesitate. Could you send your combined- or parser-
> grammar that produces the AST? I'll have a look at it to see if I can
> create a tree grammar (with a bit of comments).
>
> Regards,
>
> Bart.
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address


More information about the antlr-interest mailing list