[antlr-interest] translating a tree to another tree

Sérgio Ferreira sergio at moredata.pt
Sun Feb 10 12:35:29 PST 2008


In the current version what will be the best strategy to change the 
original AST to a changed AST that could then be used in a tree parser 
to generate code using string template ?

Thanks
Sérgio Ferreira
> 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
>
>   



More information about the antlr-interest mailing list