[antlr-interest] How to handle + when using arguments in Java code

Jim Idle jimi at temporal-wave.com
Fri Nov 14 08:28:33 PST 2008


On Fri, 2008-11-14 at 13:05 +0100, Hendrik Maryns wrote:

> Hendrik Maryns schreef:
> > Hi all,
> > 



> > The bare rule would be:
> > /**
> >  * Conjunction or disjunction.
> >  */
> > n_ary returns [Formula result]
> > 	: CONJUNCTION ( WHITESPACE formula )+
> > 	| DISJUNCTION ( WHITESPACE formula )+
> > 	;
> > 
> > And for CONJUNCTION I would like new Conjunction(Formula... args) to be
> > invoked with the formulas found (ignoring whitespace).  Similar for new
> > Disjunction(Formula... args).  As you might guess
> > 


I am not sure what your Formula class is, but the two patterns are:

n_ary returns [Formula result]

@init {
   $result = new Formula();
}
 : CONJUNCTION ( WHITESPACE f1=formula   { $result.add($f1); } ) +


And

n_ary returns [Formula result]

: CONJUNCTION ( WHITESPACE f1+=formula    ) +  { $result = new
Formula($f1); } // f1 is  a list


JIm
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20081114/e15b5ea0/attachment.html 


More information about the antlr-interest mailing list