KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jmx > snmp > IPAcl > JJTParserState


1 /*
2  * @(#)JJTParserState.java 4.11 04/07/26
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 /* Generated By:JJTree: Do not edit this line. JJTParserState.java */
9
10 package com.sun.jmx.snmp.IPAcl;
11
12 class JJTParserState {
13   private java.util.Stack JavaDoc nodes;
14   private java.util.Stack JavaDoc marks;
15
16   private int sp; // number of nodes on stack
17
private int mk; // current mark
18
private boolean node_created;
19
20   JJTParserState() {
21     nodes = new java.util.Stack JavaDoc();
22     marks = new java.util.Stack JavaDoc();
23     sp = 0;
24     mk = 0;
25   }
26
27   /* Determines whether the current node was actually closed and
28      pushed. This should only be called in the final user action of a
29      node scope. */

30   boolean nodeCreated() {
31     return node_created;
32   }
33
34   /* Call this to reinitialize the node stack. It is called
35      automatically by the parser's ReInit() method. */

36   void reset() {
37     nodes.removeAllElements();
38     marks.removeAllElements();
39     sp = 0;
40     mk = 0;
41   }
42
43   /* Returns the root node of the AST. It only makes sense to call
44      this after a successful parse. */

45   Node rootNode() {
46     return (Node)nodes.elementAt(0);
47   }
48
49   /* Pushes a node on to the stack. */
50   void pushNode(Node n) {
51     nodes.push(n);
52     ++sp;
53   }
54
55   /* Returns the node on the top of the stack, and remove it from the
56      stack. */

57   Node popNode() {
58     if (--sp < mk) {
59       mk = ((Integer JavaDoc)marks.pop()).intValue();
60     }
61     return (Node)nodes.pop();
62   }
63
64   /* Returns the node currently on the top of the stack. */
65   Node peekNode() {
66     return (Node)nodes.peek();
67   }
68
69   /* Returns the number of children on the stack in the current node
70      scope. */

71   int nodeArity() {
72     return sp - mk;
73   }
74
75
76   void clearNodeScope(Node n) {
77     while (sp > mk) {
78       popNode();
79     }
80     mk = ((Integer JavaDoc)marks.pop()).intValue();
81   }
82
83
84   void openNodeScope(Node n) {
85     marks.push(new Integer JavaDoc(mk));
86     mk = sp;
87     n.jjtOpen();
88   }
89
90
91   /* A definite node is constructed from a specified number of
92      children. That number of nodes are popped from the stack and
93      made the children of the definite node. Then the definite node
94      is pushed on to the stack. */

95   void closeNodeScope(Node n, int num) {
96     mk = ((Integer JavaDoc)marks.pop()).intValue();
97     while (num-- > 0) {
98       Node c = popNode();
99       c.jjtSetParent(n);
100       n.jjtAddChild(c, num);
101     }
102     n.jjtClose();
103     pushNode(n);
104     node_created = true;
105   }
106
107
108   /* A conditional node is constructed if its condition is true. All
109      the nodes that have been pushed since the node was opened are
110      made children of the the conditional node, which is then pushed
111      on to the stack. If the condition is false the node is not
112      constructed and they are left on the stack. */

113   void closeNodeScope(Node n, boolean condition) {
114     if (condition) {
115       int a = nodeArity();
116       mk = ((Integer JavaDoc)marks.pop()).intValue();
117       while (a-- > 0) {
118     Node c = popNode();
119     c.jjtSetParent(n);
120     n.jjtAddChild(c, a);
121       }
122       n.jjtClose();
123       pushNode(n);
124       node_created = true;
125     } else {
126       mk = ((Integer JavaDoc)marks.pop()).intValue();
127       node_created = false;
128     }
129   }
130 }
131
Popular Tags