Package org.jostraca.comp.antlr.collections

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


   *  with a specific Java object type. Typically called when you
   *  say @[PLUS,"+",PLUSNode] in an antlr action.
   *  @since 2.7.2
   */
  public AST create(int type, String txt, String className) {
        AST t = create(className);
    if ( t!=null ) {
      t.initialize(type, txt);
    }
        return t;
    }
View Full Code Here


    /** Create a new empty AST node; if the user did not specify
     *  an AST node type, then create a default one: CommonAST.
     */
    public AST create(AST tr) {
        if (tr == null) return null;    // create(null) == null
        AST t = create(tr.getType());
    if ( t!=null ) {
      t.initialize(tr);
    }
        return t;
    }
View Full Code Here

    }
        return t;
    }

  public AST create(Token tok) {
        AST t = create(tok.getType());
    if ( t!=null ) {
      t.initialize(tok);
    }
        return t;
    }
View Full Code Here

   *  and so I must call the appropriate constructor not T().
   *
   * @since 2.7.2
   */
  public AST create(Token tok, String className) {
        AST t = createUsingCtor(tok,className);
        return t;
    }
View Full Code Here

  /**
   * @since 2.7.2
   */
  protected AST createUsingCtor(Token token, String className) {
    Class c = null;
    AST t = null;
    try {
      c = Class.forName(className);
      Class[] tokenArgType = new Class[] { org.jostraca.comp.antlr.Token.class };
      try {
        Constructor ctor = c.getConstructor(tokenArgType);
        t = (AST)ctor.newInstance(new Object[]{token}); // make a new one
      }
      catch (NoSuchMethodException e){
        // for c# conversion
        e.toString();

        // just do the regular thing if you can't find the ctor
        // Your AST must have default ctor to use this.
        t = create(c);
        if ( t!=null ) {
          t.initialize(token);
        }
      }
    }
    catch (Exception e) {
      // for c# conversion
View Full Code Here

  /**
   * @since 2.7.2
   */
  protected AST create(Class c) {
    AST t = null;
    try {
      t = (AST)c.newInstance(); // make a new one
    }
    catch (Exception e) {
      // for c# conversion
View Full Code Here

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

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.