[antlr-interest] Complaints about BaseAST implementation

Andy Tripp atripp at jazillian.com
Tue Oct 11 13:57:58 PDT 2005


I guess I'm missing something here. How is it that the BaseAST class doesn't
need "down" and "right" variables. It's the base class for all ASTs, and it
needs to implement the various tree functions functions (addChild, 
getNumberOfChildren,
etc). How can it provide that functionality without having those fields?

Andy

Akhilesh Mritunjai wrote:

>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