[antlr-interest] ANTLR trees and adaptors

Manu manunews at gmail.com
Sun Dec 24 23:54:39 PST 2006


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