(file) Return to WQL.y CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / WQL

  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           //==============================================================================
 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           %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 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           	WQL_TRACE(("YACC: start\n"));
163               }
164           
165           selectStatement
166               : TOK_SELECT selectList selectExpression
167               {
168           
169               }
170           
171           selectList
172               : '*'
173 mike  1.2     {
174 kumpf 1.4 	globalParserState->statement->setAllProperties(true);
175 mike  1.2     }
176               | propertyList
177               {
178           
179               }
180           
181           propertyList 
182               : propertyName
183               {
184 kumpf 1.4 	globalParserState->statement->appendSelectPropertyName(CIMName($1));
185 mike  1.2     }
186               | propertyList ',' propertyName
187               {
188 kumpf 1.4 	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           	WQL_TRACE(("YACC: fromClause: TOK_FROM className(%s)\n", $2));
205 kumpf 1.4 	globalParserState->statement->setClassName(CIMName($2));
206 mike  1.2     }
207           
208           whereClause 
209               : TOK_WHERE searchCondition
210               {
211           
212               }
213           
214           searchCondition 
215               : searchCondition TOK_OR searchCondition
216               {
217           	WQL_TRACE(("YACC: TOK_OR\n"));
218           	globalParserState->statement->appendOperation(WQL_OR);
219               }
220               | searchCondition TOK_AND searchCondition
221               {
222           	WQL_TRACE(("YACC: TOK_AND\n"));
223           	globalParserState->statement->appendOperation(WQL_AND);
224               }
225               | TOK_NOT searchCondition
226               {
227 mike  1.2 	WQL_TRACE(("YACC: TOK_NOT\n"));
228           
229           	globalParserState->statement->appendOperation(WQL_NOT);
230               }
231               | '(' searchCondition ')'
232               {
233           
234               }
235               | predicate
236               {
237           
238               }
239               | predicate TOK_IS truthValue
240               {
241           	WQLOperation op = $3 ? WQL_IS_TRUE : WQL_IS_FALSE;
242           	globalParserState->statement->appendOperation(op);
243               }
244               | predicate TOK_IS TOK_NOT truthValue
245               {
246           	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               : comparisonTerm TOK_LT comparisonTerm 
264               {
265           	WQL_TRACE(("YACC: TOK_LT\n"));
266           	globalParserState->statement->appendOperation(WQL_LT);
267               }
268               | comparisonTerm TOK_GT comparisonTerm
269 mike  1.2     {
270           	WQL_TRACE(("YACC: TOK_GT\n"));
271           	globalParserState->statement->appendOperation(WQL_GT);
272               }
273               | comparisonTerm TOK_LE comparisonTerm
274               {
275           	WQL_TRACE(("YACC: TOK_LE\n"));
276           	globalParserState->statement->appendOperation(WQL_LE);
277               }
278               | comparisonTerm TOK_GE comparisonTerm
279               {
280           	WQL_TRACE(("YACC: TOK_GE\n"));
281           	globalParserState->statement->appendOperation(WQL_GE);
282               }
283               | comparisonTerm TOK_EQ comparisonTerm
284               {
285           	WQL_TRACE(("YACC: TOK_EQ\n"));
286           	globalParserState->statement->appendOperation(WQL_EQ);
287               }
288               | comparisonTerm TOK_NE comparisonTerm
289               {
290 mike  1.2 	WQL_TRACE(("YACC: TOK_NE\n"));
291           	globalParserState->statement->appendOperation(WQL_NE);
292               }
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           	WQL_TRACE(("YACC: nullPredicate : comparisonTerm IS NULL\n"));
306           	globalParserState->statement->appendOperation(WQL_IS_NULL);
307               }
308               | comparisonTerm TOK_IS TOK_NOT TOK_NULL
309               {
310           	WQL_TRACE(("YACC: nullPredicate : comparisonTerm IS NOT NULL\n"));
311           	globalParserState->statement->appendOperation(WQL_IS_NOT_NULL);
312               }
313           
314           truthValue 
315               : TOK_TRUE 
316               {
317           	$$ = 1;
318               }
319               | TOK_FALSE
320               {
321           	$$ = 0;
322 mike  1.2     }
323 karl  1.8 /**************
324 mike  1.2 propertyName 
325               : TOK_IDENTIFIER
326               {
327           	WQL_TRACE(("YACC: propertyName : TOK_IDENTIFIER(%s)\n", $1));
328           	$$ = $1;
329               }
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           	WQL_TRACE(("YACC: TOK_IDENTIFIER %s\n", $1));
352           	$$ = $1;
353               }
354           
355           comparisonTerm
356               : propertyName
357               {
358           	globalParserState->statement->appendOperand(
359           	    WQLOperand($1, WQL_PROPERTY_NAME_TAG));
360 kumpf 1.4 	globalParserState->statement->appendWherePropertyName(CIMName($1));
361 mike  1.2     }
362               | TOK_INTEGER
363               {
364           	globalParserState->statement->appendOperand(
365           	    WQLOperand($1, WQL_INTEGER_VALUE_TAG));
366               }
367               | TOK_DOUBLE
368               {
369           	globalParserState->statement->appendOperand(
370           	    WQLOperand($1, WQL_DOUBLE_VALUE_TAG));
371               }
372               | TOK_STRING
373               {
374           	globalParserState->statement->appendOperand(
375           	    WQLOperand($1, WQL_STRING_VALUE_TAG));
376               }
377               | truthValue
378               {
379           	globalParserState->statement->appendOperand(
380           	    WQLOperand($1 != 0, WQL_BOOLEAN_VALUE_TAG));
381               }
382 mike  1.2 
383           %%

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2