[antlr-interest] How do I skip a subtree walking in a tree grammar?
Shihwei Li
lishihwei at gmail.com
Mon Mar 16 10:34:02 PDT 2009
Hi,
How do I skip a subtree walking in a tree grammar?
I have a tree grammar to evaluate a boolean expression. What I want to do is
to implement 'conditional' boolean expression:
say the expression is 'A and B', then if the evaluation of A is already
false, I want to skip the evaluation (walking) of B subtree. How do I do
that?
It seems that I can't insert an action like:
* ^( AND a=bool_exp { if (!a) return false; } b=bool_exp) { $value =
(a && b); },*
because it messes up the token stream for further tree walking.
Here is my original tree grammar:
*bool_exp returns [boolean value]
throws ConditionExpressionException
:
not_bool_exp { $value = $not_bool_exp.value; }
|
^( OR a=bool_exp b=bool_exp) { $value = (a || b); }
|
^( AND a=bool_exp b=bool_exp) { $value = (a && b); }
;
*
--peter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090316/dd9f66b6/attachment.html
More information about the antlr-interest
mailing list