[antlr-interest] Conditional tree parsing
Bryan Ewbank
ewbank at gmail.com
Wed Nov 1 10:59:12 PST 2006
Try this:
#(IF_TOKEN t=expression
( {t == true}?
val=expression .
|
// expression was false
. val=expression
)
)
This uses the value of the expression, captured in t, to direct the parse to
only evaluate the leg of interest.
Hope this helps,
- Bryan
On 10/31/06, VAUCHER Laurent <VAUCHER at fermat.eu> wrote:
> I'm currently implementing an expression evaluator as a TreeParser, so, for
> correct evaluation semantic, I need to conditionnally evaluate some parts of
> the parse tree...
>
> When evaluating, I need to direct the tree parser to only walk the correct
> branch of the tree (expr1AST is testexpr is true, expr2Ast otherwise).
>
> My first try was to write:
>
> #(IF_TOKEN t=expression v1=expression v2=expression)
> but then both expression are evaluated (wrong!)
More information about the antlr-interest
mailing list