JJTSimpleQueryParserState JJTree节点状态分析

来源:互联网 发布:talk软件注册不了 编辑:程序博客网 时间:2024/05/22 12:58
/* Generated By:JavaCC: Do not edit this line. JJTSimpleQueryParserState.java Version 5.0 *//**  * 节点状态分为两种一种为打开了并没有关闭并且没有添加到栈中,只是标记在marks集合中 * 另外一种状态为已经关闭并且已经保存到栈中并且形成了一定的数据结构 */public class JJTSimpleQueryParserState {  /** 一个用于表达栈或者用于存放上一个节点的子节点的集合*/  private java.util.List<Node> nodes;    /** 已经被创建打开了节点作用域的节点集合 */  private java.util.List<Integer> marks;   /** 当前栈中已经被关闭了节点作用域的节点个数*/  private int sp;        // number of nodes on stack    /** 在当前打开节点作用域下打开节点个数*/  private int mk;        // current mark  private boolean node_created; /** 节点是否已经创建*/  public JJTSimpleQueryParserState() {    nodes = new java.util.ArrayList<Node>();    marks = new java.util.ArrayList<Integer>();    sp = 0;    mk = 0;  }  /* Determines whether the current node was actually closed and     pushed.  This should only be called in the final user action of a     node scope.  */  public boolean nodeCreated() {    return node_created;  }  /* Call this to reinitialize the node stack.  It is called     automatically by the parser's ReInit() method. */  public void reset() {    nodes.clear();    marks.clear();    sp = 0;    mk = 0;  }  /* Returns the root node of the AST.  It only makes sense to call     this after a successful parse. */  /** 返回抽象节点的根节点,只有在解析成功后调用才具有一定的意义*/  public Node rootNode() {    return nodes.get(0);  }    /* Pushes a node on to the stack. */  /** 将这个节点添加的nodes集合中*/  public void pushNode(Node n) {    nodes.add(n);    ++sp;/** 栈中具有集合元素加1 */  }    /* Returns the node on the top of the stack, and remove it from the     stack.  */  /** @summary     * 首先会让sp减去一所以栈中的节点就少了一个在判断* 已经关闭了节点作用域的节点个数小于打开了节点作用域的节点的个数吗* 返回栈顶部的节点,并且将他从栈中移除*/    public Node popNode() {    if (--sp < mk) {      mk = marks.remove(marks.size()-1);    }    return nodes.remove(nodes.size()-1);  }  /* Returns the node currently on the top of the stack. */  public Node peekNode() {    return nodes.get(nodes.size()-1);  }  /* Returns the number of children on the stack in the current node     scope. */  /** @summary    *  返回当前作用域节点在栈中子节点的个数*/  public int nodeArity() {    return sp - mk;  }  public void clearNodeScope(Node n) {    while (sp > mk) {      popNode();    }    mk = marks.remove(marks.size()-1);  }  /** @summary 主要用于标记已经被创建但是没有添加到栈中的节点     * @n 当前被创建并且打开了作用域的节点     */  public void openNodeScope(Node n) {    marks.add(mk);    mk = sp;    n.jjtOpen();  }  /* A definite node is constructed from a specified number of     children.  That number of nodes are popped from the stack and     made the children of the definite node.  Then the definite node     is pushed on to the stack. */  /** @summary    * 从指定的子节点数量构造定义一个节点,    * 从栈中弹出指定数量的节点并且将这些节点作为定义节点的子节点* 然后将定义的节点挤到栈中*/  public void closeNodeScope(Node n, int num) {    mk = marks.remove(marks.size()-1);    while (num-- > 0) {      Node c = popNode();      c.jjtSetParent(n);      n.jjtAddChild(c, num);    }    n.jjtClose();    pushNode(n);    node_created = true;  }  /* A conditional node is constructed if its condition is true.  All     the nodes that have been pushed since the node was opened are     made children of the conditional node, which is then pushed     on to the stack.  If the condition is false the node is not     constructed and they are left on the stack. */  /** @summary    *  关闭节点作用域决定该节点是否添加到栈中    *  如果条件为真一个条件节点会被创建.*  条件节点的子节点自从节点打开所有的节点都已经挤到栈中.*  如果条件为假节点不会被构造并且他们会从栈中离开* @condition 是否需要添加到栈中* @n 需要添加到栈顶的节点    */  public void closeNodeScope(Node n, boolean condition) {    if (condition) {      int a = nodeArity();      mk = marks.remove(marks.size()-1);      while (a-- > 0) {        Node c = popNode();        c.jjtSetParent(n);        n.jjtAddChild(c, a);      }      n.jjtClose();      pushNode(n);      node_created = true;    } else {/** 在打开的节点作用域集合中去掉这个不需要添加到栈的节点作用域*/      mk = marks.remove(marks.size()-1);      node_created = false;    }  }}/* JavaCC - OriginalChecksum=d7b30779ba9bf17c7ff82a88c0098a74 (do not edit this line) */

原创粉丝点击