Package org.jostraca.comp.antlr.collections

Examples of org.jostraca.comp.antlr.collections.AST


     */
    public AST dup(AST t) {
    if ( t==null ) {
      return null;
    }
    AST dup_t = create(t.getClass());
    dup_t.initialize(t);
    return dup_t;
    }
View Full Code Here


    return dup_t;
    }

    /** Duplicate tree including siblings of root. */
    public AST dupList(AST t) {
        AST result = dupTree(t);            // if t == null, then result==null
        AST nt = result;
        while (t != null) {            // for each sibling of the root
            t = t.getNextSibling();
            nt.setNextSibling(dupTree(t))// dup each subtree, building new tree
            nt = nt.getNextSibling();
        }
        return result;
    }
View Full Code Here

    /**Duplicate a tree, assuming this is a root node of a tree--
     * duplicate that node and what's below; ignore siblings of root node.
     */
    public AST dupTree(AST t) {
        AST result = dup(t);    // make copy of root
        // copy all children of root.
        if (t != null) {
            result.setFirstChild(dupList(t.getFirstChild()));
        }
        return result;
    }
View Full Code Here

     *  For example, build(a, b, null, c) yields tree (a b c).  build(null,a,b)
     *  yields tree (nil a b).
     */
    public AST make(AST[] nodes) {
        if (nodes == null || nodes.length == 0) return null;
        AST root = nodes[0];
        AST tail = null;
        if (root != null) {
            root.setFirstChild(null)// don't leave any old pointers set
        }
        // link in children;
        for (int i = 1; i < nodes.length; i++) {
            if (nodes[i] == null) continue// ignore null nodes
            if (root == null) {
                // Set the root and set it up for a flat list
                root = tail = nodes[i];
            }
            else if (tail == null) {
                root.setFirstChild(nodes[i]);
                tail = root.getFirstChild();
            }
            else {
                tail.setNextSibling(nodes[i]);
                tail = tail.getNextSibling();
            }
            // Chase tail to last sibling
            while (tail.getNextSibling() != null) {
                tail = tail.getNextSibling();
            }
        }
        return root;
    }
View Full Code Here

        original = cursor = t;
    }

    /** Is 'sub' a subtree of 't' beginning at the root? */
    public boolean isSubtree(AST t, AST sub) {
        AST sibling;

        // the empty tree is always a subset of any tree.
        if (sub == null) {
            return true;
        }

        // if the tree is empty, return true if the subtree template is too.
        if (t == null) {
            if (sub != null) return false;
            return true;
        }

        // Otherwise, start walking sibling lists.  First mismatch, return false.
        for (sibling = t;
             sibling != null && sub != null;
             sibling = sibling.getNextSibling(), sub = sub.getNextSibling()) {
            // as a quick optimization, check roots first.
            if (sibling.getType() != sub.getType()) return false;
            // if roots match, do full match test on children.
            if (sibling.getFirstChild() != null) {
                if (!isSubtree(sibling.getFirstChild(), sub.getFirstChild())) return false;
            }
        }
        return true;
    }
View Full Code Here

    /** Find the next subtree with structure and token types equal to
     * those of 'template'.
     */
    public AST next(AST template) {
        AST t = null;
        AST sibling = null;

        if (cursor == null) {  // do nothing if no tree to work on
            return null;
        }

View Full Code Here

    /** Is t an exact structural and equals() match of this tree.  The
     *  'this' reference is considered the start of a sibling list.
     */
    public boolean equalsList(AST t) {
        AST sibling;

        // the empty tree is not a match of any non-null tree.
        if (t == null) {
            return false;
        }

        // Otherwise, start walking sibling lists.  First mismatch, return false.
        for (sibling = this;
       sibling != null && t != null;
       sibling = sibling.getNextSibling(), t = t.getNextSibling())
    {
            // as a quick optimization, check roots first.
            if (!sibling.equals(t)) {
                return false;
            }
            // if roots match, do full list match test on children.
            if (sibling.getFirstChild() != null) {
                if (!sibling.getFirstChild().equalsList(t.getFirstChild())) {
                    return false;
                }
            }
            // sibling has no kids, make sure t doesn't either
            else if (t.getFirstChild() != null) {
View Full Code Here

    /** Is 'sub' a subtree of this list?
     *  The siblings of the root are NOT ignored.
     */
    public boolean equalsListPartial(AST sub) {
        AST sibling;

        // the empty tree is always a subset of any tree.
        if (sub == null) {
            return true;
        }

        // Otherwise, start walking sibling lists.  First mismatch, return false.
        for (sibling = this;
             sibling != null && sub != null;
             sibling = sibling.getNextSibling(), sub = sub.getNextSibling()) {
            // as a quick optimization, check roots first.
            if (!sibling.equals(sub)) return false;
            // if roots match, do partial list match test on children.
            if (sibling.getFirstChild() != null) {
                if (!sibling.getFirstChild().equalsListPartial(sub.getFirstChild())) return false;
            }
        }
        if (sibling == null && sub != null) {
            // nothing left to match in this tree, but subtree has more
            return false;
View Full Code Here

     *  an ASTEnumerator that lets the caller walk the list
     *  of subtree roots found herein.
     */
    public ASTEnumeration findAll(AST target) {
        Vector roots = new Vector(10);
        AST sibling;

        // the empty tree cannot result in an enumeration
        if (target == null) {
            return null;
        }
View Full Code Here

     *  an ASTEnumerator that lets the caller walk the list
     *  of subtree roots found herein.
     */
    public ASTEnumeration findAllPartial(AST sub) {
        Vector roots = new Vector(10);
        AST sibling;

        // the empty tree cannot result in an enumeration
        if (sub == null) {
            return null;
        }
View Full Code Here

TOP

Related Classes of org.jostraca.comp.antlr.collections.AST

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.