File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / lighttpd / src / lempar.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Mon Oct 14 10:32:47 2013 UTC (10 years, 8 months ago) by misho
Branches: lighttpd, MAIN
CVS tags: v1_4_35p0, v1_4_35, v1_4_33, HEAD
1.4.33

    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 <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.
   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 (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 = NULL;
  162: static char *yyTracePrompt = NULL;
  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: #if 0
  184: void ParseTrace(FILE *TraceFILE, char *zTracePrompt){
  185:   yyTraceFILE = TraceFILE;
  186:   yyTracePrompt = zTracePrompt;
  187:   if( yyTraceFILE==0 ) yyTracePrompt = 0;
  188:   else if( yyTracePrompt==0 ) yyTraceFILE = 0;
  189: }
  190: #endif
  191: #endif /* NDEBUG */
  192: 
  193: #ifndef NDEBUG
  194: /* For tracing shifts, the names of all terminals and nonterminals
  195: ** are required.  The following table supplies these names */
  196: static const char *yyTokenName[] = {
  197: %%
  198: };
  199: #endif /* NDEBUG */
  200: 
  201: #ifndef NDEBUG
  202: /* For tracing reduce actions, the names of all rules are required.
  203: */
  204: static const char *yyRuleName[] = {
  205: %%
  206: };
  207: #endif /* NDEBUG */
  208: 
  209: /*
  210: ** This function returns the symbolic name associated with a token
  211: ** value.
  212: */
  213: #if 0
  214: const char *ParseTokenName(int tokenType){
  215: #ifndef NDEBUG
  216:   if( tokenType>0 && (size_t)tokenType<(sizeof(yyTokenName)/sizeof(yyTokenName[0])) ){
  217:     return yyTokenName[tokenType];
  218:   }else{
  219:     return "Unknown";
  220:   }
  221: #else
  222:   return "";
  223: #endif
  224: }
  225: #endif
  226: 
  227: /*
  228: ** This function allocates a new parser.
  229: ** The only argument is a pointer to a function which works like
  230: ** malloc.
  231: **
  232: ** Inputs:
  233: ** A pointer to the function used to allocate memory.
  234: **
  235: ** Outputs:
  236: ** A pointer to a parser.  This pointer is used in subsequent calls
  237: ** to Parse and ParseFree.
  238: */
  239: void *ParseAlloc(void *(*mallocProc)(size_t)){
  240:   yyParser *pParser;
  241:   pParser = (yyParser*)(*mallocProc)( (size_t)sizeof(yyParser) );
  242:   if( pParser ){
  243:     pParser->yyidx = -1;
  244:   }
  245:   return pParser;
  246: }
  247: 
  248: /* The following function deletes the value associated with a
  249: ** symbol.  The symbol can be either a terminal or nonterminal.
  250: ** "yymajor" is the symbol code, and "yypminor" is a pointer to
  251: ** the value.
  252: */
  253: static void yy_destructor(YYCODETYPE yymajor, YYMINORTYPE *yypminor){
  254:   switch( yymajor ){
  255:     /* Here is inserted the actions which take place when a
  256:     ** terminal or non-terminal is destroyed.  This can happen
  257:     ** when the symbol is popped from the stack during a
  258:     ** reduce or during error processing or when a parser is
  259:     ** being destroyed before it is finished parsing.
  260:     **
  261:     ** Note: during a reduce, the only symbols destroyed are those
  262:     ** which appear on the RHS of the rule, but which are not used
  263:     ** inside the C code.
  264:     */
  265: %%
  266:     default:  break;   /* If no destructor action specified: do nothing */
  267:   }
  268: }
  269: 
  270: /*
  271: ** Pop the parser's stack once.
  272: **
  273: ** If there is a destructor routine associated with the token which
  274: ** is popped from the stack, then call it.
  275: **
  276: ** Return the major token number for the symbol popped.
  277: */
  278: static int yy_pop_parser_stack(yyParser *pParser){
  279:   YYCODETYPE yymajor;
  280:   yyStackEntry *yytos = &pParser->yystack[pParser->yyidx];
  281: 
  282:   if( pParser->yyidx<0 ) return 0;
  283: #ifndef NDEBUG
  284:   if( yyTraceFILE && pParser->yyidx>=0 ){
  285:     fprintf(yyTraceFILE,"%sPopping %s\n",
  286:       yyTracePrompt,
  287:       yyTokenName[yytos->major]);
  288:   }
  289: #endif
  290:   yymajor = yytos->major;
  291:   yy_destructor( yymajor, &yytos->minor);
  292:   pParser->yyidx--;
  293:   return yymajor;
  294: }
  295: 
  296: /*
  297: ** Deallocate and destroy a parser.  Destructors are all called for
  298: ** all stack elements before shutting the parser down.
  299: **
  300: ** Inputs:
  301: ** <ul>
  302: ** <li>  A pointer to the parser.  This should be a pointer
  303: **       obtained from ParseAlloc.
  304: ** <li>  A pointer to a function used to reclaim memory obtained
  305: **       from malloc.
  306: ** </ul>
  307: */
  308: void ParseFree(
  309:   void *p,                    /* The parser to be deleted */
  310:   void (*freeProc)(void*)     /* Function used to reclaim memory */
  311: ){
  312:   yyParser *pParser = (yyParser*)p;
  313:   if( pParser==NULL ) return;
  314:   while( pParser->yyidx>=0 ) yy_pop_parser_stack(pParser);
  315:   (*freeProc)((void*)pParser);
  316: }
  317: 
  318: /*
  319: ** Find the appropriate action for a parser given the terminal
  320: ** look-ahead token iLookAhead.
  321: **
  322: ** If the look-ahead token is YYNOCODE, then check to see if the action is
  323: ** independent of the look-ahead.  If it is, return the action, otherwise
  324: ** return YY_NO_ACTION.
  325: */
  326: static int yy_find_shift_action(
  327:   yyParser *pParser,        /* The parser */
  328:   int iLookAhead            /* The look-ahead token */
  329: ){
  330:   int i;
  331:   int stateno = pParser->yystack[pParser->yyidx].stateno;
  332: 
  333:   /* if( pParser->yyidx<0 ) return YY_NO_ACTION;  */
  334:   i = yy_shift_ofst[stateno];
  335:   if( i==YY_SHIFT_USE_DFLT ){
  336:     return yy_default[stateno];
  337:   }
  338:   if( iLookAhead==YYNOCODE ){
  339:     return YY_NO_ACTION;
  340:   }
  341:   i += iLookAhead;
  342:   if( i<0 || (size_t)i>=YY_SZ_ACTTAB || yy_lookahead[i]!=iLookAhead ){
  343: #ifdef YYFALLBACK
  344:     int iFallback;            /* Fallback token */
  345:     if( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0])
  346:            && (iFallback = yyFallback[iLookAhead])!=0 ){
  347: #ifndef NDEBUG
  348:       if( yyTraceFILE ){
  349:         fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n",
  350:            yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]);
  351:       }
  352: #endif
  353:       return yy_find_shift_action(pParser, iFallback);
  354:     }
  355: #endif
  356:     return yy_default[stateno];
  357:   }else{
  358:     return yy_action[i];
  359:   }
  360: }
  361: 
  362: /*
  363: ** Find the appropriate action for a parser given the non-terminal
  364: ** look-ahead token iLookAhead.
  365: **
  366: ** If the look-ahead token is YYNOCODE, then check to see if the action is
  367: ** independent of the look-ahead.  If it is, return the action, otherwise
  368: ** return YY_NO_ACTION.
  369: */
  370: static int yy_find_reduce_action(
  371:   yyParser *pParser,        /* The parser */
  372:   int iLookAhead            /* The look-ahead token */
  373: ){
  374:   int i;
  375:   int stateno = pParser->yystack[pParser->yyidx].stateno;
  376: 
  377:   i = yy_reduce_ofst[stateno];
  378:   if( i==YY_REDUCE_USE_DFLT ){
  379:     return yy_default[stateno];
  380:   }
  381:   if( iLookAhead==YYNOCODE ){
  382:     return YY_NO_ACTION;
  383:   }
  384:   i += iLookAhead;
  385:   if( i<0 || (size_t)i>=YY_SZ_ACTTAB || yy_lookahead[i]!=iLookAhead ){
  386:     return yy_default[stateno];
  387:   }else{
  388:     return yy_action[i];
  389:   }
  390: }
  391: 
  392: /*
  393: ** Perform a shift action.
  394: */
  395: static void yy_shift(
  396:   yyParser *yypParser,          /* The parser to be shifted */
  397:   int yyNewState,               /* The new state to shift in */
  398:   int yyMajor,                  /* The major token to shift in */
  399:   YYMINORTYPE *yypMinor         /* Pointer ot the minor token to shift in */
  400: ){
  401:   yyStackEntry *yytos;
  402:   yypParser->yyidx++;
  403:   if( yypParser->yyidx>=YYSTACKDEPTH ){
  404:      ParseARG_FETCH;
  405:      yypParser->yyidx--;
  406: #ifndef NDEBUG
  407:      if( yyTraceFILE ){
  408:        fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt);
  409:      }
  410: #endif
  411:      while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
  412:      /* Here code is inserted which will execute if the parser
  413:      ** stack every overflows */
  414: %%
  415:      ParseARG_STORE; /* Suppress warning about unused %extra_argument var */
  416:      return;
  417:   }
  418:   yytos = &yypParser->yystack[yypParser->yyidx];
  419:   yytos->stateno = yyNewState;
  420:   yytos->major = yyMajor;
  421:   yytos->minor = *yypMinor;
  422: #ifndef NDEBUG
  423:   if( yyTraceFILE && yypParser->yyidx>0 ){
  424:     int i;
  425:     fprintf(yyTraceFILE,"%sShift %d\n",yyTracePrompt,yyNewState);
  426:     fprintf(yyTraceFILE,"%sStack:",yyTracePrompt);
  427:     for(i=1; i<=yypParser->yyidx; i++)
  428:       fprintf(yyTraceFILE," %s",yyTokenName[yypParser->yystack[i].major]);
  429:     fprintf(yyTraceFILE,"\n");
  430:   }
  431: #endif
  432: }
  433: 
  434: /* The following table contains information about every rule that
  435: ** is used during the reduce.
  436: */
  437: static struct {
  438:   YYCODETYPE lhs;         /* Symbol on the left-hand side of the rule */
  439:   unsigned char nrhs;     /* Number of right-hand side symbols in the rule */
  440: } yyRuleInfo[] = {
  441: %%
  442: };
  443: 
  444: static void yy_accept(yyParser*);  /* Forward Declaration */
  445: 
  446: /*
  447: ** Perform a reduce action and the shift that must immediately
  448: ** follow the reduce.
  449: */
  450: static void yy_reduce(
  451:   yyParser *yypParser,         /* The parser */
  452:   int yyruleno                 /* Number of the rule by which to reduce */
  453: ){
  454:   int yygoto;                     /* The next state */
  455:   int yyact;                      /* The next action */
  456:   YYMINORTYPE yygotominor;        /* The LHS of the rule reduced */
  457:   yyStackEntry *yymsp;            /* The top of the parser's stack */
  458:   int yysize;                     /* Amount to pop the stack */
  459:   ParseARG_FETCH;
  460:   yymsp = &yypParser->yystack[yypParser->yyidx];
  461: #ifndef NDEBUG
  462:   if( yyTraceFILE && yyruleno>=0
  463:         && (size_t)yyruleno<sizeof(yyRuleName)/sizeof(yyRuleName[0]) ){
  464:     fprintf(yyTraceFILE, "%sReduce [%s].\n", yyTracePrompt,
  465:       yyRuleName[yyruleno]);
  466:   }
  467: #endif /* NDEBUG */
  468: 
  469:   switch( yyruleno ){
  470:   /* Beginning here are the reduction cases.  A typical example
  471:   ** follows:
  472:   **   case 0:
  473:   **  #line <lineno> <grammarfile>
  474:   **     { ... }           // User supplied code
  475:   **  #line <lineno> <thisfile>
  476:   **     break;
  477:   */
  478: %%
  479:   };
  480:   yygoto = yyRuleInfo[yyruleno].lhs;
  481:   yysize = yyRuleInfo[yyruleno].nrhs;
  482:   yypParser->yyidx -= yysize;
  483:   yyact = yy_find_reduce_action(yypParser,yygoto);
  484:   if( yyact < YYNSTATE ){
  485:     yy_shift(yypParser,yyact,yygoto,&yygotominor);
  486:   }else if( yyact == YYNSTATE + YYNRULE + 1 ){
  487:     yy_accept(yypParser);
  488:   }
  489: }
  490: 
  491: /*
  492: ** The following code executes when the parse fails
  493: */
  494: static void yy_parse_failed(
  495:   yyParser *yypParser           /* The parser */
  496: ){
  497:   ParseARG_FETCH;
  498: #ifndef NDEBUG
  499:   if( yyTraceFILE ){
  500:     fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt);
  501:   }
  502: #endif
  503:   while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
  504:   /* Here code is inserted which will be executed whenever the
  505:   ** parser fails */
  506: %%
  507:   ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
  508: }
  509: 
  510: /*
  511: ** The following code executes when a syntax error first occurs.
  512: */
  513: static void yy_syntax_error(
  514:   yyParser *yypParser,           /* The parser */
  515:   int yymajor,                   /* The major type of the error token */
  516:   YYMINORTYPE yyminor            /* The minor type of the error token */
  517: ){
  518:   ParseARG_FETCH;
  519:   UNUSED(yymajor);
  520:   UNUSED(yyminor);
  521: #define TOKEN (yyminor.yy0)
  522: %%
  523:   ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
  524: }
  525: 
  526: /*
  527: ** The following is executed when the parser accepts
  528: */
  529: static void yy_accept(
  530:   yyParser *yypParser           /* The parser */
  531: ){
  532:   ParseARG_FETCH;
  533: #ifndef NDEBUG
  534:   if( yyTraceFILE ){
  535:     fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt);
  536:   }
  537: #endif
  538:   while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
  539:   /* Here code is inserted which will be executed whenever the
  540:   ** parser accepts */
  541: %%
  542:   ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
  543: }
  544: 
  545: /* The main parser program.
  546: ** The first argument is a pointer to a structure obtained from
  547: ** "ParseAlloc" which describes the current state of the parser.
  548: ** The second argument is the major token number.  The third is
  549: ** the minor token.  The fourth optional argument is whatever the
  550: ** user wants (and specified in the grammar) and is available for
  551: ** use by the action routines.
  552: **
  553: ** Inputs:
  554: ** <ul>
  555: ** <li> A pointer to the parser (an opaque structure.)
  556: ** <li> The major token number.
  557: ** <li> The minor token number.
  558: ** <li> An option argument of a grammar-specified type.
  559: ** </ul>
  560: **
  561: ** Outputs:
  562: ** None.
  563: */
  564: void Parse(
  565:   void *yyp,                   /* The parser */
  566:   int yymajor,                 /* The major token code number */
  567:   ParseTOKENTYPE yyminor       /* The value for the token */
  568:   ParseARG_PDECL               /* Optional %extra_argument parameter */
  569: ){
  570:   YYMINORTYPE yyminorunion;
  571:   int yyact;            /* The parser action. */
  572:   int yyendofinput;     /* True if we are at the end of input */
  573:   int yyerrorhit = 0;   /* True if yymajor has invoked an error */
  574:   yyParser *yypParser;  /* The parser */
  575: 
  576:   /* (re)initialize the parser, if necessary */
  577:   yypParser = (yyParser*)yyp;
  578:   if( yypParser->yyidx<0 ){
  579:     if( yymajor==0 ) return;
  580:     yypParser->yyidx = 0;
  581:     yypParser->yyerrcnt = -1;
  582:     yypParser->yystack[0].stateno = 0;
  583:     yypParser->yystack[0].major = 0;
  584:   }
  585:   yyminorunion.yy0 = yyminor;
  586:   yyendofinput = (yymajor==0);
  587:   ParseARG_STORE;
  588: 
  589: #ifndef NDEBUG
  590:   if( yyTraceFILE ){
  591:     fprintf(yyTraceFILE,"%sInput %s\n",yyTracePrompt,yyTokenName[yymajor]);
  592:   }
  593: #endif
  594: 
  595:   do{
  596:     yyact = yy_find_shift_action(yypParser,yymajor);
  597:     if( yyact<YYNSTATE ){
  598:       yy_shift(yypParser,yyact,yymajor,&yyminorunion);
  599:       yypParser->yyerrcnt--;
  600:       if( yyendofinput && yypParser->yyidx>=0 ){
  601:         yymajor = 0;
  602:       }else{
  603:         yymajor = YYNOCODE;
  604:       }
  605:     }else if( yyact < YYNSTATE + YYNRULE ){
  606:       yy_reduce(yypParser,yyact-YYNSTATE);
  607:     }else if( yyact == YY_ERROR_ACTION ){
  608:       int yymx;
  609: #ifndef NDEBUG
  610:       if( yyTraceFILE ){
  611:         fprintf(yyTraceFILE,"%sSyntax Error!\n",yyTracePrompt);
  612:       }
  613: #endif
  614: #ifdef YYERRORSYMBOL
  615:       /* A syntax error has occurred.
  616:       ** The response to an error depends upon whether or not the
  617:       ** grammar defines an error token "ERROR".
  618:       **
  619:       ** This is what we do if the grammar does define ERROR:
  620:       **
  621:       **  * Call the %syntax_error function.
  622:       **
  623:       **  * Begin popping the stack until we enter a state where
  624:       **    it is legal to shift the error symbol, then shift
  625:       **    the error symbol.
  626:       **
  627:       **  * Set the error count to three.
  628:       **
  629:       **  * Begin accepting and shifting new tokens.  No new error
  630:       **    processing will occur until three tokens have been
  631:       **    shifted successfully.
  632:       **
  633:       */
  634:       if( yypParser->yyerrcnt<0 ){
  635:         yy_syntax_error(yypParser,yymajor,yyminorunion);
  636:       }
  637:       yymx = yypParser->yystack[yypParser->yyidx].major;
  638:       if( yymx==YYERRORSYMBOL || yyerrorhit ){
  639: #ifndef NDEBUG
  640:         if( yyTraceFILE ){
  641:           fprintf(yyTraceFILE,"%sDiscard input token %s\n",
  642:              yyTracePrompt,yyTokenName[yymajor]);
  643:         }
  644: #endif
  645:         yy_destructor(yymajor,&yyminorunion);
  646:         yymajor = YYNOCODE;
  647:       }else{
  648:          while(
  649:           yypParser->yyidx >= 0 &&
  650:           yymx != YYERRORSYMBOL &&
  651:           (yyact = yy_find_shift_action(yypParser,YYERRORSYMBOL)) >= YYNSTATE
  652:         ){
  653:           yy_pop_parser_stack(yypParser);
  654:         }
  655:         if( yypParser->yyidx < 0 || yymajor==0 ){
  656:           yy_destructor(yymajor,&yyminorunion);
  657:           yy_parse_failed(yypParser);
  658:           yymajor = YYNOCODE;
  659:         }else if( yymx!=YYERRORSYMBOL ){
  660:           YYMINORTYPE u2;
  661:           u2.YYERRSYMDT = 0;
  662:           yy_shift(yypParser,yyact,YYERRORSYMBOL,&u2);
  663:         }
  664:       }
  665:       yypParser->yyerrcnt = 3;
  666:       yyerrorhit = 1;
  667: #else  /* YYERRORSYMBOL is not defined */
  668:       /* This is what we do if the grammar does not define ERROR:
  669:       **
  670:       **  * Report an error message, and throw away the input token.
  671:       **
  672:       **  * If the input token is $, then fail the parse.
  673:       **
  674:       ** As before, subsequent error messages are suppressed until
  675:       ** three input tokens have been successfully shifted.
  676:       */
  677:       if( yypParser->yyerrcnt<=0 ){
  678:         yy_syntax_error(yypParser,yymajor,yyminorunion);
  679:       }
  680:       yypParser->yyerrcnt = 3;
  681:       yy_destructor(yymajor,&yyminorunion);
  682:       if( yyendofinput ){
  683:         yy_parse_failed(yypParser);
  684:       }
  685:       yymajor = YYNOCODE;
  686: #endif
  687:     }else{
  688:       yy_accept(yypParser);
  689:       yymajor = YYNOCODE;
  690:     }
  691:   }while( yymajor!=YYNOCODE && yypParser->yyidx>=0 );
  692:   return;
  693: }

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