[antlr-interest] advice for grammar modification
John B. Brodie
jbb at acm.org
Thu Aug 11 12:54:58 PDT 2005
> > > rulename : ( ( rules... )+
> > > { actions; } )?
> > > ;
> >
> > This is correct, but to me the next approach sounds better:
> >
> > > rulename : { boolean doit = false; }
> > > ( rules {doit=true;} )*
> > > { if(doit) {actions;} }
>
> > Thanks for your answer!
> > You're right, the readability is better in the variant with the boolean.
> > I'll take that in account for my future work.
>
> Readability is subjective, certainly, but it seems that the ANTLR-only
> version is clearer because it's using ANTLR to control flow, rather
> than requiring action blocks to do something that is built into the
> ANTLR language - something that you must already know if using
> ANTLR....
>
> But that's just me :-)
and I guess I fall in-between these. to me:
rule1 : ( rule2 )? ;
rule2 : ( rule3 ... )+ { action;... }
is clearer.
no flags.
avoids (directly) the (to me) confusing ((x)+)? construct.
the ((x)+)? is still there but is split across two rules.
just my 2cents...
-jbb
More information about the antlr-interest
mailing list