[antlr-interest] Problems with semantic predicates
Haralambi Haralambiev
hharalambiev at gmail.com
Thu Apr 17 09:02:37 PDT 2008
Hello,
First of all, thanks for the magnificent tool. I
consider myself new to advanced stuff, as I have been working with it
for less than a month.
So, the problem that I currently cannot resolve is described by the
following test grammar:
----------
grammar test;
options {
output=AST;
ASTLabelType=CommonTree;
backtrack=true;
memoize=true;
}
tokens
{
NODE;
}
r : Token1^ Token2! r2[true]
| Token1^ r2[false]
;
r2[boolean flag]
: {flag}? Token1 -> ^(NODE Token1)
| Token1
;
Token1 : 'TOKEN1';
Token2 : 'TOKEN2';
----------
The general idea is that depending on how one rule matches, I would like a
subrule to generate the AST differently.
I decided to do this with some boolean flag, but
the problem is that the generated Java parser class cannot compile.
In the example above - the method *synpred2_fragment()* contains a statement
*if ( !(flag) )* but the variable flag cannot be resolved.
So, if you could please guide me how to resolve this problem. Maybe I have
missed something fundamental in my understandings for developing the
grammar.
Thank you in advance!
Best Regards,
Hari
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080417/a71fa77f/attachment.html
More information about the antlr-interest
mailing list