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