KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > el > parser > JJTELParserState


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * HEADER in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  *
21  * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
22  */
/* Generated By:JJTree: Do not edit this line. /tomc/web.align/webtier-alignment/prototype/el-ri/src/com/sun/el/parser/JJTELParserState.java */
23
24 package com.sun.el.parser;
25
26 class JJTELParserState {
27   private java.util.Stack JavaDoc nodes;
28   private java.util.Stack JavaDoc marks;
29
30   private int sp; // number of nodes on stack
31
private int mk; // current mark
32
private boolean node_created;
33
34   JJTELParserState() {
35     nodes = new java.util.Stack JavaDoc();
36     marks = new java.util.Stack JavaDoc();
37     sp = 0;
38     mk = 0;
39   }
40
41   /* Determines whether the current node was actually closed and
42      pushed. This should only be called in the final user action of a
43      node scope. */

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

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

59   Node rootNode() {
60     return (Node)nodes.elementAt(0);
61   }
62
63   /* Pushes a node on to the stack. */
64   void pushNode(Node n) {
65     nodes.push(n);
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     if (--sp < mk) {
73       mk = ((Integer JavaDoc)marks.pop()).intValue();
74     }
75     return (Node)nodes.pop();
76   }
77
78   /* Returns the node currently on the top of the stack. */
79   Node peekNode() {
80     return (Node)nodes.peek();
81   }
82
83   /* Returns the number of children on the stack in the current node
84      scope. */

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

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

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