[antlr-interest] ANTLR trees and adaptors

Terence Parr parrt at cs.usfca.edu
Mon Dec 25 08:52:39 PST 2006


Hi.  The problem is that trees are like fractals: they look the same  
no matter what scale you look at.  A node is a tree in fact and so is  
a subtree.  The nil is no problem at all.  Making two classes is  
weird.  So a tree would just be the top outermost level? Then how do  
I add that to another tree?  I'd have to carve apart.

I have cleaned up the construction a bit now that subrules don't have  
subtree roots.  Only nil() call is at start of method. :)

Ter

On Dec 24, 2006, at 11:54 PM, Manu wrote:

> The tree construction seems a bit counterintuitive to me, having the
> code split in the tree and in the adaptor, with operations that have
> different behaviour if the tree has nil nodes or not.
>
> Wouldn't it be easier to implement a more robust tree data structure
> that can handle all the scenarios orthogonally?
>
> For example, defining a Tree class and TreeNode class. A tree has
> always an empty tree node where it can't store information as its root
> but it is used just as a place holder. The real data are the childs of
> that place holder. A tree node has a list of childs and maybe a
> reference to its parent. With this model a tree can have more than 1
> root tree node below the place holder tree node. This is not a
> problem, is an added feature.
>
> Some examples:
>
> 1) (a b c) will be represented as:
>
> PLACEHOLDER
> |   |   |
> a  b  c
>
> 2) (d (e f g)) will be represented as:
>
> PLACEHOLDER
> |
> d
> |
> --------
> |   |   |
> e  f  g
>
> What do you think? Am I the only one that thinks this is better?



More information about the antlr-interest mailing list