Annotation of embedaddon/lighttpd/src/mod_ssi_exprparser.c, revision 1.1.1.2

1.1       misho       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. */
1.1.1.2 ! misho       6: #include "first.h"
1.1       misho       7: #include <stdio.h>
                      8: #line 6 "../../src/mod_ssi_exprparser.y"
                      9: 
1.1.1.2 ! misho      10: #include "first.h"
1.1       misho      11: #include "mod_ssi_expr.h"
                     12: #include "buffer.h"
                     13: 
                     14: #include <assert.h>
                     15: #include <string.h>
                     16: 
1.1.1.2 ! misho      17: #line 18 "mod_ssi_exprparser.c"
1.1       misho      18: /* Next is all token values, in a form suitable for use by makeheaders.
                     19: ** This section will be null unless lemon is run with the -m switch.
                     20: */
                     21: /*
                     22: ** These constants (all generated automatically by the parser generator)
                     23: ** specify the various kinds of tokens (terminals) that the parser
                     24: ** understands.
                     25: **
                     26: ** Each symbol here is a terminal symbol in the grammar.
                     27: */
                     28: /* Make sure the INTERFACE macro is defined.
                     29: */
                     30: #ifndef INTERFACE
                     31: # define INTERFACE 1
                     32: #endif
                     33: /* The next thing included is series of defines which control
                     34: ** various aspects of the generated parser.
                     35: **    YYCODETYPE         is the data type used for storing terminal
                     36: **                       and nonterminal numbers.  "unsigned char" is
                     37: **                       used if there are fewer than 250 terminals
                     38: **                       and nonterminals.  "int" is used otherwise.
                     39: **    YYNOCODE           is a number of type YYCODETYPE which corresponds
                     40: **                       to no legal terminal or nonterminal number.  This
                     41: **                       number is used to fill in empty slots of the hash
                     42: **                       table.
                     43: **    YYFALLBACK         If defined, this indicates that one or more tokens
                     44: **                       have fall-back values which should be used if the
                     45: **                       original value of the token will not parse.
                     46: **    YYACTIONTYPE       is the data type used for storing terminal
                     47: **                       and nonterminal numbers.  "unsigned char" is
                     48: **                       used if there are fewer than 250 rules and
                     49: **                       states combined.  "int" is used otherwise.
                     50: **    ssiexprparserTOKENTYPE     is the data type used for minor tokens given
                     51: **                       directly to the parser from the tokenizer.
                     52: **    YYMINORTYPE        is the data type used for all minor tokens.
                     53: **                       This is typically a union of many types, one of
                     54: **                       which is ssiexprparserTOKENTYPE.  The entry in the union
                     55: **                       for base tokens is called "yy0".
                     56: **    YYSTACKDEPTH       is the maximum depth of the parser's stack.
                     57: **    ssiexprparserARG_SDECL     A static variable declaration for the %extra_argument
                     58: **    ssiexprparserARG_PDECL     A parameter declaration for the %extra_argument
                     59: **    ssiexprparserARG_STORE     Code to store %extra_argument into yypParser
                     60: **    ssiexprparserARG_FETCH     Code to extract %extra_argument from yypParser
                     61: **    YYNSTATE           the combined number of states.
                     62: **    YYNRULE            the number of rules in the grammar
                     63: **    YYERRORSYMBOL      is the code number of the error symbol.  If not
                     64: **                       defined, then do no error processing.
                     65: */
                     66: /* & */
                     67: #define YYCODETYPE unsigned char
                     68: #define YYNOCODE 20
                     69: #define YYACTIONTYPE unsigned char
                     70: #define ssiexprparserTOKENTYPE buffer *
                     71: typedef union {
                     72:   ssiexprparserTOKENTYPE yy0;
                     73:   int yy8;
                     74:   buffer * yy19;
                     75:   ssi_val_t * yy29;
                     76:   int yy39;
                     77: } YYMINORTYPE;
                     78: #define YYSTACKDEPTH 100
                     79: #define ssiexprparserARG_SDECL ssi_ctx_t *ctx;
                     80: #define ssiexprparserARG_PDECL ,ssi_ctx_t *ctx
                     81: #define ssiexprparserARG_FETCH ssi_ctx_t *ctx = yypParser->ctx
                     82: #define ssiexprparserARG_STORE yypParser->ctx = ctx
                     83: #define YYNSTATE 23
                     84: #define YYNRULE 16
                     85: #define YYERRORSYMBOL 13
                     86: #define YYERRSYMDT yy39
                     87: #define YY_NO_ACTION      (YYNSTATE+YYNRULE+2)
                     88: #define YY_ACCEPT_ACTION  (YYNSTATE+YYNRULE+1)
                     89: #define YY_ERROR_ACTION   (YYNSTATE+YYNRULE)
                     90: 
                     91: /* Next are that tables used to determine what action to take based on the
                     92: ** current state and lookahead token.  These tables are used to implement
                     93: ** functions that take a state number and lookahead value and return an
                     94: ** action integer.
                     95: **
                     96: ** Suppose the action integer is N.  Then the action is determined as
                     97: ** follows
                     98: **
                     99: **   0 <= N < YYNSTATE                  Shift N.  That is, push the lookahead
                    100: **                                      token onto the stack and goto state N.
                    101: **
                    102: **   YYNSTATE <= N < YYNSTATE+YYNRULE   Reduce by rule N-YYNSTATE.
                    103: **
                    104: **   N == YYNSTATE+YYNRULE              A syntax error has occurred.
                    105: **
                    106: **   N == YYNSTATE+YYNRULE+1            The parser accepts its input.
                    107: **
                    108: **   N == YYNSTATE+YYNRULE+2            No such action.  Denotes unused
                    109: **                                      slots in the yy_action[] table.
                    110: **
                    111: ** The action table is constructed as a single large table named yy_action[].
                    112: ** Given state S and lookahead X, the action is computed as
                    113: **
                    114: **      yy_action[ yy_shift_ofst[S] + X ]
                    115: **
                    116: ** If the index value yy_shift_ofst[S]+X is out of range or if the value
                    117: ** yy_lookahead[yy_shift_ofst[S]+X] is not equal to X or if yy_shift_ofst[S]
                    118: ** is equal to YY_SHIFT_USE_DFLT, it means that the action is not in the table
                    119: ** and that yy_default[S] should be used instead.
                    120: **
                    121: ** The formula above is for computing the action when the lookahead is
                    122: ** a terminal symbol.  If the lookahead is a non-terminal (as occurs after
                    123: ** a reduce action) then the yy_reduce_ofst[] array is used in place of
                    124: ** the yy_shift_ofst[] array and YY_REDUCE_USE_DFLT is used in place of
                    125: ** YY_SHIFT_USE_DFLT.
                    126: **
                    127: ** The following are the tables generated in this section:
                    128: **
                    129: **  yy_action[]        A single table containing all actions.
                    130: **  yy_lookahead[]     A table containing the lookahead for each entry in
                    131: **                     yy_action.  Used to detect hash collisions.
                    132: **  yy_shift_ofst[]    For each state, the offset into yy_action for
                    133: **                     shifting terminals.
                    134: **  yy_reduce_ofst[]   For each state, the offset into yy_action for
                    135: **                     shifting non-terminals after a reduce.
                    136: **  yy_default[]       Default action for each state.
                    137: */
                    138: static YYACTIONTYPE yy_action[] = {
                    139:  /*     0 */     5,    7,   17,   18,   22,   20,   21,   19,    2,   14,
                    140:  /*    10 */     1,   23,   40,    9,   11,    3,   16,    2,   14,   12,
                    141:  /*    20 */     4,   14,    5,    7,    6,   14,    7,    8,   14,   10,
                    142:  /*    30 */    14,   13,   37,   37,   15,
                    143: };
                    144: static YYCODETYPE yy_lookahead[] = {
                    145:  /*     0 */     1,    2,    3,    4,    5,    6,    7,    8,   14,   15,
                    146:  /*    10 */    16,    0,   18,    9,   10,   17,   12,   14,   15,   16,
                    147:  /*    20 */    14,   15,    1,    2,   14,   15,    2,   14,   15,   14,
                    148:  /*    30 */    15,   11,   19,   19,   12,
                    149: };
                    150: #define YY_SHIFT_USE_DFLT (-2)
                    151: static signed char yy_shift_ofst[] = {
                    152:  /*     0 */     4,   11,   -1,    4,   21,    4,   24,    4,   -2,    4,
                    153:  /*    10 */    -2,    4,   20,   -2,   22,   -2,   -2,   -2,   -2,   -2,
                    154:  /*    20 */    -2,   -2,   -2,
                    155: };
                    156: #define YY_REDUCE_USE_DFLT (-7)
                    157: static signed char yy_reduce_ofst[] = {
                    158:  /*     0 */    -6,   -7,   -2,    6,   -7,   10,   -7,   13,   -7,   15,
                    159:  /*    10 */    -7,    3,   -7,   -7,   -7,   -7,   -7,   -7,   -7,   -7,
                    160:  /*    20 */    -7,   -7,   -7,
                    161: };
                    162: static YYACTIONTYPE yy_default[] = {
                    163:  /*     0 */    39,   39,   25,   39,   24,   39,   26,   39,   27,   39,
                    164:  /*    10 */    28,   39,   39,   29,   30,   32,   31,   33,   34,   35,
                    165:  /*    20 */    36,   37,   38,
                    166: };
                    167: #define YY_SZ_ACTTAB (sizeof(yy_action)/sizeof(yy_action[0]))
                    168: 
                    169: /* The next table maps tokens into fallback tokens.  If a construct
                    170: ** like the following:
                    171: **
                    172: **      %fallback ID X Y Z.
                    173: **
                    174: ** appears in the grammer, then ID becomes a fallback token for X, Y,
                    175: ** and Z.  Whenever one of the tokens X, Y, or Z is input to the parser
                    176: ** but it does not parse, the type of the token is changed to ID and
                    177: ** the parse is retried before an error is thrown.
                    178: */
                    179: #ifdef YYFALLBACK
                    180: static const YYCODETYPE yyFallback[] = {
                    181: };
                    182: #endif /* YYFALLBACK */
                    183: 
                    184: /* The following structure represents a single element of the
                    185: ** parser's stack.  Information stored includes:
                    186: **
                    187: **   +  The state number for the parser at this level of the stack.
                    188: **
                    189: **   +  The value of the token stored at this level of the stack.
                    190: **      (In other words, the "major" token.)
                    191: **
                    192: **   +  The semantic value stored at this level of the stack.  This is
                    193: **      the information used by the action routines in the grammar.
                    194: **      It is sometimes called the "minor" token.
                    195: */
                    196: struct yyStackEntry {
                    197:   int stateno;       /* The state-number */
                    198:   int major;         /* The major token value.  This is the code
                    199:                      ** number for the token at this stack level */
                    200:   YYMINORTYPE minor; /* The user-supplied minor token value.  This
                    201:                      ** is the value of the token  */
                    202: };
                    203: typedef struct yyStackEntry yyStackEntry;
                    204: 
                    205: /* The state of the parser is completely contained in an instance of
                    206: ** the following structure */
                    207: struct yyParser {
                    208:   int yyidx;                    /* Index of top element in stack */
                    209:   int yyerrcnt;                 /* Shifts left before out of the error */
                    210:   ssiexprparserARG_SDECL                /* A place to hold %extra_argument */
                    211:   yyStackEntry yystack[YYSTACKDEPTH];  /* The parser's stack */
                    212: };
                    213: typedef struct yyParser yyParser;
                    214: 
                    215: #ifndef NDEBUG
                    216: #include <stdio.h>
                    217: static FILE *yyTraceFILE = NULL;
                    218: static char *yyTracePrompt = NULL;
                    219: #endif /* NDEBUG */
                    220: 
                    221: #ifndef NDEBUG
                    222: /*
                    223: ** Turn parser tracing on by giving a stream to which to write the trace
                    224: ** and a prompt to preface each trace message.  Tracing is turned off
                    225: ** by making either argument NULL
                    226: **
                    227: ** Inputs:
                    228: ** <ul>
                    229: ** <li> A FILE* to which trace output should be written.
                    230: **      If NULL, then tracing is turned off.
                    231: ** <li> A prefix string written at the beginning of every
                    232: **      line of trace output.  If NULL, then tracing is
                    233: **      turned off.
                    234: ** </ul>
                    235: **
                    236: ** Outputs:
                    237: ** None.
                    238: */
                    239: #if 0
                    240: void ssiexprparserTrace(FILE *TraceFILE, char *zTracePrompt){
                    241:   yyTraceFILE = TraceFILE;
                    242:   yyTracePrompt = zTracePrompt;
                    243:   if( yyTraceFILE==0 ) yyTracePrompt = 0;
                    244:   else if( yyTracePrompt==0 ) yyTraceFILE = 0;
                    245: }
                    246: #endif
                    247: #endif /* NDEBUG */
                    248: 
                    249: #ifndef NDEBUG
                    250: /* For tracing shifts, the names of all terminals and nonterminals
                    251: ** are required.  The following table supplies these names */
                    252: static const char *yyTokenName[] = {
                    253:   "$",             "AND",           "OR",            "EQ",          
                    254:   "NE",            "GT",            "GE",            "LT",          
                    255:   "LE",            "NOT",           "LPARAN",        "RPARAN",      
                    256:   "VALUE",         "error",         "expr",          "value",       
                    257:   "exprline",      "cond",          "input",       
                    258: };
                    259: #endif /* NDEBUG */
                    260: 
                    261: #ifndef NDEBUG
                    262: /* For tracing reduce actions, the names of all rules are required.
                    263: */
                    264: static const char *yyRuleName[] = {
                    265:  /*   0 */ "input ::= exprline",
                    266:  /*   1 */ "exprline ::= expr cond expr",
                    267:  /*   2 */ "exprline ::= expr",
                    268:  /*   3 */ "expr ::= expr AND expr",
                    269:  /*   4 */ "expr ::= expr OR expr",
                    270:  /*   5 */ "expr ::= NOT expr",
                    271:  /*   6 */ "expr ::= LPARAN exprline RPARAN",
                    272:  /*   7 */ "expr ::= value",
                    273:  /*   8 */ "value ::= VALUE",
                    274:  /*   9 */ "value ::= value VALUE",
                    275:  /*  10 */ "cond ::= EQ",
                    276:  /*  11 */ "cond ::= NE",
                    277:  /*  12 */ "cond ::= LE",
                    278:  /*  13 */ "cond ::= GE",
                    279:  /*  14 */ "cond ::= LT",
                    280:  /*  15 */ "cond ::= GT",
                    281: };
                    282: #endif /* NDEBUG */
                    283: 
                    284: /*
                    285: ** This function returns the symbolic name associated with a token
                    286: ** value.
                    287: */
                    288: #if 0
                    289: const char *ssiexprparserTokenName(int tokenType){
                    290: #ifndef NDEBUG
                    291:   if( tokenType>0 && (size_t)tokenType<(sizeof(yyTokenName)/sizeof(yyTokenName[0])) ){
                    292:     return yyTokenName[tokenType];
                    293:   }else{
                    294:     return "Unknown";
                    295:   }
                    296: #else
                    297:   return "";
                    298: #endif
                    299: }
                    300: #endif
                    301: 
                    302: /*
                    303: ** This function allocates a new parser.
                    304: ** The only argument is a pointer to a function which works like
                    305: ** malloc.
                    306: **
                    307: ** Inputs:
                    308: ** A pointer to the function used to allocate memory.
                    309: **
                    310: ** Outputs:
                    311: ** A pointer to a parser.  This pointer is used in subsequent calls
                    312: ** to ssiexprparser and ssiexprparserFree.
                    313: */
                    314: void *ssiexprparserAlloc(void *(*mallocProc)(size_t)){
                    315:   yyParser *pParser;
                    316:   pParser = (yyParser*)(*mallocProc)( (size_t)sizeof(yyParser) );
                    317:   if( pParser ){
                    318:     pParser->yyidx = -1;
                    319:   }
                    320:   return pParser;
                    321: }
                    322: 
                    323: /* The following function deletes the value associated with a
                    324: ** symbol.  The symbol can be either a terminal or nonterminal.
                    325: ** "yymajor" is the symbol code, and "yypminor" is a pointer to
                    326: ** the value.
                    327: */
                    328: static void yy_destructor(YYCODETYPE yymajor, YYMINORTYPE *yypminor){
                    329:   switch( yymajor ){
                    330:     /* Here is inserted the actions which take place when a
                    331:     ** terminal or non-terminal is destroyed.  This can happen
                    332:     ** when the symbol is popped from the stack during a
                    333:     ** reduce or during error processing or when a parser is
                    334:     ** being destroyed before it is finished parsing.
                    335:     **
                    336:     ** Note: during a reduce, the only symbols destroyed are those
                    337:     ** which appear on the RHS of the rule, but which are not used
                    338:     ** inside the C code.
                    339:     */
                    340:     case 1:
                    341:     case 2:
                    342:     case 3:
                    343:     case 4:
                    344:     case 5:
                    345:     case 6:
                    346:     case 7:
                    347:     case 8:
                    348:     case 9:
                    349:     case 10:
                    350:     case 11:
                    351:     case 12:
1.1.1.2 ! misho     352: #line 23 "../../src/mod_ssi_exprparser.y"
1.1       misho     353: { buffer_free((yypminor->yy0)); }
1.1.1.2 ! misho     354: #line 354 "mod_ssi_exprparser.c"
1.1       misho     355:       break;
                    356:     default:  break;   /* If no destructor action specified: do nothing */
                    357:   }
                    358: }
                    359: 
                    360: /*
                    361: ** Pop the parser's stack once.
                    362: **
                    363: ** If there is a destructor routine associated with the token which
                    364: ** is popped from the stack, then call it.
                    365: **
                    366: ** Return the major token number for the symbol popped.
                    367: */
                    368: static int yy_pop_parser_stack(yyParser *pParser){
                    369:   YYCODETYPE yymajor;
1.1.1.2 ! misho     370:   yyStackEntry *yytos;
1.1       misho     371: 
                    372:   if( pParser->yyidx<0 ) return 0;
1.1.1.2 ! misho     373:   yytos = &pParser->yystack[pParser->yyidx];
1.1       misho     374: #ifndef NDEBUG
                    375:   if( yyTraceFILE && pParser->yyidx>=0 ){
                    376:     fprintf(yyTraceFILE,"%sPopping %s\n",
                    377:       yyTracePrompt,
                    378:       yyTokenName[yytos->major]);
                    379:   }
                    380: #endif
                    381:   yymajor = yytos->major;
                    382:   yy_destructor( yymajor, &yytos->minor);
                    383:   pParser->yyidx--;
                    384:   return yymajor;
                    385: }
                    386: 
                    387: /*
                    388: ** Deallocate and destroy a parser.  Destructors are all called for
                    389: ** all stack elements before shutting the parser down.
                    390: **
                    391: ** Inputs:
                    392: ** <ul>
                    393: ** <li>  A pointer to the parser.  This should be a pointer
                    394: **       obtained from ssiexprparserAlloc.
                    395: ** <li>  A pointer to a function used to reclaim memory obtained
                    396: **       from malloc.
                    397: ** </ul>
                    398: */
                    399: void ssiexprparserFree(
                    400:   void *p,                    /* The parser to be deleted */
                    401:   void (*freeProc)(void*)     /* Function used to reclaim memory */
                    402: ){
                    403:   yyParser *pParser = (yyParser*)p;
                    404:   if( pParser==NULL ) return;
                    405:   while( pParser->yyidx>=0 ) yy_pop_parser_stack(pParser);
                    406:   (*freeProc)((void*)pParser);
                    407: }
                    408: 
                    409: /*
                    410: ** Find the appropriate action for a parser given the terminal
                    411: ** look-ahead token iLookAhead.
                    412: **
                    413: ** If the look-ahead token is YYNOCODE, then check to see if the action is
                    414: ** independent of the look-ahead.  If it is, return the action, otherwise
                    415: ** return YY_NO_ACTION.
                    416: */
                    417: static int yy_find_shift_action(
                    418:   yyParser *pParser,        /* The parser */
                    419:   int iLookAhead            /* The look-ahead token */
                    420: ){
                    421:   int i;
                    422:   int stateno = pParser->yystack[pParser->yyidx].stateno;
                    423: 
                    424:   /* if( pParser->yyidx<0 ) return YY_NO_ACTION;  */
                    425:   i = yy_shift_ofst[stateno];
                    426:   if( i==YY_SHIFT_USE_DFLT ){
                    427:     return yy_default[stateno];
                    428:   }
                    429:   if( iLookAhead==YYNOCODE ){
                    430:     return YY_NO_ACTION;
                    431:   }
                    432:   i += iLookAhead;
                    433:   if( i<0 || (size_t)i>=YY_SZ_ACTTAB || yy_lookahead[i]!=iLookAhead ){
                    434: #ifdef YYFALLBACK
                    435:     int iFallback;            /* Fallback token */
                    436:     if( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0])
                    437:            && (iFallback = yyFallback[iLookAhead])!=0 ){
                    438: #ifndef NDEBUG
                    439:       if( yyTraceFILE ){
                    440:         fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n",
                    441:            yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]);
                    442:       }
                    443: #endif
                    444:       return yy_find_shift_action(pParser, iFallback);
                    445:     }
                    446: #endif
                    447:     return yy_default[stateno];
                    448:   }else{
                    449:     return yy_action[i];
                    450:   }
                    451: }
                    452: 
                    453: /*
                    454: ** Find the appropriate action for a parser given the non-terminal
                    455: ** look-ahead token iLookAhead.
                    456: **
                    457: ** If the look-ahead token is YYNOCODE, then check to see if the action is
                    458: ** independent of the look-ahead.  If it is, return the action, otherwise
                    459: ** return YY_NO_ACTION.
                    460: */
                    461: static int yy_find_reduce_action(
                    462:   yyParser *pParser,        /* The parser */
                    463:   int iLookAhead            /* The look-ahead token */
                    464: ){
                    465:   int i;
                    466:   int stateno = pParser->yystack[pParser->yyidx].stateno;
                    467: 
                    468:   i = yy_reduce_ofst[stateno];
                    469:   if( i==YY_REDUCE_USE_DFLT ){
                    470:     return yy_default[stateno];
                    471:   }
                    472:   if( iLookAhead==YYNOCODE ){
                    473:     return YY_NO_ACTION;
                    474:   }
                    475:   i += iLookAhead;
                    476:   if( i<0 || (size_t)i>=YY_SZ_ACTTAB || yy_lookahead[i]!=iLookAhead ){
                    477:     return yy_default[stateno];
                    478:   }else{
                    479:     return yy_action[i];
                    480:   }
                    481: }
                    482: 
                    483: /*
                    484: ** Perform a shift action.
                    485: */
                    486: static void yy_shift(
                    487:   yyParser *yypParser,          /* The parser to be shifted */
                    488:   int yyNewState,               /* The new state to shift in */
                    489:   int yyMajor,                  /* The major token to shift in */
                    490:   YYMINORTYPE *yypMinor         /* Pointer ot the minor token to shift in */
                    491: ){
                    492:   yyStackEntry *yytos;
                    493:   yypParser->yyidx++;
                    494:   if( yypParser->yyidx>=YYSTACKDEPTH ){
                    495:      ssiexprparserARG_FETCH;
                    496:      yypParser->yyidx--;
                    497: #ifndef NDEBUG
                    498:      if( yyTraceFILE ){
                    499:        fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt);
                    500:      }
                    501: #endif
                    502:      while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
                    503:      /* Here code is inserted which will execute if the parser
                    504:      ** stack every overflows */
                    505:      ssiexprparserARG_STORE; /* Suppress warning about unused %extra_argument var */
                    506:      return;
                    507:   }
                    508:   yytos = &yypParser->yystack[yypParser->yyidx];
                    509:   yytos->stateno = yyNewState;
                    510:   yytos->major = yyMajor;
                    511:   yytos->minor = *yypMinor;
                    512: #ifndef NDEBUG
                    513:   if( yyTraceFILE && yypParser->yyidx>0 ){
                    514:     int i;
                    515:     fprintf(yyTraceFILE,"%sShift %d\n",yyTracePrompt,yyNewState);
                    516:     fprintf(yyTraceFILE,"%sStack:",yyTracePrompt);
                    517:     for(i=1; i<=yypParser->yyidx; i++)
                    518:       fprintf(yyTraceFILE," %s",yyTokenName[yypParser->yystack[i].major]);
                    519:     fprintf(yyTraceFILE,"\n");
                    520:   }
                    521: #endif
                    522: }
                    523: 
                    524: /* The following table contains information about every rule that
                    525: ** is used during the reduce.
                    526: */
                    527: static struct {
                    528:   YYCODETYPE lhs;         /* Symbol on the left-hand side of the rule */
                    529:   unsigned char nrhs;     /* Number of right-hand side symbols in the rule */
                    530: } yyRuleInfo[] = {
                    531:   { 18, 1 },
                    532:   { 16, 3 },
                    533:   { 16, 1 },
                    534:   { 14, 3 },
                    535:   { 14, 3 },
                    536:   { 14, 2 },
                    537:   { 14, 3 },
                    538:   { 14, 1 },
                    539:   { 15, 1 },
                    540:   { 15, 2 },
                    541:   { 17, 1 },
                    542:   { 17, 1 },
                    543:   { 17, 1 },
                    544:   { 17, 1 },
                    545:   { 17, 1 },
                    546:   { 17, 1 },
                    547: };
                    548: 
                    549: static void yy_accept(yyParser*);  /* Forward Declaration */
                    550: 
                    551: /*
                    552: ** Perform a reduce action and the shift that must immediately
                    553: ** follow the reduce.
                    554: */
                    555: static void yy_reduce(
                    556:   yyParser *yypParser,         /* The parser */
                    557:   int yyruleno                 /* Number of the rule by which to reduce */
                    558: ){
                    559:   int yygoto;                     /* The next state */
                    560:   int yyact;                      /* The next action */
                    561:   YYMINORTYPE yygotominor;        /* The LHS of the rule reduced */
                    562:   yyStackEntry *yymsp;            /* The top of the parser's stack */
                    563:   int yysize;                     /* Amount to pop the stack */
                    564:   ssiexprparserARG_FETCH;
                    565:   yymsp = &yypParser->yystack[yypParser->yyidx];
                    566: #ifndef NDEBUG
1.1.1.2 ! misho     567:   if( yyTraceFILE ) {
        !           568:     if (yyruleno>=0
1.1       misho     569:         && (size_t)yyruleno<sizeof(yyRuleName)/sizeof(yyRuleName[0]) ){
1.1.1.2 ! misho     570:       fprintf(yyTraceFILE, "%sReduce [%s].\n", yyTracePrompt,
        !           571:         yyRuleName[yyruleno]);
        !           572:     } else {
        !           573:       return; /*(should not happen)*/
        !           574:     }
1.1       misho     575:   }
                    576: #endif /* NDEBUG */
                    577: 
                    578:   switch( yyruleno ){
                    579:   /* Beginning here are the reduction cases.  A typical example
                    580:   ** follows:
                    581:   **   case 0:
                    582:   **  #line <lineno> <grammarfile>
                    583:   **     { ... }           // User supplied code
                    584:   **  #line <lineno> <thisfile>
                    585:   **     break;
                    586:   */
                    587:       case 0:
1.1.1.2 ! misho     588: #line 30 "../../src/mod_ssi_exprparser.y"
1.1       misho     589: {
                    590:   ctx->val.bo = ssi_val_tobool(yymsp[0].minor.yy29);
                    591:   ctx->val.type = SSI_TYPE_BOOL;
                    592: 
                    593:   ssi_val_free(yymsp[0].minor.yy29);
                    594: }
1.1.1.2 ! misho     595: #line 595 "mod_ssi_exprparser.c"
1.1       misho     596:         break;
                    597:       case 1:
1.1.1.2 ! misho     598: #line 37 "../../src/mod_ssi_exprparser.y"
1.1       misho     599: {
                    600:   int cmp;
                    601: 
                    602:   if (yymsp[-2].minor.yy29->type == SSI_TYPE_STRING &&
                    603:       yymsp[0].minor.yy29->type == SSI_TYPE_STRING) {
                    604:        cmp = strcmp(yymsp[-2].minor.yy29->str->ptr, yymsp[0].minor.yy29->str->ptr);
                    605:   } else {
                    606:     cmp = ssi_val_tobool(yymsp[-2].minor.yy29) - ssi_val_tobool(yymsp[0].minor.yy29);
                    607:   }
                    608: 
                    609:   yygotominor.yy29 = yymsp[-2].minor.yy29;
                    610: 
                    611:   switch(yymsp[-1].minor.yy8) {
                    612:   case SSI_COND_EQ: yygotominor.yy29->bo = (cmp == 0) ? 1 : 0; break;
                    613:   case SSI_COND_NE: yygotominor.yy29->bo = (cmp != 0) ? 1 : 0; break;
                    614:   case SSI_COND_GE: yygotominor.yy29->bo = (cmp >= 0) ? 1 : 0; break;
                    615:   case SSI_COND_GT: yygotominor.yy29->bo = (cmp > 0) ? 1 : 0; break;
                    616:   case SSI_COND_LE: yygotominor.yy29->bo = (cmp <= 0) ? 1 : 0; break;
                    617:   case SSI_COND_LT: yygotominor.yy29->bo = (cmp < 0) ? 1 : 0; break;
                    618:   }
                    619: 
                    620:   yygotominor.yy29->type = SSI_TYPE_BOOL;
                    621: 
                    622:   ssi_val_free(yymsp[0].minor.yy29);
                    623: }
1.1.1.2 ! misho     624: #line 624 "mod_ssi_exprparser.c"
1.1       misho     625:         break;
                    626:       case 2:
1.1.1.2 ! misho     627: #line 62 "../../src/mod_ssi_exprparser.y"
1.1       misho     628: {
                    629:   yygotominor.yy29 = yymsp[0].minor.yy29;
                    630: }
1.1.1.2 ! misho     631: #line 631 "mod_ssi_exprparser.c"
1.1       misho     632:         break;
                    633:       case 3:
1.1.1.2 ! misho     634: #line 65 "../../src/mod_ssi_exprparser.y"
1.1       misho     635: {
                    636:   int e;
                    637: 
                    638:   e = ssi_val_tobool(yymsp[-2].minor.yy29) && ssi_val_tobool(yymsp[0].minor.yy29);
                    639: 
                    640:   yygotominor.yy29 = yymsp[-2].minor.yy29;
                    641:   yygotominor.yy29->bo = e;
                    642:   yygotominor.yy29->type = SSI_TYPE_BOOL;
                    643:   ssi_val_free(yymsp[0].minor.yy29);
                    644: }
1.1.1.2 ! misho     645: #line 645 "mod_ssi_exprparser.c"
1.1       misho     646:   yy_destructor(1,&yymsp[-1].minor);
                    647:         break;
                    648:       case 4:
1.1.1.2 ! misho     649: #line 76 "../../src/mod_ssi_exprparser.y"
1.1       misho     650: {
                    651:   int e;
                    652: 
                    653:   e = ssi_val_tobool(yymsp[-2].minor.yy29) || ssi_val_tobool(yymsp[0].minor.yy29);
                    654: 
                    655:   yygotominor.yy29 = yymsp[-2].minor.yy29;
                    656:   yygotominor.yy29->bo = e;
                    657:   yygotominor.yy29->type = SSI_TYPE_BOOL;
                    658:   ssi_val_free(yymsp[0].minor.yy29);
                    659: }
1.1.1.2 ! misho     660: #line 660 "mod_ssi_exprparser.c"
1.1       misho     661:   yy_destructor(2,&yymsp[-1].minor);
                    662:         break;
                    663:       case 5:
1.1.1.2 ! misho     664: #line 87 "../../src/mod_ssi_exprparser.y"
1.1       misho     665: {
                    666:   int e;
                    667: 
                    668:   e = !ssi_val_tobool(yymsp[0].minor.yy29);
                    669: 
                    670:   yygotominor.yy29 = yymsp[0].minor.yy29;
                    671:   yygotominor.yy29->bo = e;
                    672:   yygotominor.yy29->type = SSI_TYPE_BOOL;
                    673: }
1.1.1.2 ! misho     674: #line 674 "mod_ssi_exprparser.c"
1.1       misho     675:   yy_destructor(9,&yymsp[-1].minor);
                    676:         break;
                    677:       case 6:
1.1.1.2 ! misho     678: #line 96 "../../src/mod_ssi_exprparser.y"
1.1       misho     679: {
                    680:   yygotominor.yy29 = yymsp[-1].minor.yy29;
                    681: }
1.1.1.2 ! misho     682: #line 682 "mod_ssi_exprparser.c"
1.1       misho     683:   yy_destructor(10,&yymsp[-2].minor);
                    684:   yy_destructor(11,&yymsp[0].minor);
                    685:         break;
                    686:       case 7:
1.1.1.2 ! misho     687: #line 100 "../../src/mod_ssi_exprparser.y"
1.1       misho     688: {
                    689:   yygotominor.yy29 = ssi_val_init();
                    690:   yygotominor.yy29->str = yymsp[0].minor.yy19;
                    691:   yygotominor.yy29->type = SSI_TYPE_STRING;
                    692: }
1.1.1.2 ! misho     693: #line 693 "mod_ssi_exprparser.c"
1.1       misho     694:         break;
                    695:       case 8:
1.1.1.2 ! misho     696: #line 106 "../../src/mod_ssi_exprparser.y"
1.1       misho     697: {
                    698:   yygotominor.yy19 = yymsp[0].minor.yy0;
                    699: }
1.1.1.2 ! misho     700: #line 700 "mod_ssi_exprparser.c"
1.1       misho     701:         break;
                    702:       case 9:
1.1.1.2 ! misho     703: #line 110 "../../src/mod_ssi_exprparser.y"
1.1       misho     704: {
                    705:   yygotominor.yy19 = yymsp[-1].minor.yy19;
                    706:   buffer_append_string_buffer(yygotominor.yy19, yymsp[0].minor.yy0);
                    707:   buffer_free(yymsp[0].minor.yy0);
                    708: }
1.1.1.2 ! misho     709: #line 709 "mod_ssi_exprparser.c"
1.1       misho     710:         break;
                    711:       case 10:
1.1.1.2 ! misho     712: #line 116 "../../src/mod_ssi_exprparser.y"
1.1       misho     713: { yygotominor.yy8 = SSI_COND_EQ; }
1.1.1.2 ! misho     714: #line 714 "mod_ssi_exprparser.c"
1.1       misho     715:   yy_destructor(3,&yymsp[0].minor);
                    716:         break;
                    717:       case 11:
1.1.1.2 ! misho     718: #line 117 "../../src/mod_ssi_exprparser.y"
1.1       misho     719: { yygotominor.yy8 = SSI_COND_NE; }
1.1.1.2 ! misho     720: #line 720 "mod_ssi_exprparser.c"
1.1       misho     721:   yy_destructor(4,&yymsp[0].minor);
                    722:         break;
                    723:       case 12:
1.1.1.2 ! misho     724: #line 118 "../../src/mod_ssi_exprparser.y"
1.1       misho     725: { yygotominor.yy8 = SSI_COND_LE; }
1.1.1.2 ! misho     726: #line 726 "mod_ssi_exprparser.c"
1.1       misho     727:   yy_destructor(8,&yymsp[0].minor);
                    728:         break;
                    729:       case 13:
1.1.1.2 ! misho     730: #line 119 "../../src/mod_ssi_exprparser.y"
1.1       misho     731: { yygotominor.yy8 = SSI_COND_GE; }
1.1.1.2 ! misho     732: #line 732 "mod_ssi_exprparser.c"
1.1       misho     733:   yy_destructor(6,&yymsp[0].minor);
                    734:         break;
                    735:       case 14:
1.1.1.2 ! misho     736: #line 120 "../../src/mod_ssi_exprparser.y"
1.1       misho     737: { yygotominor.yy8 = SSI_COND_LT; }
1.1.1.2 ! misho     738: #line 738 "mod_ssi_exprparser.c"
1.1       misho     739:   yy_destructor(7,&yymsp[0].minor);
                    740:         break;
                    741:       case 15:
1.1.1.2 ! misho     742: #line 121 "../../src/mod_ssi_exprparser.y"
1.1       misho     743: { yygotominor.yy8 = SSI_COND_GT; }
1.1.1.2 ! misho     744: #line 744 "mod_ssi_exprparser.c"
1.1       misho     745:   yy_destructor(5,&yymsp[0].minor);
                    746:         break;
                    747:   };
                    748:   yygoto = yyRuleInfo[yyruleno].lhs;
                    749:   yysize = yyRuleInfo[yyruleno].nrhs;
                    750:   yypParser->yyidx -= yysize;
                    751:   yyact = yy_find_reduce_action(yypParser,yygoto);
                    752:   if( yyact < YYNSTATE ){
                    753:     yy_shift(yypParser,yyact,yygoto,&yygotominor);
                    754:   }else if( yyact == YYNSTATE + YYNRULE + 1 ){
                    755:     yy_accept(yypParser);
                    756:   }
                    757: }
                    758: 
                    759: /*
                    760: ** The following code executes when the parse fails
                    761: */
                    762: static void yy_parse_failed(
                    763:   yyParser *yypParser           /* The parser */
                    764: ){
                    765:   ssiexprparserARG_FETCH;
                    766: #ifndef NDEBUG
                    767:   if( yyTraceFILE ){
                    768:     fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt);
                    769:   }
                    770: #endif
                    771:   while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
                    772:   /* Here code is inserted which will be executed whenever the
                    773:   ** parser fails */
