KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejen > ext > parsers > java_1_2 > JJTJavaParserState


1 /* Generated By:JJTree: Do not edit this line. /home/franck/devs/java/ejen-1.0-pre2-cvs/ejen/src/org/ejen/ext/parsers/java_1_2/JJTJavaParserState.java */
2 package org.ejen.ext.parsers.java_1_2;
3
4 class JJTJavaParserState {
5     private java.util.Stack JavaDoc nodes;
6     private java.util.Stack JavaDoc marks;
7     private int sp; // number of nodes on stack
8
private int mk; // current mark
9
private boolean node_created;
10     JJTJavaParserState() {
11         nodes = new java.util.Stack JavaDoc();
12         marks = new java.util.Stack JavaDoc();
13         sp = 0;
14         mk = 0;
15     }
16
17     /* Determines whether the current node was actually closed and
18      pushed. This should only be called in the final user action of a
19      node scope. */

20     boolean nodeCreated() {
21         return node_created;
22     }
23
24     /* Call this to reinitialize the node stack. It is called
25      automatically by the parser's ReInit() method. */

26     void reset() {
27         nodes.removeAllElements();
28         marks.removeAllElements();
29         sp = 0;
30         mk = 0;
31     }
32
33     /* Returns the root node of the AST. It only makes sense to call
34      this after a successful parse. */

35     Node rootNode() {
36         return (Node) nodes.elementAt(0);
37     }
38
39     /* Pushes a node on to the stack. */
40     void pushNode(Node n) {
41         nodes.push(n);
42         ++sp;
43     }
44
45     /* Returns the node on the top of the stack, and remove it from the
46      stack. */

47     Node popNode() {
48         if (--sp < mk) {
49             mk = ((Integer JavaDoc) marks.pop()).intValue();
50         }
51         return (Node) nodes.pop();
52     }
53
54     /* Returns the node currently on the top of the stack. */
55     Node peekNode() {
56         return (Node) nodes.peek();
57     }
58
59     /* Returns the number of children on the stack in the current node
60      scope. */

61     int nodeArity() {
62         return sp - mk;
63     }
64
65     void clearNodeScope(Node n) {
66         while (sp > mk) {
67             popNode();
68         }
69         mk = ((Integer JavaDoc) marks.pop()).intValue();
70     }
71
72     void openNodeScope(Node n) {
73         marks.push(new Integer JavaDoc(mk));
74         mk = sp;
75         n.jjtOpen();
76     }
77
78     /* A definite node is constructed from a specified number of
79      children. That number of nodes are popped from the stack and
80      made the children of the definite node. Then the definite node
81      is pushed on to the stack. */

82     void closeNodeScope(Node n, int num) {
83         mk = ((Integer JavaDoc) marks.pop()).intValue();
84         while (num-- > 0) {
85             Node c = popNode();
86
87             c.jjtSetParent(n);
88             n.jjtAddChild(c, num);
89         }
90         n.jjtClose();
91         pushNode(n);
92         node_created = true;
93     }
94
95     /* A conditional node is constructed if its condition is true. All
96      the nodes that have been pushed since the node was opened are
97      made children of the the conditional node, which is then pushed
98      on to the stack. If the condition is false the node is not
99      constructed and they are left on the stack. */

100     void closeNodeScope(Node n, boolean condition) {
101         if (condition) {
102             int a = nodeArity();
103
104             mk = ((Integer JavaDoc) marks.pop()).intValue();
105             while (a-- > 0) {
106                 Node c = popNode();
107
108                 c.jjtSetParent(n);
109                 n.jjtAddChild(c, a);
110             }
111             n.jjtClose();
112             pushNode(n);
113             node_created = true;
114         } else {
115             mk = ((Integer JavaDoc) marks.pop()).intValue();
116             node_created = false;
117         }
118     }
119 }
120
Popular Tags