KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > genimen > djeneric > tools > scriptengine > core > JJTDjScriptParserEngineState


1 /* Generated By:JJTree: Do not edit this line. JJTDjScriptParserEngineState.java */
2
3 package com.genimen.djeneric.tools.scriptengine.core;
4
5 class JJTDjScriptParserEngineState
6 {
7   private java.util.Stack JavaDoc nodes;
8   private java.util.Stack JavaDoc marks;
9
10   private int sp; // number of nodes on stack
11
private int mk; // current mark
12
private boolean node_created;
13
14   JJTDjScriptParserEngineState()
15   {
16     nodes = new java.util.Stack JavaDoc();
17     marks = new java.util.Stack JavaDoc();
18     sp = 0;
19     mk = 0;
20   }
21
22   /* Determines whether the current node was actually closed and
23    pushed. This should only be called in the final user action of a
24    node scope. */

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

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

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

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

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

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

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