(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 mike  1.2 
110           %token <intValue> TOK_EQ
111           %token <intValue> TOK_NE
112           %token <intValue> TOK_LT
113           %token <intValue> TOK_LE
114           %token <intValue> TOK_GT
115           %token <intValue> TOK_GE
116           
117           %token <intValue> TOK_NOT
118           %token <intValue> TOK_OR
119           %token <intValue> TOK_AND
120           %token <intValue> TOK_IS
121           
122           %token <strValue> TOK_IDENTIFIER
123           %token <intValue> TOK_SELECT
124           %token <intValue> TOK_WHERE
125           %token <intValue> TOK_FROM
126           
127           %token <intValue> TOK_UNEXPECTED_CHAR
128           
129           %type <strValue> propertyName
130 mike  1.2 %type <nodeValue> propertyList
131           %type <nodeValue> predicate
132           %type <nodeValue> comparisonPredicate
133           // %type <nodeValue> comparisonTerm
134           %type <nodeValue> nullPredicate
135           %type <nodeValue> searchCondition
136           %type <nodeValue> fromClause
137           %type <nodeValue> whereClause
138           %type <nodeValue> selectStatement
139           %type <nodeValue> selectList
140           %type <nodeValue> selectExpression
141           %type <strValue> className
142           %type <intValue> truthValue
143           
144           %left TOK_OR
145           %left TOK_AND
146           %nonassoc TOK_NOT
147           
148           %%
149           
150           /*
151 mike  1.2 **==============================================================================
152           **
153           ** The grammar itself.
154           **
155           **==============================================================================
156           */
157           
158           start
159               : selectStatement
160               {
161           	WQL_TRACE(("YACC: start\n"));
162               }
163           
164           selectStatement
165               : TOK_SELECT selectList selectExpression
166               {
167           
168               }
169           
170           selectList
171               : '*'
172 mike  1.2     {
173 kumpf 1.4 	globalParserState->statement->setAllProperties(true);
174 mike  1.2     }
175               | propertyList
176               {
177           
178               }
179           
180           propertyList 
181               : propertyName
182               {
183 kumpf 1.4 	globalParserState->statement->appendSelectPropertyName(CIMName($1));
184 mike  1.2     }
185               | propertyList ',' propertyName
186               {
187 kumpf 1.4 	globalParserState->statement->appendSelectPropertyName(CIMName($3));
188 mike  1.2     }
189           
190           selectExpression
191               : fromClause whereClause
192               {
193           
194               }
195               | fromClause
196               {
197           
198               }
199           
200           fromClause
201               : TOK_FROM className
202               {
203           	WQL_TRACE(("YACC: fromClause: TOK_FROM className(%s)\n", $2));
204 kumpf 1.4 	globalParserState->statement->setClassName(CIMName($2));
205 mike  1.2     }
206           
207           whereClause 
208               : TOK_WHERE searchCondition
209               {
210           
211               }
212           
213           searchCondition 
214               : searchCondition TOK_OR searchCondition
215               {
216           	WQL_TRACE(("YACC: TOK_OR\n"));
217           	globalParserState->statement->appendOperation(WQL_OR);
218               }
219               | searchCondition TOK_AND searchCondition
220               {
221           	WQL_TRACE(("YACC: TOK_AND\n"));
222           	globalParserState->statement->appendOperation(WQL_AND);
223               }
224               | TOK_NOT searchCondition
225               {
226 mike  1.2 	WQL_TRACE(("YACC: TOK_NOT\n"));
227           
228           	globalParserState->statement->appendOperation(WQL_NOT);
229               }
230               | '(' searchCondition ')'
231               {
232           
233               }
234               | predicate
235               {
236           
237               }
238               | predicate TOK_IS truthValue
239               {
240           	WQLOperation op = $3 ? WQL_IS_TRUE : WQL_IS_FALSE;
241           	globalParserState->statement->appendOperation(op);
242               }
243               | predicate TOK_IS TOK_NOT truthValue
244               {
245           	WQLOperation op = $4 ? WQL_IS_NOT_TRUE : WQL_IS_NOT_FALSE;
246           	globalParserState->statement->appendOperation(op);
247 mike  1.2     }
248           
249           /******************************************************************************/
250           
251           predicate
252               : comparisonPredicate
253               {
254           
255               }
256               | nullPredicate
257               {
258           
259               }
260           
261           comparisonPredicate
262               : comparisonTerm TOK_LT comparisonTerm 
263               {
264           	WQL_TRACE(("YACC: TOK_LT\n"));
265           	globalParserState->statement->appendOperation(WQL_LT);
266               }
267               | comparisonTerm TOK_GT comparisonTerm
268 mike  1.2     {
269           	WQL_TRACE(("YACC: TOK_GT\n"));
270           	globalParserState->statement->appendOperation(WQL_GT);
271               }
272               | comparisonTerm TOK_LE comparisonTerm
273               {
274           	WQL_TRACE(("YACC: TOK_LE\n"));
275           	globalParserState->statement->appendOperation(WQL_LE);
276               }
277               | comparisonTerm TOK_GE comparisonTerm
278               {
279           	WQL_TRACE(("YACC: TOK_GE\n"));
280           	globalParserState->statement->appendOperation(WQL_GE);
281               }
282               | comparisonTerm TOK_EQ comparisonTerm
283               {
284           	WQL_TRACE(("YACC: TOK_EQ\n"));
285           	globalParserState->statement->appendOperation(WQL_EQ);
286               }
287               | comparisonTerm TOK_NE comparisonTerm
288               {
289 mike  1.2 	WQL_TRACE(("YACC: TOK_NE\n"));
290           	globalParserState->statement->appendOperation(WQL_NE);
291               }
292 karl  1.6     | propertyName TOK_ISA className
293               {
294           
295               	WQL_TRACE(("YACC: TOK_ISA\n"));
296                   // ADD statement phrase.
297               }
298 mike  1.2 
299           nullPredicate
300               : comparisonTerm TOK_IS TOK_NULL
301               {
302           	WQL_TRACE(("YACC: nullPredicate : comparisonTerm IS NULL\n"));
303           	globalParserState->statement->appendOperation(WQL_IS_NULL);
304               }
305               | comparisonTerm TOK_IS TOK_NOT TOK_NULL
306               {
307           	WQL_TRACE(("YACC: nullPredicate : comparisonTerm IS NOT NULL\n"));
308           	globalParserState->statement->appendOperation(WQL_IS_NOT_NULL);
309               }
310           
311           truthValue 
312               : TOK_TRUE 
313               {
314           	$$ = 1;
315               }
316               | TOK_FALSE
317               {
318           	$$ = 0;
319 mike  1.2     }
320           
321           propertyName 
322               : TOK_IDENTIFIER
323               {
324           	WQL_TRACE(("YACC: propertyName : TOK_IDENTIFIER(%s)\n", $1));
325           	$$ = $1;
326               }
327           
328           className : TOK_IDENTIFIER
329               {
330           	WQL_TRACE(("YACC: TOK_IDENTIFIER %s\n", $1));
331           	$$ = $1;
332               }
333           
334           comparisonTerm
335               : propertyName
336               {
337           	globalParserState->statement->appendOperand(
338           	    WQLOperand($1, WQL_PROPERTY_NAME_TAG));
339 kumpf 1.4 	globalParserState->statement->appendWherePropertyName(CIMName($1));
340 mike  1.2     }
341               | TOK_INTEGER
342               {
343           	globalParserState->statement->appendOperand(
344           	    WQLOperand($1, WQL_INTEGER_VALUE_TAG));
345               }
346               | TOK_DOUBLE
347               {
348           	globalParserState->statement->appendOperand(
349           	    WQLOperand($1, WQL_DOUBLE_VALUE_TAG));
350               }
351               | TOK_STRING
352               {
353           	globalParserState->statement->appendOperand(
354           	    WQLOperand($1, WQL_STRING_VALUE_TAG));
355               }
356               | truthValue
357               {
358           	globalParserState->statement->appendOperand(
359           	    WQLOperand($1 != 0, WQL_BOOLEAN_VALUE_TAG));
360               }
361 mike  1.2 
362           %%

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2