Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Side by Side Diff: third_party/sqlite/src/lempar.c

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

Powered by Google App Engine
This is Rietveld 408576698