[antlr-interest] AST for repeated occurrences of binary operators
Jim Idle
jimi at temporal-wave.com
Tue Nov 24 10:46:38 PST 2009
expr : ^(OR expr expr)
| ^(AND expr expr)
| atoms
;
Jim
From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Caetano Sauer
Sent: Tuesday, November 24, 2009 5:34 AM
To: antlr-interest at antlr.org
Subject: [antlr-interest] AST for repeated occurrences of binary operators
Hello everyone,
I am trying to generate an AST node for a logical OR operator. This would be a parent OrExpr token with all the operands as children, for example:
a OR b OR c -> ^(OrExpr a b c)
My question is not how to do it, but I am wondering if the solution I found is the best, since similar situations occur quite often in my grammar. Here is the rule;
orExpr
: firstOperand=andExpr
(OR furtherOperands+=andExpr)*
-> { furtherOperands != null }? ^(OrExpr andExpr+)
-> $firstOperand
;
The important thing here is that I want it to skip straight to andExpr in case there is no OR token.
Thank you very much and regards,
Caetano.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20091124/3bd1b937/attachment.html
More information about the antlr-interest
mailing list