1 karl 1.5 //%2005////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
6 // IBM Corp.; EMC Corporation, The Open Group.
7 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
9 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
11 //
12 // Permission is hereby granted, free of charge, to any person obtaining a copy
13 // of this software and associated documentation files (the "Software"), to
14 // deal in the Software without restriction, including without limitation the
15 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
16 // sell copies of the Software, and to permit persons to whom the Software is
17 // furnished to do so, subject to the following conditions:
18 //
19 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
20 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
21 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
22 karl 1.5 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
23 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
25 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28 //==============================================================================
|
63 mike 1.2
64 //
65 // Define the global parser state object:
66 //
67
68 PEGASUS_USING_PEGASUS;
69
70 PEGASUS_NAMESPACE_BEGIN
71
72 extern WQLParserState* globalParserState;
73
74 PEGASUS_NAMESPACE_END
75
76 %}
77
78 /*
79 **==============================================================================
80 **
81 ** Union used to pass tokens from Lexer to this Parser.
82 **
83 **==============================================================================
84 mike 1.2 */
85
86 %union
87 {
88 int intValue;
89 double doubleValue;
90 char* strValue;
91 void* nodeValue;
92 }
93
94 /*
95 **==============================================================================
96 **
97 ** Tokens, types, and associative rules.
98 **
99 **==============================================================================
100 */
101
102 %token <intValue> TOK_INTEGER
103 %token <doubleValue> TOK_DOUBLE
104 %token <strValue> TOK_STRING
105 mike 1.2 %token <intValue> TOK_TRUE
106 %token <intValue> TOK_FALSE
107 %token <intValue> TOK_NULL
108
109 %token <intValue> TOK_EQ
110 %token <intValue> TOK_NE
111 %token <intValue> TOK_LT
112 %token <intValue> TOK_LE
113 %token <intValue> TOK_GT
114 %token <intValue> TOK_GE
115
116 %token <intValue> TOK_NOT
117 %token <intValue> TOK_OR
118 %token <intValue> TOK_AND
119 %token <intValue> TOK_IS
120
121 %token <strValue> TOK_IDENTIFIER
122 %token <intValue> TOK_SELECT
123 %token <intValue> TOK_WHERE
124 %token <intValue> TOK_FROM
125
126 mike 1.2 %token <intValue> TOK_UNEXPECTED_CHAR
127
128 %type <strValue> propertyName
129 %type <nodeValue> propertyList
130 %type <nodeValue> predicate
131 %type <nodeValue> comparisonPredicate
132 // %type <nodeValue> comparisonTerm
133 %type <nodeValue> nullPredicate
134 %type <nodeValue> searchCondition
135 %type <nodeValue> fromClause
136 %type <nodeValue> whereClause
137 %type <nodeValue> selectStatement
138 %type <nodeValue> selectList
139 %type <nodeValue> selectExpression
140 %type <strValue> className
141 %type <intValue> truthValue
142
143 %left TOK_OR
144 %left TOK_AND
145 %nonassoc TOK_NOT
146
147 mike 1.2 %%
148
149 /*
150 **==============================================================================
151 **
152 ** The grammar itself.
153 **
154 **==============================================================================
155 */
156
157 start
158 : selectStatement
159 {
160 WQL_TRACE(("YACC: start\n"));
161 }
162
163 selectStatement
164 : TOK_SELECT selectList selectExpression
165 {
166
167 }
168 mike 1.2
169 selectList
170 : '*'
171 {
|
204 mike 1.2 }
205
206 whereClause
207 : TOK_WHERE searchCondition
208 {
209
210 }
211
212 searchCondition
213 : searchCondition TOK_OR searchCondition
214 {
215 WQL_TRACE(("YACC: TOK_OR\n"));
216 globalParserState->statement->appendOperation(WQL_OR);
217 }
218 | searchCondition TOK_AND searchCondition
219 {
220 WQL_TRACE(("YACC: TOK_AND\n"));
221 globalParserState->statement->appendOperation(WQL_AND);
222 }
223 | TOK_NOT searchCondition
224 {
225 mike 1.2 WQL_TRACE(("YACC: TOK_NOT\n"));
226
227 globalParserState->statement->appendOperation(WQL_NOT);
228 }
229 | '(' searchCondition ')'
230 {
231
232 }
233 | predicate
234 {
235
236 }
237 | predicate TOK_IS truthValue
238 {
239 WQLOperation op = $3 ? WQL_IS_TRUE : WQL_IS_FALSE;
240 globalParserState->statement->appendOperation(op);
241 }
242 | predicate TOK_IS TOK_NOT truthValue
243 {
244 WQLOperation op = $4 ? WQL_IS_NOT_TRUE : WQL_IS_NOT_FALSE;
245 globalParserState->statement->appendOperation(op);
246 mike 1.2 }
247
248 /******************************************************************************/
249
250 predicate
251 : comparisonPredicate
252 {
253
254 }
255 | nullPredicate
256 {
257
258 }
259
260 comparisonPredicate
261 : comparisonTerm TOK_LT comparisonTerm
262 {
263 WQL_TRACE(("YACC: TOK_LT\n"));
264 globalParserState->statement->appendOperation(WQL_LT);
265 }
266 | comparisonTerm TOK_GT comparisonTerm
267 mike 1.2 {
268 WQL_TRACE(("YACC: TOK_GT\n"));
269 globalParserState->statement->appendOperation(WQL_GT);
270 }
271 | comparisonTerm TOK_LE comparisonTerm
272 {
273 WQL_TRACE(("YACC: TOK_LE\n"));
274 globalParserState->statement->appendOperation(WQL_LE);
275 }
276 | comparisonTerm TOK_GE comparisonTerm
277 {
278 WQL_TRACE(("YACC: TOK_GE\n"));
279 globalParserState->statement->appendOperation(WQL_GE);
280 }
281 | comparisonTerm TOK_EQ comparisonTerm
282 {
283 WQL_TRACE(("YACC: TOK_EQ\n"));
284 globalParserState->statement->appendOperation(WQL_EQ);
285 }
286 | comparisonTerm TOK_NE comparisonTerm
287 {
288 mike 1.2 WQL_TRACE(("YACC: TOK_NE\n"));
289 globalParserState->statement->appendOperation(WQL_NE);
290 }
291
292 nullPredicate
293 : comparisonTerm TOK_IS TOK_NULL
294 {
295 WQL_TRACE(("YACC: nullPredicate : comparisonTerm IS NULL\n"));
296 globalParserState->statement->appendOperation(WQL_IS_NULL);
297 }
298 | comparisonTerm TOK_IS TOK_NOT TOK_NULL
299 {
300 WQL_TRACE(("YACC: nullPredicate : comparisonTerm IS NOT NULL\n"));
301 globalParserState->statement->appendOperation(WQL_IS_NOT_NULL);
302 }
303
304 truthValue
305 : TOK_TRUE
306 {
307 $$ = 1;
308 }
309 mike 1.2 | TOK_FALSE
310 {
311 $$ = 0;
312 }
313
314 propertyName
315 : TOK_IDENTIFIER
316 {
317 WQL_TRACE(("YACC: propertyName : TOK_IDENTIFIER(%s)\n", $1));
318 $$ = $1;
319 }
320
321 className : TOK_IDENTIFIER
322 {
323 WQL_TRACE(("YACC: TOK_IDENTIFIER %s\n", $1));
324 $$ = $1;
325 }
326
327 comparisonTerm
328 : propertyName
329 {
330 mike 1.2 globalParserState->statement->appendOperand(
331 WQLOperand($1, WQL_PROPERTY_NAME_TAG));
|
333 mike 1.2 }
334 | TOK_INTEGER
335 {
336 globalParserState->statement->appendOperand(
337 WQLOperand($1, WQL_INTEGER_VALUE_TAG));
338 }
339 | TOK_DOUBLE
340 {
341 globalParserState->statement->appendOperand(
342 WQLOperand($1, WQL_DOUBLE_VALUE_TAG));
343 }
344 | TOK_STRING
345 {
346 globalParserState->statement->appendOperand(
347 WQLOperand($1, WQL_STRING_VALUE_TAG));
348 }
349 | truthValue
350 {
351 globalParserState->statement->appendOperand(
352 WQLOperand($1 != 0, WQL_BOOLEAN_VALUE_TAG));
353 }
354 mike 1.2
355 %%
|