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

  1 mike  1.2 /*
  2           **==============================================================================
  3           **
  4           ** Includes
  5           **
  6           **==============================================================================
  7           */
  8           
  9           %{
 10           
 11           #include <Pegasus/Common/Config.h>
 12           #include <Pegasus/WQL/WQLOperation.h>
 13           #include <Pegasus/WQL/WQLOperand.h>
 14           #include <Pegasus/WQL/WQLParserState.h>
 15           #include <Pegasus/WQL/WQLSelectStatement.h>
 16           #include <string.h>
 17           #include <stdlib.h>
 18           
 19           #ifdef PEGASUS_OS_TYPE_WINDOWS
 20           # include <malloc.h>
 21           #endif
 22 mike  1.2 
 23           #if defined(PEGASUS_COMPILER_ACC) && defined(PEGASUS_OS_HPUX)
 24           # include <alloca.h>
 25           #endif
 26           
 27           #if 0
 28           # define WQL_TRACE(X) printf X
 29           #else
 30           # define WQL_TRACE(X)
 31           #endif
 32           
 33           extern int WQL_lex();
 34 kumpf 1.3 extern int WQL_error(const char*);
 35 mike  1.2 
 36           //
 37           // Define the global parser state object:
 38           //
 39           
 40           PEGASUS_USING_PEGASUS;
 41           
 42           PEGASUS_NAMESPACE_BEGIN
 43           
 44           extern WQLParserState* globalParserState;
 45           
 46           PEGASUS_NAMESPACE_END
 47           
 48           %}
 49           
 50           /*
 51           **==============================================================================
 52           **
 53           ** Union used to pass tokens from Lexer to this Parser.
 54           **
 55           **==============================================================================
 56 mike  1.2 */
 57           
 58           %union 
 59           {
 60              int intValue;
 61              double doubleValue;
 62              char* strValue;
 63              void* nodeValue;
 64           }
 65           
 66           /*
 67           **==============================================================================
 68           **
 69           ** Tokens, types, and associative rules.
 70           **
 71           **==============================================================================
 72           */
 73           
 74           %token <intValue> TOK_INTEGER
 75           %token <doubleValue> TOK_DOUBLE
 76           %token <strValue> TOK_STRING
 77 mike  1.2 %token <intValue> TOK_TRUE
 78           %token <intValue> TOK_FALSE
 79           %token <intValue> TOK_NULL
 80           
 81           %token <intValue> TOK_EQ
 82           %token <intValue> TOK_NE
 83           %token <intValue> TOK_LT
 84           %token <intValue> TOK_LE
 85           %token <intValue> TOK_GT
 86           %token <intValue> TOK_GE
 87           
 88           %token <intValue> TOK_NOT
 89           %token <intValue> TOK_OR
 90           %token <intValue> TOK_AND
 91           %token <intValue> TOK_IS
 92           
 93           %token <strValue> TOK_IDENTIFIER
 94           %token <intValue> TOK_SELECT
 95           %token <intValue> TOK_WHERE
 96           %token <intValue> TOK_FROM
 97           
 98 mike  1.2 %token <intValue> TOK_UNEXPECTED_CHAR
 99           
