[antlr-interest] manual tree construction

Michael Laszlo mjl at nova.edu
Thu Sep 15 08:39:19 PDT 2005


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.

Any thoughts? Thanks, Michael


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20050915/d2a19d03/attachment.html


More information about the antlr-interest mailing list