KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > aspectwerkz > expression > ast > JJTExpressionParserState


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4
5 /* Generated By:JJTree: Do not edit this line. JJTExpressionParserState.java */
6
7 package com.tc.aspectwerkz.expression.ast;
8
9 class JJTExpressionParserState {
10   private java.util.Stack JavaDoc nodes;
11
12   private java.util.Stack JavaDoc marks;
13
14   private int sp; // number of nodes on stack
15

16   private int mk; // current mark
17

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

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

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

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

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

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

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

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