interplane.Get Omega
Read in your language

sqlite

[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.

Brought by drakestapleton

branch master Branches Tags History

sqlite / tool / lempar.c

1097 lines · 37398 bytes Raw Blame History
1/*
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" identifier 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 generated parser
20** source file.
21**
22** The following is the concatenation of all %include directives from the
23** input grammar file:
24*/
25/************ Begin %include sections from the grammar ************************/
26%%
27/**************** End of %include directives **********************************/
28/* These constants specify the various numeric values for terminal symbols.
29***************** Begin token definitions *************************************/
30%%
31/**************** End token definitions ***************************************/
32
33/* The next sections is a series of control #defines.
34** various aspects of the generated parser.
35** YYCODETYPE is the data type used to store the integer codes
36** that represent terminal and non-terminal symbols.
37** "unsigned char" is used if there are fewer than
38** 256 symbols. Larger types otherwise.
39** YYNOCODE is a number of type YYCODETYPE that is not used for
40** any terminal or nonterminal symbol.
41** YYFALLBACK If defined, this indicates that one or more tokens
42** (also known as: "terminal symbols") have fall-back
43** values which should be used if the original symbol
44** would not parse. This permits keywords to sometimes
45** be used as identifiers, for example.
46** YYACTIONTYPE is the data type used for "action codes" - numbers
47** that indicate what to do in response to the next
48** token.
49** ParseTOKENTYPE is the data type used for minor type for terminal
50** symbols. Background: A "minor type" is a semantic
51** value associated with a terminal or non-terminal
52** symbols. For example, for an "ID" terminal symbol,
53** the minor type might be the name of the identifier.
54** Each non-terminal can have a different minor type.
55** Terminal symbols all have the same minor type, though.
56** This macros defines the minor type for terminal
57** symbols.
58** YYMINORTYPE is the data type used for all minor types.
59** This is typically a union of many types, one of
60** which is ParseTOKENTYPE. The entry in the union
61** for terminal symbols is called "yy0".
62** YYSTACKDEPTH is the maximum depth of the parser's stack. If
63** zero the stack is dynamically sized using realloc()
64** ParseARG_SDECL A static variable declaration for the %extra_argument
65** ParseARG_PDECL A parameter declaration for the %extra_argument
66** ParseARG_PARAM Code to pass %extra_argument as a subroutine parameter
67** ParseARG_STORE Code to store %extra_argument into yypParser
68** ParseARG_FETCH Code to extract %extra_argument from yypParser
69** ParseCTX_* As ParseARG_ except for %extra_context
70** YYREALLOC Name of the realloc() function to use
71** YYFREE Name of the free() function to use
72** YYDYNSTACK True if stack space should be extended on heap
73** YYERRORSYMBOL is the code number of the error symbol. If not
74** defined, then do no error processing.
75** YYNSTATE the combined number of states.
76** YYNRULE the number of rules in the grammar
77** YYNTOKEN Number of terminal symbols
78** YY_MAX_SHIFT Maximum value for shift actions
79** YY_MIN_SHIFTREDUCE Minimum value for shift-reduce actions
80** YY_MAX_SHIFTREDUCE Maximum value for shift-reduce actions
81** YY_ERROR_ACTION The yy_action[] code for syntax error
82** YY_ACCEPT_ACTION The yy_action[] code for accept
83** YY_NO_ACTION The yy_action[] code for no-op
84** YY_MIN_REDUCE Minimum value for reduce actions
85** YY_MAX_REDUCE Maximum value for reduce actions
86** YY_MIN_DSTRCTR Minimum symbol value that has a destructor
87** YY_MAX_DSTRCTR Maximum symbol value that has a destructor
88*/
89#ifndef INTERFACE
90# define INTERFACE 1
91#endif
92/************* Begin control #defines *****************************************/
93%%
94/************* End control #defines *******************************************/
95#define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0])))
96
97/* Define the yytestcase() macro to be a no-op if is not already defined
98** otherwise.
99**
100** Applications can choose to define yytestcase() in the %include section
101** to a macro that can assist in verifying code coverage. For production
102** code the yytestcase() macro should be turned off. But it is useful
103** for testing.
104*/
105#ifndef yytestcase
106# define yytestcase(X)
107#endif
108
109/* Macro to determine if stack space has the ability to grow using
110** heap memory.
111*/
112#if YYSTACKDEPTH<=0 || YYDYNSTACK
113# define YYGROWABLESTACK 1
114#else
115# define YYGROWABLESTACK 0
116#endif
117
118/* Guarantee a minimum number of initial stack slots.
119*/
120#if YYSTACKDEPTH<=0
121# undef YYSTACKDEPTH
122# define YYSTACKDEPTH 2 /* Need a minimum stack size */
123#endif
124
125
126/* Next are the tables used to determine what action to take based on the
127** current state and lookahead token. These tables are used to implement
128** functions that take a state number and lookahead value and return an
129** action integer.
130**
131** Suppose the action integer is N. Then the action is determined as
132** follows
133**
134** 0 <= N <= YY_MAX_SHIFT Shift N. That is, push the lookahead
135** token onto the stack and goto state N.
136**
137** N between YY_MIN_SHIFTREDUCE Shift to an arbitrary state then
138** and YY_MAX_SHIFTREDUCE reduce by rule N-YY_MIN_SHIFTREDUCE.
139**
140** N == YY_ERROR_ACTION A syntax error has occurred.
141**
142** N == YY_ACCEPT_ACTION The parser accepts its input.
143**
144** N == YY_NO_ACTION No such action. Denotes unused
145** slots in the yy_action[] table.
146**
147** N between YY_MIN_REDUCE Reduce by rule N-YY_MIN_REDUCE
148** and YY_MAX_REDUCE
149**
150** The action table is constructed as a single large table named yy_action[].
151** Given state S and lookahead X, the action is computed as either:
152**
153** (A) N = yy_action[ yy_shift_ofst[S] + X ]
154** (B) N = yy_default[S]
155**
156** The (A) formula is preferred. The B formula is used instead if
157** yy_lookahead[yy_shift_ofst[S]+X] is not equal to X.
158**
159** The formulas above are for computing the action when the lookahead is
160** a terminal symbol. If the lookahead is a non-terminal (as occurs after
161** a reduce action) then the yy_reduce_ofst[] array is used in place of
162** the yy_shift_ofst[] array.
163**
164** The following are the tables generated in this section:
165**
166** yy_action[] A single table containing all actions.
167** yy_lookahead[] A table containing the lookahead for each entry in
168** yy_action. Used to detect hash collisions.
169** yy_shift_ofst[] For each state, the offset into yy_action for
170** shifting terminals.
171** yy_reduce_ofst[] For each state, the offset into yy_action for
172** shifting non-terminals after a reduce.
173** yy_default[] Default action for each state.
174**
175*********** Begin parsing tables **********************************************/
176%%
177/********** End of lemon-generated parsing tables *****************************/
178
179/* The next table maps tokens (terminal symbols) into fallback tokens.
180** If a construct like the following:
181**
182** %fallback ID X Y Z.
183**
184** appears in the grammar, then ID becomes a fallback token for X, Y,
185** and Z. Whenever one of the tokens X, Y, or Z is input to the parser
186** but it does not parse, the type of the token is changed to ID and
187** the parse is retried before an error is thrown.
188**
189** This feature can be used, for example, to cause some keywords in a language
190** to revert to identifiers if they keyword does not apply in the context where
191** it appears.
192*/
193#ifdef YYFALLBACK
194static const YYCODETYPE yyFallback[] = {
195%%
196};
197#endif /* YYFALLBACK */
198
199/* The following structure represents a single element of the
200** parser's stack. Information stored includes:
201**
202** + The state number for the parser at this level of the stack.
203**
204** + The value of the token stored at this level of the stack.
205** (In other words, the "major" token.)
206**
207** + The semantic value stored at this level of the stack. This is
208** the information used by the action routines in the grammar.
209** It is sometimes called the "minor" token.
210**
211** After the "shift" half of a SHIFTREDUCE action, the stateno field
212** actually contains the reduce action for the second half of the
213** SHIFTREDUCE.
214*/
215struct yyStackEntry {
216 YYACTIONTYPE stateno; /* The state-number, or reduce action in SHIFTREDUCE */
217 YYCODETYPE major; /* The major token value. This is the code
218 ** number for the token at this stack level */
219 YYMINORTYPE minor; /* The user-supplied minor token value. This
220 ** is the value of the token */
221};
222typedef struct yyStackEntry yyStackEntry;
223
224/* The state of the parser is completely contained in an instance of
225** the following structure */
226struct yyParser {
227 yyStackEntry *yytos; /* Pointer to top element of the stack */
228#ifdef YYTRACKMAXSTACKDEPTH
229 int yyhwm; /* High-water mark of the stack */
230#endif
231#ifndef YYNOERRORRECOVERY
232 int yyerrcnt; /* Shifts left before out of the error */
233#endif
234 ParseARG_SDECL /* A place to hold %extra_argument */
235 ParseCTX_SDECL /* A place to hold %extra_context */
236 yyStackEntry *yystackEnd; /* Last entry in the stack */
237 yyStackEntry *yystack; /* The parser stack */
238 yyStackEntry yystk0[YYSTACKDEPTH]; /* Initial stack space */
239};
240typedef struct yyParser yyParser;
241
242#include <assert.h>
243#ifndef NDEBUG
244#include <stdio.h>
245static FILE *yyTraceFILE = 0;
246static char *yyTracePrompt = 0;
247#endif /* NDEBUG */
248
249#ifndef NDEBUG
250/*
251** Turn parser tracing on by giving a stream to which to write the trace
252** and a prompt to preface each trace message. Tracing is turned off
253** by making either argument NULL
254**
255** Inputs:
256** <ul>
257** <li> A FILE* to which trace output should be written.
258** If NULL, then tracing is turned off.
259** <li> A prefix string written at the beginning of every
260** line of trace output. If NULL, then tracing is
261** turned off.
262** </ul>
263**
264** Outputs:
265** None.
266*/
267void ParseTrace(FILE *TraceFILE, char *zTracePrompt){
268 yyTraceFILE = TraceFILE;
269 yyTracePrompt = zTracePrompt;
270 if( yyTraceFILE==0 ) yyTracePrompt = 0;
271 else if( yyTracePrompt==0 ) yyTraceFILE = 0;
272}
273#endif /* NDEBUG */
274
275#if defined(YYCOVERAGE) || !defined(NDEBUG)
276/* For tracing shifts, the names of all terminals and nonterminals
277** are required. The following table supplies these names */
278static const char *const yyTokenName[] = {
279%%
280};
281#endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */
282
283#ifndef NDEBUG
284/* For tracing reduce actions, the names of all rules are required.
285*/
286static const char *const yyRuleName[] = {
287%%
288};
289#endif /* NDEBUG */
290
291
292#if YYGROWABLESTACK
293/*
294** Try to increase the size of the parser stack. Return the number
295** of errors. Return 0 on success.
296*/
297static int yyGrowStack(yyParser *p){
298 int oldSize = 1 + (int)(p->yystackEnd - p->yystack);
299 int newSize;
300 int idx;
301 yyStackEntry *pNew;
302#ifdef YYSIZELIMIT
303 int nLimit = YYSIZELIMIT(ParseCTX(p));
304#endif
305
306 newSize = oldSize*2 + 100;
307#ifdef YYSIZELIMIT
308 if( newSize>nLimit ){
309 newSize = nLimit;
310 if( newSize<=oldSize ) return 1;
311 }
312#endif
313 idx = (int)(p->yytos - p->yystack);
314 if( p->yystack==p->yystk0 ){
315 pNew = YYREALLOC(0, newSize*sizeof(pNew[0]), ParseCTX(p));
316 if( pNew==0 ) return 1;
317 memcpy(pNew, p->yystack, oldSize*sizeof(pNew[0]));
318 }else{
319 pNew = YYREALLOC(p->yystack, newSize*sizeof(pNew[0]), ParseCTX(p));
320 if( pNew==0 ) return 1;
321 }
322 p->yystack = pNew;
323 p->yytos = &p->yystack[idx];
324#ifndef NDEBUG
325 if( yyTraceFILE ){
326 fprintf(yyTraceFILE,"%sStack grows from %d to %d entries.\n",
327 yyTracePrompt, oldSize, newSize);
328 }
329#endif
330 p->yystackEnd = &p->yystack[newSize-1];
331 return 0;
332}
333#endif /* YYGROWABLESTACK */
334
335#if !YYGROWABLESTACK
336/* For builds that do no have a growable stack, yyGrowStack always
337** returns an error.
338*/
339# define yyGrowStack(X) 1
340#endif
341
342/* Datatype of the argument to the memory allocated passed as the
343** second argument to ParseAlloc() below. This can be changed by
344** putting an appropriate #define in the %include section of the input
345** grammar.
346*/
347#ifndef YYMALLOCARGTYPE
348# define YYMALLOCARGTYPE size_t
349#endif
350
351/* Initialize a new parser that has already been allocated.
352*/
353void ParseInit(void *yypRawParser ParseCTX_PDECL){
354 yyParser *yypParser = (yyParser*)yypRawParser;
355 ParseCTX_STORE
356#ifdef YYTRACKMAXSTACKDEPTH
357 yypParser->yyhwm = 0;
358#endif
359 yypParser->yystack = yypParser->yystk0;
360 yypParser->yystackEnd = &yypParser->yystack[YYSTACKDEPTH-1];
361#ifndef YYNOERRORRECOVERY
362 yypParser->yyerrcnt = -1;
363#endif
364 yypParser->yytos = yypParser->yystack;
365 yypParser->yystack[0].stateno = 0;
366 yypParser->yystack[0].major = 0;
367}
368
369#ifndef Parse_ENGINEALWAYSONSTACK
370/*
371** This function allocates a new parser.
372** The only argument is a pointer to a function which works like
373** malloc.
374**
375** Inputs:
376** A pointer to the function used to allocate memory.
377**
378** Outputs:
379** A pointer to a parser. This pointer is used in subsequent calls
380** to Parse and ParseFree.
381*/
382void *ParseAlloc(void *(*mallocProc)(YYMALLOCARGTYPE) ParseCTX_PDECL){
383 yyParser *yypParser;
384 yypParser = (yyParser*)(*mallocProc)( (YYMALLOCARGTYPE)sizeof(yyParser) );
385 if( yypParser ){
386 ParseCTX_STORE
387 ParseInit(yypParser ParseCTX_PARAM);
388 }
389 return (void*)yypParser;
390}
391#endif /* Parse_ENGINEALWAYSONSTACK */
392
393
394/* The following function deletes the "minor type" or semantic value
395** associated with a symbol. The symbol can be either a terminal
396** or nonterminal. "yymajor" is the symbol code, and "yypminor" is
397** a pointer to the value to be deleted. The code used to do the
398** deletions is derived from the %destructor and/or %token_destructor
399** directives of the input grammar.
400*/
401static void yy_destructor(
402 yyParser *yypParser, /* The parser */
403 YYCODETYPE yymajor, /* Type code for object to destroy */
404 YYMINORTYPE *yypminor /* The object to be destroyed */
405){
406 ParseARG_FETCH
407 ParseCTX_FETCH
408 switch( yymajor ){
409 /* Here is inserted the actions which take place when a
410 ** terminal or non-terminal is destroyed. This can happen
411 ** when the symbol is popped from the stack during a
412 ** reduce or during error processing or when a parser is
413 ** being destroyed before it is finished parsing.
414 **
415 ** Note: during a reduce, the only symbols destroyed are those
416 ** which appear on the RHS of the rule, but which are *not* used
417 ** inside the C code.
418 */
419/********* Begin destructor definitions ***************************************/
420%%
421/********* End destructor definitions *****************************************/
422 default: break; /* If no destructor action specified: do nothing */
423 }
424}
425
426/*
427** Pop the parser's stack once.
428**
429** If there is a destructor routine associated with the token which
430** is popped from the stack, then call it.
431*/
432static void yy_pop_parser_stack(yyParser *pParser){
433 yyStackEntry *yytos;
434 assert( pParser->yytos!=0 );
435 assert( pParser->yytos > pParser->yystack );
436 yytos = pParser->yytos--;
437#ifndef NDEBUG
438 if( yyTraceFILE ){
439 fprintf(yyTraceFILE,"%sPopping %s\n",
440 yyTracePrompt,
441 yyTokenName[yytos->major]);
442 }
443#endif
444 yy_destructor(pParser, yytos->major, &yytos->minor);
445}
446
447/*
448** Clear all secondary memory allocations from the parser
449*/
450void ParseFinalize(void *p){
451 yyParser *pParser = (yyParser*)p;
452
453 /* In-lined version of calling yy_pop_parser_stack() for each
454 ** element left in the stack */
455 yyStackEntry *yytos = pParser->yytos;
456 while( yytos>pParser->yystack ){
457#ifndef NDEBUG
458 if( yyTraceFILE ){
459 fprintf(yyTraceFILE,"%sPopping %s\n",
460 yyTracePrompt,
461 yyTokenName[yytos->major]);
462 }
463#endif
464 if( yytos->major>=YY_MIN_DSTRCTR ){
465 yy_destructor(pParser, yytos->major, &yytos->minor);
466 }
467 yytos--;
468 }
469
470#if YYGROWABLESTACK
471 if( pParser->yystack!=pParser->yystk0 ){
472 YYFREE(pParser->yystack, ParseCTX(pParser));
473 }
474#endif
475}
476
477#ifndef Parse_ENGINEALWAYSONSTACK
478/*
479** Deallocate and destroy a parser. Destructors are called for
480** all stack elements before shutting the parser down.
481**
482** If the YYPARSEFREENEVERNULL macro exists (for example because it
483** is defined in a %include section of the input grammar) then it is
484** assumed that the input pointer is never NULL.
485*/
486void ParseFree(
487 void *p, /* The parser to be deleted */
488 void (*freeProc)(void*) /* Function used to reclaim memory */
489){
490#ifndef YYPARSEFREENEVERNULL
491 if( p==0 ) return;
492#endif
493 ParseFinalize(p);
494 (*freeProc)(p);
495}
496#endif /* Parse_ENGINEALWAYSONSTACK */
497
498/*
499** Return the peak depth of the stack for a parser.
500*/
501#ifdef YYTRACKMAXSTACKDEPTH
502int ParseStackPeak(void *p){
503 yyParser *pParser = (yyParser*)p;
504 return pParser->yyhwm;
505}
506#endif
507
508/* This array of booleans keeps track of the parser statement
509** coverage. The element yycoverage[X][Y] is set when the parser
510** is in state X and has a lookahead token Y. In a well-tested
511** systems, every element of this matrix should end up being set.
512*/
513#if defined(YYCOVERAGE)
514static unsigned char yycoverage[YYNSTATE][YYNTOKEN];
515#endif
516
517/*
518** Write into out a description of every state/lookahead combination that
519**
520** (1) has not been used by the parser, and
521** (2) is not a syntax error.
522**
523** Return the number of missed state/lookahead combinations.
524*/
525#if defined(YYCOVERAGE)
526int ParseCoverage(FILE *out){
527 int stateno, iLookAhead, i;
528 int nMissed = 0;
529 for(stateno=0; stateno<YYNSTATE; stateno++){
530 i = yy_shift_ofst[stateno];
531 for(iLookAhead=0; iLookAhead<YYNTOKEN; iLookAhead++){
532 if( yy_lookahead[i+iLookAhead]!=iLookAhead ) continue;
533 if( yycoverage[stateno][iLookAhead]==0 ) nMissed++;
534 if( out ){
535 fprintf(out,"State %d lookahead %s %s\n", stateno,
536 yyTokenName[iLookAhead],
537 yycoverage[stateno][iLookAhead] ? "ok" : "missed");
538 }
539 }
540 }
541 return nMissed;
542}
543#endif
544
545/*
546** Find the appropriate action for a parser given the terminal
547** look-ahead token iLookAhead.
548*/
549static YYACTIONTYPE yy_find_shift_action(
550 YYCODETYPE iLookAhead, /* The look-ahead token */
551 YYACTIONTYPE stateno /* Current state number */
552){
553 int i;
554
555 if( stateno>YY_MAX_SHIFT ) return stateno;
556 assert( stateno <= YY_SHIFT_COUNT );
557#if defined(YYCOVERAGE)
558 yycoverage[stateno][iLookAhead] = 1;
559#endif
560 do{
561 i = yy_shift_ofst[stateno];
562 assert( i>=0 );
563 assert( i<=YY_ACTTAB_COUNT );
564 assert( i+YYNTOKEN<=(int)YY_NLOOKAHEAD );
565 assert( iLookAhead!=YYNOCODE );
566 assert( iLookAhead < YYNTOKEN );
567 i += iLookAhead;
568 assert( i<(int)YY_NLOOKAHEAD );
569 if( yy_lookahead[i]!=iLookAhead ){
570#ifdef YYFALLBACK
571 YYCODETYPE iFallback; /* Fallback token */
572 assert( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0]) );
573 iFallback = yyFallback[iLookAhead];
574 if( iFallback!=0 ){
575#ifndef NDEBUG
576 if( yyTraceFILE ){
577 fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n",
578 yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]);
579 }
580#endif
581 assert( yyFallback[iFallback]==0 ); /* Fallback loop must terminate */
582 iLookAhead = iFallback;
583 continue;
584 }
585#endif
586#ifdef YYWILDCARD
587 {
588 int j = i - iLookAhead + YYWILDCARD;
589 assert( j<(int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0])) );
590 if( yy_lookahead[j]==YYWILDCARD && iLookAhead>0 ){
591#ifndef NDEBUG
592 if( yyTraceFILE ){
593 fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n",
594 yyTracePrompt, yyTokenName[iLookAhead],
595 yyTokenName[YYWILDCARD]);
596 }
597#endif /* NDEBUG */
598 return yy_action[j];
599 }
600 }
601#endif /* YYWILDCARD */
602 return yy_default[stateno];
603 }else{
604 assert( i>=0 && i<(int)(sizeof(yy_action)/sizeof(yy_action[0])) );
605 return yy_action[i];
606 }
607 }while(1);
608}
609
610/*
611** Find the appropriate action for a parser given the non-terminal
612** look-ahead token iLookAhead.
613*/
614static YYACTIONTYPE yy_find_reduce_action(
615 YYACTIONTYPE stateno, /* Current state number */
616 YYCODETYPE iLookAhead /* The look-ahead token */
617){
618 int i;
619#ifdef YYERRORSYMBOL
620 if( stateno>YY_REDUCE_COUNT ){
621 return yy_default[stateno];
622 }
623#else
624 assert( stateno<=YY_REDUCE_COUNT );
625#endif
626 i = yy_reduce_ofst[stateno];
627 assert( iLookAhead!=YYNOCODE );
628 i += iLookAhead;
629#ifdef YYERRORSYMBOL
630 if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){
631 return yy_default[stateno];
632 }
633#else
634 assert( i>=0 && i<YY_ACTTAB_COUNT );
635 assert( yy_lookahead[i]==iLookAhead );
636#endif
637 return yy_action[i];
638}
639
640/*
641** The following routine is called if the stack overflows.
642*/
643static void yyStackOverflow(yyParser *yypParser){
644 ParseARG_FETCH
645 ParseCTX_FETCH
646#ifndef NDEBUG
647 if( yyTraceFILE ){
648 fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt);
649 }
650#endif
651 while( yypParser->yytos>yypParser->yystack ) yy_pop_parser_stack(yypParser);
652 /* Here code is inserted which will execute if the parser
653 ** stack every overflows */
654/******** Begin %stack_overflow code ******************************************/
655%%
656/******** End %stack_overflow code ********************************************/
657 ParseARG_STORE /* Suppress warning about unused %extra_argument var */
658 ParseCTX_STORE
659}
660
661/*
662** Print tracing information for a SHIFT action
663*/
664#ifndef NDEBUG
665static void yyTraceShift(yyParser *yypParser, int yyNewState, const char *zTag){
666 if( yyTraceFILE ){
667 if( yyNewState<YYNSTATE ){
668 fprintf(yyTraceFILE,"%s%s '%s', go to state %d\n",
669 yyTracePrompt, zTag, yyTokenName[yypParser->yytos->major],
670 yyNewState);
671 }else{
672 fprintf(yyTraceFILE,"%s%s '%s', pending reduce %d\n",
673 yyTracePrompt, zTag, yyTokenName[yypParser->yytos->major],
674 yyNewState - YY_MIN_REDUCE);
675 }
676 }
677}
678#else
679# define yyTraceShift(X,Y,Z)
680#endif
681
682/*
683** Perform a shift action.
684*/
685static void yy_shift(
686 yyParser *yypParser, /* The parser to be shifted */
687 YYACTIONTYPE yyNewState, /* The new state to shift in */
688 YYCODETYPE yyMajor, /* The major token to shift in */
689 ParseTOKENTYPE yyMinor /* The minor token to shift in */
690){
691 yyStackEntry *yytos;
692 yypParser->yytos++;
693#ifdef YYTRACKMAXSTACKDEPTH
694 if( (int)(yypParser->yytos - yypParser->yystack)>yypParser->yyhwm ){
695 yypParser->yyhwm++;
696 assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack) );
697 }
698#endif
699 yytos = yypParser->yytos;
700 if( yytos>yypParser->yystackEnd ){
701 if( yyGrowStack(yypParser) ){
702 yypParser->yytos--;
703 yyStackOverflow(yypParser);
704 return;
705 }
706 yytos = yypParser->yytos;
707 assert( yytos <= yypParser->yystackEnd );
708 }
709 if( yyNewState > YY_MAX_SHIFT ){
710 yyNewState += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE;
711 }
712 yytos->stateno = yyNewState;
713 yytos->major = yyMajor;
714 yytos->minor.yy0 = yyMinor;
715 yyTraceShift(yypParser, yyNewState, "Shift");
716}
717
718/* For rule J, yyRuleInfoLhs[J] contains the symbol on the left-hand side
719** of that rule */
720static const YYCODETYPE yyRuleInfoLhs[] = {
721%%
722};
723
724/* For rule J, yyRuleInfoNRhs[J] contains the negative of the number
725** of symbols on the right-hand side of that rule. */
726static const signed char yyRuleInfoNRhs[] = {
727%%
728};
729
730static void yy_accept(yyParser*); /* Forward Declaration */
731
732/*
733** Perform a reduce action and the shift that must immediately
734** follow the reduce.
735**
736** The yyLookahead and yyLookaheadToken parameters provide reduce actions
737** access to the lookahead token (if any). The yyLookahead will be YYNOCODE
738** if the lookahead token has already been consumed. As this procedure is
739** only called from one place, optimizing compilers will in-line it, which
740** means that the extra parameters have no performance impact.
741*/
742static YYACTIONTYPE yy_reduce(
743 yyParser *yypParser, /* The parser */
744 unsigned int yyruleno, /* Number of the rule by which to reduce */
745 int yyLookahead, /* Lookahead token, or YYNOCODE if none */
746 ParseTOKENTYPE yyLookaheadToken /* Value of the lookahead token */
747 ParseCTX_PDECL /* %extra_context */
748){
749 int yygoto; /* The next state */
750 YYACTIONTYPE yyact; /* The next action */
751 yyStackEntry *yymsp; /* The top of the parser's stack */
752 int yysize; /* Amount to pop the stack */
753 ParseARG_FETCH
754 (void)yyLookahead;
755 (void)yyLookaheadToken;
756 yymsp = yypParser->yytos;
757
758 switch( yyruleno ){
759 /* Beginning here are the reduction cases. A typical example
760 ** follows:
761 ** case 0:
762 ** #line <lineno> <grammarfile>
763 ** { ... } // User supplied code
764 ** #line <lineno> <thisfile>
765 ** break;
766 */
767/********** Begin reduce actions **********************************************/
768%%
769/********** End reduce actions ************************************************/
770 };
771 assert( yyruleno<sizeof(yyRuleInfoLhs)/sizeof(yyRuleInfoLhs[0]) );
772 yygoto = yyRuleInfoLhs[yyruleno];
773 yysize = yyRuleInfoNRhs[yyruleno];
774 yyact = yy_find_reduce_action(yymsp[yysize].stateno,(YYCODETYPE)yygoto);
775
776 /* There are no SHIFTREDUCE actions on nonterminals because the table
777 ** generator has simplified them to pure REDUCE actions. */
778 assert( !(yyact>YY_MAX_SHIFT && yyact<=YY_MAX_SHIFTREDUCE) );
779
780 /* It is not possible for a REDUCE to be followed by an error */
781 assert( yyact!=YY_ERROR_ACTION );
782
783 yymsp += yysize+1;
784 yypParser->yytos = yymsp;
785 yymsp->stateno = (YYACTIONTYPE)yyact;
786 yymsp->major = (YYCODETYPE)yygoto;
787 yyTraceShift(yypParser, yyact, "... then shift");
788 return yyact;
789}
790
791/*
792** The following code executes when the parse fails
793*/
794#ifndef YYNOERRORRECOVERY
795static void yy_parse_failed(
796 yyParser *yypParser /* The parser */
797){
798 ParseARG_FETCH
799 ParseCTX_FETCH
800#ifndef NDEBUG
801 if( yyTraceFILE ){
802 fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt);
803 }
804#endif
805 while( yypParser->yytos>yypParser->yystack ) yy_pop_parser_stack(yypParser);
806 /* Here code is inserted which will be executed whenever the
807 ** parser fails */
808/************ Begin %parse_failure code ***************************************/
809%%
810/************ End %parse_failure code *****************************************/
811 ParseARG_STORE /* Suppress warning about unused %extra_argument variable */
812 ParseCTX_STORE
813}
814#endif /* YYNOERRORRECOVERY */
815
816/*
817** The following code executes when a syntax error first occurs.
818*/
819static void yy_syntax_error(
820 yyParser *yypParser, /* The parser */
821 int yymajor, /* The major type of the error token */
822 ParseTOKENTYPE yyminor /* The minor type of the error token */
823){
824 ParseARG_FETCH
825 ParseCTX_FETCH
826#define TOKEN yyminor
827/************ Begin %syntax_error code ****************************************/
828%%
829/************ End %syntax_error code ******************************************/
830 ParseARG_STORE /* Suppress warning about unused %extra_argument variable */
831 ParseCTX_STORE
832}
833
834/*
835** The following is executed when the parser accepts
836*/
837static void yy_accept(
838 yyParser *yypParser /* The parser */
839){
840 ParseARG_FETCH
841 ParseCTX_FETCH
842#ifndef NDEBUG
843 if( yyTraceFILE ){
844 fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt);
845 }
846#endif
847#ifndef YYNOERRORRECOVERY
848 yypParser->yyerrcnt = -1;
849#endif
850 assert( yypParser->yytos==yypParser->yystack );
851 /* Here code is inserted which will be executed whenever the
852 ** parser accepts */
853/*********** Begin %parse_accept code *****************************************/
854%%
855/*********** End %parse_accept code *******************************************/
856 ParseARG_STORE /* Suppress warning about unused %extra_argument variable */
857 ParseCTX_STORE
858}
859
860/* The main parser program.
861** The first argument is a pointer to a structure obtained from
862** "ParseAlloc" which describes the current state of the parser.
863** The second argument is the major token number. The third is
864** the minor token. The fourth optional argument is whatever the
865** user wants (and specified in the grammar) and is available for
866** use by the action routines.
867**
868** Inputs:
869** <ul>
870** <li> A pointer to the parser (an opaque structure.)
871** <li> The major token number.
872** <li> The minor token number.
873** <li> An option argument of a grammar-specified type.
874** </ul>
875**
876** Outputs:
877** None.
878*/
879void Parse(
880 void *yyp, /* The parser */
881 int yymajor, /* The major token code number */
882 ParseTOKENTYPE yyminor /* The value for the token */
883 ParseARG_PDECL /* Optional %extra_argument parameter */
884){
885 YYMINORTYPE yyminorunion;
886 YYACTIONTYPE yyact; /* The parser action. */
887#if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY)
888 int yyendofinput; /* True if we are at the end of input */
889#endif
890#ifdef YYERRORSYMBOL
891 int yyerrorhit = 0; /* True if yymajor has invoked an error */
892#endif
893 yyParser *yypParser = (yyParser*)yyp; /* The parser */
894 ParseCTX_FETCH
895 ParseARG_STORE
896
897 assert( yypParser->yytos!=0 );
898#if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY)
899 yyendofinput = (yymajor==0);
900#endif
901
902 yyact = yypParser->yytos->stateno;
903#ifndef NDEBUG
904 if( yyTraceFILE ){
905 if( yyact < YY_MIN_REDUCE ){
906 fprintf(yyTraceFILE,"%sInput '%s' in state %d\n",
907 yyTracePrompt,yyTokenName[yymajor],yyact);
908 }else{
909 fprintf(yyTraceFILE,"%sInput '%s' with pending reduce %d\n",
910 yyTracePrompt,yyTokenName[yymajor],yyact-YY_MIN_REDUCE);
911 }
912 }
913#endif
914
915 while(1){ /* Exit by "break" */
916 assert( yypParser->yytos>=yypParser->yystack );
917 assert( yyact==yypParser->yytos->stateno );
918 yyact = yy_find_shift_action((YYCODETYPE)yymajor,yyact);
919 if( yyact >= YY_MIN_REDUCE ){
920 unsigned int yyruleno = yyact - YY_MIN_REDUCE; /* Reduce by this rule */
921#ifndef NDEBUG
922 assert( yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) );
923 if( yyTraceFILE ){
924 int yysize = yyRuleInfoNRhs[yyruleno];
925 if( yysize ){
926 fprintf(yyTraceFILE, "%sReduce %d [%s]%s, pop back to state %d.\n",
927 yyTracePrompt,
928 yyruleno, yyRuleName[yyruleno],
929 yyruleno<YYNRULE_WITH_ACTION ? "" : " without external action",
930 yypParser->yytos[yysize].stateno);
931 }else{
932 fprintf(yyTraceFILE, "%sReduce %d [%s]%s.\n",
933 yyTracePrompt, yyruleno, yyRuleName[yyruleno],
934 yyruleno<YYNRULE_WITH_ACTION ? "" : " without external action");
935 }
936 }
937#endif /* NDEBUG */
938
939 /* Check that the stack is large enough to grow by a single entry
940 ** if the RHS of the rule is empty. This ensures that there is room
941 ** enough on the stack to push the LHS value */
942 if( yyRuleInfoNRhs[yyruleno]==0 ){
943#ifdef YYTRACKMAXSTACKDEPTH
944 if( (int)(yypParser->yytos - yypParser->yystack)>yypParser->yyhwm ){
945 yypParser->yyhwm++;
946 assert( yypParser->yyhwm ==
947 (int)(yypParser->yytos - yypParser->yystack));
948 }
949#endif
950 if( yypParser->yytos>=yypParser->yystackEnd ){
951 if( yyGrowStack(yypParser) ){
952 yyStackOverflow(yypParser);
953 break;
954 }
955 }
956 }
957 yyact = yy_reduce(yypParser,yyruleno,yymajor,yyminor ParseCTX_PARAM);
958 }else if( yyact <= YY_MAX_SHIFTREDUCE ){
959 yy_shift(yypParser,yyact,(YYCODETYPE)yymajor,yyminor);
960#ifndef YYNOERRORRECOVERY
961 yypParser->yyerrcnt--;
962#endif
963 break;
964 }else if( yyact==YY_ACCEPT_ACTION ){
965 yypParser->yytos--;
966 yy_accept(yypParser);
967 return;
968 }else{
969 assert( yyact == YY_ERROR_ACTION );
970 yyminorunion.yy0 = yyminor;
971#ifdef YYERRORSYMBOL
972 int yymx;
973#endif
974#ifndef NDEBUG
975 if( yyTraceFILE ){
976 fprintf(yyTraceFILE,"%sSyntax Error!\n",yyTracePrompt);
977 }
978#endif
979#ifdef YYERRORSYMBOL
980 /* A syntax error has occurred.
981 ** The response to an error depends upon whether or not the
982 ** grammar defines an error token "ERROR".
983 **
984 ** This is what we do if the grammar does define ERROR:
985 **
986 ** * Call the %syntax_error function.
987 **
988 ** * Begin popping the stack until we enter a state where
989 ** it is legal to shift the error symbol, then shift
990 ** the error symbol.
991 **
992 ** * Set the error count to three.
993 **
994 ** * Begin accepting and shifting new tokens. No new error
995 ** processing will occur until three tokens have been
996 ** shifted successfully.
997 **
998 */
999 if( yypParser->yyerrcnt<0 ){
1000 yy_syntax_error(yypParser,yymajor,yyminor);
1001 }
1002 yymx = yypParser->yytos->major;
1003 if( yymx==YYERRORSYMBOL || yyerrorhit ){
1004#ifndef NDEBUG
1005 if( yyTraceFILE ){
1006 fprintf(yyTraceFILE,"%sDiscard input token %s\n",
1007 yyTracePrompt,yyTokenName[yymajor]);
1008 }
1009#endif
1010 yy_destructor(yypParser, (YYCODETYPE)yymajor, &yyminorunion);
1011 yymajor = YYNOCODE;
1012 }else{
1013 while( yypParser->yytos > yypParser->yystack ){
1014 yyact = yy_find_reduce_action(yypParser->yytos->stateno,
1015 YYERRORSYMBOL);
1016 if( yyact<=YY_MAX_SHIFTREDUCE ) break;
1017 yy_pop_parser_stack(yypParser);
1018 }
1019 if( yypParser->yytos <= yypParser->yystack || yymajor==0 ){
1020 yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
1021 yy_parse_failed(yypParser);
1022#ifndef YYNOERRORRECOVERY
1023 yypParser->yyerrcnt = -1;
1024#endif
1025 yymajor = YYNOCODE;
1026 }else if( yymx!=YYERRORSYMBOL ){
1027 yy_shift(yypParser,yyact,YYERRORSYMBOL,yyminor);
1028 }
1029 }
1030 yypParser->yyerrcnt = 3;
1031 yyerrorhit = 1;
1032 if( yymajor==YYNOCODE ) break;
1033 yyact = yypParser->yytos->stateno;
1034#elif defined(YYNOERRORRECOVERY)
1035 /* If the YYNOERRORRECOVERY macro is defined, then do not attempt to
1036 ** do any kind of error recovery. Instead, simply invoke the syntax
1037 ** error routine and continue going as if nothing had happened.
1038 **
1039 ** Applications can set this macro (for example inside %include) if
1040 ** they intend to abandon the parse upon the first syntax error seen.
1041 */
1042 yy_syntax_error(yypParser,yymajor, yyminor);
1043 yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
1044 break;
1045#else /* YYERRORSYMBOL is not defined */
1046 /* This is what we do if the grammar does not define ERROR:
1047 **
1048 ** * Report an error message, and throw away the input token.
1049 **
1050 ** * If the input token is $, then fail the parse.
1051 **
1052 ** As before, subsequent error messages are suppressed until
1053 ** three input tokens have been successfully shifted.
1054 */
1055 if( yypParser->yyerrcnt<=0 ){
1056 yy_syntax_error(yypParser,yymajor, yyminor);
1057 }
1058 yypParser->yyerrcnt = 3;
1059 yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
1060 if( yyendofinput ){
1061 yy_parse_failed(yypParser);
1062#ifndef YYNOERRORRECOVERY
1063 yypParser->yyerrcnt = -1;
1064#endif
1065 }
1066 break;
1067#endif
1068 }
1069 }
1070#ifndef NDEBUG
1071 if( yyTraceFILE ){
1072 yyStackEntry *i;
1073 char cDiv = '[';
1074 fprintf(yyTraceFILE,"%sReturn. Stack=",yyTracePrompt);
1075 for(i=&yypParser->yystack[1]; i<=yypParser->yytos; i++){
1076 fprintf(yyTraceFILE,"%c%s", cDiv, yyTokenName[i->major]);
1077 cDiv = ' ';
1078 }
1079 fprintf(yyTraceFILE,"]\n");
1080 }
1081#endif
1082 return;
1083}
1084
1085/*
1086** Return the fallback token corresponding to canonical token iToken, or
1087** 0 if iToken has no fallback.
1088*/
1089int ParseFallback(int iToken){
1090#ifdef YYFALLBACK
1091 assert( iToken<(int)(sizeof(yyFallback)/sizeof(yyFallback[0])) );
1092 return yyFallback[iToken];
1093#else
1094 (void)iToken;
1095 return 0;
1096#endif
1097}