KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > genimen > djeneric > repository > oql > core > JJTDjOqlParserEngineState


1 /* Generated By:JJTree: Do not edit this line. C:\Data\Projects\Java\Djeneric\src\com\genimen\djeneric\oql\core\JJTDjOqlParserEngineState.java */
2
3 package com.genimen.djeneric.repository.oql.core;
4
5 class JJTDjOqlParserEngineState
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   JJTDjOqlParserEngineState()
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     while (sp > mk)
81     {
82       popNode();
83     }
84     mk = ((Integer JavaDoc) marks.pop()).intValue();
85   }
86
87   void openNodeScope(Node n)
88   {
89     marks.push(new Integer JavaDoc(mk));
90     mk = sp;
91     n.jjtOpen();
92   }
93
94   /* A definite node is constructed from a specified number of
95    children. That number of nodes are popped from the stack and
96    made the children of the definite node. Then the definite node
97    is pushed on to the stack. */

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

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