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