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