| OLD | NEW |
| (Empty) |
| 1 /* Driver template for the LEMON parser generator. | |
| 2 ** The author disclaims copyright to this source code. | |
| 3 */ | |
| 4 /* First off, code is included that follows the "include" declaration | |
| 5 ** in the input grammar file. */ | |
| 6 #include <stdio.h> | |
| 7 %% | |
| 8 /* Next is all token values, in a form suitable for use by makeheaders. | |
| 9 ** This section will be null unless lemon is run with the -m switch. | |
| 10 */ | |
| 11 /* | |
| 12 ** These constants (all generated automatically by the parser generator) | |
| 13 ** specify the various kinds of tokens (terminals) that the parser | |
| 14 ** understands. | |
| 15 ** | |
| 16 ** Each symbol here is a terminal symbol in the grammar. | |
| 17 */ | |
| 18 %% | |
| 19 /* Make sure the INTERFACE macro is defined. | |
| 20 */ | |
| 21 #ifndef INTERFACE | |
| 22 # define INTERFACE 1 | |
| 23 #endif | |
| 24 /* The next thing included is series of defines which control | |
| 25 ** various aspects of the generated parser. | |
| 26 ** YYCODETYPE is the data type used for storing terminal | |
| 27 ** and nonterminal numbers. "unsigned char" is | |
| 28 ** used if there are fewer than 250 terminals | |
| 29 ** and nonterminals. "int" is used otherwise. | |
| 30 ** YYNOCODE is a number of type YYCODETYPE which corresponds | |
| 31 ** to no legal terminal or nonterminal number. This | |
| 32 ** number is used to fill in empty slots of the hash | |
| 33 ** table. | |
| 34 ** YYFALLBACK If defined, this indicates that one or more tokens | |
| 35 ** have fall-back values which should be used if the | |
| 36 ** original value of the token will not parse. | |
| 37 ** YYACTIONTYPE is the data type used for storing terminal | |
| 38 ** and nonterminal numbers. "unsigned char" is | |
| 39 ** used if there are fewer than 250 rules and | |
| 40 ** states combined. "int" is used otherwise. | |
| 41 ** ParseTOKENTYPE is the data type used for minor tokens given | |
| 42 ** directly to the parser from the tokenizer. | |
| 43 ** YYMINORTYPE is the data type used for all minor tokens. | |
| 44 ** This is typically a union of many types, one of | |
| 45 ** which is ParseTOKENTYPE. The entry in the union | |
| 46 ** for base tokens is called "yy0". | |
| 47 ** YYSTACKDEPTH is the maximum depth of the parser's stack. If | |
| 48 ** zero the stack is dynamically sized using realloc() | |
| 49 ** ParseARG_SDECL A static variable declaration for the %extra_argument | |
| 50 ** ParseARG_PDECL A parameter declaration for the %extra_argument | |
| 51 ** ParseARG_STORE Code to store %extra_argument into yypParser | |
| 52 ** ParseARG_FETCH Code to extract %extra_argument from yypParser | |
| 53 ** YYNSTATE the combined number of states. | |
| 54 ** YYNRULE the number of rules in the grammar | |
| 55 ** YYERRORSYMBOL is the code number of the error symbol. If not | |
| 56 ** defined, then do no error processing. | |
| 57 */ | |
| 58 %% | |
| 59 #define YY_NO_ACTION (YYNSTATE+YYNRULE+2) | |
| 60 #define YY_ACCEPT_ACTION (YYNSTATE+YYNRULE+1) | |
| 61 #define YY_ERROR_ACTION (YYNSTATE+YYNRULE) | |
| 62 | |
| 63 /* The yyzerominor constant is used to initialize instances of | |
| 64 ** YYMINORTYPE objects to zero. */ | |
| 65 static const YYMINORTYPE yyzerominor = { 0 }; | |
| 66 | |
| 67 /* Define the yytestcase() macro to be a no-op if is not already defined | |
| 68 ** otherwise. | |
| 69 ** | |
| 70 ** Applications can choose to define yytestcase() in the %include section | |
| 71 ** to a macro that can assist in verifying code coverage. For production | |
| 72 ** code the yytestcase() macro should be turned off. But it is useful | |
| 73 ** for testing. | |
| 74 */ | |
| 75 #ifndef yytestcase | |
| 76 # define yytestcase(X) | |
| 77 #endif | |
| 78 | |
| 79 | |
| 80 /* Next are the tables used to determine what action to take based on the | |
| 81 ** current state and lookahead token. These tables are used to implement | |
| 82 ** functions that take a state number and lookahead value and return an | |
| 83 ** action integer. | |
| 84 ** | |
| 85 ** Suppose the action integer is N. Then the action is determined as | |
| 86 ** follows | |
| 87 ** | |
| 88 ** 0 <= N < YYNSTATE Shift N. That is, push the lookahead | |
| 89 ** token onto the stack and goto state N. | |
| 90 ** | |
| 91 ** YYNSTATE <= N < YYNSTATE+YYNRULE Reduce by rule N-YYNSTATE. | |
| 92 ** | |
| 93 ** N == YYNSTATE+YYNRULE A syntax error has occurred. | |
| 94 ** | |
| 95 ** N == YYNSTATE+YYNRULE+1 The parser accepts its input. | |
| 96 ** | |
| 97 ** N == YYNSTATE+YYNRULE+2 No such action. Denotes unused | |
| 98 ** slots in the yy_action[] table. | |
| 99 ** | |
| 100 ** The action table is constructed as a single large table named yy_action[]. | |
| 101 ** Given state S and lookahead X, the action is computed as | |
| 102 ** | |
| 103 ** yy_action[ yy_shift_ofst[S] + X ] | |
| 104 ** | |
| 105 ** If the index value yy_shift_ofst[S]+X is out of range or if the value | |
| 106 ** yy_lookahead[yy_shift_ofst[S]+X] is not equal to X or if yy_shift_ofst[S] | |
| 107 ** is equal to YY_SHIFT_USE_DFLT, it means that the action is not in the table | |
| 108 ** and that yy_default[S] should be used instead. | |
| 109 ** | |
| 110 ** The formula above is for computing the action when the lookahead is | |
| 111 ** a terminal symbol. If the lookahead is a non-terminal (as occurs after | |
| 112 ** a reduce action) then the yy_reduce_ofst[] array is used in place of | |
| 113 ** the yy_shift_ofst[] array and YY_REDUCE_USE_DFLT is used in place of | |
| 114 ** YY_SHIFT_USE_DFLT. | |
| 115 ** | |
| 116 ** The following are the tables generated in this section: | |
| 117 ** | |
| 118 ** yy_action[] A single table containing all actions. | |
| 119 ** yy_lookahead[] A table containing the lookahead for each entry in | |
| 120 ** yy_action. Used to detect hash collisions. | |
| 121 ** yy_shift_ofst[] For each state, the offset into yy_action for | |
| 122 ** shifting terminals. | |
| 123 ** yy_reduce_ofst[] For each state, the offset into yy_action for | |
| 124 ** shifting non-terminals after a reduce. | |
| 125 ** yy_default[] Default action for each state. | |
| 126 */ | |
| 127 %% | |
| 128 #define YY_SZ_ACTTAB (int)(sizeof(yy_action)/sizeof(yy_action[0])) | |
| 129 | |
| 130 /* The next table maps tokens into fallback tokens. If a construct | |
| 131 ** like the following: | |
| 132 ** | |
| 133 ** %fallback ID X Y Z. | |
| 134 ** | |
| 135 ** appears in the grammar, then ID becomes a fallback token for X, Y, | |
| 136 ** and Z. Whenever one of the tokens X, Y, or Z is input to the parser | |
| 137 ** but it does not parse, the type of the token is changed to ID and | |
| 138 ** the parse is retried before an error is thrown. | |
| 139 */ | |
| 140 #ifdef YYFALLBACK | |
| 141 static const YYCODETYPE yyFallback[] = { | |
| 142 %% | |
| 143 }; | |
| 144 #endif /* YYFALLBACK */ | |
| 145 | |
| 146 /* The following structure represents a single element of the | |
| 147 ** parser's stack. Information stored includes: | |
| 148 ** | |
| 149 ** + The state number for the parser at this level of the stack. | |
| 150 ** | |
| 151 ** + The value of the token stored at this level of the stack. | |
| 152 ** (In other words, the "major" token.) | |
| 153 ** | |
| 154 ** + The semantic value stored at this level of the stack. This is | |
| 155 ** the information used by the action routines in the grammar. | |
| 156 ** It is sometimes called the "minor" token. | |
| 157 */ | |
| 158 struct yyStackEntry { | |
| 159 YYACTIONTYPE stateno; /* The state-number */ | |
| 160 YYCODETYPE major; /* The major token value. This is the code | |
| 161 ** number for the token at this stack level */ | |
| 162 YYMINORTYPE minor; /* The user-supplied minor token value. This | |
| 163 ** is the value of the token */ | |
| 164 }; | |
| 165 typedef struct yyStackEntry yyStackEntry; | |
| 166 | |
| 167 /* The state of the parser is completely contained in an instance of | |
| 168 ** the following structure */ | |
| 169 struct yyParser { | |
| 170 int yyidx; /* Index of top element in stack */ | |
| 171 #ifdef YYTRACKMAXSTACKDEPTH | |
| 172 int yyidxMax; /* Maximum value of yyidx */ | |
| 173 #endif | |
| 174 int yyerrcnt; /* Shifts left before out of the error */ | |
| 175 ParseARG_SDECL /* A place to hold %extra_argument */ | |
| 176 #if YYSTACKDEPTH<=0 | |
| 177 int yystksz; /* Current side of the stack */ | |
| 178 yyStackEntry *yystack; /* The parser's stack */ | |
| 179 #else | |
| 180 yyStackEntry yystack[YYSTACKDEPTH]; /* The parser's stack */ | |
| 181 #endif | |
| 182 }; | |
| 183 typedef struct yyParser yyParser; | |
| 184 | |
| 185 #ifndef NDEBUG | |
| 186 #include <stdio.h> | |
| 187 static FILE *yyTraceFILE = 0; | |
| 188 static char *yyTracePrompt = 0; | |
| 189 #endif /* NDEBUG */ | |
| 190 | |
| 191 #ifndef NDEBUG | |
| 192 /* | |
| 193 ** Turn parser tracing on by giving a stream to which to write the trace | |
| 194 ** and a prompt to preface each trace message. Tracing is turned off | |
| 195 ** by making either argument NULL | |
| 196 ** | |
| 197 ** Inputs: | |
| 198 ** <ul> | |
| 199 ** <li> A FILE* to which trace output should be written. | |
| 200 ** If NULL, then tracing is turned off. | |
| 201 ** <li> A prefix string written at the beginning of every | |
| 202 ** line of trace output. If NULL, then tracing is | |
| 203 ** turned off. | |
| 204 ** </ul> | |
| 205 ** | |
| 206 ** Outputs: | |
| 207 ** None. | |
| 208 */ | |
| 209 void ParseTrace(FILE *TraceFILE, char *zTracePrompt){ | |
| 210 yyTraceFILE = TraceFILE; | |
| 211 yyTracePrompt = zTracePrompt; | |
| 212 if( yyTraceFILE==0 ) yyTracePrompt = 0; | |
| 213 else if( yyTracePrompt==0 ) yyTraceFILE = 0; | |
| 214 } | |
| 215 #endif /* NDEBUG */ | |
| 216 | |
| 217 #ifndef NDEBUG | |
| 218 /* For tracing shifts, the names of all terminals and nonterminals | |
| 219 ** are required. The following table supplies these names */ | |
| 220 static const char *const yyTokenName[] = { | |
| 221 %% | |
| 222 }; | |
| 223 #endif /* NDEBUG */ | |
| 224 | |
| 225 #ifndef NDEBUG | |
| 226 /* For tracing reduce actions, the names of all rules are required. | |
| 227 */ | |
| 228 static const char *const yyRuleName[] = { | |
| 229 %% | |
| 230 }; | |
| 231 #endif /* NDEBUG */ | |
| 232 | |
| 233 | |
| 234 #if YYSTACKDEPTH<=0 | |
| 235 /* | |
| 236 ** Try to increase the size of the parser stack. | |
| 237 */ | |
| 238 static void yyGrowStack(yyParser *p){ | |
| 239 int newSize; | |
| 240 yyStackEntry *pNew; | |
| 241 | |
| 242 newSize = p->yystksz*2 + 100; | |
| 243 pNew = realloc(p->yystack, newSize*sizeof(pNew[0])); | |
| 244 if( pNew ){ | |
| 245 p->yystack = pNew; | |
| 246 p->yystksz = newSize; | |
| 247 #ifndef NDEBUG | |
| 248 if( yyTraceFILE ){ | |
| 249 fprintf(yyTraceFILE,"%sStack grows to %d entries!\n", | |
| 250 yyTracePrompt, p->yystksz); | |
| 251 } | |
| 252 #endif | |
| 253 } | |
| 254 } | |
| 255 #endif | |
| 256 | |
| 257 /* | |
| 258 ** This function allocates a new parser. | |
| 259 ** The only argument is a pointer to a function which works like | |
| 260 ** malloc. | |
| 261 ** | |
| 262 ** Inputs: | |
| 263 ** A pointer to the function used to allocate memory. | |
| 264 ** | |
| 265 ** Outputs: | |
| 266 ** A pointer to a parser. This pointer is used in subsequent calls | |
| 267 ** to Parse and ParseFree. | |
| 268 */ | |
| 269 void *ParseAlloc(void *(*mallocProc)(size_t)){ | |
| 270 yyParser *pParser; | |
| 271 pParser = (yyParser*)(*mallocProc)( (size_t)sizeof(yyParser) ); | |
| 272 if( pParser ){ | |
| 273 pParser->yyidx = -1; | |
| 274 #ifdef YYTRACKMAXSTACKDEPTH | |
| 275 pParser->yyidxMax = 0; | |
| 276 #endif | |
| 277 #if YYSTACKDEPTH<=0 | |
| 278 pParser->yystack = NULL; | |
| 279 pParser->yystksz = 0; | |
| 280 yyGrowStack(pParser); | |
| 281 #endif | |
| 282 } | |
| 283 return pParser; | |
| 284 } | |
| 285 | |
| 286 /* The following function deletes the value associated with a | |
| 287 ** symbol. The symbol can be either a terminal or nonterminal. | |
| 288 ** "yymajor" is the symbol code, and "yypminor" is a pointer to | |
| 289 ** the value. | |
| 290 */ | |
| 291 static void yy_destructor( | |
| 292 yyParser *yypParser, /* The parser */ | |
| 293 YYCODETYPE yymajor, /* Type code for object to destroy */ | |
| 294 YYMINORTYPE *yypminor /* The object to be destroyed */ | |
| 295 ){ | |
| 296 ParseARG_FETCH; | |
| 297 switch( yymajor ){ | |
| 298 /* Here is inserted the actions which take place when a | |
| 299 ** terminal or non-terminal is destroyed. This can happen | |
| 300 ** when the symbol is popped from the stack during a | |
| 301 ** reduce or during error processing or when a parser is | |
| 302 ** being destroyed before it is finished parsing. | |
| 303 ** | |
| 304 ** Note: during a reduce, the only symbols destroyed are those | |
| 305 ** which appear on the RHS of the rule, but which are not used | |
| 306 ** inside the C code. | |
| 307 */ | |
| 308 %% | |
| 309 default: break; /* If no destructor action specified: do nothing */ | |
| 310 } | |
| 311 } | |
| 312 | |
| 313 /* | |
| 314 ** Pop the parser's stack once. | |
| 315 ** | |
| 316 ** If there is a destructor routine associated with the token which | |
| 317 ** is popped from the stack, then call it. | |
| 318 ** | |
| 319 ** Return the major token number for the symbol popped. | |
| 320 */ | |
| 321 static int yy_pop_parser_stack(yyParser *pParser){ | |
| 322 YYCODETYPE yymajor; | |
| 323 yyStackEntry *yytos = &pParser->yystack[pParser->yyidx]; | |
| 324 | |
| 325 if( pParser->yyidx<0 ) return 0; | |
| 326 #ifndef NDEBUG | |
| 327 if( yyTraceFILE && pParser->yyidx>=0 ){ | |
| 328 fprintf(yyTraceFILE,"%sPopping %s\n", | |
| 329 yyTracePrompt, | |
| 330 yyTokenName[yytos->major]); | |
| 331 } | |
| 332 #endif | |
| 333 yymajor = yytos->major; | |
| 334 yy_destructor(pParser, yymajor, &yytos->minor); | |
| 335 pParser->yyidx--; | |
| 336 return yymajor; | |
| 337 } | |
| 338 | |
| 339 /* | |
| 340 ** Deallocate and destroy a parser. Destructors are all called for | |
| 341 ** all stack elements before shutting the parser down. | |
| 342 ** | |
| 343 ** Inputs: | |
| 344 ** <ul> | |
| 345 ** <li> A pointer to the parser. This should be a pointer | |
| 346 ** obtained from ParseAlloc. | |
| 347 ** <li> A pointer to a function used to reclaim memory obtained | |
| 348 ** from malloc. | |
| 349 ** </ul> | |
| 350 */ | |
| 351 void ParseFree( | |
| 352 void *p, /* The parser to be deleted */ | |
| 353 void (*freeProc)(void*) /* Function used to reclaim memory */ | |
| 354 ){ | |
| 355 yyParser *pParser = (yyParser*)p; | |
| 356 if( pParser==0 ) return; | |
| 357 while( pParser->yyidx>=0 ) yy_pop_parser_stack(pParser); | |
| 358 #if YYSTACKDEPTH<=0 | |
| 359 free(pParser->yystack); | |
| 360 #endif | |
| 361 (*freeProc)((void*)pParser); | |
| 362 } | |
| 363 | |
| 364 /* | |
| 365 ** Return the peak depth of the stack for a parser. | |
| 366 */ | |
| 367 #ifdef YYTRACKMAXSTACKDEPTH | |
| 368 int ParseStackPeak(void *p){ | |
| 369 yyParser *pParser = (yyParser*)p; | |
| 370 return pParser->yyidxMax; | |
| 371 } | |
| 372 #endif | |
| 373 | |
| 374 /* | |
| 375 ** Find the appropriate action for a parser given the terminal | |
| 376 ** look-ahead token iLookAhead. | |
| 377 ** | |
| 378 ** If the look-ahead token is YYNOCODE, then check to see if the action is | |
| 379 ** independent of the look-ahead. If it is, return the action, otherwise | |
| 380 ** return YY_NO_ACTION. | |
| 381 */ | |
| 382 static int yy_find_shift_action( | |
| 383 yyParser *pParser, /* The parser */ | |
| 384 YYCODETYPE iLookAhead /* The look-ahead token */ | |
| 385 ){ | |
| 386 int i; | |
| 387 int stateno = pParser->yystack[pParser->yyidx].stateno; | |
| 388 | |
| 389 if( stateno>YY_SHIFT_MAX || (i = yy_shift_ofst[stateno])==YY_SHIFT_USE_DFLT ){ | |
| 390 return yy_default[stateno]; | |
| 391 } | |
| 392 assert( iLookAhead!=YYNOCODE ); | |
| 393 i += iLookAhead; | |
| 394 if( i<0 || i>=YY_SZ_ACTTAB || yy_lookahead[i]!=iLookAhead ){ | |
| 395 if( iLookAhead>0 ){ | |
| 396 #ifdef YYFALLBACK | |
| 397 YYCODETYPE iFallback; /* Fallback token */ | |
| 398 if( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0]) | |
| 399 && (iFallback = yyFallback[iLookAhead])!=0 ){ | |
| 400 #ifndef NDEBUG | |
| 401 if( yyTraceFILE ){ | |
| 402 fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n", | |
| 403 yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]); | |
| 404 } | |
| 405 #endif | |
| 406 return yy_find_shift_action(pParser, iFallback); | |
| 407 } | |
| 408 #endif | |
| 409 #ifdef YYWILDCARD | |
| 410 { | |
| 411 int j = i - iLookAhead + YYWILDCARD; | |
| 412 if( j>=0 && j<YY_SZ_ACTTAB && yy_lookahead[j]==YYWILDCARD ){ | |
| 413 #ifndef NDEBUG | |
| 414 if( yyTraceFILE ){ | |
| 415 fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n", | |
| 416 yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[YYWILDCARD]); | |
| 417 } | |
| 418 #endif /* NDEBUG */ | |
| 419 return yy_action[j]; | |
| 420 } | |
| 421 } | |
| 422 #endif /* YYWILDCARD */ | |
| 423 } | |
| 424 return yy_default[stateno]; | |
| 425 }else{ | |
| 426 return yy_action[i]; | |
| 427 } | |
| 428 } | |
| 429 | |
| 430 /* | |
| 431 ** Find the appropriate action for a parser given the non-terminal | |
| 432 ** look-ahead token iLookAhead. | |
| 433 ** | |
| 434 ** If the look-ahead token is YYNOCODE, then check to see if the action is | |
| 435 ** independent of the look-ahead. If it is, return the action, otherwise | |
| 436 ** return YY_NO_ACTION. | |
| 437 */ | |
| 438 static int yy_find_reduce_action( | |
| 439 int stateno, /* Current state number */ | |
| 440 YYCODETYPE iLookAhead /* The look-ahead token */ | |
| 441 ){ | |
| 442 int i; | |
| 443 #ifdef YYERRORSYMBOL | |
| 444 if( stateno>YY_REDUCE_MAX ){ | |
| 445 return yy_default[stateno]; | |
| 446 } | |
| 447 #else | |
| 448 assert( stateno<=YY_REDUCE_MAX ); | |
| 449 #endif | |
| 450 i = yy_reduce_ofst[stateno]; | |
| 451 assert( i!=YY_REDUCE_USE_DFLT ); | |
| 452 assert( iLookAhead!=YYNOCODE ); | |
| 453 i += iLookAhead; | |
| 454 #ifdef YYERRORSYMBOL | |
| 455 if( i<0 || i>=YY_SZ_ACTTAB || yy_lookahead[i]!=iLookAhead ){ | |
| 456 return yy_default[stateno]; | |
| 457 } | |
| 458 #else | |
| 459 assert( i>=0 && i<YY_SZ_ACTTAB ); | |
| 460 assert( yy_lookahead[i]==iLookAhead ); | |
| 461 #endif | |
| 462 return yy_action[i]; | |
| 463 } | |
| 464 | |
| 465 /* | |
| 466 ** The following routine is called if the stack overflows. | |
| 467 */ | |
| 468 static void yyStackOverflow(yyParser *yypParser, YYMINORTYPE *yypMinor){ | |
| 469 ParseARG_FETCH; | |
| 470 yypParser->yyidx--; | |
| 471 #ifndef NDEBUG | |
| 472 if( yyTraceFILE ){ | |
| 473 fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt); | |
| 474 } | |
| 475 #endif | |
| 476 while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser); | |
| 477 /* Here code is inserted which will execute if the parser | |
| 478 ** stack every overflows */ | |
| 479 %% | |
| 480 ParseARG_STORE; /* Suppress warning about unused %extra_argument var */ | |
| 481 } | |
| 482 | |
| 483 /* | |
| 484 ** Perform a shift action. | |
| 485 */ | |
| 486 static void yy_shift( | |
| 487 yyParser *yypParser, /* The parser to be shifted */ | |
| 488 int yyNewState, /* The new state to shift in */ | |
| 489 int yyMajor, /* The major token to shift in */ | |
| 490 YYMINORTYPE *yypMinor /* Pointer to the minor token to shift in */ | |
| 491 ){ | |
| 492 yyStackEntry *yytos; | |
| 493 yypParser->yyidx++; | |
| 494 #ifdef YYTRACKMAXSTACKDEPTH | |
| 495 if( yypParser->yyidx>yypParser->yyidxMax ){ | |
| 496 yypParser->yyidxMax = yypParser->yyidx; | |
| 497 } | |
| 498 #endif | |
| 499 #if YYSTACKDEPTH>0 | |
| 500 if( yypParser->yyidx>=YYSTACKDEPTH ){ | |
| 501 yyStackOverflow(yypParser, yypMinor); | |
| 502 return; | |
| 503 } | |
| 504 #else | |
| 505 if( yypParser->yyidx>=yypParser->yystksz ){ | |
| 506 yyGrowStack(yypParser); | |
| 507 if( yypParser->yyidx>=yypParser->yystksz ){ | |
| 508 yyStackOverflow(yypParser, yypMinor); | |
| 509 return; | |
| 510 } | |
| 511 } | |
| 512 #endif | |
| 513 yytos = &yypParser->yystack[yypParser->yyidx]; | |
| 514 yytos->stateno = (YYACTIONTYPE)yyNewState; | |
| 515 yytos->major = (YYCODETYPE)yyMajor; | |
| 516 yytos->minor = *yypMinor; | |
| 517 #ifndef NDEBUG | |
| 518 if( yyTraceFILE && yypParser->yyidx>0 ){ | |
| 519 int i; | |
| 520 fprintf(yyTraceFILE,"%sShift %d\n",yyTracePrompt,yyNewState); | |
| 521 fprintf(yyTraceFILE,"%sStack:",yyTracePrompt); | |
| 522 for(i=1; i<=yypParser->yyidx; i++) | |
| 523 fprintf(yyTraceFILE," %s",yyTokenName[yypParser->yystack[i].major]); | |
| 524 fprintf(yyTraceFILE,"\n"); | |
| 525 } | |
| 526 #endif | |
| 527 } | |
| 528 | |
| 529 /* The following table contains information about every rule that | |
| 530 ** is used during the reduce. | |
| 531 */ | |
| 532 static const struct { | |
| 533 YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */ | |
| 534 unsigned char nrhs; /* Number of right-hand side symbols in the rule */ | |
| 535 } yyRuleInfo[] = { | |
| 536 %% | |
| 537 }; | |
| 538 | |
| 539 static void yy_accept(yyParser*); /* Forward Declaration */ | |
| 540 | |
| 541 /* | |
| 542 ** Perform a reduce action and the shift that must immediately | |
| 543 ** follow the reduce. | |
| 544 */ | |
| 545 static void yy_reduce( | |
| 546 yyParser *yypParser, /* The parser */ | |
| 547 int yyruleno /* Number of the rule by which to reduce */ | |
| 548 ){ | |
| 549 int yygoto; /* The next state */ | |
| 550 int yyact; /* The next action */ | |
| 551 YYMINORTYPE yygotominor; /* The LHS of the rule reduced */ | |
| 552 yyStackEntry *yymsp; /* The top of the parser's stack */ | |
| 553 int yysize; /* Amount to pop the stack */ | |
| 554 ParseARG_FETCH; | |
| 555 yymsp = &yypParser->yystack[yypParser->yyidx]; | |
| 556 #ifndef NDEBUG | |
| 557 if( yyTraceFILE && yyruleno>=0 | |
| 558 && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){ | |
| 559 fprintf(yyTraceFILE, "%sReduce [%s].\n", yyTracePrompt, | |
| 560 yyRuleName[yyruleno]); | |
| 561 } | |
| 562 #endif /* NDEBUG */ | |
| 563 | |
| 564 /* Silence complaints from purify about yygotominor being uninitialized | |
| 565 ** in some cases when it is copied into the stack after the following | |
| 566 ** switch. yygotominor is uninitialized when a rule reduces that does | |
| 567 ** not set the value of its left-hand side nonterminal. Leaving the | |
| 568 ** value of the nonterminal uninitialized is utterly harmless as long | |
| 569 ** as the value is never used. So really the only thing this code | |
| 570 ** accomplishes is to quieten purify. | |
| 571 ** | |
| 572 ** 2007-01-16: The wireshark project (www.wireshark.org) reports that | |
| 573 ** without this code, their parser segfaults. I'm not sure what there | |
| 574 ** parser is doing to make this happen. This is the second bug report | |
| 575 ** from wireshark this week. Clearly they are stressing Lemon in ways | |
| 576 ** that it has not been previously stressed... (SQLite ticket #2172) | |
| 577 */ | |
| 578 /*memset(&yygotominor, 0, sizeof(yygotominor));*/ | |
| 579 yygotominor = yyzerominor; | |
| 580 | |
| 581 | |
| 582 switch( yyruleno ){ | |
| 583 /* Beginning here are the reduction cases. A typical example | |
| 584 ** follows: | |
| 585 ** case 0: | |
| 586 ** #line <lineno> <grammarfile> | |
| 587 ** { ... } // User supplied code | |
| 588 ** #line <lineno> <thisfile> | |
| 589 ** break; | |
| 590 */ | |
| 591 %% | |
| 592 }; | |
| 593 yygoto = yyRuleInfo[yyruleno].lhs; | |
| 594 yysize = yyRuleInfo[yyruleno].nrhs; | |
| 595 yypParser->yyidx -= yysize; | |
| 596 yyact = yy_find_reduce_action(yymsp[-yysize].stateno,(YYCODETYPE)yygoto); | |
| 597 if( yyact < YYNSTATE ){ | |
| 598 #ifdef NDEBUG | |
| 599 /* If we are not debugging and the reduce action popped at least | |
| 600 ** one element off the stack, then we can push the new element back | |
| 601 ** onto the stack here, and skip the stack overflow test in yy_shift(). | |
| 602 ** That gives a significant speed improvement. */ | |
| 603 if( yysize ){ | |
| 604 yypParser->yyidx++; | |
| 605 yymsp -= yysize-1; | |
| 606 yymsp->stateno = (YYACTIONTYPE)yyact; | |
| 607 yymsp->major = (YYCODETYPE)yygoto; | |
| 608 yymsp->minor = yygotominor; | |
| 609 }else | |
| 610 #endif | |
| 611 { | |
| 612 yy_shift(yypParser,yyact,yygoto,&yygotominor); | |
| 613 } | |
| 614 }else{ | |
| 615 assert( yyact == YYNSTATE + YYNRULE + 1 ); | |
| 616 yy_accept(yypParser); | |
| 617 } | |
| 618 } | |
| 619 | |
| 620 /* | |
| 621 ** The following code executes when the parse fails | |
| 622 */ | |
| 623 #ifndef YYNOERRORRECOVERY | |
| 624 static void yy_parse_failed( | |
| 625 yyParser *yypParser /* The parser */ | |
| 626 ){ | |
| 627 ParseARG_FETCH; | |
| 628 #ifndef NDEBUG | |
| 629 if( yyTraceFILE ){ | |
| 630 fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt); | |
| 631 } | |
| 632 #endif | |
| 633 while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser); | |
| 634 /* Here code is inserted which will be executed whenever the | |
| 635 ** parser fails */ | |
| 636 %% | |
| 637 ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */ | |
| 638 } | |
| 639 #endif /* YYNOERRORRECOVERY */ | |
| 640 | |
| 641 /* | |
| 642 ** The following code executes when a syntax error first occurs. | |
| 643 */ | |
| 644 static void yy_syntax_error( | |
| 645 yyParser *yypParser, /* The parser */ | |
| 646 int yymajor, /* The major type of the error token */ | |
| 647 YYMINORTYPE yyminor /* The minor type of the error token */ | |
| 648 ){ | |
| 649 ParseARG_FETCH; | |
| 650 #define TOKEN (yyminor.yy0) | |
| 651 %% | |
| 652 ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */ | |
| 653 } | |
| 654 | |
| 655 /* | |
| 656 ** The following is executed when the parser accepts | |
| 657 */ | |
| 658 static void yy_accept( | |
| 659 yyParser *yypParser /* The parser */ | |
| 660 ){ | |
| 661 ParseARG_FETCH; | |
| 662 #ifndef NDEBUG | |
| 663 if( yyTraceFILE ){ | |
| 664 fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt); | |
| 665 } | |
| 666 #endif | |
| 667 while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser); | |
| 668 /* Here code is inserted which will be executed whenever the | |
| 669 ** parser accepts */ | |
| 670 %% | |
| 671 ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */ | |
| 672 } | |
| 673 | |
| 674 /* The main parser program. | |
| 675 ** The first argument is a pointer to a structure obtained from | |
| 676 ** "ParseAlloc" which describes the current state of the parser. | |
| 677 ** The second argument is the major token number. The third is | |
| 678 ** the minor token. The fourth optional argument is whatever the | |
| 679 ** user wants (and specified in the grammar) and is available for | |
| 680 ** use by the action routines. | |
| 681 ** | |
| 682 ** Inputs: | |
| 683 ** <ul> | |
| 684 ** <li> A pointer to the parser (an opaque structure.) | |
| 685 ** <li> The major token number. | |
| 686 ** <li> The minor token number. | |
| 687 ** <li> An option argument of a grammar-specified type. | |
| 688 ** </ul> | |
| 689 ** | |
| 690 ** Outputs: | |
| 691 ** None. | |
| 692 */ | |
| 693 void Parse( | |
| 694 void *yyp, /* The parser */ | |
| 695 int yymajor, /* The major token code number */ | |
| 696 ParseTOKENTYPE yyminor /* The value for the token */ | |
| 697 ParseARG_PDECL /* Optional %extra_argument parameter */ | |
| 698 ){ | |
| 699 YYMINORTYPE yyminorunion; | |
| 700 int yyact; /* The parser action. */ | |
| 701 int yyendofinput; /* True if we are at the end of input */ | |
| 702 #ifdef YYERRORSYMBOL | |
| 703 int yyerrorhit = 0; /* True if yymajor has invoked an error */ | |
| 704 #endif | |
| 705 yyParser *yypParser; /* The parser */ | |
| 706 | |
| 707 /* (re)initialize the parser, if necessary */ | |
| 708 yypParser = (yyParser*)yyp; | |
| 709 if( yypParser->yyidx<0 ){ | |
| 710 #if YYSTACKDEPTH<=0 | |
| 711 if( yypParser->yystksz <=0 ){ | |
| 712 /*memset(&yyminorunion, 0, sizeof(yyminorunion));*/ | |
| 713 yyminorunion = yyzerominor; | |
| 714 yyStackOverflow(yypParser, &yyminorunion); | |
| 715 return; | |
| 716 } | |
| 717 #endif | |
| 718 yypParser->yyidx = 0; | |
| 719 yypParser->yyerrcnt = -1; | |
| 720 yypParser->yystack[0].stateno = 0; | |
| 721 yypParser->yystack[0].major = 0; | |
| 722 } | |
| 723 yyminorunion.yy0 = yyminor; | |
| 724 yyendofinput = (yymajor==0); | |
| 725 ParseARG_STORE; | |
| 726 | |
| 727 #ifndef NDEBUG | |
| 728 if( yyTraceFILE ){ | |
| 729 fprintf(yyTraceFILE,"%sInput %s\n",yyTracePrompt,yyTokenName[yymajor]); | |
| 730 } | |
| 731 #endif | |
| 732 | |
| 733 do{ | |
| 734 yyact = yy_find_shift_action(yypParser,(YYCODETYPE)yymajor); | |
| 735 if( yyact<YYNSTATE ){ | |
| 736 assert( !yyendofinput ); /* Impossible to shift the $ token */ | |
| 737 yy_shift(yypParser,yyact,yymajor,&yyminorunion); | |
| 738 yypParser->yyerrcnt--; | |
| 739 yymajor = YYNOCODE; | |
| 740 }else if( yyact < YYNSTATE + YYNRULE ){ | |
| 741 yy_reduce(yypParser,yyact-YYNSTATE); | |
| 742 }else{ | |
| 743 assert( yyact == YY_ERROR_ACTION ); | |
| 744 #ifdef YYERRORSYMBOL | |
| 745 int yymx; | |
| 746 #endif | |
| 747 #ifndef NDEBUG | |
| 748 if( yyTraceFILE ){ | |
| 749 fprintf(yyTraceFILE,"%sSyntax Error!\n",yyTracePrompt); | |
| 750 } | |
| 751 #endif | |
| 752 #ifdef YYERRORSYMBOL | |
| 753 /* A syntax error has occurred. | |
| 754 ** The response to an error depends upon whether or not the | |
| 755 ** grammar defines an error token "ERROR". | |
| 756 ** | |
| 757 ** This is what we do if the grammar does define ERROR: | |
| 758 ** | |
| 759 ** * Call the %syntax_error function. | |
| 760 ** | |
| 761 ** * Begin popping the stack until we enter a state where | |
| 762 ** it is legal to shift the error symbol, then shift | |
| 763 ** the error symbol. | |
| 764 ** | |
| 765 ** * Set the error count to three. | |
| 766 ** | |
| 767 ** * Begin accepting and shifting new tokens. No new error | |
| 768 ** processing will occur until three tokens have been | |
| 769 ** shifted successfully. | |
| 770 ** | |
| 771 */ | |
| 772 if( yypParser->yyerrcnt<0 ){ | |
| 773 yy_syntax_error(yypParser,yymajor,yyminorunion); | |
| 774 } | |
| 775 yymx = yypParser->yystack[yypParser->yyidx].major; | |
| 776 if( yymx==YYERRORSYMBOL || yyerrorhit ){ | |
| 777 #ifndef NDEBUG | |
| 778 if( yyTraceFILE ){ | |
| 779 fprintf(yyTraceFILE,"%sDiscard input token %s\n", | |
| 780 yyTracePrompt,yyTokenName[yymajor]); | |
| 781 } | |
| 782 #endif | |
| 783 yy_destructor(yypParser, (YYCODETYPE)yymajor,&yyminorunion); | |
| 784 yymajor = YYNOCODE; | |
| 785 }else{ | |
| 786 while( | |
| 787 yypParser->yyidx >= 0 && | |
| 788 yymx != YYERRORSYMBOL && | |
| 789 (yyact = yy_find_reduce_action( | |
| 790 yypParser->yystack[yypParser->yyidx].stateno, | |
| 791 YYERRORSYMBOL)) >= YYNSTATE | |
| 792 ){ | |
| 793 yy_pop_parser_stack(yypParser); | |
| 794 } | |
| 795 if( yypParser->yyidx < 0 || yymajor==0 ){ | |
| 796 yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion); | |
| 797 yy_parse_failed(yypParser); | |
| 798 yymajor = YYNOCODE; | |
| 799 }else if( yymx!=YYERRORSYMBOL ){ | |
| 800 YYMINORTYPE u2; | |
| 801 u2.YYERRSYMDT = 0; | |
| 802 yy_shift(yypParser,yyact,YYERRORSYMBOL,&u2); | |
| 803 } | |
| 804 } | |
| 805 yypParser->yyerrcnt = 3; | |
| 806 yyerrorhit = 1; | |
| 807 #elif defined(YYNOERRORRECOVERY) | |
| 808 /* If the YYNOERRORRECOVERY macro is defined, then do not attempt to | |
| 809 ** do any kind of error recovery. Instead, simply invoke the syntax | |
| 810 ** error routine and continue going as if nothing had happened. | |
| 811 ** | |
| 812 ** Applications can set this macro (for example inside %include) if | |
| 813 ** they intend to abandon the parse upon the first syntax error seen. | |
| 814 */ | |
| 815 yy_syntax_error(yypParser,yymajor,yyminorunion); | |
| 816 yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion); | |
| 817 yymajor = YYNOCODE; | |
| 818 | |
| 819 #else /* YYERRORSYMBOL is not defined */ | |
| 820 /* This is what we do if the grammar does not define ERROR: | |
| 821 ** | |
| 822 ** * Report an error message, and throw away the input token. | |
| 823 ** | |
| 824 ** * If the input token is $, then fail the parse. | |
| 825 ** | |
| 826 ** As before, subsequent error messages are suppressed until | |
| 827 ** three input tokens have been successfully shifted. | |
| 828 */ | |
| 829 if( yypParser->yyerrcnt<=0 ){ | |
| 830 yy_syntax_error(yypParser,yymajor,yyminorunion); | |
| 831 } | |
| 832 yypParser->yyerrcnt = 3; | |
| 833 yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion); | |
| 834 if( yyendofinput ){ | |
| 835 yy_parse_failed(yypParser); | |
| 836 } | |
| 837 yymajor = YYNOCODE; | |
| 838 #endif | |
| 839 } | |
| 840 }while( yymajor!=YYNOCODE && yypParser->yyidx>=0 ); | |
| 841 return; | |
| 842 } | |
| OLD | NEW |