[antlr-interest] manual tree construction
Monty Zukowski
monty at codetransform.com
Thu Sep 15 08:56:51 PDT 2005
On Sep 15, 2005, at 8:39 AM, Michael Laszlo wrote:
> My parser includes the rules below for declarations that look like
> this:
> var a = 2, b = 3+4;
>
>
> decl_statement SEMI!
> : "var"! ID DEC_ASSIGN^ expr (DEC_COMMA^ var_decl)*
> ;
>
> var_decl! // construct these subtrees manually
> : ID DEC_ASSIGN expr { #var_decl = #(DEC_ASSIGN ID expr); }
> ;
>
> antlr.Tool gives me this error message:
> ANTLR Parser Generator Version 2.7.5 (20050128) 1989-2005
> jGuru.com
> calc.g:35:27: Syntax error in action: calc.g:35:27: expecting ')',
> found 'I'
> Exiting due to errors.
> This error message flags the second reference to ID in the var_decl
> rule. The documentation (ANTLR Tree Construction) suggests that
> this should work.
>
> I'm using heterogeneous trees, and am basically trying to construct
> a tree that looks like this:
> #(DEC_COMMA #(DEC_ASSIGN ID expr) #(DEC_ASSIGN ID expr)). Here
> DEC_COMMA serves as the backbone for the subtrees for the variable
> bindings.
>
Use labels. When you use #(TOKEN ...) ANTLR thinks you are building
a node, not a tree.
i:ID d:DEC_ASSIGN expr { #var_decl = #(i d expr); }
Monty
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20050915/bb229d89/attachment.html
More information about the antlr-interest
mailing list