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