[antlr-interest] CommonTree & Tree grammar versus DIY

Terence Parr parrt at cs.usfca.edu
Thu Aug 21 13:26:48 PDT 2008


On Aug 21, 2008, at 1:20 PM, Andy Tripp wrote:

> Terence Parr wrote:
>
>> Yep.  I'm now in favor of manipulating the text instead and
>> regenerating the AST for the altered position. Tree manipulation is
>> fraught with danger
>
> That seems to me like a very odd thing to say.
> Manipulating a tree data structure is inherently no more dangerous  
> than
> manipulating any other kind of data structure.

Apparently you've never made a cycle in a tree before ;)  Recursive/ 
self-similar data structures *ARE* more difficult to alter properly  
than a List; by hand anyway.  For lang X to X, morphing trees is ok  
but altering language makes each new pass have to match a new kind of  
tree.  lang X to Y is not so good as a result.

> Now imagine the same program working on a tree rather than a list.
> Same situation: the program changes the shape of the tree lots of
> times in lots of ways, and
> having to specify the "shape" of it after every change would be silly.
> That's the situation when trying to use treewalkers in a translator.
> It's just that the silliness isn't apparent until you get beyond
> just a couple of valid tree "shapes".

That's why I said I am liking the text rewrite approach; the approach  
you are using, no?

Ter


More information about the antlr-interest mailing list