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