AryaWu/sqlite
0
1/* This file is automatically generated by Lemon from input grammar2** source file "fts5parse.y".3*/4/*5** 2000-05-296**7** The author disclaims copyright to this source code. In place of8** a legal notice, here is a blessing:9**10** May you do good and not evil.11** May you find forgiveness for yourself and forgive others.12** May you share freely, never taking more than you give.13**14*************************************************************************15** Driver template for the LEMON parser generator.16**17** The "lemon" program processes an LALR(1) input grammar file, then uses18** this template to construct a parser. The "lemon" program inserts text19** at each "%%" line. Also, any "P-a-r-s-e" identifier prefix (without the20** interstitial "-" characters) contained in this template is changed into21** the value of the %name directive from the grammar. Otherwise, the content22** of this template is copied straight through into the generate parser23** source file.24**25** The following is the concatenation of all %include directives from the26** input grammar file:27*/28/************ Begin %include sections from the grammar ************************/29#line 47 "fts5parse.y"30 31#include "fts5Int.h"32#include "fts5parse.h"33 34/*35** Disable all error recovery processing in the parser push-down36** automaton.37*/38#define YYNOERRORRECOVERY 139 40/*41** Make yytestcase() the same as testcase()42*/43#define yytestcase(X) testcase(X)44 45/*46** Indicate that sqlite3ParserFree() will never be called with a null47** pointer.48*/49#define YYPARSEFREENOTNULL 150 51/*52** Alternative datatype for the argument to the malloc() routine passed53** into sqlite3ParserAlloc(). The default is size_t.54*/55#define YYMALLOCARGTYPE u6456 57#line 58 "fts5parse.c"58/**************** End of %include directives **********************************/59/* These constants specify the various numeric values for terminal symbols.60***************** Begin token definitions *************************************/61#ifndef FTS5_OR62#define FTS5_OR 163#define FTS5_AND 264#define FTS5_NOT 365#define FTS5_TERM 466#define FTS5_COLON 567#define FTS5_MINUS 668#define FTS5_LCP 769#define FTS5_RCP 870#define FTS5_STRING 971#define FTS5_LP 1072#define FTS5_RP 1173#define FTS5_CARET 1274#define FTS5_COMMA 1375#define FTS5_PLUS 1476#define FTS5_STAR 1577#endif78/**************** End token definitions ***************************************/79 80/* The next sections is a series of control #defines.81** various aspects of the generated parser.82** YYCODETYPE is the data type used to store the integer codes83** that represent terminal and non-terminal symbols.84** "unsigned char" is used if there are fewer than85** 256 symbols. Larger types otherwise.86** YYNOCODE is a number of type YYCODETYPE that is not used for87** any terminal or nonterminal symbol.88** YYFALLBACK If defined, this indicates that one or more tokens89** (also known as: "terminal symbols") have fall-back90** values which should be used if the original symbol91** would not parse. This permits keywords to sometimes92** be used as identifiers, for example.93** YYACTIONTYPE is the data type used for "action codes" - numbers94** that indicate what to do in response to the next95** token.96** sqlite3Fts5ParserTOKENTYPE is the data type used for minor type for terminal97** symbols. Background: A "minor type" is a semantic98** value associated with a terminal or non-terminal99** symbols. For example, for an "ID" terminal symbol,100** the minor type might be the name of the identifier.101** Each non-terminal can have a different minor type.102** Terminal symbols all have the same minor type, though.103** This macros defines the minor type for terminal 104** symbols.105** YYMINORTYPE is the data type used for all minor types.106** This is typically a union of many types, one of107** which is sqlite3Fts5ParserTOKENTYPE. The entry in the union108** for terminal symbols is called "yy0".109** YYSTACKDEPTH is the maximum depth of the parser's stack. If110** zero the stack is dynamically sized using realloc()111** sqlite3Fts5ParserARG_SDECL A static variable declaration for the %extra_argument112** sqlite3Fts5ParserARG_PDECL A parameter declaration for the %extra_argument113** sqlite3Fts5ParserARG_PARAM Code to pass %extra_argument as a subroutine parameter114** sqlite3Fts5ParserARG_STORE Code to store %extra_argument into yypParser115** sqlite3Fts5ParserARG_FETCH Code to extract %extra_argument from yypParser116** sqlite3Fts5ParserCTX_* As sqlite3Fts5ParserARG_ except for %extra_context117** YYREALLOC Name of the realloc() function to use118** YYFREE Name of the free() function to use119** YYDYNSTACK True if stack space should be extended on heap120** YYERRORSYMBOL is the code number of the error symbol. If not121** defined, then do no error processing.122** YYNSTATE the combined number of states.123** YYNRULE the number of rules in the grammar124** YYNTOKEN Number of terminal symbols125** YY_MAX_SHIFT Maximum value for shift actions126** YY_MIN_SHIFTREDUCE Minimum value for shift-reduce actions127** YY_MAX_SHIFTREDUCE Maximum value for shift-reduce actions128** YY_ERROR_ACTION The yy_action[] code for syntax error129** YY_ACCEPT_ACTION The yy_action[] code for accept130** YY_NO_ACTION The yy_action[] code for no-op131** YY_MIN_REDUCE Minimum value for reduce actions132** YY_MAX_REDUCE Maximum value for reduce actions133** YY_MIN_DSTRCTR Minimum symbol value that has a destructor134** YY_MAX_DSTRCTR Maximum symbol value that has a destructor135*/136#ifndef INTERFACE137# define INTERFACE 1138#endif139/************* Begin control #defines *****************************************/140#define YYCODETYPE unsigned char141#define YYNOCODE 27142#define YYACTIONTYPE unsigned char143#define sqlite3Fts5ParserTOKENTYPE Fts5Token144typedef union {145 int yyinit;146 sqlite3Fts5ParserTOKENTYPE yy0;147 int yy4;148 Fts5Colset* yy11;149 Fts5ExprNode* yy24;150 Fts5ExprNearset* yy46;151 Fts5ExprPhrase* yy53;152} YYMINORTYPE;153#ifndef YYSTACKDEPTH154#define YYSTACKDEPTH 100155#endif156#define sqlite3Fts5ParserARG_SDECL Fts5Parse *pParse;157#define sqlite3Fts5ParserARG_PDECL ,Fts5Parse *pParse158#define sqlite3Fts5ParserARG_PARAM ,pParse159#define sqlite3Fts5ParserARG_FETCH Fts5Parse *pParse=yypParser->pParse;160#define sqlite3Fts5ParserARG_STORE yypParser->pParse=pParse;161#undef YYREALLOC162#define YYREALLOC realloc163#undef YYFREE164#define YYFREE free165#undef YYDYNSTACK166#define YYDYNSTACK 0167#undef YYSIZELIMIT168#define sqlite3Fts5ParserCTX(P) 0169#define sqlite3Fts5ParserCTX_SDECL170#define sqlite3Fts5ParserCTX_PDECL171#define sqlite3Fts5ParserCTX_PARAM172#define sqlite3Fts5ParserCTX_FETCH173#define sqlite3Fts5ParserCTX_STORE174#undef YYERRORSYMBOL175#undef YYERRSYMDT176#undef YYFALLBACK177#define YYNSTATE 35178#define YYNRULE 28179#define YYNRULE_WITH_ACTION 28180#define YYNTOKEN 16181#define YY_MAX_SHIFT 34182#define YY_MIN_SHIFTREDUCE 52183#define YY_MAX_SHIFTREDUCE 79184#define YY_ERROR_ACTION 80185#define YY_ACCEPT_ACTION 81186#define YY_NO_ACTION 82187#define YY_MIN_REDUCE 83188#define YY_MAX_REDUCE 110189#define YY_MIN_DSTRCTR 16190#define YY_MAX_DSTRCTR 24191/************* End control #defines *******************************************/192#define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0])))193 194/* Define the yytestcase() macro to be a no-op if is not already defined195** otherwise.196**197** Applications can choose to define yytestcase() in the %include section198** to a macro that can assist in verifying code coverage. For production199** code the yytestcase() macro should be turned off. But it is useful200** for testing.201*/202#ifndef yytestcase203# define yytestcase(X)204#endif205 206/* Macro to determine if stack space has the ability to grow using207** heap memory.208*/209#if YYSTACKDEPTH<=0 || YYDYNSTACK210# define YYGROWABLESTACK 1211#else212# define YYGROWABLESTACK 0213#endif214 215/* Guarantee a minimum number of initial stack slots.216*/217#if YYSTACKDEPTH<=0218# undef YYSTACKDEPTH219# define YYSTACKDEPTH 2 /* Need a minimum stack size */220#endif221 222 223/* Next are the tables used to determine what action to take based on the224** current state and lookahead token. These tables are used to implement225** functions that take a state number and lookahead value and return an226** action integer. 227**228** Suppose the action integer is N. Then the action is determined as229** follows230**231** 0 <= N <= YY_MAX_SHIFT Shift N. That is, push the lookahead232** token onto the stack and goto state N.233**234** N between YY_MIN_SHIFTREDUCE Shift to an arbitrary state then235** and YY_MAX_SHIFTREDUCE reduce by rule N-YY_MIN_SHIFTREDUCE.236**237** N == YY_ERROR_ACTION A syntax error has occurred.238**239** N == YY_ACCEPT_ACTION The parser accepts its input.240**241** N == YY_NO_ACTION No such action. Denotes unused242** slots in the yy_action[] table.243**244** N between YY_MIN_REDUCE Reduce by rule N-YY_MIN_REDUCE245** and YY_MAX_REDUCE246**247** The action table is constructed as a single large table named yy_action[].248** Given state S and lookahead X, the action is computed as either:249**250** (A) N = yy_action[ yy_shift_ofst[S] + X ]251** (B) N = yy_default[S]252**253** The (A) formula is preferred. The B formula is used instead if254** yy_lookahead[yy_shift_ofst[S]+X] is not equal to X.255**256** The formulas above are for computing the action when the lookahead is257** a terminal symbol. If the lookahead is a non-terminal (as occurs after258** a reduce action) then the yy_reduce_ofst[] array is used in place of259** the yy_shift_ofst[] array.260**261** The following are the tables generated in this section:262**263** yy_action[] A single table containing all actions.264** yy_lookahead[] A table containing the lookahead for each entry in265** yy_action. Used to detect hash collisions.266** yy_shift_ofst[] For each state, the offset into yy_action for267** shifting terminals.268** yy_reduce_ofst[] For each state, the offset into yy_action for269** shifting non-terminals after a reduce.270** yy_default[] Default action for each state.271**272*********** Begin parsing tables **********************************************/273#define YY_ACTTAB_COUNT (105)274static const YYACTIONTYPE yy_action[] = {275 /* 0 */ 81, 20, 96, 6, 28, 99, 98, 26, 26, 18,276 /* 10 */ 96, 6, 28, 17, 98, 56, 26, 19, 96, 6,277 /* 20 */ 28, 14, 98, 14, 26, 31, 92, 96, 6, 28,278 /* 30 */ 108, 98, 25, 26, 21, 96, 6, 28, 78, 98,279 /* 40 */ 58, 26, 29, 96, 6, 28, 107, 98, 22, 26,280 /* 50 */ 24, 16, 12, 11, 1, 13, 13, 24, 16, 23,281 /* 60 */ 11, 33, 34, 13, 97, 8, 27, 32, 98, 7,282 /* 70 */ 26, 3, 4, 5, 3, 4, 5, 3, 83, 4,283 /* 80 */ 5, 3, 63, 5, 3, 62, 12, 2, 86, 13,284 /* 90 */ 9, 30, 10, 10, 54, 57, 75, 78, 78, 53,285 /* 100 */ 57, 15, 82, 82, 71,286};287static const YYCODETYPE yy_lookahead[] = {288 /* 0 */ 16, 17, 18, 19, 20, 22, 22, 24, 24, 17,289 /* 10 */ 18, 19, 20, 7, 22, 9, 24, 17, 18, 19,290 /* 20 */ 20, 9, 22, 9, 24, 13, 17, 18, 19, 20,291 /* 30 */ 26, 22, 24, 24, 17, 18, 19, 20, 15, 22,292 /* 40 */ 9, 24, 17, 18, 19, 20, 26, 22, 21, 24,293 /* 50 */ 6, 7, 9, 9, 10, 12, 12, 6, 7, 21,294 /* 60 */ 9, 24, 25, 12, 18, 5, 20, 14, 22, 5,295 /* 70 */ 24, 3, 1, 2, 3, 1, 2, 3, 0, 1,296 /* 80 */ 2, 3, 11, 2, 3, 11, 9, 10, 5, 12,297 /* 90 */ 23, 24, 10, 10, 8, 9, 9, 15, 15, 8,298 /* 100 */ 9, 9, 27, 27, 11, 27, 27, 27, 27, 27,299 /* 110 */ 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,300 /* 120 */ 27,301};302#define YY_SHIFT_COUNT (34)303#define YY_SHIFT_MIN (0)304#define YY_SHIFT_MAX (93)305static const unsigned char yy_shift_ofst[] = {306 /* 0 */ 44, 44, 44, 44, 44, 44, 51, 77, 43, 12,307 /* 10 */ 14, 83, 82, 14, 23, 23, 31, 31, 71, 74,308 /* 20 */ 78, 81, 86, 91, 6, 53, 53, 60, 64, 68,309 /* 30 */ 53, 87, 92, 53, 93,310};311#define YY_REDUCE_COUNT (17)312#define YY_REDUCE_MIN (-17)313#define YY_REDUCE_MAX (67)314static const signed char yy_reduce_ofst[] = {315 /* 0 */ -16, -8, 0, 9, 17, 25, 46, -17, -17, 37,316 /* 10 */ 67, 4, 4, 8, 4, 20, 27, 38,317};318static const YYACTIONTYPE yy_default[] = {319 /* 0 */ 80, 80, 80, 80, 80, 80, 95, 80, 80, 105,320 /* 10 */ 80, 110, 110, 80, 110, 110, 80, 80, 80, 80,321 /* 20 */ 80, 91, 80, 80, 80, 101, 100, 80, 80, 90,322 /* 30 */ 103, 80, 80, 104, 80,323};324/********** End of lemon-generated parsing tables *****************************/325 326/* The next table maps tokens (terminal symbols) into fallback tokens. 327** If a construct like the following:328** 329** %fallback ID X Y Z.330**331** appears in the grammar, then ID becomes a fallback token for X, Y,332** and Z. Whenever one of the tokens X, Y, or Z is input to the parser333** but it does not parse, the type of the token is changed to ID and334** the parse is retried before an error is thrown.335**336** This feature can be used, for example, to cause some keywords in a language337** to revert to identifiers if they keyword does not apply in the context where338** it appears.339*/340#ifdef YYFALLBACK341static const YYCODETYPE yyFallback[] = {342};343#endif /* YYFALLBACK */344 345/* The following structure represents a single element of the346** parser's stack. Information stored includes:347**348** + The state number for the parser at this level of the stack.349**350** + The value of the token stored at this level of the stack.351** (In other words, the "major" token.)352**353** + The semantic value stored at this level of the stack. This is354** the information used by the action routines in the grammar.355** It is sometimes called the "minor" token.356**357** After the "shift" half of a SHIFTREDUCE action, the stateno field358** actually contains the reduce action for the second half of the359** SHIFTREDUCE.360*/361struct yyStackEntry {362 YYACTIONTYPE stateno; /* The state-number, or reduce action in SHIFTREDUCE */363 YYCODETYPE major; /* The major token value. This is the code364 ** number for the token at this stack level */365 YYMINORTYPE minor; /* The user-supplied minor token value. This366 ** is the value of the token */367};368typedef struct yyStackEntry yyStackEntry;369 370/* The state of the parser is completely contained in an instance of371** the following structure */372struct yyParser {373 yyStackEntry *yytos; /* Pointer to top element of the stack */374#ifdef YYTRACKMAXSTACKDEPTH375 int yyhwm; /* High-water mark of the stack */376#endif377#ifndef YYNOERRORRECOVERY378 int yyerrcnt; /* Shifts left before out of the error */379#endif380 sqlite3Fts5ParserARG_SDECL /* A place to hold %extra_argument */381 sqlite3Fts5ParserCTX_SDECL /* A place to hold %extra_context */382 yyStackEntry *yystackEnd; /* Last entry in the stack */383 yyStackEntry *yystack; /* The parser stack */384 yyStackEntry yystk0[YYSTACKDEPTH]; /* Initial stack space */385};386typedef struct yyParser yyParser;387 388#include <assert.h>389#ifndef NDEBUG390#include <stdio.h>391static FILE *yyTraceFILE = 0;392static char *yyTracePrompt = 0;393#endif /* NDEBUG */394 395#ifndef NDEBUG396/* 397** Turn parser tracing on by giving a stream to which to write the trace398** and a prompt to preface each trace message. Tracing is turned off399** by making either argument NULL 400**401** Inputs:402** <ul>403** <li> A FILE* to which trace output should be written.404** If NULL, then tracing is turned off.405** <li> A prefix string written at the beginning of every406** line of trace output. If NULL, then tracing is407** turned off.408** </ul>409**410** Outputs:411** None.412*/413void sqlite3Fts5ParserTrace(FILE *TraceFILE, char *zTracePrompt){414 yyTraceFILE = TraceFILE;415 yyTracePrompt = zTracePrompt;416 if( yyTraceFILE==0 ) yyTracePrompt = 0;417 else if( yyTracePrompt==0 ) yyTraceFILE = 0;418}419#endif /* NDEBUG */420 421#if defined(YYCOVERAGE) || !defined(NDEBUG)422/* For tracing shifts, the names of all terminals and nonterminals423** are required. The following table supplies these names */424static const char *const yyTokenName[] = { 425 /* 0 */ "$",426 /* 1 */ "OR",427 /* 2 */ "AND",428 /* 3 */ "NOT",429 /* 4 */ "TERM",430 /* 5 */ "COLON",431 /* 6 */ "MINUS",432 /* 7 */ "LCP",433 /* 8 */ "RCP",434 /* 9 */ "STRING",435 /* 10 */ "LP",436 /* 11 */ "RP",437 /* 12 */ "CARET",438 /* 13 */ "COMMA",439 /* 14 */ "PLUS",440 /* 15 */ "STAR",441 /* 16 */ "input",442 /* 17 */ "expr",443 /* 18 */ "cnearset",444 /* 19 */ "exprlist",445 /* 20 */ "colset",446 /* 21 */ "colsetlist",447 /* 22 */ "nearset",448 /* 23 */ "nearphrases",449 /* 24 */ "phrase",450 /* 25 */ "neardist_opt",451 /* 26 */ "star_opt",452};453#endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */454 455#ifndef NDEBUG456/* For tracing reduce actions, the names of all rules are required.457*/458static const char *const yyRuleName[] = {459 /* 0 */ "input ::= expr",460 /* 1 */ "colset ::= MINUS LCP colsetlist RCP",461 /* 2 */ "colset ::= LCP colsetlist RCP",462 /* 3 */ "colset ::= STRING",463 /* 4 */ "colset ::= MINUS STRING",464 /* 5 */ "colsetlist ::= colsetlist STRING",465 /* 6 */ "colsetlist ::= STRING",466 /* 7 */ "expr ::= expr AND expr",467 /* 8 */ "expr ::= expr OR expr",468 /* 9 */ "expr ::= expr NOT expr",469 /* 10 */ "expr ::= colset COLON LP expr RP",470 /* 11 */ "expr ::= LP expr RP",471 /* 12 */ "expr ::= exprlist",472 /* 13 */ "exprlist ::= cnearset",473 /* 14 */ "exprlist ::= exprlist cnearset",474 /* 15 */ "cnearset ::= nearset",475 /* 16 */ "cnearset ::= colset COLON nearset",476 /* 17 */ "nearset ::= phrase",477 /* 18 */ "nearset ::= CARET phrase",478 /* 19 */ "nearset ::= STRING LP nearphrases neardist_opt RP",479 /* 20 */ "nearphrases ::= phrase",480 /* 21 */ "nearphrases ::= nearphrases phrase",481 /* 22 */ "neardist_opt ::=",482 /* 23 */ "neardist_opt ::= COMMA STRING",483 /* 24 */ "phrase ::= phrase PLUS STRING star_opt",484 /* 25 */ "phrase ::= STRING star_opt",485 /* 26 */ "star_opt ::= STAR",486 /* 27 */ "star_opt ::=",487};488#endif /* NDEBUG */489 490 491#if YYGROWABLESTACK492/*493** Try to increase the size of the parser stack. Return the number494** of errors. Return 0 on success.495*/496static int yyGrowStack(yyParser *p){497 int oldSize = 1 + (int)(p->yystackEnd - p->yystack);498 int newSize;499 int idx;500 yyStackEntry *pNew;501#ifdef YYSIZELIMIT502 int nLimit = YYSIZELIMIT(sqlite3Fts5ParserCTX(p));503#endif504 505 newSize = oldSize*2 + 100;506#ifdef YYSIZELIMIT507 if( newSize>nLimit ){508 newSize = nLimit;509 if( newSize<=oldSize ) return 1;510 }511#endif512 idx = (int)(p->yytos - p->yystack);513 if( p->yystack==p->yystk0 ){514 pNew = YYREALLOC(0, newSize*sizeof(pNew[0]), sqlite3Fts5ParserCTX(p));515 if( pNew==0 ) return 1;516 memcpy(pNew, p->yystack, oldSize*sizeof(pNew[0]));517 }else{518 pNew = YYREALLOC(p->yystack, newSize*sizeof(pNew[0]), sqlite3Fts5ParserCTX(p));519 if( pNew==0 ) return 1;520 }521 p->yystack = pNew;522 p->yytos = &p->yystack[idx];523#ifndef NDEBUG524 if( yyTraceFILE ){525 fprintf(yyTraceFILE,"%sStack grows from %d to %d entries.\n",526 yyTracePrompt, oldSize, newSize);527 }528#endif529 p->yystackEnd = &p->yystack[newSize-1];530 return 0;531}532#endif /* YYGROWABLESTACK */533 534#if !YYGROWABLESTACK535/* For builds that do no have a growable stack, yyGrowStack always536** returns an error.537*/538# define yyGrowStack(X) 1539#endif540 541/* Datatype of the argument to the memory allocated passed as the542** second argument to sqlite3Fts5ParserAlloc() below. This can be changed by543** putting an appropriate #define in the %include section of the input544** grammar.545*/546#ifndef YYMALLOCARGTYPE547# define YYMALLOCARGTYPE size_t548#endif549 550/* Initialize a new parser that has already been allocated.551*/552void sqlite3Fts5ParserInit(void *yypRawParser sqlite3Fts5ParserCTX_PDECL){553 yyParser *yypParser = (yyParser*)yypRawParser;554 sqlite3Fts5ParserCTX_STORE555#ifdef YYTRACKMAXSTACKDEPTH556 yypParser->yyhwm = 0;557#endif558 yypParser->yystack = yypParser->yystk0;559 yypParser->yystackEnd = &yypParser->yystack[YYSTACKDEPTH-1];560#ifndef YYNOERRORRECOVERY561 yypParser->yyerrcnt = -1;562#endif563 yypParser->yytos = yypParser->yystack;564 yypParser->yystack[0].stateno = 0;565 yypParser->yystack[0].major = 0;566}567 568#ifndef sqlite3Fts5Parser_ENGINEALWAYSONSTACK569/* 570** This function allocates a new parser.571** The only argument is a pointer to a function which works like572** malloc.573**574** Inputs:575** A pointer to the function used to allocate memory.576**577** Outputs:578** A pointer to a parser. This pointer is used in subsequent calls579** to sqlite3Fts5Parser and sqlite3Fts5ParserFree.580*/581void *sqlite3Fts5ParserAlloc(void *(*mallocProc)(YYMALLOCARGTYPE) sqlite3Fts5ParserCTX_PDECL){582 yyParser *yypParser;583 yypParser = (yyParser*)(*mallocProc)( (YYMALLOCARGTYPE)sizeof(yyParser) );584 if( yypParser ){585 sqlite3Fts5ParserCTX_STORE586 sqlite3Fts5ParserInit(yypParser sqlite3Fts5ParserCTX_PARAM);587 }588 return (void*)yypParser;589}590#endif /* sqlite3Fts5Parser_ENGINEALWAYSONSTACK */591 592 593/* The following function deletes the "minor type" or semantic value594** associated with a symbol. The symbol can be either a terminal595** or nonterminal. "yymajor" is the symbol code, and "yypminor" is596** a pointer to the value to be deleted. The code used to do the 597** deletions is derived from the %destructor and/or %token_destructor598** directives of the input grammar.599*/600static void yy_destructor(601 yyParser *yypParser, /* The parser */602 YYCODETYPE yymajor, /* Type code for object to destroy */603 YYMINORTYPE *yypminor /* The object to be destroyed */604){605 sqlite3Fts5ParserARG_FETCH606 sqlite3Fts5ParserCTX_FETCH607 switch( yymajor ){608 /* Here is inserted the actions which take place when a609 ** terminal or non-terminal is destroyed. This can happen610 ** when the symbol is popped from the stack during a611 ** reduce or during error processing or when a parser is 612 ** being destroyed before it is finished parsing.613 **614 ** Note: during a reduce, the only symbols destroyed are those615 ** which appear on the RHS of the rule, but which are *not* used616 ** inside the C code.617 */618/********* Begin destructor definitions ***************************************/619 case 16: /* input */620{621#line 83 "fts5parse.y"622 (void)pParse; 623#line 624 "fts5parse.c"624}625 break;626 case 17: /* expr */627 case 18: /* cnearset */628 case 19: /* exprlist */629{630#line 89 "fts5parse.y"631 sqlite3Fts5ParseNodeFree((yypminor->yy24)); 632#line 633 "fts5parse.c"633}634 break;635 case 20: /* colset */636 case 21: /* colsetlist */637{638#line 93 "fts5parse.y"639 sqlite3_free((yypminor->yy11)); 640#line 641 "fts5parse.c"641}642 break;643 case 22: /* nearset */644 case 23: /* nearphrases */645{646#line 148 "fts5parse.y"647 sqlite3Fts5ParseNearsetFree((yypminor->yy46)); 648#line 649 "fts5parse.c"649}650 break;651 case 24: /* phrase */652{653#line 183 "fts5parse.y"654 sqlite3Fts5ParsePhraseFree((yypminor->yy53)); 655#line 656 "fts5parse.c"656}657 break;658/********* End destructor definitions *****************************************/659 default: break; /* If no destructor action specified: do nothing */660 }661}662 663/*664** Pop the parser's stack once.665**666** If there is a destructor routine associated with the token which667** is popped from the stack, then call it.668*/669static void yy_pop_parser_stack(yyParser *pParser){670 yyStackEntry *yytos;671 assert( pParser->yytos!=0 );672 assert( pParser->yytos > pParser->yystack );673 yytos = pParser->yytos--;674#ifndef NDEBUG675 if( yyTraceFILE ){676 fprintf(yyTraceFILE,"%sPopping %s\n",677 yyTracePrompt,678 yyTokenName[yytos->major]);679 }680#endif681 yy_destructor(pParser, yytos->major, &yytos->minor);682}683 684/*685** Clear all secondary memory allocations from the parser686*/687void sqlite3Fts5ParserFinalize(void *p){688 yyParser *pParser = (yyParser*)p;689 690 /* In-lined version of calling yy_pop_parser_stack() for each691 ** element left in the stack */692 yyStackEntry *yytos = pParser->yytos;693 while( yytos>pParser->yystack ){694#ifndef NDEBUG695 if( yyTraceFILE ){696 fprintf(yyTraceFILE,"%sPopping %s\n",697 yyTracePrompt,698 yyTokenName[yytos->major]);699 }700#endif701 if( yytos->major>=YY_MIN_DSTRCTR ){702 yy_destructor(pParser, yytos->major, &yytos->minor);703 }704 yytos--;705 }706 707#if YYGROWABLESTACK708 if( pParser->yystack!=pParser->yystk0 ){709 YYFREE(pParser->yystack, sqlite3Fts5ParserCTX(pParser));710 }711#endif712}713 714#ifndef sqlite3Fts5Parser_ENGINEALWAYSONSTACK715/* 716** Deallocate and destroy a parser. Destructors are called for717** all stack elements before shutting the parser down.718**719** If the YYPARSEFREENEVERNULL macro exists (for example because it720** is defined in a %include section of the input grammar) then it is721** assumed that the input pointer is never NULL.722*/723void sqlite3Fts5ParserFree(724 void *p, /* The parser to be deleted */725 void (*freeProc)(void*) /* Function used to reclaim memory */726){727#ifndef YYPARSEFREENEVERNULL728 if( p==0 ) return;729#endif730 sqlite3Fts5ParserFinalize(p);731 (*freeProc)(p);732}733#endif /* sqlite3Fts5Parser_ENGINEALWAYSONSTACK */734 735/*736** Return the peak depth of the stack for a parser.737*/738#ifdef YYTRACKMAXSTACKDEPTH739int sqlite3Fts5ParserStackPeak(void *p){740 yyParser *pParser = (yyParser*)p;741 return pParser->yyhwm;742}743#endif744 745/* This array of booleans keeps track of the parser statement746** coverage. The element yycoverage[X][Y] is set when the parser747** is in state X and has a lookahead token Y. In a well-tested748** systems, every element of this matrix should end up being set.749*/750#if defined(YYCOVERAGE)751static unsigned char yycoverage[YYNSTATE][YYNTOKEN];752#endif753 754/*755** Write into out a description of every state/lookahead combination that756**757** (1) has not been used by the parser, and758** (2) is not a syntax error.759**760** Return the number of missed state/lookahead combinations.761*/762#if defined(YYCOVERAGE)763int sqlite3Fts5ParserCoverage(FILE *out){764 int stateno, iLookAhead, i;765 int nMissed = 0;766 for(stateno=0; stateno<YYNSTATE; stateno++){767 i = yy_shift_ofst[stateno];768 for(iLookAhead=0; iLookAhead<YYNTOKEN; iLookAhead++){769 if( yy_lookahead[i+iLookAhead]!=iLookAhead ) continue;770 if( yycoverage[stateno][iLookAhead]==0 ) nMissed++;771 if( out ){772 fprintf(out,"State %d lookahead %s %s\n", stateno,773 yyTokenName[iLookAhead],774 yycoverage[stateno][iLookAhead] ? "ok" : "missed");775 }776 }777 }778 return nMissed;779}780#endif781 782/*783** Find the appropriate action for a parser given the terminal784** look-ahead token iLookAhead.785*/786static YYACTIONTYPE yy_find_shift_action(787 YYCODETYPE iLookAhead, /* The look-ahead token */788 YYACTIONTYPE stateno /* Current state number */789){790 int i;791 792 if( stateno>YY_MAX_SHIFT ) return stateno;793 assert( stateno <= YY_SHIFT_COUNT );794#if defined(YYCOVERAGE)795 yycoverage[stateno][iLookAhead] = 1;796#endif797 do{798 i = yy_shift_ofst[stateno];799 assert( i>=0 );800 assert( i<=YY_ACTTAB_COUNT );801 assert( i+YYNTOKEN<=(int)YY_NLOOKAHEAD );802 assert( iLookAhead!=YYNOCODE );803 assert( iLookAhead < YYNTOKEN );804 i += iLookAhead;805 assert( i<(int)YY_NLOOKAHEAD );806 if( yy_lookahead[i]!=iLookAhead ){807#ifdef YYFALLBACK808 YYCODETYPE iFallback; /* Fallback token */809 assert( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0]) );810 iFallback = yyFallback[iLookAhead];811 if( iFallback!=0 ){812#ifndef NDEBUG813 if( yyTraceFILE ){814 fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n",815 yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]);816 }817#endif818 assert( yyFallback[iFallback]==0 ); /* Fallback loop must terminate */819 iLookAhead = iFallback;820 continue;821 }822#endif823#ifdef YYWILDCARD824 {825 int j = i - iLookAhead + YYWILDCARD;826 assert( j<(int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0])) );827 if( yy_lookahead[j]==YYWILDCARD && iLookAhead>0 ){828#ifndef NDEBUG829 if( yyTraceFILE ){830 fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n",831 yyTracePrompt, yyTokenName[iLookAhead],832 yyTokenName[YYWILDCARD]);833 }834#endif /* NDEBUG */835 return yy_action[j];836 }837 }838#endif /* YYWILDCARD */839 return yy_default[stateno];840 }else{841 assert( i>=0 && i<(int)(sizeof(yy_action)/sizeof(yy_action[0])) );842 return yy_action[i];843 }844 }while(1);845}846 847/*848** Find the appropriate action for a parser given the non-terminal849** look-ahead token iLookAhead.850*/851static YYACTIONTYPE yy_find_reduce_action(852 YYACTIONTYPE stateno, /* Current state number */853 YYCODETYPE iLookAhead /* The look-ahead token */854){855 int i;856#ifdef YYERRORSYMBOL857 if( stateno>YY_REDUCE_COUNT ){858 return yy_default[stateno];859 }860#else861 assert( stateno<=YY_REDUCE_COUNT );862#endif863 i = yy_reduce_ofst[stateno];864 assert( iLookAhead!=YYNOCODE );865 i += iLookAhead;866#ifdef YYERRORSYMBOL867 if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){868 return yy_default[stateno];869 }870#else871 assert( i>=0 && i<YY_ACTTAB_COUNT );872 assert( yy_lookahead[i]==iLookAhead );873#endif874 return yy_action[i];875}876 877/*878** The following routine is called if the stack overflows.879*/880static void yyStackOverflow(yyParser *yypParser){881 sqlite3Fts5ParserARG_FETCH882 sqlite3Fts5ParserCTX_FETCH883#ifndef NDEBUG884 if( yyTraceFILE ){885 fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt);886 }887#endif888 while( yypParser->yytos>yypParser->yystack ) yy_pop_parser_stack(yypParser);889 /* Here code is inserted which will execute if the parser890 ** stack every overflows */891/******** Begin %stack_overflow code ******************************************/892#line 36 "fts5parse.y"893 894 sqlite3Fts5ParseError(pParse, "fts5: parser stack overflow");895#line 896 "fts5parse.c"896/******** End %stack_overflow code ********************************************/897 sqlite3Fts5ParserARG_STORE /* Suppress warning about unused %extra_argument var */898 sqlite3Fts5ParserCTX_STORE899}900 901/*902** Print tracing information for a SHIFT action903*/904#ifndef NDEBUG905static void yyTraceShift(yyParser *yypParser, int yyNewState, const char *zTag){906 if( yyTraceFILE ){907 if( yyNewState<YYNSTATE ){908 fprintf(yyTraceFILE,"%s%s '%s', go to state %d\n",909 yyTracePrompt, zTag, yyTokenName[yypParser->yytos->major],910 yyNewState);911 }else{912 fprintf(yyTraceFILE,"%s%s '%s', pending reduce %d\n",913 yyTracePrompt, zTag, yyTokenName[yypParser->yytos->major],914 yyNewState - YY_MIN_REDUCE);915 }916 }917}918#else919# define yyTraceShift(X,Y,Z)920#endif921 922/*923** Perform a shift action.924*/925static void yy_shift(926 yyParser *yypParser, /* The parser to be shifted */927 YYACTIONTYPE yyNewState, /* The new state to shift in */928 YYCODETYPE yyMajor, /* The major token to shift in */929 sqlite3Fts5ParserTOKENTYPE yyMinor /* The minor token to shift in */930){931 yyStackEntry *yytos;932 yypParser->yytos++;933#ifdef YYTRACKMAXSTACKDEPTH934 if( (int)(yypParser->yytos - yypParser->yystack)>yypParser->yyhwm ){935 yypParser->yyhwm++;936 assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack) );937 }938#endif939 yytos = yypParser->yytos;940 if( yytos>yypParser->yystackEnd ){941 if( yyGrowStack(yypParser) ){942 yypParser->yytos--;943 yyStackOverflow(yypParser);944 return;945 }946 yytos = yypParser->yytos;947 assert( yytos <= yypParser->yystackEnd );948 }949 if( yyNewState > YY_MAX_SHIFT ){950 yyNewState += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE;951 }952 yytos->stateno = yyNewState;953 yytos->major = yyMajor;954 yytos->minor.yy0 = yyMinor;955 yyTraceShift(yypParser, yyNewState, "Shift");956}957 958/* For rule J, yyRuleInfoLhs[J] contains the symbol on the left-hand side959** of that rule */960static const YYCODETYPE yyRuleInfoLhs[] = {961 16, /* (0) input ::= expr */962 20, /* (1) colset ::= MINUS LCP colsetlist RCP */963 20, /* (2) colset ::= LCP colsetlist RCP */964 20, /* (3) colset ::= STRING */965 20, /* (4) colset ::= MINUS STRING */966 21, /* (5) colsetlist ::= colsetlist STRING */967 21, /* (6) colsetlist ::= STRING */968 17, /* (7) expr ::= expr AND expr */969 17, /* (8) expr ::= expr OR expr */970 17, /* (9) expr ::= expr NOT expr */971 17, /* (10) expr ::= colset COLON LP expr RP */972 17, /* (11) expr ::= LP expr RP */973 17, /* (12) expr ::= exprlist */974 19, /* (13) exprlist ::= cnearset */975 19, /* (14) exprlist ::= exprlist cnearset */976 18, /* (15) cnearset ::= nearset */977 18, /* (16) cnearset ::= colset COLON nearset */978 22, /* (17) nearset ::= phrase */979 22, /* (18) nearset ::= CARET phrase */980 22, /* (19) nearset ::= STRING LP nearphrases neardist_opt RP */981 23, /* (20) nearphrases ::= phrase */982 23, /* (21) nearphrases ::= nearphrases phrase */983 25, /* (22) neardist_opt ::= */984 25, /* (23) neardist_opt ::= COMMA STRING */985 24, /* (24) phrase ::= phrase PLUS STRING star_opt */986 24, /* (25) phrase ::= STRING star_opt */987 26, /* (26) star_opt ::= STAR */988 26, /* (27) star_opt ::= */989};990 991/* For rule J, yyRuleInfoNRhs[J] contains the negative of the number992** of symbols on the right-hand side of that rule. */993static const signed char yyRuleInfoNRhs[] = {994 -1, /* (0) input ::= expr */995 -4, /* (1) colset ::= MINUS LCP colsetlist RCP */996 -3, /* (2) colset ::= LCP colsetlist RCP */997 -1, /* (3) colset ::= STRING */998 -2, /* (4) colset ::= MINUS STRING */999 -2, /* (5) colsetlist ::= colsetlist STRING */1000 -1, /* (6) colsetlist ::= STRING */1001 -3, /* (7) expr ::= expr AND expr */1002 -3, /* (8) expr ::= expr OR expr */1003 -3, /* (9) expr ::= expr NOT expr */1004 -5, /* (10) expr ::= colset COLON LP expr RP */1005 -3, /* (11) expr ::= LP expr RP */1006 -1, /* (12) expr ::= exprlist */1007 -1, /* (13) exprlist ::= cnearset */1008 -2, /* (14) exprlist ::= exprlist cnearset */1009 -1, /* (15) cnearset ::= nearset */1010 -3, /* (16) cnearset ::= colset COLON nearset */1011 -1, /* (17) nearset ::= phrase */1012 -2, /* (18) nearset ::= CARET phrase */1013 -5, /* (19) nearset ::= STRING LP nearphrases neardist_opt RP */1014 -1, /* (20) nearphrases ::= phrase */1015 -2, /* (21) nearphrases ::= nearphrases phrase */1016 0, /* (22) neardist_opt ::= */1017 -2, /* (23) neardist_opt ::= COMMA STRING */1018 -4, /* (24) phrase ::= phrase PLUS STRING star_opt */1019 -2, /* (25) phrase ::= STRING star_opt */1020 -1, /* (26) star_opt ::= STAR */1021 0, /* (27) star_opt ::= */1022};1023 1024static void yy_accept(yyParser*); /* Forward Declaration */1025 1026/*1027** Perform a reduce action and the shift that must immediately1028** follow the reduce.1029**1030** The yyLookahead and yyLookaheadToken parameters provide reduce actions1031** access to the lookahead token (if any). The yyLookahead will be YYNOCODE1032** if the lookahead token has already been consumed. As this procedure is1033** only called from one place, optimizing compilers will in-line it, which1034** means that the extra parameters have no performance impact.1035*/1036static YYACTIONTYPE yy_reduce(1037 yyParser *yypParser, /* The parser */1038 unsigned int yyruleno, /* Number of the rule by which to reduce */1039 int yyLookahead, /* Lookahead token, or YYNOCODE if none */1040 sqlite3Fts5ParserTOKENTYPE yyLookaheadToken /* Value of the lookahead token */1041 sqlite3Fts5ParserCTX_PDECL /* %extra_context */1042){1043 int yygoto; /* The next state */1044 YYACTIONTYPE yyact; /* The next action */1045 yyStackEntry *yymsp; /* The top of the parser's stack */1046 int yysize; /* Amount to pop the stack */1047 sqlite3Fts5ParserARG_FETCH1048 (void)yyLookahead;1049 (void)yyLookaheadToken;1050 yymsp = yypParser->yytos;1051 1052 switch( yyruleno ){1053 /* Beginning here are the reduction cases. A typical example1054 ** follows:1055 ** case 0:1056 ** #line <lineno> <grammarfile>1057 ** { ... } // User supplied code1058 ** #line <lineno> <thisfile>1059 ** break;1060 */1061/********** Begin reduce actions **********************************************/1062 YYMINORTYPE yylhsminor;1063 case 0: /* input ::= expr */1064#line 82 "fts5parse.y"1065{ sqlite3Fts5ParseFinished(pParse, yymsp[0].minor.yy24); }1066#line 1067 "fts5parse.c"1067 break;1068 case 1: /* colset ::= MINUS LCP colsetlist RCP */1069#line 97 "fts5parse.y"1070{ 1071 yymsp[-3].minor.yy11 = sqlite3Fts5ParseColsetInvert(pParse, yymsp[-1].minor.yy11);1072}1073#line 1074 "fts5parse.c"1074 break;1075 case 2: /* colset ::= LCP colsetlist RCP */1076#line 100 "fts5parse.y"1077{ yymsp[-2].minor.yy11 = yymsp[-1].minor.yy11; }1078#line 1079 "fts5parse.c"1079 break;1080 case 3: /* colset ::= STRING */1081#line 101 "fts5parse.y"1082{1083 yylhsminor.yy11 = sqlite3Fts5ParseColset(pParse, 0, &yymsp[0].minor.yy0);1084}1085#line 1086 "fts5parse.c"1086 yymsp[0].minor.yy11 = yylhsminor.yy11;1087 break;1088 case 4: /* colset ::= MINUS STRING */1089#line 104 "fts5parse.y"1090{1091 yymsp[-1].minor.yy11 = sqlite3Fts5ParseColset(pParse, 0, &yymsp[0].minor.yy0);1092 yymsp[-1].minor.yy11 = sqlite3Fts5ParseColsetInvert(pParse, yymsp[-1].minor.yy11);1093}1094#line 1095 "fts5parse.c"1095 break;1096 case 5: /* colsetlist ::= colsetlist STRING */1097#line 109 "fts5parse.y"1098{ 1099 yylhsminor.yy11 = sqlite3Fts5ParseColset(pParse, yymsp[-1].minor.yy11, &yymsp[0].minor.yy0); }1100#line 1101 "fts5parse.c"1101 yymsp[-1].minor.yy11 = yylhsminor.yy11;1102 break;1103 case 6: /* colsetlist ::= STRING */1104#line 111 "fts5parse.y"1105{ 1106 yylhsminor.yy11 = sqlite3Fts5ParseColset(pParse, 0, &yymsp[0].minor.yy0); 1107}1108#line 1109 "fts5parse.c"1109 yymsp[0].minor.yy11 = yylhsminor.yy11;1110 break;1111 case 7: /* expr ::= expr AND expr */1112#line 115 "fts5parse.y"1113{1114 yylhsminor.yy24 = sqlite3Fts5ParseNode(pParse, FTS5_AND, yymsp[-2].minor.yy24, yymsp[0].minor.yy24, 0);1115}1116#line 1117 "fts5parse.c"1117 yymsp[-2].minor.yy24 = yylhsminor.yy24;1118 break;1119 case 8: /* expr ::= expr OR expr */1120#line 118 "fts5parse.y"1121{1122 yylhsminor.yy24 = sqlite3Fts5ParseNode(pParse, FTS5_OR, yymsp[-2].minor.yy24, yymsp[0].minor.yy24, 0);1123}1124#line 1125 "fts5parse.c"1125 yymsp[-2].minor.yy24 = yylhsminor.yy24;1126 break;1127 case 9: /* expr ::= expr NOT expr */1128#line 121 "fts5parse.y"1129{1130 yylhsminor.yy24 = sqlite3Fts5ParseNode(pParse, FTS5_NOT, yymsp[-2].minor.yy24, yymsp[0].minor.yy24, 0);1131}1132#line 1133 "fts5parse.c"1133 yymsp[-2].minor.yy24 = yylhsminor.yy24;1134 break;1135 case 10: /* expr ::= colset COLON LP expr RP */1136#line 125 "fts5parse.y"1137{1138 sqlite3Fts5ParseSetColset(pParse, yymsp[-1].minor.yy24, yymsp[-4].minor.yy11);1139 yylhsminor.yy24 = yymsp[-1].minor.yy24;1140}1141#line 1142 "fts5parse.c"1142 yymsp[-4].minor.yy24 = yylhsminor.yy24;1143 break;1144 case 11: /* expr ::= LP expr RP */1145#line 129 "fts5parse.y"1146{yymsp[-2].minor.yy24 = yymsp[-1].minor.yy24;}1147#line 1148 "fts5parse.c"1148 break;1149 case 12: /* expr ::= exprlist */1150 case 13: /* exprlist ::= cnearset */ yytestcase(yyruleno==13);1151#line 130 "fts5parse.y"1152{yylhsminor.yy24 = yymsp[0].minor.yy24;}1153#line 1154 "fts5parse.c"1154 yymsp[0].minor.yy24 = yylhsminor.yy24;1155 break;1156 case 14: /* exprlist ::= exprlist cnearset */1157#line 133 "fts5parse.y"1158{1159 yylhsminor.yy24 = sqlite3Fts5ParseImplicitAnd(pParse, yymsp[-1].minor.yy24, yymsp[0].minor.yy24);1160}1161#line 1162 "fts5parse.c"1162 yymsp[-1].minor.yy24 = yylhsminor.yy24;1163 break;1164 case 15: /* cnearset ::= nearset */1165#line 137 "fts5parse.y"1166{ 1167 yylhsminor.yy24 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, yymsp[0].minor.yy46); 1168}1169#line 1170 "fts5parse.c"1170 yymsp[0].minor.yy24 = yylhsminor.yy24;1171 break;1172 case 16: /* cnearset ::= colset COLON nearset */1173#line 140 "fts5parse.y"1174{ 1175 yylhsminor.yy24 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, yymsp[0].minor.yy46); 1176 sqlite3Fts5ParseSetColset(pParse, yylhsminor.yy24, yymsp[-2].minor.yy11);1177}1178#line 1179 "fts5parse.c"1179 yymsp[-2].minor.yy24 = yylhsminor.yy24;1180 break;1181 case 17: /* nearset ::= phrase */1182#line 151 "fts5parse.y"1183{ yylhsminor.yy46 = sqlite3Fts5ParseNearset(pParse, 0, yymsp[0].minor.yy53); }1184#line 1185 "fts5parse.c"1185 yymsp[0].minor.yy46 = yylhsminor.yy46;1186 break;1187 case 18: /* nearset ::= CARET phrase */1188#line 152 "fts5parse.y"1189{ 1190 sqlite3Fts5ParseSetCaret(yymsp[0].minor.yy53);1191 yymsp[-1].minor.yy46 = sqlite3Fts5ParseNearset(pParse, 0, yymsp[0].minor.yy53); 1192}1193#line 1194 "fts5parse.c"1194 break;1195 case 19: /* nearset ::= STRING LP nearphrases neardist_opt RP */1196#line 156 "fts5parse.y"1197{1198 sqlite3Fts5ParseNear(pParse, &yymsp[-4].minor.yy0);1199 sqlite3Fts5ParseSetDistance(pParse, yymsp[-2].minor.yy46, &yymsp[-1].minor.yy0);1200 yylhsminor.yy46 = yymsp[-2].minor.yy46;