Package persistence.antlr.collections

Examples of persistence.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

    /** 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

        return getText();
    }

    /** Print out a child-sibling tree in LISP notation */
    public String toStringList() {
        AST t = this;
        String ts = "";
        if (t.getFirstChild() != null) ts += " (";
        ts += " " + this.toString();
        if (t.getFirstChild() != null) {
            ts += ((BaseAST)t.getFirstChild()).toStringList();
        }
        if (t.getFirstChild() != null) ts += " )";
        if (t.getNextSibling() != null) {
            ts += ((BaseAST)t.getNextSibling()).toStringList();
        }
        return ts;
    }
View Full Code Here

        }
        return ts;
    }

    public String toStringTree() {
        AST t = this;
        String ts = "";
        if (t.getFirstChild() != null) ts += " (";
        ts += " " + this.toString();
        if (t.getFirstChild() != null) {
            ts += ((BaseAST)t.getFirstChild()).toStringList();
        }
        if (t.getFirstChild() != null) ts += " )";
        return ts;
    }
View Full Code Here

    if ( step<=0 ) {
      buf.append(' ');
      buf.append(toString());
      return numReplacements;
    }
    AST child = getFirstChild();
    numReplacements = 1;
    // walk child printing them out, descending into at most one
    while ( child!=null ) {
      if ( numReplacements>=step || child instanceof ParseTreeToken ) {
        buf.append(' ');
        buf.append(child.toString());
      }
      else {
        // descend for at least one more derivation; update count
        int remainingReplacements = step-numReplacements;
        int n = ((ParseTree)child).getLeftmostDerivation(buf,
                                 remainingReplacements);
        numReplacements += n;
      }
      child = child.getNextSibling();
    }
    return numReplacements;
  }
View Full Code Here

TOP

Related Classes of persistence.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.