OLD | NEW |
1 /* | 1 /* |
2 ** 2000-05-29 | 2 ** 2000-05-29 |
3 ** | 3 ** |
4 ** The author disclaims copyright to this source code. In place of | 4 ** The author disclaims copyright to this source code. In place of |
5 ** a legal notice, here is a blessing: | 5 ** a legal notice, here is a blessing: |
6 ** | 6 ** |
7 ** May you do good and not evil. | 7 ** May you do good and not evil. |
8 ** May you find forgiveness for yourself and forgive others. | 8 ** May you find forgiveness for yourself and forgive others. |
9 ** May you share freely, never taking more than you give. | 9 ** May you share freely, never taking more than you give. |
10 ** | 10 ** |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 ** YY_ACCEPT_ACTION The yy_action[] code for accept | 80 ** YY_ACCEPT_ACTION The yy_action[] code for accept |
81 ** YY_NO_ACTION The yy_action[] code for no-op | 81 ** YY_NO_ACTION The yy_action[] code for no-op |
82 */ | 82 */ |
83 #ifndef INTERFACE | 83 #ifndef INTERFACE |
84 # define INTERFACE 1 | 84 # define INTERFACE 1 |
85 #endif | 85 #endif |
86 /************* Begin control #defines *****************************************/ | 86 /************* Begin control #defines *****************************************/ |
87 %% | 87 %% |
88 /************* End control #defines *******************************************/ | 88 /************* End control #defines *******************************************/ |
89 | 89 |
90 /* The yyzerominor constant is used to initialize instances of | |
91 ** YYMINORTYPE objects to zero. */ | |
92 static const YYMINORTYPE yyzerominor = { 0 }; | |
93 | |
94 /* Define the yytestcase() macro to be a no-op if is not already defined | 90 /* Define the yytestcase() macro to be a no-op if is not already defined |
95 ** otherwise. | 91 ** otherwise. |
96 ** | 92 ** |
97 ** Applications can choose to define yytestcase() in the %include section | 93 ** Applications can choose to define yytestcase() in the %include section |
98 ** to a macro that can assist in verifying code coverage. For production | 94 ** to a macro that can assist in verifying code coverage. For production |
99 ** code the yytestcase() macro should be turned off. But it is useful | 95 ** code the yytestcase() macro should be turned off. But it is useful |
100 ** for testing. | 96 ** for testing. |
101 */ | 97 */ |
102 #ifndef yytestcase | 98 #ifndef yytestcase |
103 # define yytestcase(X) | 99 # define yytestcase(X) |
104 #endif | 100 #endif |
105 | 101 |
106 | 102 |
107 /* Next are the tables used to determine what action to take based on the | 103 /* Next are the tables used to determine what action to take based on the |
108 ** current state and lookahead token. These tables are used to implement | 104 ** current state and lookahead token. These tables are used to implement |
109 ** functions that take a state number and lookahead value and return an | 105 ** functions that take a state number and lookahead value and return an |
110 ** action integer. | 106 ** action integer. |
111 ** | 107 ** |
112 ** Suppose the action integer is N. Then the action is determined as | 108 ** Suppose the action integer is N. Then the action is determined as |
113 ** follows | 109 ** follows |
114 ** | 110 ** |
115 ** 0 <= N <= YY_MAX_SHIFT Shift N. That is, push the lookahead | 111 ** 0 <= N <= YY_MAX_SHIFT Shift N. That is, push the lookahead |
116 ** token onto the stack and goto state N. | 112 ** token onto the stack and goto state N. |
117 ** | 113 ** |
118 ** N between YY_MIN_SHIFTREDUCE Shift to an arbitrary state then | 114 ** N between YY_MIN_SHIFTREDUCE Shift to an arbitrary state then |
119 ** and YY_MAX_SHIFTREDUCE reduce by rule N-YY_MIN_SHIFTREDUCE. | 115 ** and YY_MAX_SHIFTREDUCE reduce by rule N-YY_MIN_SHIFTREDUCE. |
120 ** | 116 ** |
121 ** N between YY_MIN_REDUCE Reduce by rule N-YY_MIN_REDUCE | 117 ** N between YY_MIN_REDUCE Reduce by rule N-YY_MIN_REDUCE |
122 ** and YY_MAX_REDUCE | 118 ** and YY_MAX_REDUCE |
123 | 119 ** |
124 ** N == YY_ERROR_ACTION A syntax error has occurred. | 120 ** N == YY_ERROR_ACTION A syntax error has occurred. |
125 ** | 121 ** |
126 ** N == YY_ACCEPT_ACTION The parser accepts its input. | 122 ** N == YY_ACCEPT_ACTION The parser accepts its input. |
127 ** | 123 ** |
128 ** N == YY_NO_ACTION No such action. Denotes unused | 124 ** N == YY_NO_ACTION No such action. Denotes unused |
129 ** slots in the yy_action[] table. | 125 ** slots in the yy_action[] table. |
130 ** | 126 ** |
131 ** The action table is constructed as a single large table named yy_action[]. | 127 ** The action table is constructed as a single large table named yy_action[]. |
132 ** Given state S and lookahead X, the action is computed as | 128 ** Given state S and lookahead X, the action is computed as either: |
133 ** | 129 ** |
134 ** yy_action[ yy_shift_ofst[S] + X ] | 130 ** (A) N = yy_action[ yy_shift_ofst[S] + X ] |
| 131 ** (B) N = yy_default[S] |
135 ** | 132 ** |
136 ** If the index value yy_shift_ofst[S]+X is out of range or if the value | 133 ** The (A) formula is preferred. The B formula is used instead if: |
137 ** yy_lookahead[yy_shift_ofst[S]+X] is not equal to X or if yy_shift_ofst[S] | 134 ** (1) The yy_shift_ofst[S]+X value is out of range, or |
138 ** is equal to YY_SHIFT_USE_DFLT, it means that the action is not in the table | 135 ** (2) yy_lookahead[yy_shift_ofst[S]+X] is not equal to X, or |
139 ** and that yy_default[S] should be used instead. | 136 ** (3) yy_shift_ofst[S] equal YY_SHIFT_USE_DFLT. |
| 137 ** (Implementation note: YY_SHIFT_USE_DFLT is chosen so that |
| 138 ** YY_SHIFT_USE_DFLT+X will be out of range for all possible lookaheads X. |
| 139 ** Hence only tests (1) and (2) need to be evaluated.) |
140 ** | 140 ** |
141 ** The formula above is for computing the action when the lookahead is | 141 ** The formulas above are for computing the action when the lookahead is |
142 ** a terminal symbol. If the lookahead is a non-terminal (as occurs after | 142 ** a terminal symbol. If the lookahead is a non-terminal (as occurs after |
143 ** a reduce action) then the yy_reduce_ofst[] array is used in place of | 143 ** a reduce action) then the yy_reduce_ofst[] array is used in place of |
144 ** the yy_shift_ofst[] array and YY_REDUCE_USE_DFLT is used in place of | 144 ** the yy_shift_ofst[] array and YY_REDUCE_USE_DFLT is used in place of |
145 ** YY_SHIFT_USE_DFLT. | 145 ** YY_SHIFT_USE_DFLT. |
146 ** | 146 ** |
147 ** The following are the tables generated in this section: | 147 ** The following are the tables generated in this section: |
148 ** | 148 ** |
149 ** yy_action[] A single table containing all actions. | 149 ** yy_action[] A single table containing all actions. |
150 ** yy_lookahead[] A table containing the lookahead for each entry in | 150 ** yy_lookahead[] A table containing the lookahead for each entry in |
151 ** yy_action. Used to detect hash collisions. | 151 ** yy_action. Used to detect hash collisions. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 YYCODETYPE major; /* The major token value. This is the code | 200 YYCODETYPE major; /* The major token value. This is the code |
201 ** number for the token at this stack level */ | 201 ** number for the token at this stack level */ |
202 YYMINORTYPE minor; /* The user-supplied minor token value. This | 202 YYMINORTYPE minor; /* The user-supplied minor token value. This |
203 ** is the value of the token */ | 203 ** is the value of the token */ |
204 }; | 204 }; |
205 typedef struct yyStackEntry yyStackEntry; | 205 typedef struct yyStackEntry yyStackEntry; |
206 | 206 |
207 /* The state of the parser is completely contained in an instance of | 207 /* The state of the parser is completely contained in an instance of |
208 ** the following structure */ | 208 ** the following structure */ |
209 struct yyParser { | 209 struct yyParser { |
210 int yyidx; /* Index of top element in stack */ | 210 yyStackEntry *yytos; /* Pointer to top element of the stack */ |
211 #ifdef YYTRACKMAXSTACKDEPTH | 211 #ifdef YYTRACKMAXSTACKDEPTH |
212 int yyidxMax; /* Maximum value of yyidx */ | 212 int yyhwm; /* High-water mark of the stack */ |
213 #endif | 213 #endif |
| 214 #ifndef YYNOERRORRECOVERY |
214 int yyerrcnt; /* Shifts left before out of the error */ | 215 int yyerrcnt; /* Shifts left before out of the error */ |
| 216 #endif |
215 ParseARG_SDECL /* A place to hold %extra_argument */ | 217 ParseARG_SDECL /* A place to hold %extra_argument */ |
216 #if YYSTACKDEPTH<=0 | 218 #if YYSTACKDEPTH<=0 |
217 int yystksz; /* Current side of the stack */ | 219 int yystksz; /* Current side of the stack */ |
218 yyStackEntry *yystack; /* The parser's stack */ | 220 yyStackEntry *yystack; /* The parser's stack */ |
| 221 yyStackEntry yystk0; /* First stack entry */ |
219 #else | 222 #else |
220 yyStackEntry yystack[YYSTACKDEPTH]; /* The parser's stack */ | 223 yyStackEntry yystack[YYSTACKDEPTH]; /* The parser's stack */ |
221 #endif | 224 #endif |
222 }; | 225 }; |
223 typedef struct yyParser yyParser; | 226 typedef struct yyParser yyParser; |
224 | 227 |
225 #ifndef NDEBUG | 228 #ifndef NDEBUG |
226 #include <stdio.h> | 229 #include <stdio.h> |
227 static FILE *yyTraceFILE = 0; | 230 static FILE *yyTraceFILE = 0; |
228 static char *yyTracePrompt = 0; | 231 static char *yyTracePrompt = 0; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 /* For tracing reduce actions, the names of all rules are required. | 269 /* For tracing reduce actions, the names of all rules are required. |
267 */ | 270 */ |
268 static const char *const yyRuleName[] = { | 271 static const char *const yyRuleName[] = { |
269 %% | 272 %% |
270 }; | 273 }; |
271 #endif /* NDEBUG */ | 274 #endif /* NDEBUG */ |
272 | 275 |
273 | 276 |
274 #if YYSTACKDEPTH<=0 | 277 #if YYSTACKDEPTH<=0 |
275 /* | 278 /* |
276 ** Try to increase the size of the parser stack. | 279 ** Try to increase the size of the parser stack. Return the number |
| 280 ** of errors. Return 0 on success. |
277 */ | 281 */ |
278 static void yyGrowStack(yyParser *p){ | 282 static int yyGrowStack(yyParser *p){ |
279 int newSize; | 283 int newSize; |
| 284 int idx; |
280 yyStackEntry *pNew; | 285 yyStackEntry *pNew; |
281 | 286 |
282 newSize = p->yystksz*2 + 100; | 287 newSize = p->yystksz*2 + 100; |
283 pNew = realloc(p->yystack, newSize*sizeof(pNew[0])); | 288 idx = p->yytos ? (int)(p->yytos - p->yystack) : 0; |
| 289 if( p->yystack==&p->yystk0 ){ |
| 290 pNew = malloc(newSize*sizeof(pNew[0])); |
| 291 if( pNew ) pNew[0] = p->yystk0; |
| 292 }else{ |
| 293 pNew = realloc(p->yystack, newSize*sizeof(pNew[0])); |
| 294 } |
284 if( pNew ){ | 295 if( pNew ){ |
285 p->yystack = pNew; | 296 p->yystack = pNew; |
286 p->yystksz = newSize; | 297 p->yytos = &p->yystack[idx]; |
287 #ifndef NDEBUG | 298 #ifndef NDEBUG |
288 if( yyTraceFILE ){ | 299 if( yyTraceFILE ){ |
289 fprintf(yyTraceFILE,"%sStack grows to %d entries!\n", | 300 fprintf(yyTraceFILE,"%sStack grows from %d to %d entries.\n", |
290 yyTracePrompt, p->yystksz); | 301 yyTracePrompt, p->yystksz, newSize); |
291 } | 302 } |
292 #endif | 303 #endif |
| 304 p->yystksz = newSize; |
293 } | 305 } |
| 306 return pNew==0; |
294 } | 307 } |
295 #endif | 308 #endif |
296 | 309 |
297 /* Datatype of the argument to the memory allocated passed as the | 310 /* Datatype of the argument to the memory allocated passed as the |
298 ** second argument to ParseAlloc() below. This can be changed by | 311 ** second argument to ParseAlloc() below. This can be changed by |
299 ** putting an appropriate #define in the %include section of the input | 312 ** putting an appropriate #define in the %include section of the input |
300 ** grammar. | 313 ** grammar. |
301 */ | 314 */ |
302 #ifndef YYMALLOCARGTYPE | 315 #ifndef YYMALLOCARGTYPE |
303 # define YYMALLOCARGTYPE size_t | 316 # define YYMALLOCARGTYPE size_t |
304 #endif | 317 #endif |
305 | 318 |
| 319 /* Initialize a new parser that has already been allocated. |
| 320 */ |
| 321 void ParseInit(void *yypParser){ |
| 322 yyParser *pParser = (yyParser*)yypParser; |
| 323 #ifdef YYTRACKMAXSTACKDEPTH |
| 324 pParser->yyhwm = 0; |
| 325 #endif |
| 326 #if YYSTACKDEPTH<=0 |
| 327 pParser->yytos = NULL; |
| 328 pParser->yystack = NULL; |
| 329 pParser->yystksz = 0; |
| 330 if( yyGrowStack(pParser) ){ |
| 331 pParser->yystack = &pParser->yystk0; |
| 332 pParser->yystksz = 1; |
| 333 } |
| 334 #endif |
| 335 #ifndef YYNOERRORRECOVERY |
| 336 pParser->yyerrcnt = -1; |
| 337 #endif |
| 338 pParser->yytos = pParser->yystack; |
| 339 pParser->yystack[0].stateno = 0; |
| 340 pParser->yystack[0].major = 0; |
| 341 } |
| 342 |
| 343 #ifndef Parse_ENGINEALWAYSONSTACK |
306 /* | 344 /* |
307 ** This function allocates a new parser. | 345 ** This function allocates a new parser. |
308 ** The only argument is a pointer to a function which works like | 346 ** The only argument is a pointer to a function which works like |
309 ** malloc. | 347 ** malloc. |
310 ** | 348 ** |
311 ** Inputs: | 349 ** Inputs: |
312 ** A pointer to the function used to allocate memory. | 350 ** A pointer to the function used to allocate memory. |
313 ** | 351 ** |
314 ** Outputs: | 352 ** Outputs: |
315 ** A pointer to a parser. This pointer is used in subsequent calls | 353 ** A pointer to a parser. This pointer is used in subsequent calls |
316 ** to Parse and ParseFree. | 354 ** to Parse and ParseFree. |
317 */ | 355 */ |
318 void *ParseAlloc(void *(*mallocProc)(YYMALLOCARGTYPE)){ | 356 void *ParseAlloc(void *(*mallocProc)(YYMALLOCARGTYPE)){ |
319 yyParser *pParser; | 357 yyParser *pParser; |
320 pParser = (yyParser*)(*mallocProc)( (YYMALLOCARGTYPE)sizeof(yyParser) ); | 358 pParser = (yyParser*)(*mallocProc)( (YYMALLOCARGTYPE)sizeof(yyParser) ); |
321 if( pParser ){ | 359 if( pParser ) ParseInit(pParser); |
322 pParser->yyidx = -1; | |
323 #ifdef YYTRACKMAXSTACKDEPTH | |
324 pParser->yyidxMax = 0; | |
325 #endif | |
326 #if YYSTACKDEPTH<=0 | |
327 pParser->yystack = NULL; | |
328 pParser->yystksz = 0; | |
329 yyGrowStack(pParser); | |
330 #endif | |
331 } | |
332 return pParser; | 360 return pParser; |
333 } | 361 } |
| 362 #endif /* Parse_ENGINEALWAYSONSTACK */ |
| 363 |
334 | 364 |
335 /* The following function deletes the "minor type" or semantic value | 365 /* The following function deletes the "minor type" or semantic value |
336 ** associated with a symbol. The symbol can be either a terminal | 366 ** associated with a symbol. The symbol can be either a terminal |
337 ** or nonterminal. "yymajor" is the symbol code, and "yypminor" is | 367 ** or nonterminal. "yymajor" is the symbol code, and "yypminor" is |
338 ** a pointer to the value to be deleted. The code used to do the | 368 ** a pointer to the value to be deleted. The code used to do the |
339 ** deletions is derived from the %destructor and/or %token_destructor | 369 ** deletions is derived from the %destructor and/or %token_destructor |
340 ** directives of the input grammar. | 370 ** directives of the input grammar. |
341 */ | 371 */ |
342 static void yy_destructor( | 372 static void yy_destructor( |
343 yyParser *yypParser, /* The parser */ | 373 yyParser *yypParser, /* The parser */ |
(...skipping 20 matching lines...) Expand all Loading... |
364 } | 394 } |
365 | 395 |
366 /* | 396 /* |
367 ** Pop the parser's stack once. | 397 ** Pop the parser's stack once. |
368 ** | 398 ** |
369 ** If there is a destructor routine associated with the token which | 399 ** If there is a destructor routine associated with the token which |
370 ** is popped from the stack, then call it. | 400 ** is popped from the stack, then call it. |
371 */ | 401 */ |
372 static void yy_pop_parser_stack(yyParser *pParser){ | 402 static void yy_pop_parser_stack(yyParser *pParser){ |
373 yyStackEntry *yytos; | 403 yyStackEntry *yytos; |
374 assert( pParser->yyidx>=0 ); | 404 assert( pParser->yytos!=0 ); |
375 yytos = &pParser->yystack[pParser->yyidx--]; | 405 assert( pParser->yytos > pParser->yystack ); |
| 406 yytos = pParser->yytos--; |
376 #ifndef NDEBUG | 407 #ifndef NDEBUG |
377 if( yyTraceFILE ){ | 408 if( yyTraceFILE ){ |
378 fprintf(yyTraceFILE,"%sPopping %s\n", | 409 fprintf(yyTraceFILE,"%sPopping %s\n", |
379 yyTracePrompt, | 410 yyTracePrompt, |
380 yyTokenName[yytos->major]); | 411 yyTokenName[yytos->major]); |
381 } | 412 } |
382 #endif | 413 #endif |
383 yy_destructor(pParser, yytos->major, &yytos->minor); | 414 yy_destructor(pParser, yytos->major, &yytos->minor); |
384 } | 415 } |
385 | 416 |
| 417 /* |
| 418 ** Clear all secondary memory allocations from the parser |
| 419 */ |
| 420 void ParseFinalize(void *p){ |
| 421 yyParser *pParser = (yyParser*)p; |
| 422 while( pParser->yytos>pParser->yystack ) yy_pop_parser_stack(pParser); |
| 423 #if YYSTACKDEPTH<=0 |
| 424 if( pParser->yystack!=&pParser->yystk0 ) free(pParser->yystack); |
| 425 #endif |
| 426 } |
| 427 |
| 428 #ifndef Parse_ENGINEALWAYSONSTACK |
386 /* | 429 /* |
387 ** Deallocate and destroy a parser. Destructors are called for | 430 ** Deallocate and destroy a parser. Destructors are called for |
388 ** all stack elements before shutting the parser down. | 431 ** all stack elements before shutting the parser down. |
389 ** | 432 ** |
390 ** If the YYPARSEFREENEVERNULL macro exists (for example because it | 433 ** If the YYPARSEFREENEVERNULL macro exists (for example because it |
391 ** is defined in a %include section of the input grammar) then it is | 434 ** is defined in a %include section of the input grammar) then it is |
392 ** assumed that the input pointer is never NULL. | 435 ** assumed that the input pointer is never NULL. |
393 */ | 436 */ |
394 void ParseFree( | 437 void ParseFree( |
395 void *p, /* The parser to be deleted */ | 438 void *p, /* The parser to be deleted */ |
396 void (*freeProc)(void*) /* Function used to reclaim memory */ | 439 void (*freeProc)(void*) /* Function used to reclaim memory */ |
397 ){ | 440 ){ |
398 yyParser *pParser = (yyParser*)p; | |
399 #ifndef YYPARSEFREENEVERNULL | 441 #ifndef YYPARSEFREENEVERNULL |
400 if( pParser==0 ) return; | 442 if( p==0 ) return; |
401 #endif | 443 #endif |
402 while( pParser->yyidx>=0 ) yy_pop_parser_stack(pParser); | 444 ParseFinalize(p); |
403 #if YYSTACKDEPTH<=0 | 445 (*freeProc)(p); |
404 free(pParser->yystack); | |
405 #endif | |
406 (*freeProc)((void*)pParser); | |
407 } | 446 } |
| 447 #endif /* Parse_ENGINEALWAYSONSTACK */ |
408 | 448 |
409 /* | 449 /* |
410 ** Return the peak depth of the stack for a parser. | 450 ** Return the peak depth of the stack for a parser. |
411 */ | 451 */ |
412 #ifdef YYTRACKMAXSTACKDEPTH | 452 #ifdef YYTRACKMAXSTACKDEPTH |
413 int ParseStackPeak(void *p){ | 453 int ParseStackPeak(void *p){ |
414 yyParser *pParser = (yyParser*)p; | 454 yyParser *pParser = (yyParser*)p; |
415 return pParser->yyidxMax; | 455 return pParser->yyhwm; |
416 } | 456 } |
417 #endif | 457 #endif |
418 | 458 |
419 /* | 459 /* |
420 ** Find the appropriate action for a parser given the terminal | 460 ** Find the appropriate action for a parser given the terminal |
421 ** look-ahead token iLookAhead. | 461 ** look-ahead token iLookAhead. |
422 */ | 462 */ |
423 static int yy_find_shift_action( | 463 static unsigned int yy_find_shift_action( |
424 yyParser *pParser, /* The parser */ | 464 yyParser *pParser, /* The parser */ |
425 YYCODETYPE iLookAhead /* The look-ahead token */ | 465 YYCODETYPE iLookAhead /* The look-ahead token */ |
426 ){ | 466 ){ |
427 int i; | 467 int i; |
428 int stateno = pParser->yystack[pParser->yyidx].stateno; | 468 int stateno = pParser->yytos->stateno; |
429 | 469 |
430 if( stateno>=YY_MIN_REDUCE ) return stateno; | 470 if( stateno>=YY_MIN_REDUCE ) return stateno; |
431 assert( stateno <= YY_SHIFT_COUNT ); | 471 assert( stateno <= YY_SHIFT_COUNT ); |
432 do{ | 472 do{ |
433 i = yy_shift_ofst[stateno]; | 473 i = yy_shift_ofst[stateno]; |
434 if( i==YY_SHIFT_USE_DFLT ) return yy_default[stateno]; | |
435 assert( iLookAhead!=YYNOCODE ); | 474 assert( iLookAhead!=YYNOCODE ); |
436 i += iLookAhead; | 475 i += iLookAhead; |
437 if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){ | 476 if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){ |
438 if( iLookAhead>0 ){ | |
439 #ifdef YYFALLBACK | 477 #ifdef YYFALLBACK |
440 YYCODETYPE iFallback; /* Fallback token */ | 478 YYCODETYPE iFallback; /* Fallback token */ |
441 if( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0]) | 479 if( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0]) |
442 && (iFallback = yyFallback[iLookAhead])!=0 ){ | 480 && (iFallback = yyFallback[iLookAhead])!=0 ){ |
| 481 #ifndef NDEBUG |
| 482 if( yyTraceFILE ){ |
| 483 fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n", |
| 484 yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]); |
| 485 } |
| 486 #endif |
| 487 assert( yyFallback[iFallback]==0 ); /* Fallback loop must terminate */ |
| 488 iLookAhead = iFallback; |
| 489 continue; |
| 490 } |
| 491 #endif |
| 492 #ifdef YYWILDCARD |
| 493 { |
| 494 int j = i - iLookAhead + YYWILDCARD; |
| 495 if( |
| 496 #if YY_SHIFT_MIN+YYWILDCARD<0 |
| 497 j>=0 && |
| 498 #endif |
| 499 #if YY_SHIFT_MAX+YYWILDCARD>=YY_ACTTAB_COUNT |
| 500 j<YY_ACTTAB_COUNT && |
| 501 #endif |
| 502 yy_lookahead[j]==YYWILDCARD && iLookAhead>0 |
| 503 ){ |
443 #ifndef NDEBUG | 504 #ifndef NDEBUG |
444 if( yyTraceFILE ){ | 505 if( yyTraceFILE ){ |
445 fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n", | 506 fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n", |
446 yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]); | 507 yyTracePrompt, yyTokenName[iLookAhead], |
| 508 yyTokenName[YYWILDCARD]); |
447 } | 509 } |
448 #endif | 510 #endif /* NDEBUG */ |
449 assert( yyFallback[iFallback]==0 ); /* Fallback loop must terminate */ | 511 return yy_action[j]; |
450 iLookAhead = iFallback; | |
451 continue; | |
452 } | 512 } |
453 #endif | 513 } |
454 #ifdef YYWILDCARD | |
455 { | |
456 int j = i - iLookAhead + YYWILDCARD; | |
457 if( | |
458 #if YY_SHIFT_MIN+YYWILDCARD<0 | |
459 j>=0 && | |
460 #endif | |
461 #if YY_SHIFT_MAX+YYWILDCARD>=YY_ACTTAB_COUNT | |
462 j<YY_ACTTAB_COUNT && | |
463 #endif | |
464 yy_lookahead[j]==YYWILDCARD | |
465 ){ | |
466 #ifndef NDEBUG | |
467 if( yyTraceFILE ){ | |
468 fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n", | |
469 yyTracePrompt, yyTokenName[iLookAhead], | |
470 yyTokenName[YYWILDCARD]); | |
471 } | |
472 #endif /* NDEBUG */ | |
473 return yy_action[j]; | |
474 } | |
475 } | |
476 #endif /* YYWILDCARD */ | 514 #endif /* YYWILDCARD */ |
477 } | |
478 return yy_default[stateno]; | 515 return yy_default[stateno]; |
479 }else{ | 516 }else{ |
480 return yy_action[i]; | 517 return yy_action[i]; |
481 } | 518 } |
482 }while(1); | 519 }while(1); |
483 } | 520 } |
484 | 521 |
485 /* | 522 /* |
486 ** Find the appropriate action for a parser given the non-terminal | 523 ** Find the appropriate action for a parser given the non-terminal |
487 ** look-ahead token iLookAhead. | 524 ** look-ahead token iLookAhead. |
(...skipping 21 matching lines...) Expand all Loading... |
509 #else | 546 #else |
510 assert( i>=0 && i<YY_ACTTAB_COUNT ); | 547 assert( i>=0 && i<YY_ACTTAB_COUNT ); |
511 assert( yy_lookahead[i]==iLookAhead ); | 548 assert( yy_lookahead[i]==iLookAhead ); |
512 #endif | 549 #endif |
513 return yy_action[i]; | 550 return yy_action[i]; |
514 } | 551 } |
515 | 552 |
516 /* | 553 /* |
517 ** The following routine is called if the stack overflows. | 554 ** The following routine is called if the stack overflows. |
518 */ | 555 */ |
519 static void yyStackOverflow(yyParser *yypParser, YYMINORTYPE *yypMinor){ | 556 static void yyStackOverflow(yyParser *yypParser){ |
520 ParseARG_FETCH; | 557 ParseARG_FETCH; |
521 yypParser->yyidx--; | |
522 #ifndef NDEBUG | 558 #ifndef NDEBUG |
523 if( yyTraceFILE ){ | 559 if( yyTraceFILE ){ |
524 fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt); | 560 fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt); |
525 } | 561 } |
526 #endif | 562 #endif |
527 while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser); | 563 while( yypParser->yytos>yypParser->yystack ) yy_pop_parser_stack(yypParser); |
528 /* Here code is inserted which will execute if the parser | 564 /* Here code is inserted which will execute if the parser |
529 ** stack every overflows */ | 565 ** stack every overflows */ |
530 /******** Begin %stack_overflow code ******************************************/ | 566 /******** Begin %stack_overflow code ******************************************/ |
531 %% | 567 %% |
532 /******** End %stack_overflow code ********************************************/ | 568 /******** End %stack_overflow code ********************************************/ |
533 ParseARG_STORE; /* Suppress warning about unused %extra_argument var */ | 569 ParseARG_STORE; /* Suppress warning about unused %extra_argument var */ |
534 } | 570 } |
535 | 571 |
536 /* | 572 /* |
537 ** Print tracing information for a SHIFT action | 573 ** Print tracing information for a SHIFT action |
538 */ | 574 */ |
539 #ifndef NDEBUG | 575 #ifndef NDEBUG |
540 static void yyTraceShift(yyParser *yypParser, int yyNewState){ | 576 static void yyTraceShift(yyParser *yypParser, int yyNewState){ |
541 if( yyTraceFILE ){ | 577 if( yyTraceFILE ){ |
542 if( yyNewState<YYNSTATE ){ | 578 if( yyNewState<YYNSTATE ){ |
543 fprintf(yyTraceFILE,"%sShift '%s', go to state %d\n", | 579 fprintf(yyTraceFILE,"%sShift '%s', go to state %d\n", |
544 yyTracePrompt,yyTokenName[yypParser->yystack[yypParser->yyidx].major], | 580 yyTracePrompt,yyTokenName[yypParser->yytos->major], |
545 yyNewState); | 581 yyNewState); |
546 }else{ | 582 }else{ |
547 fprintf(yyTraceFILE,"%sShift '%s'\n", | 583 fprintf(yyTraceFILE,"%sShift '%s'\n", |
548 yyTracePrompt,yyTokenName[yypParser->yystack[yypParser->yyidx].major]); | 584 yyTracePrompt,yyTokenName[yypParser->yytos->major]); |
549 } | 585 } |
550 } | 586 } |
551 } | 587 } |
552 #else | 588 #else |
553 # define yyTraceShift(X,Y) | 589 # define yyTraceShift(X,Y) |
554 #endif | 590 #endif |
555 | 591 |
556 /* | 592 /* |
557 ** Perform a shift action. | 593 ** Perform a shift action. |
558 */ | 594 */ |
559 static void yy_shift( | 595 static void yy_shift( |
560 yyParser *yypParser, /* The parser to be shifted */ | 596 yyParser *yypParser, /* The parser to be shifted */ |
561 int yyNewState, /* The new state to shift in */ | 597 int yyNewState, /* The new state to shift in */ |
562 int yyMajor, /* The major token to shift in */ | 598 int yyMajor, /* The major token to shift in */ |
563 YYMINORTYPE *yypMinor /* Pointer to the minor token to shift in */ | 599 ParseTOKENTYPE yyMinor /* The minor token to shift in */ |
564 ){ | 600 ){ |
565 yyStackEntry *yytos; | 601 yyStackEntry *yytos; |
566 yypParser->yyidx++; | 602 yypParser->yytos++; |
567 #ifdef YYTRACKMAXSTACKDEPTH | 603 #ifdef YYTRACKMAXSTACKDEPTH |
568 if( yypParser->yyidx>yypParser->yyidxMax ){ | 604 if( (int)(yypParser->yytos - yypParser->yystack)>yypParser->yyhwm ){ |
569 yypParser->yyidxMax = yypParser->yyidx; | 605 yypParser->yyhwm++; |
| 606 assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack) ); |
570 } | 607 } |
571 #endif | 608 #endif |
572 #if YYSTACKDEPTH>0 | 609 #if YYSTACKDEPTH>0 |
573 if( yypParser->yyidx>=YYSTACKDEPTH ){ | 610 if( yypParser->yytos>=&yypParser->yystack[YYSTACKDEPTH] ){ |
574 yyStackOverflow(yypParser, yypMinor); | 611 yypParser->yytos--; |
| 612 yyStackOverflow(yypParser); |
575 return; | 613 return; |
576 } | 614 } |
577 #else | 615 #else |
578 if( yypParser->yyidx>=yypParser->yystksz ){ | 616 if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz] ){ |
579 yyGrowStack(yypParser); | 617 if( yyGrowStack(yypParser) ){ |
580 if( yypParser->yyidx>=yypParser->yystksz ){ | 618 yypParser->yytos--; |
581 yyStackOverflow(yypParser, yypMinor); | 619 yyStackOverflow(yypParser); |
582 return; | 620 return; |
583 } | 621 } |
584 } | 622 } |
585 #endif | 623 #endif |
586 yytos = &yypParser->yystack[yypParser->yyidx]; | 624 if( yyNewState > YY_MAX_SHIFT ){ |
| 625 yyNewState += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE; |
| 626 } |
| 627 yytos = yypParser->yytos; |
587 yytos->stateno = (YYACTIONTYPE)yyNewState; | 628 yytos->stateno = (YYACTIONTYPE)yyNewState; |
588 yytos->major = (YYCODETYPE)yyMajor; | 629 yytos->major = (YYCODETYPE)yyMajor; |
589 yytos->minor = *yypMinor; | 630 yytos->minor.yy0 = yyMinor; |
590 yyTraceShift(yypParser, yyNewState); | 631 yyTraceShift(yypParser, yyNewState); |
591 } | 632 } |
592 | 633 |
593 /* The following table contains information about every rule that | 634 /* The following table contains information about every rule that |
594 ** is used during the reduce. | 635 ** is used during the reduce. |
595 */ | 636 */ |
596 static const struct { | 637 static const struct { |
597 YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */ | 638 YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */ |
598 unsigned char nrhs; /* Number of right-hand side symbols in the rule */ | 639 unsigned char nrhs; /* Number of right-hand side symbols in the rule */ |
599 } yyRuleInfo[] = { | 640 } yyRuleInfo[] = { |
600 %% | 641 %% |
601 }; | 642 }; |
602 | 643 |
603 static void yy_accept(yyParser*); /* Forward Declaration */ | 644 static void yy_accept(yyParser*); /* Forward Declaration */ |
604 | 645 |
605 /* | 646 /* |
606 ** Perform a reduce action and the shift that must immediately | 647 ** Perform a reduce action and the shift that must immediately |
607 ** follow the reduce. | 648 ** follow the reduce. |
608 */ | 649 */ |
609 static void yy_reduce( | 650 static void yy_reduce( |
610 yyParser *yypParser, /* The parser */ | 651 yyParser *yypParser, /* The parser */ |
611 int yyruleno /* Number of the rule by which to reduce */ | 652 unsigned int yyruleno /* Number of the rule by which to reduce */ |
612 ){ | 653 ){ |
613 int yygoto; /* The next state */ | 654 int yygoto; /* The next state */ |
614 int yyact; /* The next action */ | 655 int yyact; /* The next action */ |
615 YYMINORTYPE yygotominor; /* The LHS of the rule reduced */ | |
616 yyStackEntry *yymsp; /* The top of the parser's stack */ | 656 yyStackEntry *yymsp; /* The top of the parser's stack */ |
617 int yysize; /* Amount to pop the stack */ | 657 int yysize; /* Amount to pop the stack */ |
618 ParseARG_FETCH; | 658 ParseARG_FETCH; |
619 yymsp = &yypParser->yystack[yypParser->yyidx]; | 659 yymsp = yypParser->yytos; |
620 #ifndef NDEBUG | 660 #ifndef NDEBUG |
621 if( yyTraceFILE && yyruleno>=0 | 661 if( yyTraceFILE && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){ |
622 && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){ | |
623 yysize = yyRuleInfo[yyruleno].nrhs; | 662 yysize = yyRuleInfo[yyruleno].nrhs; |
624 fprintf(yyTraceFILE, "%sReduce [%s], go to state %d.\n", yyTracePrompt, | 663 fprintf(yyTraceFILE, "%sReduce [%s], go to state %d.\n", yyTracePrompt, |
625 yyRuleName[yyruleno], yymsp[-yysize].stateno); | 664 yyRuleName[yyruleno], yymsp[-yysize].stateno); |
626 } | 665 } |
627 #endif /* NDEBUG */ | 666 #endif /* NDEBUG */ |
628 yygotominor = yyzerominor; | 667 |
| 668 /* Check that the stack is large enough to grow by a single entry |
| 669 ** if the RHS of the rule is empty. This ensures that there is room |
| 670 ** enough on the stack to push the LHS value */ |
| 671 if( yyRuleInfo[yyruleno].nrhs==0 ){ |
| 672 #ifdef YYTRACKMAXSTACKDEPTH |
| 673 if( (int)(yypParser->yytos - yypParser->yystack)>yypParser->yyhwm ){ |
| 674 yypParser->yyhwm++; |
| 675 assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack)); |
| 676 } |
| 677 #endif |
| 678 #if YYSTACKDEPTH>0 |
| 679 if( yypParser->yytos>=&yypParser->yystack[YYSTACKDEPTH-1] ){ |
| 680 yyStackOverflow(yypParser); |
| 681 return; |
| 682 } |
| 683 #else |
| 684 if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz-1] ){ |
| 685 if( yyGrowStack(yypParser) ){ |
| 686 yyStackOverflow(yypParser); |
| 687 return; |
| 688 } |
| 689 yymsp = yypParser->yytos; |
| 690 } |
| 691 #endif |
| 692 } |
629 | 693 |
630 switch( yyruleno ){ | 694 switch( yyruleno ){ |
631 /* Beginning here are the reduction cases. A typical example | 695 /* Beginning here are the reduction cases. A typical example |
632 ** follows: | 696 ** follows: |
633 ** case 0: | 697 ** case 0: |
634 ** #line <lineno> <grammarfile> | 698 ** #line <lineno> <grammarfile> |
635 ** { ... } // User supplied code | 699 ** { ... } // User supplied code |
636 ** #line <lineno> <thisfile> | 700 ** #line <lineno> <thisfile> |
637 ** break; | 701 ** break; |
638 */ | 702 */ |
639 /********** Begin reduce actions **********************************************/ | 703 /********** Begin reduce actions **********************************************/ |
640 %% | 704 %% |
641 /********** End reduce actions ************************************************/ | 705 /********** End reduce actions ************************************************/ |
642 }; | 706 }; |
643 assert( yyruleno>=0 && yyruleno<sizeof(yyRuleInfo)/sizeof(yyRuleInfo[0]) ); | 707 assert( yyruleno<sizeof(yyRuleInfo)/sizeof(yyRuleInfo[0]) ); |
644 yygoto = yyRuleInfo[yyruleno].lhs; | 708 yygoto = yyRuleInfo[yyruleno].lhs; |
645 yysize = yyRuleInfo[yyruleno].nrhs; | 709 yysize = yyRuleInfo[yyruleno].nrhs; |
646 yypParser->yyidx -= yysize; | |
647 yyact = yy_find_reduce_action(yymsp[-yysize].stateno,(YYCODETYPE)yygoto); | 710 yyact = yy_find_reduce_action(yymsp[-yysize].stateno,(YYCODETYPE)yygoto); |
648 if( yyact <= YY_MAX_SHIFTREDUCE ){ | 711 if( yyact <= YY_MAX_SHIFTREDUCE ){ |
649 if( yyact>YY_MAX_SHIFT ) yyact += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE; | 712 if( yyact>YY_MAX_SHIFT ){ |
650 /* If the reduce action popped at least | 713 yyact += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE; |
651 ** one element off the stack, then we can push the new element back | |
652 ** onto the stack here, and skip the stack overflow test in yy_shift(). | |
653 ** That gives a significant speed improvement. */ | |
654 if( yysize ){ | |
655 yypParser->yyidx++; | |
656 yymsp -= yysize-1; | |
657 yymsp->stateno = (YYACTIONTYPE)yyact; | |
658 yymsp->major = (YYCODETYPE)yygoto; | |
659 yymsp->minor = yygotominor; | |
660 yyTraceShift(yypParser, yyact); | |
661 }else{ | |
662 yy_shift(yypParser,yyact,yygoto,&yygotominor); | |
663 } | 714 } |
| 715 yymsp -= yysize-1; |
| 716 yypParser->yytos = yymsp; |
| 717 yymsp->stateno = (YYACTIONTYPE)yyact; |
| 718 yymsp->major = (YYCODETYPE)yygoto; |
| 719 yyTraceShift(yypParser, yyact); |
664 }else{ | 720 }else{ |
665 assert( yyact == YY_ACCEPT_ACTION ); | 721 assert( yyact == YY_ACCEPT_ACTION ); |
| 722 yypParser->yytos -= yysize; |
666 yy_accept(yypParser); | 723 yy_accept(yypParser); |
667 } | 724 } |
668 } | 725 } |
669 | 726 |
670 /* | 727 /* |
671 ** The following code executes when the parse fails | 728 ** The following code executes when the parse fails |
672 */ | 729 */ |
673 #ifndef YYNOERRORRECOVERY | 730 #ifndef YYNOERRORRECOVERY |
674 static void yy_parse_failed( | 731 static void yy_parse_failed( |
675 yyParser *yypParser /* The parser */ | 732 yyParser *yypParser /* The parser */ |
676 ){ | 733 ){ |
677 ParseARG_FETCH; | 734 ParseARG_FETCH; |
678 #ifndef NDEBUG | 735 #ifndef NDEBUG |
679 if( yyTraceFILE ){ | 736 if( yyTraceFILE ){ |
680 fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt); | 737 fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt); |
681 } | 738 } |
682 #endif | 739 #endif |
683 while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser); | 740 while( yypParser->yytos>yypParser->yystack ) yy_pop_parser_stack(yypParser); |
684 /* Here code is inserted which will be executed whenever the | 741 /* Here code is inserted which will be executed whenever the |
685 ** parser fails */ | 742 ** parser fails */ |
686 /************ Begin %parse_failure code ***************************************/ | 743 /************ Begin %parse_failure code ***************************************/ |
687 %% | 744 %% |
688 /************ End %parse_failure code *****************************************/ | 745 /************ End %parse_failure code *****************************************/ |
689 ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */ | 746 ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */ |
690 } | 747 } |
691 #endif /* YYNOERRORRECOVERY */ | 748 #endif /* YYNOERRORRECOVERY */ |
692 | 749 |
693 /* | 750 /* |
694 ** The following code executes when a syntax error first occurs. | 751 ** The following code executes when a syntax error first occurs. |
695 */ | 752 */ |
696 static void yy_syntax_error( | 753 static void yy_syntax_error( |
697 yyParser *yypParser, /* The parser */ | 754 yyParser *yypParser, /* The parser */ |
698 int yymajor, /* The major type of the error token */ | 755 int yymajor, /* The major type of the error token */ |
699 YYMINORTYPE yyminor /* The minor type of the error token */ | 756 ParseTOKENTYPE yyminor /* The minor type of the error token */ |
700 ){ | 757 ){ |
701 ParseARG_FETCH; | 758 ParseARG_FETCH; |
702 #define TOKEN (yyminor.yy0) | 759 #define TOKEN yyminor |
703 /************ Begin %syntax_error code ****************************************/ | 760 /************ Begin %syntax_error code ****************************************/ |
704 %% | 761 %% |
705 /************ End %syntax_error code ******************************************/ | 762 /************ End %syntax_error code ******************************************/ |
706 ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */ | 763 ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */ |
707 } | 764 } |
708 | 765 |
709 /* | 766 /* |
710 ** The following is executed when the parser accepts | 767 ** The following is executed when the parser accepts |
711 */ | 768 */ |
712 static void yy_accept( | 769 static void yy_accept( |
713 yyParser *yypParser /* The parser */ | 770 yyParser *yypParser /* The parser */ |
714 ){ | 771 ){ |
715 ParseARG_FETCH; | 772 ParseARG_FETCH; |
716 #ifndef NDEBUG | 773 #ifndef NDEBUG |
717 if( yyTraceFILE ){ | 774 if( yyTraceFILE ){ |
718 fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt); | 775 fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt); |
719 } | 776 } |
720 #endif | 777 #endif |
721 while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser); | 778 #ifndef YYNOERRORRECOVERY |
| 779 yypParser->yyerrcnt = -1; |
| 780 #endif |
| 781 assert( yypParser->yytos==yypParser->yystack ); |
722 /* Here code is inserted which will be executed whenever the | 782 /* Here code is inserted which will be executed whenever the |
723 ** parser accepts */ | 783 ** parser accepts */ |
724 /*********** Begin %parse_accept code *****************************************/ | 784 /*********** Begin %parse_accept code *****************************************/ |
725 %% | 785 %% |
726 /*********** End %parse_accept code *******************************************/ | 786 /*********** End %parse_accept code *******************************************/ |
727 ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */ | 787 ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */ |
728 } | 788 } |
729 | 789 |
730 /* The main parser program. | 790 /* The main parser program. |
731 ** The first argument is a pointer to a structure obtained from | 791 ** The first argument is a pointer to a structure obtained from |
(...skipping 14 matching lines...) Expand all Loading... |
746 ** Outputs: | 806 ** Outputs: |
747 ** None. | 807 ** None. |
748 */ | 808 */ |
749 void Parse( | 809 void Parse( |
750 void *yyp, /* The parser */ | 810 void *yyp, /* The parser */ |
751 int yymajor, /* The major token code number */ | 811 int yymajor, /* The major token code number */ |
752 ParseTOKENTYPE yyminor /* The value for the token */ | 812 ParseTOKENTYPE yyminor /* The value for the token */ |
753 ParseARG_PDECL /* Optional %extra_argument parameter */ | 813 ParseARG_PDECL /* Optional %extra_argument parameter */ |
754 ){ | 814 ){ |
755 YYMINORTYPE yyminorunion; | 815 YYMINORTYPE yyminorunion; |
756 int yyact; /* The parser action. */ | 816 unsigned int yyact; /* The parser action. */ |
757 #if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY) | 817 #if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY) |
758 int yyendofinput; /* True if we are at the end of input */ | 818 int yyendofinput; /* True if we are at the end of input */ |
759 #endif | 819 #endif |
760 #ifdef YYERRORSYMBOL | 820 #ifdef YYERRORSYMBOL |
761 int yyerrorhit = 0; /* True if yymajor has invoked an error */ | 821 int yyerrorhit = 0; /* True if yymajor has invoked an error */ |
762 #endif | 822 #endif |
763 yyParser *yypParser; /* The parser */ | 823 yyParser *yypParser; /* The parser */ |
764 | 824 |
765 /* (re)initialize the parser, if necessary */ | |
766 yypParser = (yyParser*)yyp; | 825 yypParser = (yyParser*)yyp; |
767 if( yypParser->yyidx<0 ){ | 826 assert( yypParser->yytos!=0 ); |
768 #if YYSTACKDEPTH<=0 | |
769 if( yypParser->yystksz <=0 ){ | |
770 /*memset(&yyminorunion, 0, sizeof(yyminorunion));*/ | |
771 yyminorunion = yyzerominor; | |
772 yyStackOverflow(yypParser, &yyminorunion); | |
773 return; | |
774 } | |
775 #endif | |
776 yypParser->yyidx = 0; | |
777 yypParser->yyerrcnt = -1; | |
778 yypParser->yystack[0].stateno = 0; | |
779 yypParser->yystack[0].major = 0; | |
780 #ifndef NDEBUG | |
781 if( yyTraceFILE ){ | |
782 fprintf(yyTraceFILE,"%sInitialize. Empty stack. State 0\n", | |
783 yyTracePrompt); | |
784 } | |
785 #endif | |
786 } | |
787 yyminorunion.yy0 = yyminor; | |
788 #if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY) | 827 #if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY) |
789 yyendofinput = (yymajor==0); | 828 yyendofinput = (yymajor==0); |
790 #endif | 829 #endif |
791 ParseARG_STORE; | 830 ParseARG_STORE; |
792 | 831 |
793 #ifndef NDEBUG | 832 #ifndef NDEBUG |
794 if( yyTraceFILE ){ | 833 if( yyTraceFILE ){ |
795 fprintf(yyTraceFILE,"%sInput '%s'\n",yyTracePrompt,yyTokenName[yymajor]); | 834 fprintf(yyTraceFILE,"%sInput '%s'\n",yyTracePrompt,yyTokenName[yymajor]); |
796 } | 835 } |
797 #endif | 836 #endif |
798 | 837 |
799 do{ | 838 do{ |
800 yyact = yy_find_shift_action(yypParser,(YYCODETYPE)yymajor); | 839 yyact = yy_find_shift_action(yypParser,(YYCODETYPE)yymajor); |
801 if( yyact <= YY_MAX_SHIFTREDUCE ){ | 840 if( yyact <= YY_MAX_SHIFTREDUCE ){ |
802 if( yyact > YY_MAX_SHIFT ) yyact += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE; | 841 yy_shift(yypParser,yyact,yymajor,yyminor); |
803 yy_shift(yypParser,yyact,yymajor,&yyminorunion); | 842 #ifndef YYNOERRORRECOVERY |
804 yypParser->yyerrcnt--; | 843 yypParser->yyerrcnt--; |
| 844 #endif |
805 yymajor = YYNOCODE; | 845 yymajor = YYNOCODE; |
806 }else if( yyact <= YY_MAX_REDUCE ){ | 846 }else if( yyact <= YY_MAX_REDUCE ){ |
807 yy_reduce(yypParser,yyact-YY_MIN_REDUCE); | 847 yy_reduce(yypParser,yyact-YY_MIN_REDUCE); |
808 }else{ | 848 }else{ |
809 assert( yyact == YY_ERROR_ACTION ); | 849 assert( yyact == YY_ERROR_ACTION ); |
| 850 yyminorunion.yy0 = yyminor; |
810 #ifdef YYERRORSYMBOL | 851 #ifdef YYERRORSYMBOL |
811 int yymx; | 852 int yymx; |
812 #endif | 853 #endif |
813 #ifndef NDEBUG | 854 #ifndef NDEBUG |
814 if( yyTraceFILE ){ | 855 if( yyTraceFILE ){ |
815 fprintf(yyTraceFILE,"%sSyntax Error!\n",yyTracePrompt); | 856 fprintf(yyTraceFILE,"%sSyntax Error!\n",yyTracePrompt); |
816 } | 857 } |
817 #endif | 858 #endif |
818 #ifdef YYERRORSYMBOL | 859 #ifdef YYERRORSYMBOL |
819 /* A syntax error has occurred. | 860 /* A syntax error has occurred. |
820 ** The response to an error depends upon whether or not the | 861 ** The response to an error depends upon whether or not the |
821 ** grammar defines an error token "ERROR". | 862 ** grammar defines an error token "ERROR". |
822 ** | 863 ** |
823 ** This is what we do if the grammar does define ERROR: | 864 ** This is what we do if the grammar does define ERROR: |
824 ** | 865 ** |
825 ** * Call the %syntax_error function. | 866 ** * Call the %syntax_error function. |
826 ** | 867 ** |
827 ** * Begin popping the stack until we enter a state where | 868 ** * Begin popping the stack until we enter a state where |
828 ** it is legal to shift the error symbol, then shift | 869 ** it is legal to shift the error symbol, then shift |
829 ** the error symbol. | 870 ** the error symbol. |
830 ** | 871 ** |
831 ** * Set the error count to three. | 872 ** * Set the error count to three. |
832 ** | 873 ** |
833 ** * Begin accepting and shifting new tokens. No new error | 874 ** * Begin accepting and shifting new tokens. No new error |
834 ** processing will occur until three tokens have been | 875 ** processing will occur until three tokens have been |
835 ** shifted successfully. | 876 ** shifted successfully. |
836 ** | 877 ** |
837 */ | 878 */ |
838 if( yypParser->yyerrcnt<0 ){ | 879 if( yypParser->yyerrcnt<0 ){ |
839 yy_syntax_error(yypParser,yymajor,yyminorunion); | 880 yy_syntax_error(yypParser,yymajor,yyminor); |
840 } | 881 } |
841 yymx = yypParser->yystack[yypParser->yyidx].major; | 882 yymx = yypParser->yytos->major; |
842 if( yymx==YYERRORSYMBOL || yyerrorhit ){ | 883 if( yymx==YYERRORSYMBOL || yyerrorhit ){ |
843 #ifndef NDEBUG | 884 #ifndef NDEBUG |
844 if( yyTraceFILE ){ | 885 if( yyTraceFILE ){ |
845 fprintf(yyTraceFILE,"%sDiscard input token %s\n", | 886 fprintf(yyTraceFILE,"%sDiscard input token %s\n", |
846 yyTracePrompt,yyTokenName[yymajor]); | 887 yyTracePrompt,yyTokenName[yymajor]); |
847 } | 888 } |
848 #endif | 889 #endif |
849 yy_destructor(yypParser, (YYCODETYPE)yymajor,&yyminorunion); | 890 yy_destructor(yypParser, (YYCODETYPE)yymajor, &yyminorunion); |
850 yymajor = YYNOCODE; | 891 yymajor = YYNOCODE; |
851 }else{ | 892 }else{ |
852 while( | 893 while( yypParser->yytos >= yypParser->yystack |
853 yypParser->yyidx >= 0 && | 894 && yymx != YYERRORSYMBOL |
854 yymx != YYERRORSYMBOL && | 895 && (yyact = yy_find_reduce_action( |
855 (yyact = yy_find_reduce_action( | 896 yypParser->yytos->stateno, |
856 yypParser->yystack[yypParser->yyidx].stateno, | |
857 YYERRORSYMBOL)) >= YY_MIN_REDUCE | 897 YYERRORSYMBOL)) >= YY_MIN_REDUCE |
858 ){ | 898 ){ |
859 yy_pop_parser_stack(yypParser); | 899 yy_pop_parser_stack(yypParser); |
860 } | 900 } |
861 if( yypParser->yyidx < 0 || yymajor==0 ){ | 901 if( yypParser->yytos < yypParser->yystack || yymajor==0 ){ |
862 yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion); | 902 yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion); |
863 yy_parse_failed(yypParser); | 903 yy_parse_failed(yypParser); |
| 904 #ifndef YYNOERRORRECOVERY |
| 905 yypParser->yyerrcnt = -1; |
| 906 #endif |
864 yymajor = YYNOCODE; | 907 yymajor = YYNOCODE; |
865 }else if( yymx!=YYERRORSYMBOL ){ | 908 }else if( yymx!=YYERRORSYMBOL ){ |
866 YYMINORTYPE u2; | 909 yy_shift(yypParser,yyact,YYERRORSYMBOL,yyminor); |
867 u2.YYERRSYMDT = 0; | |
868 yy_shift(yypParser,yyact,YYERRORSYMBOL,&u2); | |
869 } | 910 } |
870 } | 911 } |
871 yypParser->yyerrcnt = 3; | 912 yypParser->yyerrcnt = 3; |
872 yyerrorhit = 1; | 913 yyerrorhit = 1; |
873 #elif defined(YYNOERRORRECOVERY) | 914 #elif defined(YYNOERRORRECOVERY) |
874 /* If the YYNOERRORRECOVERY macro is defined, then do not attempt to | 915 /* If the YYNOERRORRECOVERY macro is defined, then do not attempt to |
875 ** do any kind of error recovery. Instead, simply invoke the syntax | 916 ** do any kind of error recovery. Instead, simply invoke the syntax |
876 ** error routine and continue going as if nothing had happened. | 917 ** error routine and continue going as if nothing had happened. |
877 ** | 918 ** |
878 ** Applications can set this macro (for example inside %include) if | 919 ** Applications can set this macro (for example inside %include) if |
879 ** they intend to abandon the parse upon the first syntax error seen. | 920 ** they intend to abandon the parse upon the first syntax error seen. |
880 */ | 921 */ |
881 yy_syntax_error(yypParser,yymajor,yyminorunion); | 922 yy_syntax_error(yypParser,yymajor, yyminor); |
882 yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion); | 923 yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion); |
883 yymajor = YYNOCODE; | 924 yymajor = YYNOCODE; |
884 | 925 |
885 #else /* YYERRORSYMBOL is not defined */ | 926 #else /* YYERRORSYMBOL is not defined */ |
886 /* This is what we do if the grammar does not define ERROR: | 927 /* This is what we do if the grammar does not define ERROR: |
887 ** | 928 ** |
888 ** * Report an error message, and throw away the input token. | 929 ** * Report an error message, and throw away the input token. |
889 ** | 930 ** |
890 ** * If the input token is $, then fail the parse. | 931 ** * If the input token is $, then fail the parse. |
891 ** | 932 ** |
892 ** As before, subsequent error messages are suppressed until | 933 ** As before, subsequent error messages are suppressed until |
893 ** three input tokens have been successfully shifted. | 934 ** three input tokens have been successfully shifted. |
894 */ | 935 */ |
895 if( yypParser->yyerrcnt<=0 ){ | 936 if( yypParser->yyerrcnt<=0 ){ |
896 yy_syntax_error(yypParser,yymajor,yyminorunion); | 937 yy_syntax_error(yypParser,yymajor, yyminor); |
897 } | 938 } |
898 yypParser->yyerrcnt = 3; | 939 yypParser->yyerrcnt = 3; |
899 yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion); | 940 yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion); |
900 if( yyendofinput ){ | 941 if( yyendofinput ){ |
901 yy_parse_failed(yypParser); | 942 yy_parse_failed(yypParser); |
| 943 #ifndef YYNOERRORRECOVERY |
| 944 yypParser->yyerrcnt = -1; |
| 945 #endif |
902 } | 946 } |
903 yymajor = YYNOCODE; | 947 yymajor = YYNOCODE; |
904 #endif | 948 #endif |
905 } | 949 } |
906 }while( yymajor!=YYNOCODE && yypParser->yyidx>=0 ); | 950 }while( yymajor!=YYNOCODE && yypParser->yytos>yypParser->yystack ); |
907 #ifndef NDEBUG | 951 #ifndef NDEBUG |
908 if( yyTraceFILE ){ | 952 if( yyTraceFILE ){ |
909 int i; | 953 yyStackEntry *i; |
| 954 char cDiv = '['; |
910 fprintf(yyTraceFILE,"%sReturn. Stack=",yyTracePrompt); | 955 fprintf(yyTraceFILE,"%sReturn. Stack=",yyTracePrompt); |
911 for(i=1; i<=yypParser->yyidx; i++) | 956 for(i=&yypParser->yystack[1]; i<=yypParser->yytos; i++){ |
912 fprintf(yyTraceFILE,"%c%s", i==1 ? '[' : ' ', | 957 fprintf(yyTraceFILE,"%c%s", cDiv, yyTokenName[i->major]); |
913 yyTokenName[yypParser->yystack[i].major]); | 958 cDiv = ' '; |
| 959 } |
914 fprintf(yyTraceFILE,"]\n"); | 960 fprintf(yyTraceFILE,"]\n"); |
915 } | 961 } |
916 #endif | 962 #endif |
917 return; | 963 return; |
918 } | 964 } |
OLD | NEW |