[antlr-interest] translating a tree to another tree

Benjamin Niemann pink at odahoda.de
Sun Feb 10 03:24:32 PST 2008


Hi Philippe,

Philippe Faes wrote:

> I would like to translate an AST, generated with ANTLR to another AST.
> This is usefull for having layers of intermediate representations, each
> new layer more abstract than the previous.
> I tried using a treewalker and setting output=AST, but this gives two
> problems.
> First, I need to set   ASTLabelType=Token so that the TreeAdaptor can take
> Tokens as input. This is not what I want, since the tree being walked
> constists of Tree nodes.
> Second, the generated code tries to read retval.stop on objects of
> TreeRuleReturnScope, but these objects only have a "start" field. The
> "stop" field is found in ParserRuleReturnScope, but the tree walker uses
> TreeRuleReturnScope instead.
> 
> Am I doing something wrong? Is the generation of new trees from old trees
> not supported in ANTLR? If not: Why? It seems like a natural thing to try.

output=AST for tree parsers is supported by the upcoming 3.1 release. 3.0
can't do it. You could try a recent daily build from
<http://www.antlr.org/download/build/>. The official release should not be
far ahead.

HTH

-- 
Benjamin Niemann
Email: pink at odahoda dot de
WWW: http://pink.odahoda.de/



More information about the antlr-interest mailing list