100           %type <strValue> propertyName
101           %type <nodeValue> propertyList
102           %type <nodeValue> predicate
103           %type <nodeValue> comparisonPredicate
104           // %type <nodeValue> comparisonTerm
105           %type <nodeValue> nullPredicate
106           %type <nodeValue> searchCondition
107           %type <nodeValue> fromClause
108           %type <nodeValue> whereClause
109           %type <nodeValue> selectStatement
110           %type <nodeValue> selectList
111           %type <nodeValue> selectExpression
112           %type <strValue> className
113           %type <intValue> truthValue
114           
115           %left TOK_OR
116           %left TOK_AND
117           %nonassoc TOK_NOT
118           
119 mike  1.2 %%
120           
121           /*
122           **==============================================================================
123           **
124           ** The grammar itself.
125           **
126           **==============================================================================
127           */
128           
129           start
130               : selectStatement
131               {
132           	WQL_TRACE(("YACC: start\n"));
133               }
134           
135           selectStatement
136               : TOK_SELECT selectList selectExpression
137               {
138           
139               }
140 mike  1.2 
141           selectList
142               : '*'
143               {
144           	globalParserState->statement->appendSelectPropertyName("*");
145               }
146               | propertyList
147               {
148           
149               }
150           
151           propertyList 
152               : propertyName
153               {
154           	globalParserState->statement->appendSelectPropertyName($1);
155               }
156               | propertyList ',' propertyName
157               {
158           	globalParserState->statement->appendSelectPropertyName($3);
159               }
160           
161 mike  1.2 selectExpression
162               : fromClause whereClause
163               {
164           
165               }
166               | fromClause
167               {
168           
169               }
170           
171           fromClause
172               : TOK_FROM className
173               {
174           	WQL_TRACE(("YACC: fromClause: TOK_FROM className(%s)\n", $2));
175           	globalParserState->statement->setClassName($2);
176               }
177           
178           whereClause 
179               : TOK_WHERE searchCondition
180               {
181           
182 mike  1.2     }
183           
184           searchCondition 
185               : searchCondition TOK_OR searchCondition
186               {
187           	WQL_TRACE(("YACC: TOK_OR\n"));
188           	globalParserState->statement->appendOperation(WQL_OR);
189               }
190               | searchCondition TOK_AND searchCondition
191               {
192           	WQL_TRACE(("YACC: TOK_AND\n"));
193           	globalParserState->statement->appendOperation(WQL_AND);
194               }
195               | TOK_NOT searchCondition
196               {
197           	WQL_TRACE(("YACC: TOK_NOT\n"));
198           
199           	globalParserState->statement->appendOperation(WQL_NOT);
200               }
201               | '(' searchCondition ')'
202               {
203 mike  1.2 
204               }
205               | predicate
206               {
207           
208               }
209               | predicate TOK_IS truthValue
210               {
211           	WQLOperation op = $3 ? WQL_IS_TRUE : WQL_IS_FALSE;
212           	globalParserState->statement->appendOperation(op);
213               }
214               | predicate TOK_IS TOK_NOT truthValue
215               {
216           	WQLOperation op = $4 ? WQL_IS_NOT_TRUE : WQL_IS_NOT_FALSE;
217           	globalParserState->statement->appendOperation(op);
218               }
219           
220           /******************************************************************************/
221           
222           predicate
223               : comparisonPredicate
224 mike  1.2     {
225           
226               }
227               | nullPredicate
228               {
229           
230               }
231           
232           comparisonPredicate
233               : comparisonTerm TOK_LT comparisonTerm 
234               {
235           	WQL_TRACE(("YACC: TOK_LT\n"));
236           	globalParserState->statement->appendOperation(WQL_LT);
237               }
238               | comparisonTerm TOK_GT comparisonTerm
239               {
240           	WQL_TRACE(("YACC: TOK_GT\n"));
241           	globalParserState->statement->appendOperation(WQL_GT);
242               }
243               | comparisonTerm TOK_LE comparisonTerm
244               {
245 mike  1.2 	WQL_TRACE(("YACC: TOK_LE\n"));
246           	globalParserState->statement->appendOperation(WQL_LE);
247               }
248               | comparisonTerm TOK_GE comparisonTerm
249               {
250           	WQL_TRACE(("YACC: TOK_GE\n"));
251           	globalParserState->statement->appendOperation(WQL_GE);
252               }
253               | comparisonTerm TOK_EQ comparisonTerm
254               {
255           	WQL_TRACE(("YACC: TOK_EQ\n"));
256           	globalParserState->statement->appendOperation(WQL_EQ);
257               }
258               | comparisonTerm TOK_NE comparisonTerm
259               {
260           	WQL_TRACE(("YACC: TOK_NE\n"));
261           	globalParserState->statement->appendOperation(WQL_NE);
262               }
263           
264           nullPredicate
265               : comparisonTerm TOK_IS TOK_NULL
266 mike  1.2     {
267           	WQL_TRACE(("YACC: nullPredicate : comparisonTerm IS NULL\n"));
268           	globalParserState->statement->appendOperation(WQL_IS_NULL);
269               }
270               | comparisonTerm TOK_IS TOK_NOT TOK_NULL
271               {
272           	WQL_TRACE(("YACC: nullPredicate : comparisonTerm IS NOT NULL\n"));
273           	globalParserState->statement->appendOperation(WQL_IS_NOT_NULL);
274               }
275           
276           truthValue 
277               : TOK_TRUE 
278               {
279           	$$ = 1;
280               }
281               | TOK_FALSE
282               {
283           	$$ = 0;
284               }
285           
286           propertyName 
287 mike  1.2     : TOK_IDENTIFIER
288               {
289           	WQL_TRACE(("YACC: propertyName : TOK_IDENTIFIER(%s)\n", $1));
290           	$$ = $1;
291               }
292           
293           className : TOK_IDENTIFIER
294               {
295           	WQL_TRACE(("YACC: TOK_IDENTIFIER %s\n", $1));
296           	$$ = $1;
297               }
298           
299           comparisonTerm
300               : propertyName
301               {
302           	globalParserState->statement->appendOperand(
303           	    WQLOperand($1, WQL_PROPERTY_NAME_TAG));
304           	globalParserState->statement->appendWherePropertyName($1);
305               }
306               | TOK_INTEGER
307               {
308 mike  1.2 	globalParserState->statement->appendOperand(
309           	    WQLOperand($1, WQL_INTEGER_VALUE_TAG));
310               }
311               | TOK_DOUBLE
312               {
313           	globalParserState->statement->appendOperand(
314           	    WQLOperand($1, WQL_DOUBLE_VALUE_TAG));
315               }
316               | TOK_STRING
317               {
318           	globalParserState->statement->appendOperand(
319           	    WQLOperand($1, WQL_STRING_VALUE_TAG));
320               }
321               | truthValue
322               {
323           	globalParserState->statement->appendOperand(
324           	    WQLOperand($1 != 0, WQL_BOOLEAN_VALUE_TAG));
325               }
326           
327           %%

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2