[antlr-interest] AST tree output from Tree Parser

Surinder Jain surifilms at gmail.com
Tue Nov 27 15:41:14 PST 2007


I remember (vaiguly since it was many years ago) that ANTLR2 tree walker (or
its equivalent) could read a tree, transform it (as per tree grammar rewrite
rules) and produce a new different output tree.  This allowed multiple
passes making translation job into many simple steps rather than one complex
one.

It appears that this ability has been taken away in ANTLR3.

Is my understanding correct or am I missing something that is not in the
defintive book.  If I am correct then is there any plan to add tree
transformation feature in near future?

Thanks.

Suri

PS:  (ANTLR 3 produces much simpler and mroe useful AST, I am glad I am
using the new version).

If I try to use output=AST on a tree grammar, it produces the tree walker
java code but it does not compile with errors like

E:\surinder\ZEN07\java>javac TestTree.java
TestTree.java:86: cannot find symbol
symbol  : variable stop
location: class TestTree.start_return
                adaptor.setTokenBoundaries(retval.tree, retval.start,
retval.sto
p);

^
TestTree.java:191: cannot find symbol
symbol  : method create(org.antlr.runtime.tree.CommonTree)
location: interface org.antlr.runtime.tree.TreeAdaptor
                    string_literal2_tree =
(CommonTree)adaptor.create(string_lit
eral2);
                                                              ^
TestTree.java:218: cannot find symbol
symbol  : method create(org.antlr.runtime.tree.CommonTree)
location: interface org.antlr.runtime.tree.TreeAdaptor
                    string_literal5_tree =
(CommonTree)adaptor.create(string_lit
eral5);
                                                              ^
TestTree.java:245: cannot find symbol
symbol  : method create(org.antlr.runtime.tree.CommonTree)
location: interface org.antlr.runtime.tree.TreeAdaptor
                    char_literal8_tree =
(CommonTree)adaptor.create(char_literal
8);
                                                            ^
TestTree.java:272: cannot find symbol
symbol  : method create(org.antlr.runtime.tree.CommonTree)
location: interface org.antlr.runtime.tree.TreeAdaptor
                    char_literal11_tree =
(CommonTree)adaptor.create(char_litera
l11);
                                                             ^
TestTree.java:299: cannot find symbol
symbol  : method create(org.antlr.runtime.tree.CommonTree)
location: interface org.antlr.runtime.tree.TreeAdaptor
                    ID14_tree = (CommonTree)adaptor.create(ID14);
                                                   ^
TestTree.java:312: cannot find symbol
symbol  : method create(org.antlr.runtime.tree.CommonTree)
location: interface org.antlr.runtime.tree.TreeAdaptor
                    INT15_tree = (CommonTree)adaptor.create(INT15);
                                                    ^
TestTree.java:321: cannot find symbol
symbol  : variable stop
location: class TestTree.expr_return
                adaptor.setTokenBoundaries(retval.tree, retval.start,
retval.sto
p);


My TestTree,g is :


tree grammar TestTree;

options {tokenVocab=Java; ASTLabelType=CommonTree;output=AST;}

start:expr;

expr: ^('==' expr expr)

| ^('!=' expr expr)

| ^('+' expr expr)

| ^('*' expr expr)

| ID

| INT

;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20071128/031b6432/attachment.html 


More information about the antlr-interest mailing list