1.1.1.2 ! misho     774: #line 15 "../../src/mod_ssi_exprparser.y"
1.1       misho     775: 
                    776:   ctx->ok = 0;
                    777: 
1.1.1.2 ! misho     778: #line 778 "mod_ssi_exprparser.c"
1.1       misho     779:   ssiexprparserARG_STORE; /* Suppress warning about unused %extra_argument variable */
                    780: }
                    781: 
                    782: /*
                    783: ** The following code executes when a syntax error first occurs.
                    784: */
                    785: static void yy_syntax_error(
                    786:   yyParser *yypParser,           /* The parser */
                    787:   int yymajor,                   /* The major type of the error token */
                    788:   YYMINORTYPE yyminor            /* The minor type of the error token */
                    789: ){
                    790:   ssiexprparserARG_FETCH;
                    791:   UNUSED(yymajor);
                    792:   UNUSED(yyminor);
                    793: #define TOKEN (yyminor.yy0)
                    794:   ssiexprparserARG_STORE; /* Suppress warning about unused %extra_argument variable */
                    795: }
                    796: 
                    797: /*
                    798: ** The following is executed when the parser accepts
                    799: */
                    800: static void yy_accept(
                    801:   yyParser *yypParser           /* The parser */
                    802: ){
                    803:   ssiexprparserARG_FETCH;
                    804: #ifndef NDEBUG
                    805:   if( yyTraceFILE ){
                    806:     fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt);
                    807:   }
                    808: #endif
                    809:   while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
                    810:   /* Here code is inserted which will be executed whenever the
                    811:   ** parser accepts */
                    812:   ssiexprparserARG_STORE; /* Suppress warning about unused %extra_argument variable */
                    813: }
                    814: 
                    815: /* The main parser program.
                    816: ** The first argument is a pointer to a structure obtained from
                    817: ** "ssiexprparserAlloc" which describes the current state of the parser.
                    818: ** The second argument is the major token number.  The third is
                    819: ** the minor token.  The fourth optional argument is whatever the
                    820: ** user wants (and specified in the grammar) and is available for
                    821: ** use by the action routines.
                    822: **
                    823: ** Inputs:
                    824: ** <ul>
                    825: ** <li> A pointer to the parser (an opaque structure.)
                    826: ** <li> The major token number.
                    827: ** <li> The minor token number.
                    828: ** <li> An option argument of a grammar-specified type.
                    829: ** </ul>
                    830: **
                    831: ** Outputs:
                    832: ** None.
                    833: */
                    834: void ssiexprparser(
                    835:   void *yyp,                   /* The parser */
                    836:   int yymajor,                 /* The major token code number */
                    837:   ssiexprparserTOKENTYPE yyminor       /* The value for the token */
                    838:   ssiexprparserARG_PDECL               /* Optional %extra_argument parameter */
                    839: ){
                    840:   YYMINORTYPE yyminorunion;
                    841:   int yyact;            /* The parser action. */
                    842:   int yyendofinput;     /* True if we are at the end of input */
                    843:   int yyerrorhit = 0;   /* True if yymajor has invoked an error */
                    844:   yyParser *yypParser;  /* The parser */
                    845: 
                    846:   /* (re)initialize the parser, if necessary */
                    847:   yypParser = (yyParser*)yyp;
                    848:   if( yypParser->yyidx<0 ){
                    849:     if( yymajor==0 ) return;
                    850:     yypParser->yyidx = 0;
                    851:     yypParser->yyerrcnt = -1;
                    852:     yypParser->yystack[0].stateno = 0;
                    853:     yypParser->yystack[0].major = 0;
                    854:   }
                    855:   yyminorunion.yy0 = yyminor;
                    856:   yyendofinput = (yymajor==0);
                    857:   ssiexprparserARG_STORE;
                    858: 
                    859: #ifndef NDEBUG
                    860:   if( yyTraceFILE ){
                    861:     fprintf(yyTraceFILE,"%sInput %s\n",yyTracePrompt,yyTokenName[yymajor]);
                    862:   }
                    863: #endif
                    864: 
                    865:   do{
                    866:     yyact = yy_find_shift_action(yypParser,yymajor);
                    867:     if( yyact<YYNSTATE ){
                    868:       yy_shift(yypParser,yyact,yymajor,&yyminorunion);
                    869:       yypParser->yyerrcnt--;
                    870:       if( yyendofinput && yypParser->yyidx>=0 ){
                    871:         yymajor = 0;
                    872:       }else{
                    873:         yymajor = YYNOCODE;
                    874:       }
                    875:     }else if( yyact < YYNSTATE + YYNRULE ){
                    876:       yy_reduce(yypParser,yyact-YYNSTATE);
                    877:     }else if( yyact == YY_ERROR_ACTION ){
                    878:       int yymx;
                    879: #ifndef NDEBUG
                    880:       if( yyTraceFILE ){
                    881:         fprintf(yyTraceFILE,"%sSyntax Error!\n",yyTracePrompt);
                    882:       }
                    883: #endif
                    884: #ifdef YYERRORSYMBOL
                    885:       /* A syntax error has occurred.
                    886:       ** The response to an error depends upon whether or not the
                    887:       ** grammar defines an error token "ERROR".
                    888:       **
                    889:       ** This is what we do if the grammar does define ERROR:
                    890:       **
                    891:       **  * Call the %syntax_error function.
                    892:       **
                    893:       **  * Begin popping the stack until we enter a state where
                    894:       **    it is legal to shift the error symbol, then shift
                    895:       **    the error symbol.
                    896:       **
                    897:       **  * Set the error count to three.
                    898:       **
                    899:       **  * Begin accepting and shifting new tokens.  No new error
                    900:       **    processing will occur until three tokens have been
                    901:       **    shifted successfully.
                    902:       **
                    903:       */
                    904:       if( yypParser->yyerrcnt<0 ){
                    905:         yy_syntax_error(yypParser,yymajor,yyminorunion);
                    906:       }
                    907:       yymx = yypParser->yystack[yypParser->yyidx].major;
                    908:       if( yymx==YYERRORSYMBOL || yyerrorhit ){
                    909: #ifndef NDEBUG
                    910:         if( yyTraceFILE ){
                    911:           fprintf(yyTraceFILE,"%sDiscard input token %s\n",
                    912:              yyTracePrompt,yyTokenName[yymajor]);
                    913:         }
                    914: #endif
                    915:         yy_destructor(yymajor,&yyminorunion);
                    916:         yymajor = YYNOCODE;
                    917:       }else{
                    918:          while(
                    919:           yypParser->yyidx >= 0 &&
                    920:           yymx != YYERRORSYMBOL &&
                    921:           (yyact = yy_find_shift_action(yypParser,YYERRORSYMBOL)) >= YYNSTATE
                    922:         ){
                    923:           yy_pop_parser_stack(yypParser);
                    924:         }
                    925:         if( yypParser->yyidx < 0 || yymajor==0 ){
                    926:           yy_destructor(yymajor,&yyminorunion);
                    927:           yy_parse_failed(yypParser);
                    928:           yymajor = YYNOCODE;
                    929:         }else if( yymx!=YYERRORSYMBOL ){
                    930:           YYMINORTYPE u2;
                    931:           u2.YYERRSYMDT = 0;
                    932:           yy_shift(yypParser,yyact,YYERRORSYMBOL,&u2);
                    933:         }
                    934:       }
                    935:       yypParser->yyerrcnt = 3;
                    936:       yyerrorhit = 1;
                    937: #else  /* YYERRORSYMBOL is not defined */
                    938:       /* This is what we do if the grammar does not define ERROR:
                    939:       **
                    940:       **  * Report an error message, and throw away the input token.
                    941:       **
                    942:       **  * If the input token is $, then fail the parse.
                    943:       **
                    944:       ** As before, subsequent error messages are suppressed until
                    945:       ** three input tokens have been successfully shifted.
                    946:       */
                    947:       if( yypParser->yyerrcnt<=0 ){
                    948:         yy_syntax_error(yypParser,yymajor,yyminorunion);
                    949:       }
                    950:       yypParser->yyerrcnt = 3;
                    951:       yy_destructor(yymajor,&yyminorunion);
                    952:       if( yyendofinput ){
                    953:         yy_parse_failed(yypParser);
                    954:       }
                    955:       yymajor = YYNOCODE;
                    956: #endif
                    957:     }else{
                    958:       yy_accept(yypParser);
                    959:       yymajor = YYNOCODE;
                    960:     }
                    961:   }while( yymajor!=YYNOCODE && yypParser->yyidx>=0 );
                    962:   return;
                    963: }

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