[antlr-interest] How to handle + when using arguments in Java code
Hendrik Maryns
qwizv9b02 at sneakemail.com
Fri Nov 14 04:05:04 PST 2008
Hendrik Maryns schreef:
> Hi all,
>
> I have a rule like the following:
>
> binary returns [Formula result]
> : IMPLICATION WHITESPACE first=formula WHITESPACE second=formula {
> $result = new Implication($first, $second); }
> | EQUIVALENCE WHITESPACE first=formula WHITESPACE second=formula {
> $result = new Equivalence($first, $second); }
> ;
>
> and I would like to do something similar for n-ary junctors, that is
> junctors that can take an arbitrary number of arguments.
>
> 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
>
> formula returns [Formula result] …
>
> is the starting rule.
>
> Can I simply do { $result = new Equivalence($formula); } or something?
Surely this can’t be too difficult, I read something about adding stuff
to a list, but I forgot where. Just a pointer would be fine really. I
could define a constructor taking a list for both classes, NP.
TIA, 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 257 bytes
Desc: OpenPGP digital signature
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20081114/096beb6d/attachment.bin
More information about the antlr-interest
mailing list