[antlr-interest] Using labels in actions of a tree parser

Foust javafoust at gmail.com
Wed Aug 13 14:15:14 PDT 2008


Oliver,

> But is there a way to get access to the tree node itself? I tried to
> use the ".tree" attribute, but it leads to an compile error, since .tree
> isn't translated to ".getTree()".
> 
> So, what can I do to get the tree node?

Although it's counter-intuitive, there is no ".tree" attribute on nodes of a
tree grammar (only in the parser). See p. 132. Although $t does represent
your 'term' tree node, only "text", "start", and "st" are defined.

Brent

---------

> 
> Oliver B. Fischer schrieb:
> | Dear all,
> |
> | I would like to use labels in the actions of my tree parser to have
> an
> | alternative way to access the tree nodes. Unfortunately ANTLR reports
> an
> | error I can't understand.
> |
> | Here is my action definition:
> |
> |
> | term returns [DataType rt]
> |   : factor { $rt = $factor.rt; }
> |     -> template(f={$factor.st})"<f>"
> |   | ^(ASTERISK t1=term t2=term)
> |   | ^(SLASH t1=term t2=term)
> |   | ^(AND t=term term)
> |     { System.out.println($t); }
> |   ;
> |
> 
> 
> - --
> Oliver B. Fischer, Schönhauser Allee 64, 10437 Berlin
> Tel. +49 30 44793251, Mobil: +49 178 7903538
> Mail: o.b.fischer at gmx.de Blog: http://www.sw-blog.net
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.8 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
> 
> iEYEARECAAYFAkijTFYACgkQbyc4N0PdoAzBFwCgzYfQHP9luDnCwF8/doZXw+w8
> McgAn3TiHdDJ6sPO/UDbOFbuXcEBjvLh
> =uzjK
> -----END PGP SIGNATURE-----



More information about the antlr-interest mailing list