KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > jexl > parser > JJTParserState


1 /*
2  * Copyright 2002-2006 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 /* Generated By:JJTree: Do not edit this line. JJTParserState.java */
17
18 package org.apache.commons.jexl.parser;
19
20 import java.util.Stack JavaDoc;
21
22 class JJTParserState {
23     private final Stack JavaDoc nodes;
24
25     private final Stack JavaDoc marks;
26
27     private int sp; // number of nodes on stack
28

29     private int mk; // current mark
30

31     private boolean node_created;
32
33     JJTParserState() {
34         nodes = new Stack JavaDoc();
35         marks = new Stack JavaDoc();
36         sp = 0;
37         mk = 0;
38     }
39
40     /*
41      * Determines whether the current node was actually closed and pushed. This
42      * should only be called in the final user action of a node scope.
43      */

44     boolean nodeCreated() {
45         return node_created;
46     }
47
48     /*
49      * Call this to reinitialize the node stack. It is called automatically by
50      * the parser's ReInit() method.
51      */

52     void reset() {
53         nodes.removeAllElements();
54         marks.removeAllElements();
55         sp = 0;
56         mk = 0;
57     }
58
59     /*
60      * Returns the root node of the AST. It only makes sense to call this after
61      * a successful parse.
62      */

63     Node rootNode() {
64         return (Node) nodes.elementAt(0);
65     }
66
67     /* Pushes a node on to the stack. */
68     void pushNode(Node n) {
69         nodes.push(n);
70         ++sp;
71     }
72
73     /*
74      * Returns the node on the top of the stack, and remove it from the stack.
75      */

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

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

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

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