- Remove GLIB1 code
[obnox/wireshark/wip.git] / tools / lemon / lempar.c
1 /* Driver template for the LEMON parser generator.
2 ** Copyright 1991-1995 by D. Richard Hipp.
3 **
4 ** This library is free software; you can redistribute it and/or
5 ** modify it under the terms of the GNU Library General Public
6 ** License as published by the Free Software Foundation; either
7 ** version 2 of the License, or (at your option) any later version.
8 **
9 ** This library is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 ** Library General Public License for more details.
13 **
14 ** You should have received a copy of the GNU Library General Public
15 ** License along with this library; if not, write to the
16 ** Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 ** Boston, MA  02111-1307, USA.
18 **
19 ** Modified 1997 to make it suitable for use with makeheaders.
20 * Updated to sqlite lemon version 1.22
21 */
22 /* First off, code is include which follows the "include" declaration
23 ** in the input file. */
24 %%
25 #include <stdio.h>
26 #include <string.h>
27 /* Next is all token values, in a form suitable for use by makeheaders.
28 ** This section will be null unless lemon is run with the -m switch.
29 */
30 /*
31 ** These constants (all generated automatically by the parser generator)
32 ** specify the various kinds of tokens (terminals) that the parser
33 ** understands.
34 **
35 ** Each symbol here is a terminal symbol in the grammar.
36 */
37 %%
38 /* Make sure the INTERFACE macro is defined.
39 */
40 #ifndef INTERFACE
41 # define INTERFACE 1
42 #endif
43 /* The next thing included is series of defines which control
44 ** various aspects of the generated parser.
45 **    YYCODETYPE         is the data type used for storing terminal
46 **                       and nonterminal numbers.  "unsigned char" is
47 **                       used if there are fewer than 250 terminals
48 **                       and nonterminals.  "int" is used otherwise.
49 **    YYNOCODE           is a number of type YYCODETYPE which corresponds
50 **                       to no legal terminal or nonterminal number.  This
51 **                       number is used to fill in empty slots of the hash
52 **                       table.
53 **    YYFALLBACK         If defined, this indicates that one or more tokens
54 **                       have fall-back values which should be used if the
55 **                       original value of the token will not parse.
56 **    YYACTIONTYPE       is the data type used for storing terminal
57 **                       and nonterminal numbers.  "unsigned char" is
58 **                       used if there are fewer than 250 rules and
59 **                       states combined.  "int" is used otherwise.
60 **    ParseTOKENTYPE     is the data type used for minor tokens given
61 **                       directly to the parser from the tokenizer.
62 **    YYMINORTYPE        is the data type used for all minor tokens.
63 **                       This is typically a union of many types, one of
64 **                       which is ParseTOKENTYPE.  The entry in the union
65 **                       for base tokens is called "yy0".
66 **    YYSTACKDEPTH       is the maximum depth of the parser's stack.
67 **    ParseARG_SDECL     A static variable declaration for the %extra_argument
68 **    ParseARG_PDECL     A parameter declaration for the %extra_argument
69 **    ParseARG_STORE     Code to store %extra_argument into yypParser
70 **    ParseARG_FETCH     Code to extract %extra_argument from yypParser
71 **    YYNSTATE           the combined number of states.
72 **    YYNRULE            the number of rules in the grammar
73 **    YYERRORSYMBOL      is the code number of the error symbol.  If not
74 **                       defined, then do no error processing.
75 */
76 %%
77 #define YY_NO_ACTION      (YYNSTATE+YYNRULE+2)
78 #define YY_ACCEPT_ACTION  (YYNSTATE+YYNRULE+1)
79 #define YY_ERROR_ACTION   (YYNSTATE+YYNRULE)
80
81 /* Next are that tables used to determine what action to take based on the
82 ** current state and lookahead token.  These tables are used to implement
83 ** functions that take a state number and lookahead value and return an
84 ** action integer.  
85 **
86 ** Suppose the action integer is N.  Then the action is determined as
87 ** follows
88 **
89 **   0 <= N < YYNSTATE                  Shift N.  That is, push the lookahead
90 **                                      token onto the stack and goto state N.
91 **
92 **   YYNSTATE <= N < YYNSTATE+YYNRULE   Reduce by rule N-YYNSTATE.
93 **
94 **   N == YYNSTATE+YYNRULE              A syntax error has occurred.
95 **
96 **   N == YYNSTATE+YYNRULE+1            The parser accepts its input.
97 **
98 **   N == YYNSTATE+YYNRULE+2            No such action.  Denotes unused
99 **                                      slots in the yy_action[] table.
100 **
101 ** The action table is constructed as a single large table named yy_action[].
102 ** Given state S and lookahead X, the action is computed as
103 **
104 **      yy_action[ yy_shift_ofst[S] + X ]
105 **
106 ** If the index value yy_shift_ofst[S]+X is out of range or if the value
107 ** yy_lookahead[yy_shift_ofst[S]+X] is not equal to X or if yy_shift_ofst[S]
108 ** is equal to YY_SHIFT_USE_DFLT, it means that the action is not in the table
109 ** and that yy_default[S] should be used instead.  
110 **
111 ** The formula above is for computing the action when the lookahead is
112 ** a terminal symbol.  If the lookahead is a non-terminal (as occurs after
113 ** a reduce action) then the yy_reduce_ofst[] array is used in place of
114 ** the yy_shift_ofst[] array and YY_REDUCE_USE_DFLT is used in place of
115 ** YY_SHIFT_USE_DFLT.
116 **
117 ** The following are the tables generated in this section:
118 **
119 **  yy_action[]        A single table containing all actions.
120 **  yy_lookahead[]     A table containing the lookahead for each entry in
121 **                     yy_action.  Used to detect hash collisions.
122 **  yy_shift_ofst[]    For each state, the offset into yy_action for
123 **                     shifting terminals.
124 **  yy_reduce_ofst[]   For each state, the offset into yy_action for
125 **                     shifting non-terminals after a reduce.
126 **  yy_default[]       Default action for each state.
127 */
128 %%
129 #define YY_SZ_ACTTAB (int)(sizeof(yy_action)/sizeof(yy_action[0]))
130
131
132 /* The next table maps tokens into fallback tokens.  If a construct
133 ** like the following:
134 ** 
135 **      %fallback ID X Y Z.
136 **
137 ** appears in the grammer, 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.
141 */
142 #ifdef YYFALLBACK
143 static const YYCODETYPE yyFallback[] = {
144 %%
145 };
146 #endif /* YYFALLBACK */
147
148 /* The following structure represents a single element of the
149 ** parser's stack.  Information stored includes:
150 **
151 **   +  The state number for the parser at this level of the stack.
152 **
153 **   +  The value of the token stored at this level of the stack.
154 **      (In other words, the "major" token.)
155 **
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.
159 */
160 struct yyStackEntry {
161   int stateno;       /* The state-number */
162   int 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  */
166 };
167 typedef struct yyStackEntry yyStackEntry;
168
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   int yyerrcnt;                 /* Shifts left before out of the error */
174   ParseARG_SDECL                /* A place to hold %extra_argument */
175   yyStackEntry yystack[YYSTACKDEPTH];  /* The parser's stack */
176 };
177 typedef struct yyParser yyParser;
178
179 #ifndef NDEBUG
180 #include <stdio.h>
181 static FILE *yyTraceFILE = 0;
182 static char *yyTracePrompt = 0;
183 #endif /* NDEBUG */
184  
185 #ifndef NDEBUG
186 /*
187 ** Turn parser tracing on by giving a stream to which to write the trace
188 ** and a prompt to preface each trace message.  Tracing is turned off
189 ** by making either argument NULL
190 **
191 ** Inputs:
192 ** <ul>
193 ** <li> A FILE* to which trace output should be written.
194 **      If NULL, then tracing is turned off.
195 ** <li> A prefix string written at the beginning of every
196 **      line of trace output.  If NULL, then tracing is
197 **      turned off.
198 ** </ul>
199 **
200 ** Outputs:
201 ** None.
202 */
203 void ParseTrace(FILE *TraceFILE, char *zTracePrompt){
204   yyTraceFILE = TraceFILE;
205   yyTracePrompt = zTracePrompt;
206   if( yyTraceFILE==0 ) yyTracePrompt = 0;
207   else if( yyTracePrompt==0 ) yyTraceFILE = 0;
208 }
209 #endif /* NDEBUG */
210  
211 #ifndef NDEBUG
212 /* For tracing shifts, the names of all terminals and nonterminals
213 ** are required.  The following table supplies these names */
214 static const char *const yyTokenName[] = {
215 %%
216 };
217 #endif /* NDEBUG */
218
219 #ifndef NDEBUG
220 /* For tracing reduce actions, the names of all rules are required.
221 */
222 static const char *const yyRuleName[] = {
223 %%
224 };
225 #endif /* NDEBUG */
226
227 /*
228 ** This function returns the symbolic name associated with a token
229 ** value.
230 */
231 const char *ParseTokenName(int tokenType){
232 #ifndef NDEBUG
233   if( tokenType>0 && tokenType<(int)(sizeof(yyTokenName)/sizeof(yyTokenName[0])) ){
234     return yyTokenName[tokenType];
235   }else{
236     return "Unknown";
237   }
238 #else
239   return "";
240 #endif
241 }
242
243 /*
244 ** This function allocates a new parser.
245 ** The only argument is a pointer to a function which works like
246 ** malloc.
247 **
248 ** Inputs:
249 ** A pointer to the function used to allocate memory.
250 **
251 ** Outputs:
252 ** A pointer to a parser.  This pointer is used in subsequent calls
253 ** to Parse and ParseFree.
254 */
255 #if GLIB_CHECK_VERSION(2,16,0)
256 void *ParseAlloc(void *(*mallocProc)(gsize)){
257   yyParser *pParser;
258   pParser = (yyParser*)(*mallocProc)( (gsize)sizeof(yyParser) );
259 #else
260 void *ParseAlloc(void *(*mallocProc)(gulong)){
261   yyParser *pParser;
262   pParser = (yyParser*)(*mallocProc)( (gulong)sizeof(yyParser) );
263 #endif
264   if( pParser ){
265     pParser->yyidx = -1;
266   }
267   return pParser;
268 }
269
270 /* The following function deletes the value associated with a
271 ** symbol.  The symbol can be either a terminal or nonterminal.
272 ** "yymajor" is the symbol code, and "yypminor" is a pointer to
273 ** the value.
274 */
275 static void yy_destructor(YYCODETYPE yymajor, YYMINORTYPE *yypminor){
276   switch( yymajor ){
277     /* Here is inserted the actions which take place when a
278     ** terminal or non-terminal is destroyed.  This can happen
279     ** when the symbol is popped from the stack during a
280     ** reduce or during error processing or when a parser is
281     ** being destroyed before it is finished parsing.
282     **
283     ** Note: during a reduce, the only symbols destroyed are those
284     ** which appear on the RHS of the rule, but which are not used
285     ** inside the C code.
286     */
287 %%
288     default:  break;   /* If no destructor action specified: do nothing */
289   }
290 }
291
292 /*
293 ** Pop the parser's stack once.
294 **
295 ** If there is a destructor routine associated with the token which
296 ** is popped from the stack, then call it.
297 **
298 ** Return the major token number for the symbol popped.
299 */
300 static int yy_pop_parser_stack(yyParser *pParser){
301   YYCODETYPE yymajor;
302   yyStackEntry *yytos = &pParser->yystack[pParser->yyidx];
303
304   if( pParser->yyidx<0 ) return 0;
305 #ifndef NDEBUG
306   if( yyTraceFILE && pParser->yyidx>=0 ){
307     fprintf(yyTraceFILE,"%sPopping %s\n",
308       yyTracePrompt,
309      yyTokenName[yytos->major]);
310   }
311 #endif
312   yymajor = yytos->major;
313   yy_destructor( yymajor, &yytos->minor);
314   pParser->yyidx--;
315   return yymajor;
316 }
317
318 /*
319 ** Deallocate and destroy a parser.  Destructors are all called for
320 ** all stack elements before shutting the parser down.
321 **
322 ** Inputs:
323 ** <ul>
324 ** <li>  A pointer to the parser.  This should be a pointer
325 **       obtained from ParseAlloc.
326 ** <li>  A pointer to a function used to reclaim memory obtained
327 **       from malloc.
328 ** </ul>
329 */
330 void ParseFree(
331   void *p,                 /* The parser to be deleted */
332   void (*freeProc)(void*)  /* Function used to reclaim memory */
333 ){
334   yyParser *pParser = (yyParser*)p;
335   if( pParser==0 ) return;
336   while( pParser->yyidx>=0 ) yy_pop_parser_stack(pParser);
337   (*freeProc)(pParser);
338 }
339
340 /*
341 ** Find the appropriate action for a parser given the terminal
342 ** look-ahead token iLookAhead.
343 **
344 ** If the look-ahead token is YYNOCODE, then check to see if the action is
345 ** independent of the look-ahead.  If it is, return the action, otherwise
346 ** return YY_NO_ACTION.
347 */
348 static int yy_find_shift_action(
349   yyParser *pParser,        /* The parser */
350   YYCODETYPE iLookAhead     /* The look-ahead token */
351 ){
352   int i;
353   int stateno = pParser->yystack[pParser->yyidx].stateno;
354
355   if( stateno>YY_SHIFT_MAX || (i = yy_shift_ofst[stateno])==YY_SHIFT_USE_DFLT ){
356     return yy_default[stateno];
357   }
358   if( iLookAhead==YYNOCODE ){
359     return YY_NO_ACTION;
360   }
361   i += iLookAhead;
362   if( i<0 || i>=YY_SZ_ACTTAB || yy_lookahead[i]!=iLookAhead ){
363     if( iLookAhead>0 ){
364 #ifdef YYFALLBACK
365       int iFallback;            /* Fallback token */
366       if( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0])
367              && (iFallback = yyFallback[iLookAhead])!=0 ){
368 #ifndef NDEBUG
369         if( yyTraceFILE ){
370           fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n",
371              yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]);
372         }
373 #endif
374         return yy_find_shift_action(pParser, iFallback);
375       }
376 #endif
377 #ifdef YYWILDCARD
378       int j = i - iLookAhead + YYWILDCARD;
379       if( j>=0 && j<YY_SZ_ACTTAB && yy_lookahead[j]==YYWILDCARD ){
380 #ifndef NDEBUG
381         if( yyTraceFILE ){
382           fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n",
383              yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[YYWILDCARD]);
384         }
385 #endif /* NDEBUG */
386
387         return yy_action[j];
388       }
389 #endif /* YYWILDCARD */
390     }
391     return yy_default[stateno];
392   }else{
393     return yy_action[i];
394   }
395 }
396
397 /*
398 ** Find the appropriate action for a parser given the non-terminal
399 ** look-ahead token iLookAhead.
400 **
401 ** If the look-ahead token is YYNOCODE, then check to see if the action is
402 ** independent of the look-ahead.  If it is, return the action, otherwise
403 ** return YY_NO_ACTION.
404 */
405 static int yy_find_reduce_action(
406   int stateno,              /* Current state number */
407   YYCODETYPE iLookAhead     /* The look-ahead token */
408 ){
409   int i;
410   /* int stateno = pParser->yystack[pParser->yyidx].stateno; */
411  
412   if( stateno>YY_REDUCE_MAX ||
413       (i = yy_reduce_ofst[stateno])==YY_REDUCE_USE_DFLT ){
414     return yy_default[stateno];
415   }
416   if( iLookAhead==YYNOCODE ){
417     return YY_NO_ACTION;
418   }
419   i += iLookAhead;
420   if( i<0 || i>=YY_SZ_ACTTAB || yy_lookahead[i]!=iLookAhead ){
421     return yy_default[stateno];
422   }else{
423     return yy_action[i];
424   }
425 }
426
427 /*
428 ** Perform a shift action.
429 */
430 static void yy_shift(
431   yyParser *yypParser,          /* The parser to be shifted */
432   int yyNewState,               /* The new state to shift in */
433   int yyMajor,                  /* The major token to shift in */
434   YYMINORTYPE *yypMinor         /* Pointer ot the minor token to shift in */
435 ){
436   yyStackEntry *yytos;
437   yypParser->yyidx++;
438   if( yypParser->yyidx>=YYSTACKDEPTH ){
439      ParseARG_FETCH;
440      yypParser->yyidx--;
441 #ifndef NDEBUG
442      if( yyTraceFILE ){
443        fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt);
444      }
445 #endif
446      while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
447      /* Here code is inserted which will execute if the parser
448      ** stack every overflows */
449 %%
450          ParseARG_STORE; /* Suppress warning about unused %extra_argument var */
451      return;
452   }
453   yytos = &yypParser->yystack[yypParser->yyidx];
454   yytos->stateno = yyNewState;
455   yytos->major = yyMajor;
456   yytos->minor = *yypMinor;
457 #ifndef NDEBUG
458   if( yyTraceFILE && yypParser->yyidx>0 ){
459     int i;
460     fprintf(yyTraceFILE,"%sShift %d\n",yyTracePrompt,yyNewState);
461     fprintf(yyTraceFILE,"%sStack:",yyTracePrompt);
462     for(i=1; i<=yypParser->yyidx; i++)
463       fprintf(yyTraceFILE," %s",yyTokenName[yypParser->yystack[i].major]);
464     fprintf(yyTraceFILE,"\n");
465   }
466 #endif
467 }
468
469 /* The following table contains information about every rule that
470 ** is used during the reduce.
471 */
472 static const struct {
473   YYCODETYPE lhs;         /* Symbol on the left-hand side of the rule */
474   unsigned char nrhs;     /* Number of right-hand side symbols in the rule */
475 } yyRuleInfo[] = {
476 %%
477 };
478
479 static void yy_accept(
480   yyParser *yypParser           /* The parser */
481 );  /* Forward declaration */
482
483 /*
484 ** Perform a reduce action and the shift that must immediately
485 ** follow the reduce.
486 */
487 static void yy_reduce(
488   yyParser *yypParser,         /* The parser */
489   int yyruleno                 /* Number of the rule by which to reduce */
490 ){
491   int yygoto;                     /* The next state */
492   int yyact;                      /* The next action */
493   YYMINORTYPE yygotominor;        /* The LHS of the rule reduced */
494   yyStackEntry *yymsp;            /* The top of the parser's stack */
495   int yysize;                     /* Amount to pop the stack */
496   ParseARG_FETCH;
497   yymsp = &yypParser->yystack[yypParser->yyidx];
498 #ifndef NDEBUG
499   if( yyTraceFILE && yyruleno>=0 
500         && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){
501     fprintf(yyTraceFILE, "%sReduce [%s].\n", yyTracePrompt,
502       yyRuleName[yyruleno]);
503   }
504 #endif /* NDEBUG */
505
506 #ifndef NDEBUG
507   /* Silence complaints from purify about yygotominor being uninitialized
508   ** in some cases when it is copied into the stack after the following
509   ** switch.  yygotominor is uninitialized when a rule reduces that does
510   ** not set the value of its left-hand side nonterminal.  Leaving the
511   ** value of the nonterminal uninitialized is utterly harmless as long
512   ** as the value is never used.  So really the only thing this code
513   ** accomplishes is to quieten purify.  
514   */
515   memset(&yygotominor, 0, sizeof(yygotominor));
516 #endif
517
518   switch( yyruleno ){
519   /* Beginning here are the reduction cases.  A typical example
520   ** follows:
521   **   case 0:
522   **  #line <lineno> <grammarfile>
523   **     { ... }           // User supplied code
524   **  #line <lineno> <thisfile>
525   **     break;
526   */
527 %%
528   };
529   yygoto = yyRuleInfo[yyruleno].lhs;
530   yysize = yyRuleInfo[yyruleno].nrhs;
531   yypParser->yyidx -= yysize;
532   yyact = yy_find_reduce_action(yymsp[-yysize].stateno,(YYCODETYPE)yygoto);
533   if( yyact < YYNSTATE ){
534 #ifdef NDEBUG
535     /* If we are not debugging and the reduce action popped at least
536     ** one element off the stack, then we can push the new element back
537     ** onto the stack here, and skip the stack overflow test in yy_shift().
538     ** That gives a significant speed improvement. */
539     if( yysize ){
540       yypParser->yyidx++;
541       yymsp -= yysize-1;
542       yymsp->stateno = yyact;
543       yymsp->major = yygoto;
544       yymsp->minor = yygotominor;
545     }else
546 #endif
547     {
548       yy_shift(yypParser,yyact,yygoto,&yygotominor);
549     }
550   }else if( yyact == YYNSTATE + YYNRULE + 1 ){
551     yy_accept(yypParser);
552   }
553 }
554
555 /*
556 ** The following code executes when the parse fails
557 */
558 static void yy_parse_failed(
559   yyParser *yypParser           /* The parser */
560 ){
561   ParseARG_FETCH;
562 #ifndef NDEBUG
563   if( yyTraceFILE ){
564     fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt);
565   }
566 #endif
567   while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
568   /* Here code is inserted which will be executed whenever the
569   ** parser fails */
570 %%
571   ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
572 }
573
574 /*
575 ** The following code executes when a syntax error first occurs.
576 */
577 static void yy_syntax_error(
578   yyParser *yypParser _U_,       /* The parser */
579   int yymajor _U_,               /* The major type of the error token */
580   YYMINORTYPE yyminor            /* The minor type of the error token */
581 ){
582   ParseARG_FETCH;
583 #define TOKEN (yyminor.yy0)
584 %%
585   ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
586 }
587
588 /*
589 ** The following is executed when the parser accepts
590 */
591 static void yy_accept(
592   yyParser *yypParser           /* The parser */
593 ){
594   ParseARG_FETCH;
595 #ifndef NDEBUG
596   if( yyTraceFILE ){
597     fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt);
598   }
599 #endif
600   while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
601   /* Here code is inserted which will be executed whenever the
602   ** parser accepts */
603 %%
604   ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
605 }
606
607 /* The main parser program.
608 ** The first argument is a pointer to a structure obtained from
609 ** "ParseAlloc" which describes the current state of the parser.
610 ** The second argument is the major token number.  The third is
611 ** the minor token.  The fourth optional argument is whatever the
612 ** user wants (and specified in the grammar) and is available for
613 ** use by the action routines.
614 **
615 ** Inputs:
616 ** <ul>
617 ** <li> A pointer to the parser (an opaque structure.)
618 ** <li> The major token number.
619 ** <li> The minor token number.
620 ** <li> An option argument of a grammar-specified type.
621 ** </ul>
622 **
623 ** Outputs:
624 ** None.
625 */
626 void Parse(
627   void *yyp,                   /* The parser */
628   int yymajor,                 /* The major token code number */
629   ParseTOKENTYPE yyminor       /* The value for the token */
630   ParseARG_PDECL               /* Optional %extra_argument parameter */
631 ){
632   YYMINORTYPE yyminorunion;
633   int yyact;            /* The parser action. */
634   int yyendofinput;     /* True if we are at the end of input */
635   int yyerrorhit = 0;   /* True if yymajor has invoked an error */
636   yyParser *yypParser;  /* The parser */
637
638   /* (re)initialize the parser, if necessary */
639   yypParser = (yyParser*)yyp;
640   if( yypParser->yyidx<0 ){
641     /* if( yymajor==0 ) return; // not sure why this was here... */
642     yypParser->yyidx = 0;
643     yypParser->yyerrcnt = -1;
644     yypParser->yystack[0].stateno = 0;
645     yypParser->yystack[0].major = 0;
646   }
647   yyminorunion.yy0 = yyminor;
648   yyendofinput = (yymajor==0);
649   ParseARG_STORE;
650
651 #ifndef NDEBUG
652   if( yyTraceFILE ){
653     fprintf(yyTraceFILE,"%sInput %s\n",yyTracePrompt,yyTokenName[yymajor]);
654   }
655 #endif
656
657   do{
658     yyact = yy_find_shift_action(yypParser,(YYCODETYPE)yymajor);
659     if( yyact<YYNSTATE ){
660       yy_shift(yypParser,yyact,yymajor,&yyminorunion);
661       yypParser->yyerrcnt--;
662       if( yyendofinput && yypParser->yyidx>=0 ){
663         yymajor = 0;
664       }else{
665         yymajor = YYNOCODE;
666       }
667     }else if( yyact < YYNSTATE + YYNRULE ){
668       yy_reduce(yypParser,yyact-YYNSTATE);
669     }else if( yyact == YY_ERROR_ACTION ){
670       int yymx;
671 #ifndef NDEBUG
672       if( yyTraceFILE ){
673         fprintf(yyTraceFILE,"%sSyntax Error!\n",yyTracePrompt);
674       }
675 #endif
676 #ifdef YYERRORSYMBOL
677       /* A syntax error has occurred.
678       ** The response to an error depends upon whether or not the
679       ** grammar defines an error token "ERROR".
680       **
681       ** This is what we do if the grammar does define ERROR:
682       **
683       **  * Call the %syntax_error function.
684       **
685       **  * Begin popping the stack until we enter a state where
686       **    it is legal to shift the error symbol, then shift
687       **    the error symbol.
688       **
689       **  * Set the error count to three.
690       **
691       **  * Begin accepting and shifting new tokens.  No new error
692       **    processing will occur until three tokens have been
693       **    shifted successfully.
694       **
695       */
696       if( yypParser->yyerrcnt<0 ){
697         yy_syntax_error(yypParser,yymajor,yyminorunion);
698       }
699       yymx = yypParser->yystack[yypParser->yyidx].major;
700       if( yymx==YYERRORSYMBOL || yyerrorhit ){
701 #ifndef NDEBUG
702         if( yyTraceFILE ){
703           fprintf(yyTraceFILE,"%sDiscard input token %s\n",
704              yyTracePrompt,yyTokenName[yymajor]);
705         }
706 #endif
707         yy_destructor((YYCODETYPE)yymajor,&yyminorunion);
708         yymajor = YYNOCODE;
709       }else{
710          while(
711           yypParser->yyidx >= 0 &&
712           yymx != YYERRORSYMBOL &&
713           (yyact = yy_find_shift_action(yypParser,YYERRORSYMBOL)) >= YYNSTATE
714         ){
715           yy_pop_parser_stack(yypParser);
716         }
717         if( yypParser->yyidx < 0 || yymajor==0 ){
718           yy_destructor((YYCODETYPE)yymajor,&yyminorunion);
719           yy_parse_failed(yypParser);
720           yymajor = YYNOCODE;
721         }else if( yymx!=YYERRORSYMBOL ){
722           YYMINORTYPE u2;
723           u2.YYERRSYMDT = 0;
724           yy_shift(yypParser,yyact,YYERRORSYMBOL,&u2);
725         }
726       }
727       yypParser->yyerrcnt = 3;
728       yyerrorhit = 1;
729 #else  /* YYERRORSYMBOL is not defined */
730       /* This is what we do if the grammar does not define ERROR:
731       **
732       **  * Report an error message, and throw away the input token.
733       **
734       **  * If the input token is $, then fail the parse.
735       **
736       ** As before, subsequent error messages are suppressed until
737       ** three input tokens have been successfully shifted.
738       */
739       if( yypParser->yyerrcnt<=0 ){
740         yy_syntax_error(yypParser,yymajor,yyminorunion);
741       }
742       yypParser->yyerrcnt = 3;
743       yy_destructor(yymajor,&yyminorunion);
744       if( yyendofinput ){
745         yy_parse_failed(yypParser);
746       }
747       yymajor = YYNOCODE;
748 #endif
749     }else{
750       yy_accept(yypParser);
751       yymajor = YYNOCODE;
752     }
753   }while( yymajor!=YYNOCODE && yypParser->yyidx>=0 );
754   return;
755 }
756