[antlr-interest] advice for grammar modification

Oliver Zeigermann oliver.zeigermann at gmail.com
Thu Aug 11 08:04:05 PDT 2005


To me this looks correct.

Cheers
Oliver

On 8/11/05, Daniel Zuberbuehler <dzubi at users.sourceforge.net> wrote:
> Hello
> 
> I have to adapt an existing grammar but I'm new to the topic of grammars, so I
> could use some advice.
> 
> In my grammar, there are several rules with actions. The rules allow empty
> matches, and as it is, the actions get executed even if it was an empty
> match. I have to modify the rules, so that the actions get only executed if
> the match is not empty.
> I think I have modified the rules correctly, but would be grateful if anybody
> could check if my modifications make sense:
> 
> < original version
> > modified version
> 
> ---------------------------------------
> < rulename : ( rule )?
> <              { actions; }
> <          ;
> 
> > rulename : ( rule
> >              { actions; } )?
> >          ;
> ---------------------------------------
> < rulename : ( rule | /*empty*/ )
> <              { actions; }
> <          ;
> 
> > rulename : ( rule { actions; } |
> >              /*empty*/ )
> >          ;
> ---------------------------------------
> < rulename : ( rules... )*
> <              { actions; }
> <          ;
> 
> > rulename : ( ( rules... )+
> >              { actions; } )?
> >          ;
> ---------------------------------------
> < rulename : ( rule1 )? ( rule2 )?
> <              { actions; }
> <          ;
> 
> > rulename : { boolean doit = false; }
> >              ( rule1 { doit = true; } )?
> >              ( rule2 { doit = true; } )?
> >              { if(doit){ actions; }}
> ---------------------------------------
> < rulename : ( rule1 )* ( rule2 )*
> <              { actions; }
> <          ;
> 
> > rulename : { boolean doit = false; }
> >              ( rule1 { doit = true; } )*
> >              ( rule2 { doit = true; } )*
> >              { if(doit){ actions; }}
> ---------------------------------------
> 
> 
> Thanks a lot for your help
> Daniel Zuberbühler
>


More information about the antlr-interest mailing list