[antlr-interest] How do I skip a subtree walking in a tree grammar?
Shihwei Li
lishihwei at gmail.com
Mon Mar 16 13:38:06 PDT 2009
Ok. time to learn more about predicates..
Still got problems. After removing '=>', compilation errors were reduced
from 35 to 34. All erros are the same: 'a' can not be resolved.
if ( ((a)) ) {s = 18;}
else if ( (true) ) {s = 19;}
Any idea why? Antlr I am using is 3.1.1
Here is the grammar I touched:
bool_exp returns [boolean value]
throws ConditionExpressionException
:
not_bool_exp { $value = $not_bool_exp.value; }
|
^(OR a=bool_exp
( {$a.value}? ignore { $value = true; }
| b=bool_exp { $value = $b.value; }
))
| ^(AND a=bool_exp
( {$a.value}? b=bool_exp { $value = $b.value; }
| ignore { $value = false; }
))
;
--peter
2009/3/16 Gavin Lambert <antlr at mirality.co.nz>
> At 09:09 17/03/2009, Shihwei Li wrote:
>
>> Is this related to syntactic predicate? I can sort of understand the idea
>> behind, but I am not familiar with the syntactic predicate yet. So still
>> need some help from you.
>>
>
> These are actually semantic predicates.
>
> I tried the tree grammar you provided, and I got compilation errors in the
>> generated java code, such as
>>
>> if ( ((a)) ) {s = 18;}
>> else if ( (true) ) {s = 19;}
>>
>> Saying that 'a' is not defined.
>>
>
> Ah, ok; looks like the predicates are being hoisted out of context. Try
> removing the => arrows. I can never remember when one should be used vs.
> the other :)
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090316/cc565be4/attachment.html
More information about the antlr-interest
mailing list