[antlr-interest] Complaints about BaseAST implementation
Akhilesh Mritunjai
virtualaspirin at yahoo.com
Tue Oct 11 09:24:08 PDT 2005
Hi
The problem is bit more than that. If the fields are
removed from BaseAST (there is no reason for them to
be there), following classes are affected:
BaseAST
CommonAST
ParserTree
ParseTreeRule
ParseTreeToken
I finally forked the code, and made changesin ANTLR
rather than copying/pasting the algorithms and making
a new MyBaseAST class that I might need to update
everytime a new release comes over. And I figured that
I can submit the diffs to Terence after I test it.
In our testing so far, there haven't been any
problems. The fix works like a charm and now our
appliction handles multi-million node trees with
default heap settings :-)
- Akhilesh
--- Andy Tripp <atripp at jazillian.com> wrote:
> Looks to me that the only places where the "right"
> and "down" fields are
> misused are in
> the addChild() and getNumberOfChildren() methods of
> BaseAST.
> Here is what they should look like:
>
> /**Add a node to the end of the child list for this
> node */
> public void addChild(AST node) {
> if (node == null) return;
> BaseAST t = getFirstChild();
> if (t != null) {
> while (t.right != null) {
> t = t.getNextSibling();
> }
> t.right = (BaseAST)node;
> }
> else {
> this.down = (BaseAST)node;
> }
> }
>
> /** How many children does this node have? */
> public int getNumberOfChildren() {
> BaseAST t = getFirstChild();
> int n = 0;
> if (t != null) {
> n = 1;
> while (t.getNextSibling() != null) {
> t = t.getNextSibling();
> n++;
> }
> return n;
> }
> return n;
> }
>
>
__________________________________
Yahoo! Music Unlimited
Access over 1 million songs. Try it free.
http://music.yahoo.com/unlimited/
More information about the antlr-interest
mailing list