KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > rdql > parser > JJTRDQLParserState


1 /*
2  * (c) Copyright 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
3  * [See end of file]
4  */

5
6 /* Generated By:JJTree: Do not edit this line. C:/home/afs/Projects/RDQL/src/rdql/parser\JJTRDQLParserState.java */
7
8 package com.hp.hpl.jena.rdql.parser;
9
10 class JJTRDQLParserState {
11   private java.util.Stack JavaDoc nodes;
12   private java.util.Stack JavaDoc marks;
13
14   private int sp; // number of nodes on stack
15
private int mk; // current mark
16
private boolean node_created;
17
18   JJTRDQLParserState() {
19     nodes = new java.util.Stack JavaDoc();
20     marks = new java.util.Stack JavaDoc();
21     sp = 0;
22     mk = 0;
23   }
24
25   /* Determines whether the current node was actually closed and
26      pushed. This should only be called in the final user action of a
27      node scope. */

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

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

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

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

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

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
107      the nodes that have been pushed since the node was opened are
108      made children of the the conditional node, which is then pushed
109      on to the stack. If the condition is false the node is not
110      constructed and they are left on the stack. */

111   void closeNodeScope(Node n, boolean condition) {
112     if (condition) {
113       int a = nodeArity();
114       mk = ((Integer JavaDoc)marks.pop()).intValue();
115       while (a-- > 0) {
116     Node c = popNode();
117     c.jjtSetParent(n);
118     n.jjtAddChild(c, a);
119       }
120       n.jjtClose();
121       pushNode(n);
122       node_created = true;
123     } else {
124       mk = ((Integer JavaDoc)marks.pop()).intValue();
125       node_created = false;
126     }
127   }
128 }
129
130 /*
131  * (c) Copyright 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
132  * All rights reserved.
133  *
134  * Redistribution and use in source and binary forms, with or without
135  * modification, are permitted provided that the following conditions
136  * are met:
137  * 1. Redistributions of source code must retain the above copyright
138  * notice, this list of conditions and the following disclaimer.
139  * 2. Redistributions in binary form must reproduce the above copyright
140  * notice, this list of conditions and the following disclaimer in the
141  * documentation and/or other materials provided with the distribution.
142  * 3. The name of the author may not be used to endorse or promote products
143  * derived from this software without specific prior written permission.
144  *
145  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
146  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
147  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
148  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
149  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
150  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
151  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
152  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
153  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
154  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
155  */

156
Popular Tags