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

Hendrik Maryns qwizv9b02 at sneakemail.com
Wed Nov 12 09:27:04 PST 2008


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?

Thanks, 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/20081112/2ec4df08/attachment.bin 


More information about the antlr-interest mailing list