4 ** The author disclaims copyright to this source code. In place of
5 ** a legal notice, here is a blessing:
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
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
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
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
90 /************* Begin control #defines *****************************************/
92 /************* End control #defines *******************************************/
94 /* Define the yytestcase() macro to be a no-op if is not already defined
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
103 # define yytestcase(X)
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
112 ** Suppose the action integer is N. Then the action is determined as
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
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:
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
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
196 struct yyStackEntry {
201 yyStackEntry(YYACTIONTYPE stateno_, YYCODETYPE major_, ParseTOKENTYPE minor_) {
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 */
219 #ifdef YYTRACKMAXSTACKDEPTH
220 int yyhwm; /* High-water mark of the stack */
222 #ifndef YYNOERRORRECOVERY
223 int yyerrcnt; /* Shifts left before out of the error */
225 ParseARG_SDECL /* A place to hold %extra_argument */
226 vector<yyStackEntry> yystack; /* The parser's stack */
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
256 static const char *ParseTokenName(int tokenType){
257 if( tokenType>=0 && tokenType<(int)(sizeof(yyTokenName)/sizeof(yyTokenName[0])) ){
258 return yyTokenName[tokenType];
264 ** This function returns the symbolic name associated with a rule
267 static const char *ParseRuleName(int ruleNum){
268 if( ruleNum>=0 && ruleNum<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){
269 return yyRuleName[ruleNum];
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
280 #ifndef YYMALLOCARGTYPE
281 # define YYMALLOCARGTYPE size_t
284 /* Initialize a new parser that has already been allocated.
287 void ParseInit(yyParser *pParser){
288 #ifdef YYTRACKMAXSTACKDEPTH
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;
302 #ifndef YYNOERRORRECOVERY
303 pParser->yyerrcnt = -1;
306 pParser->yytos = pParser->yystack;
307 pParser->yystack[0].stateno = 0;
308 pParser->yystack[0].major = 0;
310 pParser->yystackEnd = &pParser->yystack[YYSTACKDEPTH-1];
313 pParser->yystack.push_back(yyStackEntry());
317 #ifndef Parse_ENGINEALWAYSONSTACK
319 ** This function allocates a new parser.
325 ** A pointer to a parser. This pointer is used in subsequent calls
326 ** to Parse and ParseFree.
328 static yyParser *ParseAlloc(void){
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 */
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.
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.
358 /********* Begin destructor definitions ***************************************/
360 /********* End destructor definitions *****************************************/
361 default: break; /* If no destructor action specified: do nothing */
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
385 void ParseFinalize(yyParser *pParser){
386 while( pParser->yystack.size() > 1 ) yy_pop_parser_stack(pParser);
389 #ifndef Parse_ENGINEALWAYSONSTACK
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.
400 yyParser *pParser /* The parser to be deleted */
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;
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];
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;
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++;
442 fprintf(out,"State %d lookahead %s %s\n", stateno,
443 yyTokenName[iLookAhead],
444 yycoverage[stateno][iLookAhead] ? "ok" : "missed");
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 */
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;
469 i = yy_shift_ofst[stateno];
471 Assert( i+YYNTOKEN<=(int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0])) );
472 Assert( iLookAhead!=YYNOCODE );
473 Assert( iLookAhead < YYNTOKEN );
475 if( yy_lookahead[i]!=iLookAhead ){
477 YYCODETYPE iFallback; /* Fallback token */
478 if( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0])
479 && (iFallback = yyFallback[iLookAhead])!=0 ){
481 "FALLBACK " << ParseTokenName(iLookAhead) << " => " <<
482 ParseTokenName(iFallback));
483 Assert( yyFallback[iFallback]==0 ); /* Fallback loop must terminate */
484 iLookAhead = iFallback;
490 int j = i - iLookAhead + YYWILDCARD;
492 #if YY_SHIFT_MIN+YYWILDCARD<0
495 #if YY_SHIFT_MAX+YYWILDCARD>=YY_ACTTAB_COUNT
498 yy_lookahead[j]==YYWILDCARD && iLookAhead>0
501 "WILDCARD " << ParseTokenName(iLookAhead) << " => " <<
502 ParseTokenName(YYWILDCARD));
506 #endif /* YYWILDCARD */
507 return yy_default[stateno];
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 */
524 if( stateno>YY_REDUCE_COUNT ){
525 return yy_default[stateno];
528 Assert( stateno<=YY_REDUCE_COUNT );
530 i = yy_reduce_ofst[stateno];
531 Assert( iLookAhead!=YYNOCODE );
534 if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){
535 return yy_default[stateno];
538 Assert( i>=0 && i<YY_ACTTAB_COUNT );
539 Assert( yy_lookahead[i]==iLookAhead );
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.
550 static void yyStackOverflow(yyParser *yypParser){
555 fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt);
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 */
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);
578 LOGLINE(QUERYPARSER, zTag << " '" <<
579 yyTokenName[yypParser->yystack.back().major] <<
580 "', pending reduce " << yyNewState - YY_MIN_REDUCE);
584 # define yyTraceShift(X,Y,Z)
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;
599 yypParser->yystack.push_back(yyStackEntry(yyNewState, yyMajor, yyMinor));
600 #ifdef YYTRACKMAXSTACKDEPTH
601 if( (int)(yypParser->yystack.size()>yypParser->yyhwm ){
603 Assert( yypParser->yyhwm == (int)(yypParser->yystack.size() );
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 */
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 */
643 (void)yyLookaheadToken;
644 yymsp = &yypParser->yystack.back();
645 Assert( yyruleno<sizeof(yyRuleInfo)/sizeof(yyRuleInfo[0]) );
646 #ifdef XAPIAN_DEBUG_LOG
648 yysize = yyRuleInfo[yyruleno].nrhs;
650 LOGLINE(QUERYPARSER, "Reduce " << yyruleno << " [" <<
651 ParseRuleName(yyruleno) << "], go to state " <<
652 yymsp[yysize].stateno);
654 LOGLINE(QUERYPARSER, "Reduce " << yyruleno << " [" <<
655 ParseRuleName(yyruleno) << "].");
658 #endif /* XAPIAN_DEBUG_LOG */
659 /* yygotominor = yyzerominor; */
661 /* Check that the stack is large enough to grow by a single entry
662 ** if the RHS of the rule is empty. This ensures that there is room
663 ** enough on the stack to push the LHS value without invalidating
664 ** pointers into the stack. */
665 if( yyRuleInfo[yyruleno].nrhs==0 ){
667 yypParser->yystack.resize(yypParser->yystack.size() + 1);
668 yymsp = &(yypParser->yystack.back()) - 1;
670 #ifdef YYTRACKMAXSTACKDEPTH
671 if( (int)(yypParser->yytos - yypParser->yystack)>yypParser->yyhwm ){
673 Assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack));
677 if( yypParser->yytos>=yypParser->yystackEnd ){
678 yyStackOverflow(yypParser);
682 if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz-1] ){
683 if( yyGrowStack(yypParser) ){
684 yyStackOverflow(yypParser);
687 yymsp = yypParser->yytos;
694 /* Beginning here are the reduction cases. A typical example
697 ** #line <lineno> <grammarfile>
698 ** { ... } // User supplied code
699 ** #line <lineno> <thisfile>
702 /********** Begin reduce actions **********************************************/
704 /********** End reduce actions ************************************************/
706 Assert( yyruleno<sizeof(yyRuleInfo)/sizeof(yyRuleInfo[0]) );
707 yygoto = yyRuleInfo[yyruleno].lhs;
708 yysize = yyRuleInfo[yyruleno].nrhs;
709 yyact = yy_find_reduce_action(yymsp[yysize].stateno,static_cast<YYCODETYPE>(yygoto));
711 /* There are no SHIFTREDUCE actions on nonterminals because the table
712 ** generator has simplified them to pure REDUCE actions. */
713 Assert( !(yyact>YY_MAX_SHIFT && yyact<=YY_MAX_SHIFTREDUCE) );
715 /* It is not possible for a REDUCE to be followed by an error */
716 Assert( yyact!=YY_ERROR_ACTION );
720 yypParser->yystack.resize(UNSIGNED_OVERFLOW_OK(yypParser->yystack.size() +
723 yymsp->stateno = static_cast<YYACTIONTYPE>(yyact);
724 yymsp->major = static_cast<YYCODETYPE>(yygoto);
725 yyTraceShift(yypParser, yyact, "... then shift");
729 ** The following code executes when the parse fails
731 #ifndef YYNOERRORRECOVERY
732 static void yy_parse_failed(
733 yyParser *yypParser /* The parser */
736 LOGLINE(QUERYPARSER, "Fail!");
737 while( yypParser->yystack.size() > 1 ) yy_pop_parser_stack(yypParser);
738 /* Here code is inserted which will be executed whenever the
740 /************ Begin %parse_failure code ***************************************/
742 /************ End %parse_failure code *****************************************/
743 ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
745 #endif /* YYNOERRORRECOVERY */
748 ** The following code executes when a syntax error first occurs.
750 static void yy_syntax_error(
751 yyParser *yypParser, /* The parser */
752 int yymajor, /* The major type of the error token */
753 ParseTOKENTYPE yyminor /* The minor type of the error token */
758 #define TOKEN yyminor
759 /************ Begin %syntax_error code ****************************************/
761 /************ End %syntax_error code ******************************************/
762 ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
766 ** The following is executed when the parser accepts
768 static void yy_accept(
769 yyParser *yypParser /* The parser */
772 LOGLINE(QUERYPARSER, "Accept!");
773 #ifndef YYNOERRORRECOVERY
774 yypParser->yyerrcnt = -1;
776 AssertEq( yypParser->yystack.size(), 1 );
777 /* Here code is inserted which will be executed whenever the
779 /*********** Begin %parse_accept code *****************************************/
781 /*********** End %parse_accept code *******************************************/
782 ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
785 /* The main parser program.
786 ** The first argument is a pointer to a structure obtained from
787 ** "ParseAlloc" which describes the current state of the parser.
788 ** The second argument is the major token number. The third is
789 ** the minor token. The fourth optional argument is whatever the
790 ** user wants (and specified in the grammar) and is available for
791 ** use by the action routines.
795 ** <li> A pointer to the parser (an opaque structure.)
796 ** <li> The major token number.
797 ** <li> The minor token number.
798 ** <li> An option argument of a grammar-specified type.
806 yyParser *yypParser, /* The parser */
807 int yymajor, /* The major token code number */
808 ParseTOKENTYPE yyminor /* The value for the token */
809 ParseARG_PDECL /* Optional %extra_argument parameter */
811 YYMINORTYPE yyminorunion;
812 unsigned int yyact; /* The parser action. */
813 #if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY)
814 int yyendofinput; /* True if we are at the end of input */
817 int yyerrorhit = 0; /* True if yymajor has invoked an error */
820 #if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY)
821 yyendofinput = (yymajor==0);
825 #ifdef XAPIAN_DEBUG_LOG
827 int stateno = yypParser->yystack.back().stateno;
828 if( stateno < YY_MIN_REDUCE ){
829 LOGLINE(QUERYPARSER, "Input '" << ParseTokenName(yymajor) <<
830 "'," << (yyminor ? yyminor->name : "<<null>>") <<
831 "in state " << stateno);
833 LOGLINE(QUERYPARSER, "Input '" << ParseTokenName(yymajor) <<
834 "'," << (yyminor ? yyminor->name : "<<null>>") <<
835 "with pending reduce " << stateno-YY_MIN_REDUCE);
841 yyact = yy_find_shift_action(yypParser,static_cast<YYCODETYPE>(yymajor));
842 if( yyact >= YY_MIN_REDUCE ){
843 yy_reduce(yypParser,yyact-YY_MIN_REDUCE,yymajor,yyminor);
844 }else if( yyact <= YY_MAX_SHIFTREDUCE ){
845 yy_shift(yypParser,yyact,yymajor,yyminor);
846 #ifndef YYNOERRORRECOVERY
847 yypParser->yyerrcnt--;
850 }else if( yyact==YY_ACCEPT_ACTION ){
851 yypParser->yystack.pop_back();
852 yy_accept(yypParser);
855 Assert( yyact == YY_ERROR_ACTION );
856 yyminorunion.yy0 = yyminor;
860 LOGLINE(QUERYPARSER, "Syntax Error!");
862 /* A syntax error has occurred.
863 ** The response to an error depends upon whether or not the
864 ** grammar defines an error token "ERROR".
866 ** This is what we do if the grammar does define ERROR:
868 ** * Call the %syntax_error function.
870 ** * Begin popping the stack until we enter a state where
871 ** it is legal to shift the error symbol, then shift
874 ** * Set the error count to three.
876 ** * Begin accepting and shifting new tokens. No new error
877 ** processing will occur until three tokens have been
878 ** shifted successfully.
881 if( yypParser->yyerrcnt<0 ){
882 yy_syntax_error(yypParser,yymajor,yyminor);
884 yymx = yypParser->yystack.back().major;
885 if( yymx==YYERRORSYMBOL || yyerrorhit ){
886 LOGLINE(QUERYPARSER, "Discard input token " << ParseTokenName(yymajor));
887 yy_destructor(yypParser, static_cast<YYCODETYPE>(yymajor), &yyminorunion);
890 while( !yypParser->yystack.empty()
891 && yymx != YYERRORSYMBOL
892 && (yyact = yy_find_reduce_action(
893 yypParser->yystack.back().stateno,
894 YYERRORSYMBOL)) >= YY_MIN_REDUCE
896 yy_pop_parser_stack(yypParser);
898 if( yypParser->yystack.empty() || yymajor==0 ){
899 yy_destructor(yypParser,static_cast<YYCODETYPE>(yymajor),&yyminorunion);
900 yy_parse_failed(yypParser);
901 #ifndef YYNOERRORRECOVERY
902 yypParser->yyerrcnt = -1;
905 }else if( yymx!=YYERRORSYMBOL ){
906 yy_shift(yypParser,yyact,YYERRORSYMBOL,yyminor);
909 yypParser->yyerrcnt = 3;
911 #elif defined(YYNOERRORRECOVERY)
912 /* If the YYNOERRORRECOVERY macro is defined, then do not attempt to
913 ** do any kind of error recovery. Instead, simply invoke the syntax
914 ** error routine and continue going as if nothing had happened.
916 ** Applications can set this macro (for example inside %include) if
917 ** they intend to abandon the parse upon the first syntax error seen.
919 yy_syntax_error(yypParser,yymajor, yyminor);
920 yy_destructor(yypParser,static_cast<YYCODETYPE>(yymajor),&yyminorunion);
923 #else /* YYERRORSYMBOL is not defined */
924 /* This is what we do if the grammar does not define ERROR:
926 ** * Report an error message, and throw away the input token.
928 ** * If the input token is $, then fail the parse.
930 ** As before, subsequent error messages are suppressed until
931 ** three input tokens have been successfully shifted.
933 if( yypParser->yyerrcnt<=0 ){
934 yy_syntax_error(yypParser,yymajor, yyminor);
936 yypParser->yyerrcnt = 3;
937 yy_destructor(yypParser,static_cast<YYCODETYPE>(yymajor),&yyminorunion);
939 yy_parse_failed(yypParser);
940 #ifndef YYNOERRORRECOVERY
941 yypParser->yyerrcnt = -1;
947 }while( yymajor!=YYNOCODE && yypParser->yystack.size() > 1 );
948 #ifdef XAPIAN_DEBUG_LOG
951 LOGLINE(QUERYPARSER, "Return. Stack=");
952 for(i=1; i<=(int)yypParser->yystack.size(); i++)
953 LOGLINE(QUERYPARSER, yyTokenName[yypParser->yystack[i].major]);
959 // Select C++ syntax highlighting in vim editor: vim: syntax=cpp