Add regression test for previous commit
[xapian.git] / xapian-core / queryparser / queryparser.lt
blob28ea86a82af80504b9d7602755afbc545dd7e262
1 /*
2 ** 2000-05-29
3 **
4 ** The author disclaims copyright to this source code.  In place of
5 ** a legal notice, here is a blessing:
6 **
7 **    May you do good and not evil.
8 **    May you find forgiveness for yourself and forgive others.
9 **    May you share freely, never taking more than you give.
11 *************************************************************************
12 ** Driver template for the LEMON parser generator.
14 ** Synced with upstream:
15 ** https://www.sqlite.org/src/artifact/468a155e8729cfbccfe1d85bf60d064f1dab76167a51149ec5c7928a2de63953
17 ** The "lemon" program processes an LALR(1) input grammar file, then uses
18 ** this template to construct a parser.  The "lemon" program inserts text
19 ** at each "%%" line.  Also, any "P-a-r-s-e" identifier prefix (without the
20 ** interstitial "-" characters) contained in this template is changed into
21 ** the value of the %name directive from the grammar.  Otherwise, the content
22 ** of this template is copied straight through into the generate parser
23 ** source file.
25 ** The following is the concatenation of all %include directives from the
26 ** input grammar file:
28 /************ Begin %include sections from the grammar ************************/
30 /**************** End of %include directives **********************************/
31 /* These constants specify the various numeric values for terminal symbols
32 ** in a format understandable to "makeheaders".  This section is blank unless
33 ** "lemon" is run with the "-m" command-line option.
34 ***************** Begin makeheaders token definitions *************************/
36 /**************** End makeheaders token definitions ***************************/
38 /* The next section is a series of control #defines.
39 ** various aspects of the generated parser.
40 **    YYCODETYPE         is the data type used to store the integer codes
41 **                       that represent terminal and non-terminal symbols.
42 **                       "unsigned char" is used if there are fewer than
43 **                       256 symbols.  Larger types otherwise.
44 **    YYNOCODE           is a number of type YYCODETYPE that is not used for
45 **                       any terminal or nonterminal symbol.
46 **    YYFALLBACK         If defined, this indicates that one or more tokens
47 **                       (also known as: "terminal symbols") have fall-back
48 **                       values which should be used if the original symbol
49 **                       would not parse.  This permits keywords to sometimes
50 **                       be used as identifiers, for example.
51 **    YYACTIONTYPE       is the data type used for "action codes" - numbers
52 **                       that indicate what to do in response to the next
53 **                       token.
54 **    ParseTOKENTYPE     is the data type used for minor type for terminal
55 **                       symbols.  Background: A "minor type" is a semantic
56 **                       value associated with a terminal or non-terminal
57 **                       symbols.  For example, for an "ID" terminal symbol,
58 **                       the minor type might be the name of the identifier.
59 **                       Each non-terminal can have a different minor type.
60 **                       Terminal symbols all have the same minor type, though.
61 **                       This macros defines the minor type for terminal 
62 **                       symbols.
63 **    YYMINORTYPE        is the data type used for all minor types.
64 **                       This is typically a union of many types, one of
65 **                       which is ParseTOKENTYPE.  The entry in the union
66 **                       for terminal symbols is called "yy0".
67 **    YYSTACKDEPTH       is the maximum depth of the parser's stack.  If
68 **                       zero the stack is dynamically sized using realloc()
69 **    ParseARG_SDECL     A static variable declaration for the %extra_argument
70 **    ParseARG_PDECL     A parameter declaration for the %extra_argument
71 **    ParseARG_STORE     Code to store %extra_argument into yypParser
72 **    ParseARG_FETCH     Code to extract %extra_argument from yypParser
73 **    YYERRORSYMBOL      is the code number of the error symbol.  If not
74 **                       defined, then do no error processing.
75 **    YYNSTATE           the combined number of states.
76 **    YYNRULE            the number of rules in the grammar
77 **    YYNTOKEN           Number of terminal symbols
78 **    YY_MAX_SHIFT       Maximum value for shift actions
79 **    YY_MIN_SHIFTREDUCE Minimum value for shift-reduce actions
80 **    YY_MAX_SHIFTREDUCE Maximum value for shift-reduce actions
81 **    YY_ERROR_ACTION    The yy_action[] code for syntax error
82 **    YY_ACCEPT_ACTION   The yy_action[] code for accept
83 **    YY_NO_ACTION       The yy_action[] code for no-op
84 **    YY_MIN_REDUCE      Minimum value for reduce actions
85 **    YY_MAX_REDUCE      Maximum value for reduce actions
87 #ifndef INTERFACE
88 # define INTERFACE 1
89 #endif
90 /************* Begin control #defines *****************************************/
92 /************* End control #defines *******************************************/
94 /* Define the yytestcase() macro to be a no-op if is not already defined
95 ** otherwise.
97 ** Applications can choose to define yytestcase() in the %include section
98 ** to a macro that can assist in verifying code coverage.  For production
99 ** code the yytestcase() macro should be turned off.  But it is useful
100 ** for testing.
102 #ifndef yytestcase
103 # define yytestcase(X)
104 #endif
107 /* Next are the tables used to determine what action to take based on the
108 ** current state and lookahead token.  These tables are used to implement
109 ** functions that take a state number and lookahead value and return an
110 ** action integer.  
112 ** Suppose the action integer is N.  Then the action is determined as
113 ** follows
115 **   0 <= N <= YY_MAX_SHIFT             Shift N.  That is, push the lookahead
116 **                                      token onto the stack and goto state N.
118 **   N between YY_MIN_SHIFTREDUCE       Shift to an arbitrary state then
119 **     and YY_MAX_SHIFTREDUCE           reduce by rule N-YY_MIN_SHIFTREDUCE.
121 **   N == YY_ERROR_ACTION               A syntax error has occurred.
123 **   N == YY_ACCEPT_ACTION              The parser accepts its input.
125 **   N == YY_NO_ACTION                  No such action.  Denotes unused
126 **                                      slots in the yy_action[] table.
128 **   N between YY_MIN_REDUCE            Reduce by rule N-YY_MIN_REDUCE
129 **     and YY_MAX_REDUCE
131 ** The action table is constructed as a single large table named yy_action[].
132 ** Given state S and lookahead X, the action is computed as either:
134 **    (A)   N = yy_action[ yy_shift_ofst[S] + X ]
135 **    (B)   N = yy_default[S]
137 ** The (A) formula is preferred.  The B formula is used instead if
138 ** yy_lookahead[yy_shift_ofst[S]+X] is not equal to X.
140 ** The formulas above are for computing the action when the lookahead is
141 ** a terminal symbol.  If the lookahead is a non-terminal (as occurs after
142 ** a reduce action) then the yy_reduce_ofst[] array is used in place of
143 ** the yy_shift_ofst[] array.
145 ** The following are the tables generated in this section:
147 **  yy_action[]        A single table containing all actions.
148 **  yy_lookahead[]     A table containing the lookahead for each entry in
149 **                     yy_action.  Used to detect hash collisions.
150 **  yy_shift_ofst[]    For each state, the offset into yy_action for
151 **                     shifting terminals.
152 **  yy_reduce_ofst[]   For each state, the offset into yy_action for
153 **                     shifting non-terminals after a reduce.
154 **  yy_default[]       Default action for each state.
156 *********** Begin parsing tables **********************************************/
158 /********** End of lemon-generated parsing tables *****************************/
160 /* The next table maps tokens (terminal symbols) into fallback tokens.  
161 ** If a construct like the following:
162 ** 
163 **      %fallback ID X Y Z.
165 ** appears in the grammar, then ID becomes a fallback token for X, Y,
166 ** and Z.  Whenever one of the tokens X, Y, or Z is input to the parser
167 ** but it does not parse, the type of the token is changed to ID and
168 ** the parse is retried before an error is thrown.
170 ** This feature can be used, for example, to cause some keywords in a language
171 ** to revert to identifiers if they keyword does not apply in the context where
172 ** it appears.
174 #ifdef YYFALLBACK
175 static const YYCODETYPE yyFallback[] = {
178 #endif /* YYFALLBACK */
180 /* The following structure represents a single element of the
181 ** parser's stack.  Information stored includes:
183 **   +  The state number for the parser at this level of the stack.
185 **   +  The value of the token stored at this level of the stack.
186 **      (In other words, the "major" token.)
188 **   +  The semantic value stored at this level of the stack.  This is
189 **      the information used by the action routines in the grammar.
190 **      It is sometimes called the "minor" token.
192 ** After the "shift" half of a SHIFTREDUCE action, the stateno field
193 ** actually contains the reduce action for the second half of the
194 ** SHIFTREDUCE.
196 struct yyStackEntry {
197   yyStackEntry() {
198     stateno = 0;
199     major = 0;
200   }
201   yyStackEntry(YYACTIONTYPE stateno_, YYCODETYPE major_, ParseTOKENTYPE minor_) {
202     stateno = stateno_;
203     major = major_;
204     minor.yy0 = minor_;
205   }
206   YYACTIONTYPE stateno;  /* The state-number, or reduce action in SHIFTREDUCE */
207   YYCODETYPE major;      /* The major token value.  This is the code
208                          ** number for the token at this stack level */
209   YYMINORTYPE minor;     /* The user-supplied minor token value.  This
210                          ** is the value of the token  */
213 static void ParseInit(yyParser *pParser);
214 static void ParseFinalize(yyParser *pParser);
216 /* The state of the parser is completely contained in an instance of
217 ** the following structure */
218 struct yyParser {
219 #ifdef YYTRACKMAXSTACKDEPTH
220   int yyhwm;                    /* High-water mark of the stack */
221 #endif
222 #ifndef YYNOERRORRECOVERY
223   int yyerrcnt;                 /* Shifts left before out of the error */
224 #endif
225   ParseARG_SDECL                /* A place to hold %extra_argument */
226   vector<yyStackEntry> yystack; /* The parser's stack */
227   yyParser() {
228     ParseInit(this);
229   }
230   ~yyParser() {
231     ParseFinalize(this);
232   }
234 typedef struct yyParser yyParser;
236 #include "omassert.h"
237 #include "debuglog.h"
239 #if defined(YYCOVERAGE) || defined(XAPIAN_DEBUG_LOG)
240 /* For tracing shifts, the names of all terminals and nonterminals
241 ** are required.  The following table supplies these names */
242 static const char *const yyTokenName[] = { 
246 /* For tracing reduce actions, the names of all rules are required.
248 static const char *const yyRuleName[] = {
253 ** This function returns the symbolic name associated with a token
254 ** value.
256 static const char *ParseTokenName(int tokenType){
257   if( tokenType>=0 && tokenType<(int)(sizeof(yyTokenName)/sizeof(yyTokenName[0])) ){
258     return yyTokenName[tokenType];
259   }
260   return "Unknown";
264 ** This function returns the symbolic name associated with a rule
265 ** value.
267 static const char *ParseRuleName(int ruleNum){
268   if( ruleNum>=0 && ruleNum<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){
269     return yyRuleName[ruleNum];
270   }
271   return "Unknown";
273 #endif /* defined(YYCOVERAGE) || defined(XAPIAN_DEBUG_LOG) */
275 /* Datatype of the argument to the memory allocated passed as the
276 ** second argument to ParseAlloc() below.  This can be changed by
277 ** putting an appropriate #define in the %include section of the input
278 ** grammar.
280 #ifndef YYMALLOCARGTYPE
281 # define YYMALLOCARGTYPE size_t
282 #endif
284 /* Initialize a new parser that has already been allocated.
286 static
287 void ParseInit(yyParser *pParser){
288 #ifdef YYTRACKMAXSTACKDEPTH
289   pParser->yyhwm = 0;
290 #endif
291 #if 0
292 #if YYSTACKDEPTH<=0
293   pParser->yytos = NULL;
294   pParser->yystack = NULL;
295   pParser->yystksz = 0;
296   if( yyGrowStack(pParser) ){
297     pParser->yystack = &pParser->yystk0;
298     pParser->yystksz = 1;
299   }
300 #endif
301 #endif
302 #ifndef YYNOERRORRECOVERY
303   pParser->yyerrcnt = -1;
304 #endif
305 #if 0
306   pParser->yytos = pParser->yystack;
307   pParser->yystack[0].stateno = 0;
308   pParser->yystack[0].major = 0;
309 #if YYSTACKDEPTH>0
310   pParser->yystackEnd = &pParser->yystack[YYSTACKDEPTH-1];
311 #endif
312 #else
313   pParser->yystack.push_back(yyStackEntry());
314 #endif
317 #ifndef Parse_ENGINEALWAYSONSTACK
318 /* 
319 ** This function allocates a new parser.
321 ** Inputs:
322 ** None.
324 ** Outputs:
325 ** A pointer to a parser.  This pointer is used in subsequent calls
326 ** to Parse and ParseFree.
328 static yyParser *ParseAlloc(void){
329   return new yyParser;
331 #endif /* Parse_ENGINEALWAYSONSTACK */
334 /* The following function deletes the "minor type" or semantic value
335 ** associated with a symbol.  The symbol can be either a terminal
336 ** or nonterminal. "yymajor" is the symbol code, and "yypminor" is
337 ** a pointer to the value to be deleted.  The code used to do the 
338 ** deletions is derived from the %destructor and/or %token_destructor
339 ** directives of the input grammar.
341 static void yy_destructor(
342   yyParser *yypParser,    /* The parser */
343   YYCODETYPE yymajor,     /* Type code for object to destroy */
344   YYMINORTYPE *yypminor   /* The object to be destroyed */
346   ParseARG_FETCH;
347   switch( yymajor ){
348     /* Here is inserted the actions which take place when a
349     ** terminal or non-terminal is destroyed.  This can happen
350     ** when the symbol is popped from the stack during a
351     ** reduce or during error processing or when a parser is 
352     ** being destroyed before it is finished parsing.
353     **
354     ** Note: during a reduce, the only symbols destroyed are those
355     ** which appear on the RHS of the rule, but which are *not* used
356     ** inside the C code.
357     */
358 /********* Begin destructor definitions ***************************************/
360 /********* End destructor definitions *****************************************/
361     default:  break;   /* If no destructor action specified: do nothing */
362   }
363   ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
367 ** Pop the parser's stack once.
369 ** If there is a destructor routine associated with the token which
370 ** is popped from the stack, then call it.
372 static void yy_pop_parser_stack(yyParser *pParser){
373   Assert( pParser->yystack.size() > 1 );
374   yyStackEntry *yytos = &pParser->yystack.back();
376   LOGLINE(QUERYPARSER, "Popping " << ParseTokenName(yytos->major));
377   yy_destructor(pParser, yytos->major, &yytos->minor);
378   pParser->yystack.pop_back();
382 ** Clear all secondary memory allocations from the parser
384 static
385 void ParseFinalize(yyParser *pParser){
386   while( pParser->yystack.size() > 1 ) yy_pop_parser_stack(pParser);
389 #ifndef Parse_ENGINEALWAYSONSTACK
390 /* 
391 ** Deallocate and destroy a parser.  Destructors are called for
392 ** all stack elements before shutting the parser down.
394 ** If the YYPARSEFREENEVERNULL macro exists (for example because it
395 ** is defined in a %include section of the input grammar) then it is
396 ** assumed that the input pointer is never NULL.
398 static
399 void ParseFree(
400   yyParser *pParser           /* The parser to be deleted */
402   delete pParser;
404 #endif /* Parse_ENGINEALWAYSONSTACK */
407 ** Return the peak depth of the stack for a parser.
409 #ifdef YYTRACKMAXSTACKDEPTH
410 int ParseStackPeak(yyParser *pParser){
411   return pParser->yyhwm;
413 #endif
415 /* This array of booleans keeps track of the parser statement
416 ** coverage.  The element yycoverage[X][Y] is set when the parser
417 ** is in state X and has a lookahead token Y.  In a well-tested
418 ** systems, every element of this matrix should end up being set.
420 #if defined(YYCOVERAGE)
421 static unsigned char yycoverage[YYNSTATE][YYNTOKEN];
422 #endif
425 ** Write into out a description of every state/lookahead combination that
427 **   (1)  has not been used by the parser, and
428 **   (2)  is not a syntax error.
430 ** Return the number of missed state/lookahead combinations.
432 #if defined(YYCOVERAGE)
433 int ParseCoverage(FILE *out){
434   int stateno, iLookAhead, i;
435   int nMissed = 0;
436   for(stateno=0; stateno<YYNSTATE; stateno++){
437     i = yy_shift_ofst[stateno];
438     for(iLookAhead=0; iLookAhead<YYNTOKEN; iLookAhead++){
439       if( yy_lookahead[i+iLookAhead]!=iLookAhead ) continue;
440       if( yycoverage[stateno][iLookAhead]==0 ) nMissed++;
441       if( out ){
442         fprintf(out,"State %d lookahead %s %s\n", stateno,
443                 yyTokenName[iLookAhead],
444                 yycoverage[stateno][iLookAhead] ? "ok" : "missed");
445       }
446     }
447   }
448   return nMissed;
450 #endif
453 ** Find the appropriate action for a parser given the terminal
454 ** look-ahead token iLookAhead.
456 static unsigned int yy_find_shift_action(
457   yyParser *pParser,        /* The parser */
458   YYCODETYPE iLookAhead     /* The look-ahead token */
460   int i;
461   int stateno = pParser->yystack.back().stateno;
463   if( stateno>YY_MAX_SHIFT ) return stateno;
464   Assert( stateno <= YY_SHIFT_COUNT );
465 #if defined(YYCOVERAGE)
466   yycoverage[stateno][iLookAhead] = 1;
467 #endif
468   do{
469     i = yy_shift_ofst[stateno];
470     Assert( i>=0 );
471     Assert( i+YYNTOKEN<=(int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0])) );
472     Assert( iLookAhead!=YYNOCODE );
473     Assert( iLookAhead < YYNTOKEN );
474     i += iLookAhead;
475     if( yy_lookahead[i]!=iLookAhead ){
476 #ifdef YYFALLBACK
477       YYCODETYPE iFallback;            /* Fallback token */
478       if( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0])
479              && (iFallback = yyFallback[iLookAhead])!=0 ){
480         LOGLINE(QUERYPARSER,
481                 "FALLBACK " << ParseTokenName(iLookAhead) << " => " <<
482                 ParseTokenName(iFallback));
483         Assert( yyFallback[iFallback]==0 ); /* Fallback loop must terminate */
484         iLookAhead = iFallback;
485         continue;
486       }
487 #endif
488 #ifdef YYWILDCARD
489       {
490         int j = i - iLookAhead + YYWILDCARD;
491         if( 
492 #if YY_SHIFT_MIN+YYWILDCARD<0
493           j>=0 &&
494 #endif
495 #if YY_SHIFT_MAX+YYWILDCARD>=YY_ACTTAB_COUNT
496           j<YY_ACTTAB_COUNT &&
497 #endif
498           yy_lookahead[j]==YYWILDCARD && iLookAhead>0
499         ){
500           LOGLINE(QUERYPARSER,
501                   "WILDCARD " << ParseTokenName(iLookAhead) << " => " <<
502                   ParseTokenName(YYWILDCARD));
503           return yy_action[j];
504         }
505       }
506 #endif /* YYWILDCARD */
507       return yy_default[stateno];
508     }else{
509       return yy_action[i];
510     }
511   }while(1);
515 ** Find the appropriate action for a parser given the non-terminal
516 ** look-ahead token iLookAhead.
518 static int yy_find_reduce_action(
519   int stateno,              /* Current state number */
520   YYCODETYPE iLookAhead     /* The look-ahead token */
522   int i;
523 #ifdef YYERRORSYMBOL
524   if( stateno>YY_REDUCE_COUNT ){
525     return yy_default[stateno];
526   }
527 #else
528   Assert( stateno<=YY_REDUCE_COUNT );
529 #endif
530   i = yy_reduce_ofst[stateno];
531   Assert( iLookAhead!=YYNOCODE );
532   i += iLookAhead;
533 #ifdef YYERRORSYMBOL
534   if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){
535     return yy_default[stateno];
536   }
537 #else
538   Assert( i>=0 && i<YY_ACTTAB_COUNT );
539   Assert( yy_lookahead[i]==iLookAhead );
540 #endif
541   return yy_action[i];
545 ** The following routine is called if the stack overflows.
546 ** In Xapian this can never happen as we use std::vector to provide a stack
547 ** of indefinite size.
549 #if 0
550 static void yyStackOverflow(yyParser *yypParser){
551    ParseARG_FETCH;
552    yypParser->yyidx--;
553 #ifndef NDEBUG
554    if( yyTraceFILE ){
555      fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt);
556    }
557 #endif
558    while( yypParser->yytos>yypParser->yystack ) yy_pop_parser_stack(yypParser);
559    /* Here code is inserted which will execute if the parser
560    ** stack ever overflows */
561 /******** Begin %stack_overflow code ******************************************/
563 /******** End %stack_overflow code ********************************************/
564    ParseARG_STORE; /* Suppress warning about unused %extra_argument var */
566 #endif
569 ** Print tracing information for a SHIFT action
571 #ifdef XAPIAN_DEBUG_LOG
572 static void yyTraceShift(yyParser *yypParser, int yyNewState, const char *zTag){
573   if( yyNewState<YYNSTATE ){
574     LOGLINE(QUERYPARSER, zTag << " '" <<
575                          yyTokenName[yypParser->yystack.back().major] <<
576                          "', go to state " << yyNewState);
577   }else{
578     LOGLINE(QUERYPARSER, zTag << " '" <<
579                          yyTokenName[yypParser->yystack.back().major] <<
580                          "', pending reduce " << yyNewState - YY_MIN_REDUCE);
581   }
583 #else
584 # define yyTraceShift(X,Y,Z)
585 #endif
588 ** Perform a shift action.
590 static void yy_shift(
591   yyParser *yypParser,          /* The parser to be shifted */
592   int yyNewState,               /* The new state to shift in */
593   int yyMajor,                  /* The major token to shift in */
594   ParseTOKENTYPE yyMinor        /* The minor token to shift in */
596   if( yyNewState > YY_MAX_SHIFT ){
597     yyNewState += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE;
598   }
599   yypParser->yystack.push_back(yyStackEntry(yyNewState, yyMajor, yyMinor));
600 #ifdef YYTRACKMAXSTACKDEPTH
601   if( (int)(yypParser->yystack.size()>yypParser->yyhwm ){
602     yypParser->yyhwm++;
603     Assert( yypParser->yyhwm == (int)(yypParser->yystack.size() );
604   }
605 #endif
606   yyTraceShift(yypParser, yyNewState, "Shift");
609 /* The following table contains information about every rule that
610 ** is used during the reduce.
612 static const struct {
613   YYCODETYPE lhs;       /* Symbol on the left-hand side of the rule */
614   signed char nrhs;     /* Negative of the number of RHS symbols in the rule */
615 } yyRuleInfo[] = {
619 static void yy_accept(yyParser*);  /* Forward Declaration */
622 ** Perform a reduce action and the shift that must immediately
623 ** follow the reduce.
625 ** The yyLookahead and yyLookaheadToken parameters provide reduce actions
626 ** access to the lookahead token (if any).  The yyLookahead will be YYNOCODE
627 ** if the lookahead token has already been consumed.  As this procedure is
628 ** only called from one place, optimizing compilers will in-line it, which
629 ** means that the extra parameters have no performance impact.
631 static void yy_reduce(
632   yyParser *yypParser,         /* The parser */
633   unsigned int yyruleno,       /* Number of the rule by which to reduce */
634   int yyLookahead,             /* Lookahead token, or YYNOCODE if none */
635   ParseTOKENTYPE yyLookaheadToken  /* Value of the lookahead token */
637   int yygoto;                     /* The next state */
638   int yyact;                      /* The next action */
639   yyStackEntry *yymsp;            /* The top of the parser's stack */
640   int yysize;                     /* Amount to pop the stack */
641   ParseARG_FETCH;
642   (void)yyLookahead;
643   (void)yyLookaheadToken;
644   yymsp = &yypParser->yystack.back();
645 #ifdef XAPIAN_DEBUG_LOG
646   if( yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){
647     yysize = yyRuleInfo[yyruleno].nrhs;
648     if( yysize ){
649       LOGLINE(QUERYPARSER, "Reduce " << yyruleno << " [" <<
650                            ParseRuleName(yyruleno) << "], go to state " <<
651                            yymsp[yysize].stateno);
652     } else {
653       LOGLINE(QUERYPARSER, "Reduce " << yyruleno << " [" <<
654                            ParseRuleName(yyruleno) << "].");
655     }
656   }
657 #endif /* XAPIAN_DEBUG_LOG */
658   /*  yygotominor = yyzerominor; */
660   /* Check that the stack is large enough to grow by a single entry
661   ** if the RHS of the rule is empty.  This ensures that there is room
662   ** enough on the stack to push the LHS value without invalidating
663   ** pointers into the stack. */
664   if( yyRuleInfo[yyruleno].nrhs==0 ){
665 #if 1
666     yypParser->yystack.resize(yypParser->yystack.size() + 1);
667     yymsp = &(yypParser->yystack.back()) - 1;
668 #else
669 #ifdef YYTRACKMAXSTACKDEPTH
670     if( (int)(yypParser->yytos - yypParser->yystack)>yypParser->yyhwm ){
671       yypParser->yyhwm++;
672       Assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack));
673     }
674 #endif
675 #if YYSTACKDEPTH>0 
676     if( yypParser->yytos>=yypParser->yystackEnd ){
677       yyStackOverflow(yypParser);
678       return;
679     }
680 #else
681     if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz-1] ){
682       if( yyGrowStack(yypParser) ){
683         yyStackOverflow(yypParser);
684         return;
685       }
686       yymsp = yypParser->yytos;
687     }
688 #endif
689 #endif
690   }
692   switch( yyruleno ){
693   /* Beginning here are the reduction cases.  A typical example
694   ** follows:
695   **   case 0:
696   **  #line <lineno> <grammarfile>
697   **     { ... }           // User supplied code
698   **  #line <lineno> <thisfile>
699   **     break;
700   */
701 /********** Begin reduce actions **********************************************/
703 /********** End reduce actions ************************************************/
704   }
705   Assert( yyruleno<sizeof(yyRuleInfo)/sizeof(yyRuleInfo[0]) );
706   yygoto = yyRuleInfo[yyruleno].lhs;
707   yysize = yyRuleInfo[yyruleno].nrhs;
708   yyact = yy_find_reduce_action(yymsp[yysize].stateno,static_cast<YYCODETYPE>(yygoto));
710   /* There are no SHIFTREDUCE actions on nonterminals because the table
711   ** generator has simplified them to pure REDUCE actions. */
712   Assert( !(yyact>YY_MAX_SHIFT && yyact<=YY_MAX_SHIFTREDUCE) );
714   /* It is not possible for a REDUCE to be followed by an error */
715   Assert( yyact!=YY_ERROR_ACTION );
717   yymsp += yysize+1;
718   if (yysize) {
719     yypParser->yystack.resize(yypParser->yystack.size() + yysize+1);
720   }
721   yymsp->stateno = static_cast<YYACTIONTYPE>(yyact);
722   yymsp->major = static_cast<YYCODETYPE>(yygoto);
723   yyTraceShift(yypParser, yyact, "... then shift");
727 ** The following code executes when the parse fails
729 #ifndef YYNOERRORRECOVERY
730 static void yy_parse_failed(
731   yyParser *yypParser           /* The parser */
733   ParseARG_FETCH;
734   LOGLINE(QUERYPARSER, "Fail!");
735   while( yypParser->yystack.size() > 1 ) yy_pop_parser_stack(yypParser);
736   /* Here code is inserted which will be executed whenever the
737   ** parser fails */
738 /************ Begin %parse_failure code ***************************************/
740 /************ End %parse_failure code *****************************************/
741   ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
743 #endif /* YYNOERRORRECOVERY */
746 ** The following code executes when a syntax error first occurs.
748 static void yy_syntax_error(
749   yyParser *yypParser,           /* The parser */
750   int yymajor,                   /* The major type of the error token */
751   ParseTOKENTYPE yyminor         /* The minor type of the error token */
753   ParseARG_FETCH;
754   (void)yymajor;
755   (void)yyminor;
756 #define TOKEN yyminor
757 /************ Begin %syntax_error code ****************************************/
759 /************ End %syntax_error code ******************************************/
760   ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
764 ** The following is executed when the parser accepts
766 static void yy_accept(
767   yyParser *yypParser           /* The parser */
769   ParseARG_FETCH;
770   LOGLINE(QUERYPARSER, "Accept!");
771 #ifndef YYNOERRORRECOVERY
772   yypParser->yyerrcnt = -1;
773 #endif
774   AssertEq( yypParser->yystack.size(), 1 );
775   /* Here code is inserted which will be executed whenever the
776   ** parser accepts */
777 /*********** Begin %parse_accept code *****************************************/
779 /*********** End %parse_accept code *******************************************/
780   ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
783 /* The main parser program.
784 ** The first argument is a pointer to a structure obtained from
785 ** "ParseAlloc" which describes the current state of the parser.
786 ** The second argument is the major token number.  The third is
787 ** the minor token.  The fourth optional argument is whatever the
788 ** user wants (and specified in the grammar) and is available for
789 ** use by the action routines.
791 ** Inputs:
792 ** <ul>
793 ** <li> A pointer to the parser (an opaque structure.)
794 ** <li> The major token number.
795 ** <li> The minor token number.
796 ** <li> An option argument of a grammar-specified type.
797 ** </ul>
799 ** Outputs:
800 ** None.
802 static
803 void Parse(
804   yyParser *yypParser,         /* The parser */
805   int yymajor,                 /* The major token code number */
806   ParseTOKENTYPE yyminor       /* The value for the token */
807   ParseARG_PDECL               /* Optional %extra_argument parameter */
809   YYMINORTYPE yyminorunion;
810   unsigned int yyact;   /* The parser action. */
811 #if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY)
812   int yyendofinput;     /* True if we are at the end of input */
813 #endif
814 #ifdef YYERRORSYMBOL
815   int yyerrorhit = 0;   /* True if yymajor has invoked an error */
816 #endif
818 #if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY)
819   yyendofinput = (yymajor==0);
820 #endif
821   ParseARG_STORE;
823 #ifdef XAPIAN_DEBUG_LOG
824   {
825     int stateno = yypParser->yystack.back().stateno;
826     if( stateno < YY_MIN_REDUCE ){
827       LOGLINE(QUERYPARSER, "Input '" << ParseTokenName(yymajor) <<
828                            "'," << (yyminor ? yyminor->name : "<<null>>") <<
829                            "in state " << stateno);
830     }else{
831       LOGLINE(QUERYPARSER, "Input '" << ParseTokenName(yymajor) <<
832                            "'," << (yyminor ? yyminor->name : "<<null>>") <<
833                            "with pending reduce " << stateno-YY_MIN_REDUCE);
834     }
835   }
836 #endif
838   do{
839     yyact = yy_find_shift_action(yypParser,static_cast<YYCODETYPE>(yymajor));
840     if( yyact >= YY_MIN_REDUCE ){
841       yy_reduce(yypParser,yyact-YY_MIN_REDUCE,yymajor,yyminor);
842     }else if( yyact <= YY_MAX_SHIFTREDUCE ){
843       yy_shift(yypParser,yyact,yymajor,yyminor);
844 #ifndef YYNOERRORRECOVERY
845       yypParser->yyerrcnt--;
846 #endif
847       yymajor = YYNOCODE;
848     }else if( yyact==YY_ACCEPT_ACTION ){
849       yypParser->yystack.pop_back();
850       yy_accept(yypParser);
851       return;
852     }else{
853       Assert( yyact == YY_ERROR_ACTION );
854       yyminorunion.yy0 = yyminor;
855 #ifdef YYERRORSYMBOL
856       int yymx;
857 #endif
858       LOGLINE(QUERYPARSER, "Syntax Error!");
859 #ifdef YYERRORSYMBOL
860       /* A syntax error has occurred.
861       ** The response to an error depends upon whether or not the
862       ** grammar defines an error token "ERROR".  
863       **
864       ** This is what we do if the grammar does define ERROR:
865       **
866       **  * Call the %syntax_error function.
867       **
868       **  * Begin popping the stack until we enter a state where
869       **    it is legal to shift the error symbol, then shift
870       **    the error symbol.
871       **
872       **  * Set the error count to three.
873       **
874       **  * Begin accepting and shifting new tokens.  No new error
875       **    processing will occur until three tokens have been
876       **    shifted successfully.
877       **
878       */
879       if( yypParser->yyerrcnt<0 ){
880         yy_syntax_error(yypParser,yymajor,yyminor);
881       }
882       yymx = yypParser->yystack.back().major;
883       if( yymx==YYERRORSYMBOL || yyerrorhit ){
884         LOGLINE(QUERYPARSER, "Discard input token " << ParseTokenName(yymajor));
885         yy_destructor(yypParser, static_cast<YYCODETYPE>(yymajor), &yyminorunion);
886         yymajor = YYNOCODE;
887       }else{
888         while( !yypParser->yystack.empty()
889             && yymx != YYERRORSYMBOL
890             && (yyact = yy_find_reduce_action(
891                         yypParser->yystack.back().stateno,
892                         YYERRORSYMBOL)) >= YY_MIN_REDUCE
893         ){
894           yy_pop_parser_stack(yypParser);
895         }
896         if( yypParser->yystack.empty() || yymajor==0 ){
897           yy_destructor(yypParser,static_cast<YYCODETYPE>(yymajor),&yyminorunion);
898           yy_parse_failed(yypParser);
899 #ifndef YYNOERRORRECOVERY
900           yypParser->yyerrcnt = -1;
901 #endif
902           yymajor = YYNOCODE;
903         }else if( yymx!=YYERRORSYMBOL ){
904           yy_shift(yypParser,yyact,YYERRORSYMBOL,yyminor);
905         }
906       }
907       yypParser->yyerrcnt = 3;
908       yyerrorhit = 1;
909 #elif defined(YYNOERRORRECOVERY)
910       /* If the YYNOERRORRECOVERY macro is defined, then do not attempt to
911       ** do any kind of error recovery.  Instead, simply invoke the syntax
912       ** error routine and continue going as if nothing had happened.
913       **
914       ** Applications can set this macro (for example inside %include) if
915       ** they intend to abandon the parse upon the first syntax error seen.
916       */
917       yy_syntax_error(yypParser,yymajor, yyminor);
918       yy_destructor(yypParser,static_cast<YYCODETYPE>(yymajor),&yyminorunion);
919       yymajor = YYNOCODE;
920       
921 #else  /* YYERRORSYMBOL is not defined */
922       /* This is what we do if the grammar does not define ERROR:
923       **
924       **  * Report an error message, and throw away the input token.
925       **
926       **  * If the input token is $, then fail the parse.
927       **
928       ** As before, subsequent error messages are suppressed until
929       ** three input tokens have been successfully shifted.
930       */
931       if( yypParser->yyerrcnt<=0 ){
932         yy_syntax_error(yypParser,yymajor, yyminor);
933       }
934       yypParser->yyerrcnt = 3;
935       yy_destructor(yypParser,static_cast<YYCODETYPE>(yymajor),&yyminorunion);
936       if( yyendofinput ){
937         yy_parse_failed(yypParser);
938 #ifndef YYNOERRORRECOVERY
939         yypParser->yyerrcnt = -1;
940 #endif
941       }
942       yymajor = YYNOCODE;
943 #endif
944     }
945   }while( yymajor!=YYNOCODE && yypParser->yystack.size() > 1 );
946 #ifdef XAPIAN_DEBUG_LOG
947   {
948     int i;
949     LOGLINE(QUERYPARSER, "Return. Stack=");
950     for(i=1; i<=(int)yypParser->yystack.size(); i++)
951       LOGLINE(QUERYPARSER, yyTokenName[yypParser->yystack[i].major]);
952   }
953 #endif
954   return;
957 // Select C++ syntax highlighting in vim editor: vim: syntax=cpp