[antlr-interest] AST for repeated occurrences of binary operators

Caetano Sauer caetanosauer at gmail.com
Tue Nov 24 05:34:09 PST 2009


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/509b85ba/attachment.html 


More information about the antlr-interest mailing list