[antlr-interest] tree grammar clarification

Bernardo Elayda belayda at gmail.com
Fri Jun 29 20:19:03 PDT 2007


Hi,

> Your rewrite produces:
>
> ^(MYNONZEROS MYNZTN) ^(MYNONZEROS MYNZTN) ^(MYNONZEROS MYNZTN) ...
>
> Which I think you are aware of. So, I think that if you use:
>
> rulea: nonzeros+ ;
>
> nonzeros : ^(MYNONZEROS MNZTN) ;
>
> I think you will be good to go.
Yup.  My original rewrite does and was intended to produces a list of
MYNONZEROS subtrees.  The suggestion you proposed was something I
already tried.  It ended up producing a familiar warning on the
'rulea':

Decision can match input such as "MYNONZERS" using multiple alternatives : 1,2
As a result, alternative(s) 2 were disabled for that input.

The solution ANTLR 3 seems to like is to edit the rule nonzeros as you
suggested, and then going back and using '*' or '?' througout my tree
grammar.  Luckily, my grammar is small but this could be a pain if the
grammar was much bigger.

Regards,
Bernardo


On 6/29/07, Jim Idle <jimi at temporal-wave.com> wrote:
>
>
> > -----Original Message-----
> > From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> > bounces at antlr.org] On Behalf Of Bernardo Elayda
>
>
> > I'm having a problem converting a grammar to a tree grammar.
> >
> > The grammar rule I need to translate is:
> >
> > nonzeros : MYNZTN+ -> ^(MYNONZEROS MNZTN)+
> >               ;
> >
>
> Your rewrite produces:
>
> ^(MYNONZEROS MYNZTN) ^(MYNONZEROS MYNZTN) ^(MYNONZEROS MYNZTN) ...
>
> Which I think you are aware of. So, I think that if you use:
>
> rulea: nonzeros+ ;
>
> nonzeros : ^(MYNONZEROS MNZTN) ;
>
> I think you will be good to go.
>
> Jim
>


More information about the antlr-interest mailing list