File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / lighttpd / src / lempar.c
Revision 1.1.1.2 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Wed Nov 2 10:35:00 2016 UTC (7 years, 9 months ago) by misho
Branches: lighttpd, MAIN
CVS tags: v1_4_41p8, HEAD
lighttpd 1.4.41

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>