[antlr-interest] Problem with ASTLabelType unlike CommonTree

Jose Ventura jose.ventura.roda at gmail.com
Fri Jul 7 04:33:01 PDT 2006


I have problems with the ASTLabelType=DoubleLinkTree. I'm going to explain
some question about CommonTree and DoubleLink.

BaseTree implements Tree
CommonTree extends BaseTree
DoubleLink extends BaseTree


- Question 1.
=============

Tree interface have

              public static final Tree INVALID_NODE = new CommonTree(
Token.INVALID_TOKEN);

I think this sentence can to give problems because finally DoubleLink also
implements Tree trought BaseTree, when it's use this var (INVALID_NODE) in
any class derived from BaseTree (except CommonTree), the cast will be
incorrect.


- Question 2.
=============

When I use the ASTLabelType=DoubleLink I have problem with the code
generated in parser, because the treeAdaptor even use the CommonTreeAdaptor.

               protected TreeAdaptor adaptor = new CommonTreeAdaptor();

Then the sentence like

               root_0 = (DoubleLinkTree)adaptor.nil();

have problems with cast

               Exception in thread "main" java.lang.ClassCastException:
org.antlr.runtime.tree.CommonTree


My Suggestion
=============

I have think very much before to do this suggestion because I'm not have a
large java experiency, but ...


I think:

- INVALID_NODE must declared like "public static final Tree INVALID_NODE =
new BaseTree(Token.INVALID_TOKEN)", for this, BaseTree must have the token
var and it can't be abstract class.

- When it's use an ASTLabelType unlike CommonTree, we must have a
TreeAdaptor specific for the AST type, and the antlr generated code must to
use this TreeAdaptor.

- Maybe it's the same with the CommonTreeNodeStream, even tought I don't
research it.



I hope don't tell too much stupidities.

Thank's
José Ventura
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20060707/341b252e/attachment.html


More information about the antlr-interest mailing list