[antlr-interest] Supplying my on (Homogeneous) Tree Class

John B. Brodie jbb at acm.org
Thu Aug 14 14:29:34 PDT 2008


Greetings!

I have just now gotten back to an earlier ANTLR project after 9 or
more months and am trying to update it to use v3.1.

I uses its own tree node class which extends CommonTree.

I know about providing a alternate TreeAdapter as a factory for my
tree nodes - the adapter provides implementations for create(Token t)
and dupNode(Object o).

I now see that when the class CommonErrorNode was added early this
year that the TreeAdapter also must supply a errorNode(....) method in
order to spawn error items for the tree - seems to be a placeholder
node in the tree to book-keep a sequence of erroneous tokens.

Fine. Good.

But CommonErrorNode extends CommonTree and can not be cast to my tree
node type (which the generated code does when errorNode() is not
overridden in the supplied tree adapter) because my node also extends
CommonTree and casting between siblings in the inheritance hiearchy is
not permissible in Java (i guess).

I tried having my node class extend CommonErrorNode but that does not
compile because of missing constructors in CommonErrorNode. And that
solution would not be desirable due to the increase in memory
footprint of every tree node comprising a large tree.

Keeping the footprint of syntactically correct trees is an excellent
idea (to me) and seems to be the very valid reason for having a
separate CommonErrorNode in the first place. Anyway...

I ended up copying CommonErrorNode.java and changing it to extend
from my tree class (and changing names to protect the innocent).

Is that the proper / intended way to provide my own tree node class?

Thankx (sorry if this is a stupid question)
   -jbb


More information about the antlr-interest mailing list