[antlr-interest] Automatic lists

John B. Brodie jbb at acm.org
Tue May 17 08:03:05 PDT 2011


Greetings!
On Tue, 2011-05-17 at 15:44 +0200, Ben Corne wrote:
> Found it in the definitive antlr guide: adding a ? behind $docs did the
> trick.

actually i think you want a * in the rewrite expression. 
test with 2 or more documentation constructs....

> 
> 2011/5/17 Ben Corne <ben.corne at gmail.com>
> 
> > Hi
> >
> > I'm trying to create a rule looking like this:
> > ==================================
> > statement
> >   : ( docs+=documentation )*
> >   ( def=definition -> ^(AGSTATEMENT $docs $def)
> >  | tdef=typedefinition -> ^(AGSTATEMENT $docs $tdef)
> > | imp=imports -> ^(AGSTATEMENT $docs $imp)
> >    // TODO: (variable EQL) => varassignment
> >    // TODO: (assignment) => assignment
> >  | exp=expression -> ^(AGSTATEMENT $exp $docs)
> >   ;
> > ==================================
> >
> > This rule should add a bunch of documentation constructs to each type of
> > statement. Testing with at least one documentation per statement, everything
> > works as expected.
> >
> > Now the problem is that when I test statements without any documentation
> > added to a statement, the ANTLRworks debugger seems to stop after the first
> > such statement, refusing to go parse the folowing statements.
> >
> > I suspect that it is because the $docs variable is never initialized since
> > nothing is added. How should I fix this?
> >
> > Regards
> > Ben C.
> >
> 
> 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