1 martin 1.10 //%LICENSE////////////////////////////////////////////////////////////////
|
2 martin 1.11 //
|
3 martin 1.10 // Licensed to The Open Group (TOG) under one or more contributor license
4 // agreements. Refer to the OpenPegasusNOTICE.txt file distributed with
5 // this work for additional information regarding copyright ownership.
6 // Each contributor licenses this file to you under the OpenPegasus Open
7 // Source License; you may not use this file except in compliance with the
8 // License.
|
9 martin 1.11 //
|
10 martin 1.10 // Permission is hereby granted, free of charge, to any person obtaining a
11 // copy of this software and associated documentation files (the "Software"),
12 // to deal in the Software without restriction, including without limitation
13 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 // and/or sell copies of the Software, and to permit persons to whom the
15 // Software is furnished to do so, subject to the following conditions:
|
16 martin 1.11 //
|
17 martin 1.10 // The above copyright notice and this permission notice shall be included
18 // in all copies or substantial portions of the Software.
|
19 martin 1.11 //
|
20 martin 1.10 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
21 martin 1.11 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
22 martin 1.10 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
27 martin 1.11 //
|
28 martin 1.10 //////////////////////////////////////////////////////////////////////////
|
29 mike 1.2 /*
30 **==============================================================================
31 **
32 ** Includes
33 **
34 **==============================================================================
35 */
36
37 %{
38
39 #include <Pegasus/Common/Config.h>
40 #include <Pegasus/WQL/WQLOperation.h>
41 #include <Pegasus/WQL/WQLOperand.h>
42 #include <Pegasus/WQL/WQLParserState.h>
43 #include <Pegasus/WQL/WQLSelectStatement.h>
44 #include <string.h>
45 #include <stdlib.h>
46
47 #ifdef PEGASUS_OS_TYPE_WINDOWS
48 # include <malloc.h>
49 #endif
50 mike 1.2
51 #if defined(PEGASUS_COMPILER_ACC) && defined(PEGASUS_OS_HPUX)
52 # include <alloca.h>
53 #endif
54
55 #if 0
56 # define WQL_TRACE(X) printf X
57 #else
58 # define WQL_TRACE(X)
59 #endif
60
61 extern int WQL_lex();
|
62 kumpf 1.3 extern int WQL_error(const char*);
|
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 kumpf 1.12 %union
|
87 mike 1.2 {
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 %token <intValue> TOK_TRUE
106 %token <intValue> TOK_FALSE
107 %token <intValue> TOK_NULL
|
108 karl 1.6 %token <intValue> TOK_ISA
|
109 karl 1.8 %token <intValue> TOK_DOT
|
110 mike 1.2
111 %token <intValue> TOK_EQ
112 %token <intValue> TOK_NE
113 %token <intValue> TOK_LT
114 %token <intValue> TOK_LE
115 %token <intValue> TOK_GT
116 %token <intValue> TOK_GE
117
118 %token <intValue> TOK_NOT
119 %token <intValue> TOK_OR
120 %token <intValue> TOK_AND
121 %token <intValue> TOK_IS
122
123 %token <strValue> TOK_IDENTIFIER
124 %token <intValue> TOK_SELECT
125 %token <intValue> TOK_WHERE
126 %token <intValue> TOK_FROM
127
128 %token <intValue> TOK_UNEXPECTED_CHAR
129
130 %type <strValue> propertyName
131 mike 1.2 %type <nodeValue> propertyList
132 %type <nodeValue> predicate
133 %type <nodeValue> comparisonPredicate
134 // %type <nodeValue> comparisonTerm
135 %type <nodeValue> nullPredicate
136 %type <nodeValue> searchCondition
137 %type <nodeValue> fromClause
138 %type <nodeValue> whereClause
139 %type <nodeValue> selectStatement
140 %type <nodeValue> selectList
141 %type <nodeValue> selectExpression
142 %type <strValue> className
143 %type <intValue> truthValue
144
145 %left TOK_OR
146 %left TOK_AND
147 %nonassoc TOK_NOT
148
149 %%
150
151 /*
152 mike 1.2 **==============================================================================
153 **
154 ** The grammar itself.
155 **
156 **==============================================================================
157 */
158
159 start
160 : selectStatement
161 {
|
162 martin 1.10 WQL_TRACE(("YACC: start\n"));
|
163 mike 1.2 }
164
165 selectStatement
166 : TOK_SELECT selectList selectExpression
167 {
168
169 }
170
171 selectList
172 : '*'
173 {
|
174 martin 1.10 globalParserState->statement->setAllProperties(true);
|
175 mike 1.2 }
176 | propertyList
177 {
178
179 }
180
|
181 kumpf 1.12 propertyList
|
182 mike 1.2 : propertyName
183 {
|
184 martin 1.10 globalParserState->statement->appendSelectPropertyName(CIMName($1));
|
185 mike 1.2 }
186 | propertyList ',' propertyName
187 {
|
188 martin 1.10 globalParserState->statement->appendSelectPropertyName(CIMName($3));
|
189 mike 1.2 }
190
191 selectExpression
192 : fromClause whereClause
193 {
194
195 }
196 | fromClause
197 {
198
199 }
200
201 fromClause
202 : TOK_FROM className
203 {
|
204 martin 1.10 WQL_TRACE(("YACC: fromClause: TOK_FROM className(%s)\n", $2));
205 globalParserState->statement->setClassName(CIMName($2));
|
206 mike 1.2 }
207
|
208 kumpf 1.12 whereClause
|
209 mike 1.2 : TOK_WHERE searchCondition
210 {
211
212 }
213
|
214 kumpf 1.12 searchCondition
|
215 mike 1.2 : searchCondition TOK_OR searchCondition
216 {
|
217 martin 1.10 WQL_TRACE(("YACC: TOK_OR\n"));
218 globalParserState->statement->appendOperation(WQL_OR);
|
219 mike 1.2 }
220 | searchCondition TOK_AND searchCondition
221 {
|
222 martin 1.10 WQL_TRACE(("YACC: TOK_AND\n"));
223 globalParserState->statement->appendOperation(WQL_AND);
|
224 mike 1.2 }
225 | TOK_NOT searchCondition
226 {
|
227 martin 1.10 WQL_TRACE(("YACC: TOK_NOT\n"));
|
228 mike 1.2
|
229 martin 1.10 globalParserState->statement->appendOperation(WQL_NOT);
|
230 mike 1.2 }
231 | '(' searchCondition ')'
232 {
233
234 }
235 | predicate
236 {
237
238 }
239 | predicate TOK_IS truthValue
240 {
|
241 martin 1.10 WQLOperation op = $3 ? WQL_IS_TRUE : WQL_IS_FALSE;
242 globalParserState->statement->appendOperation(op);
|
243 mike 1.2 }
244 | predicate TOK_IS TOK_NOT truthValue
245 {
|
246 martin 1.10 WQLOperation op = $4 ? WQL_IS_NOT_TRUE : WQL_IS_NOT_FALSE;
247 globalParserState->statement->appendOperation(op);
|
248 mike 1.2 }
249
250 /******************************************************************************/
251
252 predicate
253 : comparisonPredicate
254 {
255
256 }
257 | nullPredicate
258 {
259
260 }
261
262 comparisonPredicate
|
263 kumpf 1.12 : comparisonTerm TOK_LT comparisonTerm
|
264 mike 1.2 {
|
265 martin 1.10 WQL_TRACE(("YACC: TOK_LT\n"));
266 globalParserState->statement->appendOperation(WQL_LT);
|
267 mike 1.2 }
268 | comparisonTerm TOK_GT comparisonTerm
269 {
|
270 martin 1.10 WQL_TRACE(("YACC: TOK_GT\n"));
271 globalParserState->statement->appendOperation(WQL_GT);
|
272 mike 1.2 }
273 | comparisonTerm TOK_LE comparisonTerm
274 {
|
275 martin 1.10 WQL_TRACE(("YACC: TOK_LE\n"));
276 globalParserState->statement->appendOperation(WQL_LE);
|
277 mike 1.2 }
278 | comparisonTerm TOK_GE comparisonTerm
279 {
|
280 martin 1.10 WQL_TRACE(("YACC: TOK_GE\n"));
281 globalParserState->statement->appendOperation(WQL_GE);
|
282 mike 1.2 }
283 | comparisonTerm TOK_EQ comparisonTerm
284 {
|
285 martin 1.10 WQL_TRACE(("YACC: TOK_EQ\n"));
286 globalParserState->statement->appendOperation(WQL_EQ);
|
287 mike 1.2 }
288 | comparisonTerm TOK_NE comparisonTerm
289 {
|
290 martin 1.10 WQL_TRACE(("YACC: TOK_NE\n"));
291 globalParserState->statement->appendOperation(WQL_NE);
|
292 mike 1.2 }
|
293 karl 1.6 | propertyName TOK_ISA className
294 {
|
295 karl 1.7 WQL_TRACE(("YACC: TOK_ISA\n"));
|
296 karl 1.8 #ifndef PEGASUS_SNIA_EXTENSIONS
297 // If SNIA tests, allow the ISA but do not pass className
|
298 karl 1.7 yyerror("ISA Token Not Supported");
|
299 karl 1.8 #endif
|
300 karl 1.6 }
|
301 mike 1.2
302 nullPredicate
303 : comparisonTerm TOK_IS TOK_NULL
304 {
|
305 martin 1.10 WQL_TRACE(("YACC: nullPredicate : comparisonTerm IS NULL\n"));
306 globalParserState->statement->appendOperation(WQL_IS_NULL);
|
307 mike 1.2 }
308 | comparisonTerm TOK_IS TOK_NOT TOK_NULL
309 {
|
310 martin 1.10 WQL_TRACE(("YACC: nullPredicate : comparisonTerm IS NOT NULL\n"));
311 globalParserState->statement->appendOperation(WQL_IS_NOT_NULL);
|
312 mike 1.2 }
313
|
314 kumpf 1.12 truthValue
315 : TOK_TRUE
|
316 mike 1.2 {
|
317 martin 1.10 $$ = 1;
|
318 mike 1.2 }
319 | TOK_FALSE
320 {
|
321 martin 1.10 $$ = 0;
|
322 mike 1.2 }
|
323 karl 1.8 /**************
|
324 kumpf 1.12 propertyName
|
325 mike 1.2 : TOK_IDENTIFIER
326 {
|
327 martin 1.10 WQL_TRACE(("YACC: propertyName : TOK_IDENTIFIER(%s)\n", $1));
328 $$ = $1;
|
329 mike 1.2 }
|
330 karl 1.8 *****************/
331 propertyName
332 : TOK_IDENTIFIER
333 {
334 WQL_TRACE(("YACC: propertyName : TOK_IDENTIFIER(%s)\n", $1));
335 $$ = $1;
336 }
337 | TOK_IDENTIFIER TOK_DOT TOK_IDENTIFIER
338 {
339 WQL_TRACE(("YACC: propertyName : TOK_IDENTIFIER(%s.%s)\n", $1, $3));
340 #ifdef PEGASUS_SNIA_EXTENSIONS
341 // Pass anything as a property name to fool parser for SNIA testing
342 $$ = strdup("dummy");
343 #else
344 yyerror("Scoped (dotted) property names not supported");
345 #endif
346 }
347
|
348 mike 1.2
349 className : TOK_IDENTIFIER
350 {
|
351 martin 1.10 WQL_TRACE(("YACC: TOK_IDENTIFIER %s\n", $1));
352 $$ = $1;
|
353 mike 1.2 }
354
355 comparisonTerm
356 : propertyName
357 {
|
358 martin 1.10 globalParserState->statement->appendOperand(
359 WQLOperand($1, WQL_PROPERTY_NAME_TAG));
360 globalParserState->statement->appendWherePropertyName(CIMName($1));
|
361 mike 1.2 }
362 | TOK_INTEGER
363 {
|
364 martin 1.10 globalParserState->statement->appendOperand(
365 WQLOperand($1, WQL_INTEGER_VALUE_TAG));
|
366 mike 1.2 }
367 | TOK_DOUBLE
368 {
|
369 martin 1.10 globalParserState->statement->appendOperand(
370 WQLOperand($1, WQL_DOUBLE_VALUE_TAG));
|
371 mike 1.2 }
372 | TOK_STRING
373 {
|
374 martin 1.10 globalParserState->statement->appendOperand(
375 WQLOperand($1, WQL_STRING_VALUE_TAG));
|
376 mike 1.2 }
377 | truthValue
378 {
|
379 martin 1.10 globalParserState->statement->appendOperand(
380 WQLOperand($1 != 0, WQL_BOOLEAN_VALUE_TAG));
|
381 mike 1.2 }
382
383 %%
|