[antlr-interest] conditional tree jumping,
Bryan Ewbank
ewbank at gmail.com
Sun Feb 19 20:30:11 PST 2006
Yes, a semantic predicate avoids evaluating the "wrong half". Something like
this will work (assume that "condition" returns a boolean value:
#(TOK_IF
res=condition
( {res==true}?
(statement)* TOK_ELSE ( . )*
| {res==false}?
( . )* TOK_ELSE (statement)*
)
)
Note that this form as a bit of a problem figuring out which node is the
"right" TOK_ELSE because there might be another TOK_IF statement therein.
I find it easier/cleaner to add a statement-list node so that the TOK_ELSE is
eliminated and there's no ambiguity. This leads to:
#(TOK_IF res=condition
( {res==true}? stmt .
| . stmt )
)
On 2/19/06, Craig Main <craig at palantir.co.za> wrote:
> Hi Jeff,
>
> Thanks for the response.
> I agree completely with your appraisal of the Boolean rule.
>
> My question is somewhat more sinister though. I need to know how to choose a
> branch of the AST tree based on the outcome of the expression. I want to skip
> processing the false loop if the condition is true, and vice versa.
>
> I want the tree parser to skip parsing the correct section of the true. A
> kind of semantic predicate I think?
>
> Regards
> Craig
More information about the antlr-interest
mailing list