KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > standard > lang > jpath > expression > JJTParserState


1 /*
2  * Copyright 1999,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17
18 /* Generated By:JJTree: Do not edit this line. JJTParserState.java */
19 package org.apache.taglibs.standard.lang.jpath.expression;
20
21 class JJTParserState {
22
23     private java.util.Stack JavaDoc nodes;
24     private java.util.Stack JavaDoc marks;
25     private int sp; // number of nodes on stack
26
private int mk; // current mark
27
private boolean node_created;
28
29     JJTParserState() {
30
31         nodes = new java.util.Stack JavaDoc();
32         marks = new java.util.Stack JavaDoc();
33         sp = 0;
34         mk = 0;
35     }
36
37     /* Determines whether the current node was actually closed and
38        pushed. This should only be called in the final user action of a
39        node scope. */

40     boolean nodeCreated() {
41         return node_created;
42     }
43
44     /* Call this to reinitialize the node stack. It is called
45        automatically by the parser's ReInit() method. */

46     void reset() {
47
48         nodes.removeAllElements();
49         marks.removeAllElements();
50
51         sp = 0;
52         mk = 0;
53     }
54
55     /* Returns the root node of the AST. It only makes sense to call
56        this after a successful parse. */

57     Node rootNode() {
58         return (Node) nodes.elementAt(0);
59     }
60
61     /* Pushes a node on to the stack. */
62     void pushNode(Node n) {
63
64         nodes.push(n);
65
66         ++sp;
67     }
68
69     /* Returns the node on the top of the stack, and remove it from the
70        stack. */

71     Node popNode() {
72
73         if (--sp < mk) {
74             mk = ((Integer JavaDoc) marks.pop()).intValue();
75         }
76
77         return (Node) nodes.pop();
78     }
79
80     /* Returns the node currently on the top of the stack. */
81     Node peekNode() {
82         return (Node) nodes.peek();
83     }
84
85     /* Returns the number of children on the stack in the current node
86        scope. */

87     int nodeArity() {
88         return sp - mk;
89     }
90
91     void clearNodeScope(Node n) {
92
93         while (sp > mk) {
94             popNode();
95         }
96
97         mk = ((Integer JavaDoc) marks.pop()).intValue();
98     }
99
100     void openNodeScope(Node n) {
101
102         marks.push(new Integer JavaDoc(mk));
103
104         mk = sp;
105
106         n.jjtOpen();
107     }
108
109     /* A definite node is constructed from a specified number of
110        children. That number of nodes are popped from the stack and
111        made the children of the definite node. Then the definite node
112        is pushed on to the stack. */

113     void closeNodeScope(Node n, int num) {
114
115         mk = ((Integer JavaDoc) marks.pop()).intValue();
116
117         while (num-- > 0) {
118             Node c = popNode();
119
120             c.jjtSetParent(n);
121             n.jjtAddChild(c, num);
122         }
123
124         n.jjtClose();
125         pushNode(n);
126
127         node_created = true;
128     }
129
130     /* A conditional node is constructed if its condition is true. All
131        the nodes that have been pushed since the node was opened are
132        made children of the the conditional node, which is then pushed
133        on to the stack. If the condition is false the node is not
134        constructed and they are left on the stack. */

135     void closeNodeScope(Node n, boolean condition) {
136
137         if (condition) {
138             int a = nodeArity();
139
140             mk = ((Integer JavaDoc) marks.pop()).intValue();
141
142             while (a-- > 0) {
143                 Node c = popNode();
144
145                 c.jjtSetParent(n);
146                 n.jjtAddChild(c, a);
147             }
148
149             n.jjtClose();
150             pushNode(n);
151
152             node_created = true;
153         } else {
154             mk = ((Integer JavaDoc) marks.pop()).intValue();
155             node_created = false;
156         }
157     }
158 }
159
Popular Tags