Fix signed vs unsigned warnings with assertions on
[xapian.git] / xapian-core / queryparser / queryparser.lt
blob7c98de2ef45aaef66bb38d00b3f18e242acb867e
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/dddd4f592b8bad36aec4500d456c5db5fe42fefc4ee384913880439d8917f87a
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 && i+YYNTOKEN<=(int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0])) );
471     Assert( iLookAhead!=YYNOCODE );
472     Assert( iLookAhead < YYNTOKEN );
473     i += iLookAhead;
474     if( yy_lookahead[i]!=iLookAhead ){
475 #ifdef YYFALLBACK
476       YYCODETYPE iFallback;            /* Fallback token */
477       if( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0])
478              && (iFallback = yyFallback[iLookAhead])!=0 ){
479         LOGLINE(QUERYPARSER,
480                 "FALLBACK " << ParseTokenName(iLookAhead) << " => " <<
481                 ParseTokenName(iFallback));
482         Assert( yyFallback[iFallback]==0 ); /* Fallback loop must terminate */
483         iLookAhead = iFallback;
484         continue;
485       }
486 #endif
487 #ifdef YYWILDCARD
488       {
489         int j = i - iLookAhead + YYWILDCARD;
490         if( 
491 #if YY_SHIFT_MIN+YYWILDCARD<0
492           j>=0 &&
493 #endif
494 #if YY_SHIFT_MAX+YYWILDCARD>=YY_ACTTAB_COUNT
495           j<YY_ACTTAB_COUNT &&
496 #endif
497           yy_lookahead[j]==YYWILDCARD
498         ){
499           LOGLINE(QUERYPARSER,
500                   "WILDCARD " << ParseTokenName(iLookAhead) << " => " <<
501                   ParseTokenName(YYWILDCARD));
502           return yy_action[j];
503         }
504       }
505 #endif /* YYWILDCARD */
506       return yy_default[stateno];
507     }else{
508       return yy_action[i];
509     }
510   }while(1);
514 ** Find the appropriate action for a parser given the non-terminal
515 ** look-ahead token iLookAhead.
517 static int yy_find_reduce_action(
518   int stateno,              /* Current state number */
519   YYCODETYPE iLookAhead     /* The look-ahead token */
521   int i;
522 #ifdef YYERRORSYMBOL
523   if( stateno>YY_REDUCE_COUNT ){
524     return yy_default[stateno];
525   }
526 #else
527   Assert( stateno<=YY_REDUCE_COUNT );
528 #endif
529   i = yy_reduce_ofst[stateno];
530   Assert( iLookAhead!=YYNOCODE );
531   i += iLookAhead;
532 #ifdef YYERRORSYMBOL
533   if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){
534     return yy_default[stateno];
535   }
536 #else
537   Assert( i>=0 && i<YY_ACTTAB_COUNT );
538   Assert( yy_lookahead[i]==iLookAhead );
539 #endif
540   return yy_action[i];
544 ** The following routine is called if the stack overflows.
545 ** In Xapian this can never happen as we use std::vector to provide a stack
546 ** of indefinite size.
548 #if 0
549 static void yyStackOverflow(yyParser *yypParser){
550    ParseARG_FETCH;
551    yypParser->yyidx--;
552 #ifndef NDEBUG
553    if( yyTraceFILE ){
554      fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt);
555    }
556 #endif
557    while( yypParser->yytos>yypParser->yystack ) yy_pop_parser_stack(yypParser);
558    /* Here code is inserted which will execute if the parser
559    ** stack ever overflows */
560 /******** Begin %stack_overflow code ******************************************/
562 /******** End %stack_overflow code ********************************************/
563    ParseARG_STORE; /* Suppress warning about unused %extra_argument var */
565 #endif
568 ** Print tracing information for a SHIFT action
570 #ifdef XAPIAN_DEBUG_LOG
571 static void yyTraceShift(yyParser *yypParser, int yyNewState, const char *zTag){
572   if( yyTraceFILE ){
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     }
582   }
584 #else
585 # define yyTraceShift(X,Y,Z)
586 #endif
589 ** Perform a shift action.
591 static void yy_shift(
592   yyParser *yypParser,          /* The parser to be shifted */
593   int yyNewState,               /* The new state to shift in */
594   int yyMajor,                  /* The major token to shift in */
595   ParseTOKENTYPE yyMinor        /* The minor token to shift in */
597   if( yyNewState > YY_MAX_SHIFT ){
598     yyNewState += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE;
599   }
600   yypParser->yystack.push_back(yyStackEntry(yyNewState, yyMajor, yyMinor));
601 #ifdef YYTRACKMAXSTACKDEPTH
602   if( (int)(yypParser->yystack.size()>yypParser->yyhwm ){
603     yypParser->yyhwm++;
604     Assert( yypParser->yyhwm == (int)(yypParser->yystack.size() );
605   }
606 #endif
607   yyTraceShift(yypParser, yyNewState, "Shift");
610 /* The following table contains information about every rule that
611 ** is used during the reduce.
613 static const struct {
614   YYCODETYPE lhs;       /* Symbol on the left-hand side of the rule */
615   signed char nrhs;     /* Negative of the number of RHS symbols in the rule */
616 } yyRuleInfo[] = {
620 static void yy_accept(yyParser*);  /* Forward Declaration */
623 ** Perform a reduce action and the shift that must immediately
624 ** follow the reduce.
626 ** The yyLookahead and yyLookaheadToken parameters provide reduce actions
627 ** access to the lookahead token (if any).  The yyLookahead will be YYNOCODE
628 ** if the lookahead token has already been consumed.  As this procedure is
629 ** only called from one place, optimizing compilers will in-line it, which
630 ** means that the extra parameters have no performance impact.
632 static void yy_reduce(
633   yyParser *yypParser,         /* The parser */
634   unsigned int yyruleno,       /* Number of the rule by which to reduce */
635   int yyLookahead,             /* Lookahead token, or YYNOCODE if none */
636   ParseTOKENTYPE yyLookaheadToken  /* Value of the lookahead token */
638   int yygoto;                     /* The next state */
639   int yyact;                      /* The next action */
640   yyStackEntry *yymsp;            /* The top of the parser's stack */
641   int yysize;                     /* Amount to pop the stack */
642   ParseARG_FETCH;
643   /* Suppress any "unused variable" warnings. */
644   (void)yyLookahead;
645   (void)yyLookaheadToken;
646   yymsp = &yypParser->yystack.back();
647 #ifdef XAPIAN_DEBUG_LOG
648   if( yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){
649     yysize = yyRuleInfo[yyruleno].nrhs;
650     if( yysize ){
651       LOGLINE(QUERYPARSER, "Reduce " << yyruleno << " [" <<
652                            ParseRuleName(yyruleno) << "], go to state " <<
653                            yymsp[yysize].stateno);
654     } else {
655       LOGLINE(QUERYPARSER, "Reduce " << yyruleno << " [" <<
656                            ParseRuleName(yyruleno) << "].");
657     }
658   }
659 #endif /* XAPIAN_DEBUG_LOG */
660   /*  yygotominor = yyzerominor; */
662   /* Check that the stack is large enough to grow by a single entry
663   ** if the RHS of the rule is empty.  This ensures that there is room
664   ** enough on the stack to push the LHS value without invalidating
665   ** pointers into the stack. */
666   if( yyRuleInfo[yyruleno].nrhs==0 ){
667 #if 1
668     yypParser->yystack.reserve(yypParser->yystack.size() + 1);
669     yymsp = &(yypParser->yystack.back());
670 #else
671 #ifdef YYTRACKMAXSTACKDEPTH
672     if( (int)(yypParser->yytos - yypParser->yystack)>yypParser->yyhwm ){
673       yypParser->yyhwm++;
674       Assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack));
675     }
676 #endif
677 #if YYSTACKDEPTH>0 
678     if( yypParser->yytos>=yypParser->yystackEnd ){
679       yyStackOverflow(yypParser);
680       return;
681     }
682 #else
683     if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz-1] ){
684       if( yyGrowStack(yypParser) ){
685         yyStackOverflow(yypParser);
686         return;
687       }
688       yymsp = yypParser->yytos;
689     }
690 #endif
691 #endif
692   }
694   switch( yyruleno ){
695   /* Beginning here are the reduction cases.  A typical example
696   ** follows:
697   **   case 0:
698   **  #line <lineno> <grammarfile>
699   **     { ... }           // User supplied code
700   **  #line <lineno> <thisfile>
701   **     break;
702   */
703 /********** Begin reduce actions **********************************************/
705 /********** End reduce actions ************************************************/
706   }
707   Assert( yyruleno<sizeof(yyRuleInfo)/sizeof(yyRuleInfo[0]) );
708   yygoto = yyRuleInfo[yyruleno].lhs;
709   yysize = yyRuleInfo[yyruleno].nrhs;
710   yyact = yy_find_reduce_action(yymsp[yysize].stateno,static_cast<YYCODETYPE>(yygoto));
712   /* There are no SHIFTREDUCE actions on nonterminals because the table
713   ** generator has simplified them to pure REDUCE actions. */
714   Assert( !(yyact>YY_MAX_SHIFT && yyact<=YY_MAX_SHIFTREDUCE) );
716   /* It is not possible for a REDUCE to be followed by an error */
717   Assert( yyact!=YY_ERROR_ACTION );
719   yymsp += yysize+1;
720   yypParser->yystack.resize(yypParser->yystack.size() + yysize+1);
721   //yymsp = &yypParser->yystack.back();
722   yymsp->stateno = static_cast<YYACTIONTYPE>(yyact);
723   yymsp->major = static_cast<YYCODETYPE>(yygoto);
724   yyTraceShift(yypParser, yyact, "... then shift");
728 ** The following code executes when the parse fails
730 #ifndef YYNOERRORRECOVERY
731 static void yy_parse_failed(
732   yyParser *yypParser           /* The parser */
734   ParseARG_FETCH;
735   LOGLINE(QUERYPARSER, "Fail!");
736   while( yypParser->yystack.size() > 1 ) yy_pop_parser_stack(yypParser);
737   /* Here code is inserted which will be executed whenever the
738   ** parser fails */
739 /************ Begin %parse_failure code ***************************************/
741 /************ End %parse_failure code *****************************************/
742   ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
744 #endif /* YYNOERRORRECOVERY */
747 ** The following code executes when a syntax error first occurs.
749 static void yy_syntax_error(
750   yyParser *yypParser,           /* The parser */
751   int yymajor,                   /* The major type of the error token */
752   ParseTOKENTYPE yyminor         /* The minor type of the error token */
754   ParseARG_FETCH;
755   (void)yymajor;
756   (void)yyminor;
757 #define TOKEN yyminor
758 /************ Begin %syntax_error code ****************************************/
760 /************ End %syntax_error code ******************************************/
761   ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
765 ** The following is executed when the parser accepts
767 static void yy_accept(
768   yyParser *yypParser           /* The parser */
770   ParseARG_FETCH;
771   LOGLINE(QUERYPARSER, "Accept!");
772 #ifndef YYNOERRORRECOVERY
773   yypParser->yyerrcnt = -1;
774 #endif
775   AssertEq( yypParser->yystack.size(), 1 );
776   /* Here code is inserted which will be executed whenever the
777   ** parser accepts */
778 /*********** Begin %parse_accept code *****************************************/
780 /*********** End %parse_accept code *******************************************/
781   ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
784 /* The main parser program.
785 ** The first argument is a pointer to a structure obtained from
786 ** "ParseAlloc" which describes the current state of the parser.
787 ** The second argument is the major token number.  The third is
788 ** the minor token.  The fourth optional argument is whatever the
789 ** user wants (and specified in the grammar) and is available for
790 ** use by the action routines.
792 ** Inputs:
793 ** <ul>
794 ** <li> A pointer to the parser (an opaque structure.)
795 ** <li> The major token number.
796 ** <li> The minor token number.
797 ** <li> An option argument of a grammar-specified type.
798 ** </ul>
800 ** Outputs:
801 ** None.
803 static
804 void Parse(
805   yyParser *yypParser,         /* The parser */
806   int yymajor,                 /* The major token code number */
807   ParseTOKENTYPE yyminor       /* The value for the token */
808   ParseARG_PDECL               /* Optional %extra_argument parameter */
810   YYMINORTYPE yyminorunion;
811   unsigned int yyact;   /* The parser action. */
812 #if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY)
813   int yyendofinput;     /* True if we are at the end of input */
814 #endif
815 #ifdef YYERRORSYMBOL
816   int yyerrorhit = 0;   /* True if yymajor has invoked an error */
817 #endif
819 #if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY)
820   yyendofinput = (yymajor==0);
821 #endif
822   ParseARG_STORE;
824 #ifdef XAPIAN_DEBUG_LOG
825   {
826     int stateno = yypParser->yystack.back()->stateno;
827     if( stateno < YY_MIN_REDUCE ){
828       fprintf(yyTraceFILE,"%sInput '%s' in state %d\n",
829               yyTracePrompt,yyTokenName[yymajor],stateno);
830       LOGLINE(QUERYPARSER, "Input '" << ParseTokenName(yymajor) <<
831                            "'," << (yyminor ? yyminor->name : "<<null>>")) <<
832                            "in state " << stateno);
833     }else{
834       LOGLINE(QUERYPARSER, "Input '" << ParseTokenName(yymajor) <<
835                            "'," << (yyminor ? yyminor->name : "<<null>>")) <<
836                            "with pending reduce " << stateno-YY_MIN_REDUCE);
837     }
838   }
839 #endif
841   do{
842     yyact = yy_find_shift_action(yypParser,static_cast<YYCODETYPE>(yymajor));
843     if( yyact >= YY_MIN_REDUCE ){
844       yy_reduce(yypParser,yyact-YY_MIN_REDUCE,yymajor,yyminor);
845     }else if( yyact <= YY_MAX_SHIFTREDUCE ){
846       yy_shift(yypParser,yyact,yymajor,yyminor);
847 #ifndef YYNOERRORRECOVERY
848       yypParser->yyerrcnt--;
849 #endif
850       yymajor = YYNOCODE;
851     }else if( yyact==YY_ACCEPT_ACTION ){
852       yypParser->yystack.pop_back();
853       yy_accept(yypParser);
854       return;
855     }else{
856       Assert( yyact == YY_ERROR_ACTION );
857       yyminorunion.yy0 = yyminor;
858 #ifdef YYERRORSYMBOL
859       int yymx;
860 #endif
861       LOGLINE(QUERYPARSER, "Syntax Error!");
862 #ifdef YYERRORSYMBOL
863       /* A syntax error has occurred.
864       ** The response to an error depends upon whether or not the
865       ** grammar defines an error token "ERROR".  
866       **
867       ** This is what we do if the grammar does define ERROR:
868       **
869       **  * Call the %syntax_error function.
870       **
871       **  * Begin popping the stack until we enter a state where
872       **    it is legal to shift the error symbol, then shift
873       **    the error symbol.
874       **
875       **  * Set the error count to three.
876       **
877       **  * Begin accepting and shifting new tokens.  No new error
878       **    processing will occur until three tokens have been
879       **    shifted successfully.
880       **
881       */
882       if( yypParser->yyerrcnt<0 ){
883         yy_syntax_error(yypParser,yymajor,yyminor);
884       }
885       yymx = yypParser->yystack.back().major;
886       if( yymx==YYERRORSYMBOL || yyerrorhit ){
887         LOGLINE(QUERYPARSER, "Discard input token " << ParseTokenName(yymajor));
888         yy_destructor(yypParser, static_cast<YYCODETYPE>(yymajor), &yyminorunion);
889         yymajor = YYNOCODE;
890       }else{
891         while( !yypParser->yystack.empty()
892             && yymx != YYERRORSYMBOL
893             && (yyact = yy_find_reduce_action(
894                         yypParser->yystack.back().stateno,
895                         YYERRORSYMBOL)) >= YY_MIN_REDUCE
896         ){
897           yy_pop_parser_stack(yypParser);
898         }
899         if( yypParser->yystack.empty() || yymajor==0 ){
900           yy_destructor(yypParser,static_cast<YYCODETYPE>(yymajor),&yyminorunion);
901           yy_parse_failed(yypParser);
902 #ifndef YYNOERRORRECOVERY
903           yypParser->yyerrcnt = -1;
904 #endif
905           yymajor = YYNOCODE;
906         }else if( yymx!=YYERRORSYMBOL ){
907           yy_shift(yypParser,yyact,YYERRORSYMBOL,yyminor);
908         }
909       }
910       yypParser->yyerrcnt = 3;
911       yyerrorhit = 1;
912 #elif defined(YYNOERRORRECOVERY)
913       /* If the YYNOERRORRECOVERY macro is defined, then do not attempt to
914       ** do any kind of error recovery.  Instead, simply invoke the syntax
915       ** error routine and continue going as if nothing had happened.
916       **
917       ** Applications can set this macro (for example inside %include) if
918       ** they intend to abandon the parse upon the first syntax error seen.
919       */
920       yy_syntax_error(yypParser,yymajor, yyminor);
921       yy_destructor(yypParser,static_cast<YYCODETYPE>(yymajor),&yyminorunion);
922       yymajor = YYNOCODE;
923       
924 #else  /* YYERRORSYMBOL is not defined */
925       /* This is what we do if the grammar does not define ERROR:
926       **
927       **  * Report an error message, and throw away the input token.
928       **
929       **  * If the input token is $, then fail the parse.
930       **
931       ** As before, subsequent error messages are suppressed until
932       ** three input tokens have been successfully shifted.
933       */
934       if( yypParser->yyerrcnt<=0 ){
935         yy_syntax_error(yypParser,yymajor, yyminor);
936       }
937       yypParser->yyerrcnt = 3;
938       yy_destructor(yypParser,static_cast<YYCODETYPE>(yymajor),&yyminorunion);
939       if( yyendofinput ){
940         yy_parse_failed(yypParser);
941 #ifndef YYNOERRORRECOVERY
942         yypParser->yyerrcnt = -1;
943 #endif
944       }
945       yymajor = YYNOCODE;
946 #endif
947     }
948   }while( yymajor!=YYNOCODE && yypParser->yystack.size() > 1 );
949 #ifdef XAPIAN_DEBUG_LOG
950   {
951     int i;
952     LOGLINE(QUERYPARSER, "Return. Stack=");
953     for(i=1; i<=yypParser->yyidx; i++)
954       LOGLINE(QUERYPARSER, yyTokenName[yypParser->yystack[i].major]);
955   }
956 #endif
957   return;
960 // Select C++ syntax highlighting in vim editor: vim: syntax=cpp