KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cayenne > exp > parser > JJTExpressionParserState


1 /* Generated By:JJTree: Do not edit this line. src/cayenne/java/org.apache.cayenne/exp/parser/JJTExpressionParserState.java */
2
3 /*****************************************************************
4  * Licensed to the Apache Software Foundation (ASF) under one
5  * or more contributor license agreements. See the NOTICE file
6  * distributed with this work for additional information
7  * regarding copyright ownership. The ASF licenses this file
8  * to you under the Apache License, Version 2.0 (the
9  * "License"); you may not use this file except in compliance
10  * with the License. You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing,
15  * software distributed under the License is distributed on an
16  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17  * KIND, either express or implied. See the License for the
18  * specific language governing permissions and limitations
19  * under the License.
20  ****************************************************************/

21
22
23 package org.apache.cayenne.exp.parser;
24
25 class JJTExpressionParserState {
26   private java.util.Stack JavaDoc nodes;
27   private java.util.Stack JavaDoc marks;
28
29   private int sp; // number of nodes on stack
30
private int mk; // current mark
31
private boolean node_created;
32
33   JJTExpressionParserState() {
34     nodes = new java.util.Stack JavaDoc();
35     marks = new java.util.Stack JavaDoc();
36     sp = 0;
37     mk = 0;
38   }
39
40   /* Determines whether the current node was actually closed and
41      pushed. This should only be called in the final user action of a
42      node scope. */

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

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

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

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

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

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

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