Jim Idle schreef:
> 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); } ) +

I found this solution by myself, made a subrule as follows:

n_aryArguments returns [List<Formula> result]
@init{ $result = new ArrayList<Formula>(); }
        : ( WHITESPACE arg=formula { $result.add(arg) } )+
        ;

> And
> 
> n_ary returns [Formula result]
> 
> : CONJUNCTION ( WHITESPACE f1+=formula    ) +  { $result = new
> Formula($f1); } // f1 is  a list

This looks better, but I get an error:

(134): rule '+=' list labels are not allowed w/o output option: f1

Cheers, H.
-- 
Hendrik Maryns
http://tcl.sfs.uni-tuebingen.de/~hendrik/
==================
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html

Attachment: signature.asc
Description: OpenPGP digital signature

List: http://www.antlr.org:8080/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org:8080/mailman/options/antlr-interest/your-email-address

Reply via email to