KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > codehaus > aspectwerkz > expression > ast > JJTExpressionParserState


1 /* Generated By:JJTree: Do not edit this line. JJTExpressionParserState.java */
2
3 package org.codehaus.aspectwerkz.expression.ast;
4
5 class JJTExpressionParserState {
6     private java.util.Stack JavaDoc nodes;
7
8     private java.util.Stack JavaDoc marks;
9
10     private int sp; // number of nodes on stack
11

12     private int mk; // current mark
13

14     private boolean node_created;
15
16     JJTExpressionParserState() {
17         nodes = new java.util.Stack JavaDoc();
18         marks = new java.util.Stack JavaDoc();
19         sp = 0;
20         mk = 0;
21     }
22
23     /*
24      * Determines whether the current node was actually closed and pushed. This should only be called in the final user
25      * action of a node scope.
26      */

27     boolean nodeCreated() {
28         return node_created;
29     }
30
31     /*
32      * Call this to reinitialize the node stack. It is called automatically by the parser's ReInit() method.
33      */

34     void reset() {
35         nodes.removeAllElements();
36         marks.removeAllElements();
37         sp = 0;
38         mk = 0;
39     }
40
41     /*
42      * Returns the root node of the AST. It only makes sense to call this after a successful parse.
43      */

44     Node rootNode() {
45         return (Node) nodes.elementAt(0);
46     }
47
48     /* Pushes a node on to the stack. */
49     void pushNode(Node n) {
50         nodes.push(n);
51         ++sp;
52     }
53
54     /*
55      * Returns the node on the top of the stack, and remove it from the stack.
56      */

57     Node popNode() {
58         if (--sp < mk) {
59             mk = ((Integer JavaDoc) marks.pop()).intValue();
60         }
61         return (Node) nodes.pop();
62     }
63
64     /* Returns the node currently on the top of the stack. */
65     Node peekNode() {
66         return (Node) nodes.peek();
67     }
68
69     /*
70      * Returns the number of children on the stack in the current node scope.
71      */

72     int nodeArity() {
73         return sp - mk;
74     }
75
76     void clearNodeScope(Node n) {
77         while (sp > mk) {
78             popNode();
79         }
80         mk = ((Integer JavaDoc) marks.pop()).intValue();
81     }
82
83     void openNodeScope(Node n) {
84         marks.push(new Integer JavaDoc(mk));
85         mk = sp;
86         n.jjtOpen();
87     }
88
89     /*
90      * A definite node is constructed from a specified number of children. That number of nodes are popped from the
91      * stack and made the children of the definite node. Then the definite node is pushed on to the stack.
92      */

93     void closeNodeScope(Node n, int num) {
94         mk = ((Integer JavaDoc) marks.pop()).intValue();
95         while (num-- > 0) {
96             Node c = popNode();
97             c.jjtSetParent(n);
98             n.jjtAddChild(c, num);
99         }
100         n.jjtClose();
101         pushNode(n);
102         node_created = true;
103     }
104
105     /*
106      * A conditional node is constructed if its condition is true. All the nodes that have been pushed since the node
107      * was opened are made children of the the conditional node, which is then pushed on to the stack. If the condition
108      * is false the node is not constructed and they are left on the stack.
109      */

110     void closeNodeScope(Node n, boolean condition) {
111         if (condition) {
112             int a = nodeArity();
113             mk = ((Integer JavaDoc) marks.pop()).intValue();
114             while (a-- > 0) {
115                 Node c = popNode();
116                 c.jjtSetParent(n);
117                 n.jjtAddChild(c, a);
118             }
119             n.jjtClose();
120             pushNode(n);
121             node_created = true;
122         } else {
123             mk = ((Integer JavaDoc) marks.pop()).intValue();
124             node_created = false;
125         }
126     }
127 }
Popular Tags