• source navigation  • diff markup  • identifier search  • freetext search  • 

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

This page was automatically generated by LXR 0.3.1.  •  OpenWrt