[antlr-interest] conditional tree jumping,

Craig Main craig at palantir.co.za
Sun Feb 19 20:46:25 PST 2006


Hi Bryan,

How would you eliminate the else with the statement list?
I am not quite sure what you mean here - I am still trying to wrap my brain
around the tree matching syntax.

Would you be in a position to give me a small example? I assume that you
eliminate the node in the parser.

Regards
Craig

-----Original Message-----
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Bryan Ewbank
Sent: 20 February 2006 06:30
To: ANTLR Interest
Subject: Re: [antlr-interest] conditional tree jumping,

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