drh | 82415f2 | 2015-11-09 19:33:42 +0000 | [diff] [blame] | 1 | /* |
| 2 | ** 2000-05-29 |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 3 | ** |
drh | 82415f2 | 2015-11-09 19:33:42 +0000 | [diff] [blame] | 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. |
| 10 | ** |
| 11 | ************************************************************************* |
| 12 | ** Driver template for the LEMON parser generator. |
| 13 | ** |
| 14 | ** The "lemon" program processes an LALR(1) input grammar file, then uses |
| 15 | ** this template to construct a parser. The "lemon" program inserts text |
| 16 | ** at each "%%" line. Also, any "P-a-r-s-e" identifer prefix (without the |
| 17 | ** interstitial "-" characters) contained in this template is changed into |
| 18 | ** the value of the %name directive from the grammar. Otherwise, the content |
| 19 | ** of this template is copied straight through into the generate parser |
| 20 | ** source file. |
| 21 | ** |
| 22 | ** The following is the concatenation of all %include directives from the |
| 23 | ** input grammar file: |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 24 | */ |
drh | 82415f2 | 2015-11-09 19:33:42 +0000 | [diff] [blame] | 25 | /************ Begin %include sections from the grammar ************************/ |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 26 | %% |
drh | 82415f2 | 2015-11-09 19:33:42 +0000 | [diff] [blame] | 27 | /**************** End of %include directives **********************************/ |
drh | 60c71b0 | 2020-09-01 11:20:03 +0000 | [diff] [blame] | 28 | /* These constants specify the various numeric values for terminal symbols. |
| 29 | ***************** Begin token definitions *************************************/ |
drh | 82415f2 | 2015-11-09 19:33:42 +0000 | [diff] [blame] | 30 | %% |
drh | 60c71b0 | 2020-09-01 11:20:03 +0000 | [diff] [blame] | 31 | /**************** End token definitions ***************************************/ |
drh | 822a62f | 2015-11-09 19:35:18 +0000 | [diff] [blame] | 32 | |
| 33 | /* The next sections is a series of control #defines. |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 34 | ** various aspects of the generated parser. |
drh | 82415f2 | 2015-11-09 19:33:42 +0000 | [diff] [blame] | 35 | ** YYCODETYPE is the data type used to store the integer codes |
| 36 | ** that represent terminal and non-terminal symbols. |
| 37 | ** "unsigned char" is used if there are fewer than |
| 38 | ** 256 symbols. Larger types otherwise. |
| 39 | ** YYNOCODE is a number of type YYCODETYPE that is not used for |
| 40 | ** any terminal or nonterminal symbol. |
drh | 0bd1f4e | 2002-06-06 18:54:39 +0000 | [diff] [blame] | 41 | ** YYFALLBACK If defined, this indicates that one or more tokens |
drh | 82415f2 | 2015-11-09 19:33:42 +0000 | [diff] [blame] | 42 | ** (also known as: "terminal symbols") have fall-back |
| 43 | ** values which should be used if the original symbol |
| 44 | ** would not parse. This permits keywords to sometimes |
| 45 | ** be used as identifiers, for example. |
| 46 | ** YYACTIONTYPE is the data type used for "action codes" - numbers |
| 47 | ** that indicate what to do in response to the next |
| 48 | ** token. |
| 49 | ** ParseTOKENTYPE is the data type used for minor type for terminal |
| 50 | ** symbols. Background: A "minor type" is a semantic |
| 51 | ** value associated with a terminal or non-terminal |
| 52 | ** symbols. For example, for an "ID" terminal symbol, |
| 53 | ** the minor type might be the name of the identifier. |
| 54 | ** Each non-terminal can have a different minor type. |
| 55 | ** Terminal symbols all have the same minor type, though. |
| 56 | ** This macros defines the minor type for terminal |
| 57 | ** symbols. |
| 58 | ** YYMINORTYPE is the data type used for all minor types. |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 59 | ** This is typically a union of many types, one of |
| 60 | ** which is ParseTOKENTYPE. The entry in the union |
drh | 82415f2 | 2015-11-09 19:33:42 +0000 | [diff] [blame] | 61 | ** for terminal symbols is called "yy0". |
drh | b19fd01 | 2007-03-29 01:44:45 +0000 | [diff] [blame] | 62 | ** YYSTACKDEPTH is the maximum depth of the parser's stack. If |
| 63 | ** zero the stack is dynamically sized using realloc() |
drh | 1f245e4 | 2002-03-11 13:55:50 +0000 | [diff] [blame] | 64 | ** ParseARG_SDECL A static variable declaration for the %extra_argument |
| 65 | ** ParseARG_PDECL A parameter declaration for the %extra_argument |
drh | fb32c44 | 2018-04-21 13:51:42 +0000 | [diff] [blame] | 66 | ** ParseARG_PARAM Code to pass %extra_argument as a subroutine parameter |
drh | 1f245e4 | 2002-03-11 13:55:50 +0000 | [diff] [blame] | 67 | ** ParseARG_STORE Code to store %extra_argument into yypParser |
| 68 | ** ParseARG_FETCH Code to extract %extra_argument from yypParser |
drh | fb32c44 | 2018-04-21 13:51:42 +0000 | [diff] [blame] | 69 | ** ParseCTX_* As ParseARG_ except for %extra_context |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 70 | ** YYERRORSYMBOL is the code number of the error symbol. If not |
| 71 | ** defined, then do no error processing. |
drh | 3bd48ab | 2015-09-07 18:23:37 +0000 | [diff] [blame] | 72 | ** YYNSTATE the combined number of states. |
| 73 | ** YYNRULE the number of rules in the grammar |
drh | 0d9de99 | 2017-12-26 18:04:23 +0000 | [diff] [blame] | 74 | ** YYNTOKEN Number of terminal symbols |
drh | 3bd48ab | 2015-09-07 18:23:37 +0000 | [diff] [blame] | 75 | ** YY_MAX_SHIFT Maximum value for shift actions |
| 76 | ** YY_MIN_SHIFTREDUCE Minimum value for shift-reduce actions |
| 77 | ** YY_MAX_SHIFTREDUCE Maximum value for shift-reduce actions |
drh | 3bd48ab | 2015-09-07 18:23:37 +0000 | [diff] [blame] | 78 | ** YY_ERROR_ACTION The yy_action[] code for syntax error |
| 79 | ** YY_ACCEPT_ACTION The yy_action[] code for accept |
| 80 | ** YY_NO_ACTION The yy_action[] code for no-op |
drh | 5c8241b | 2017-12-24 23:38:10 +0000 | [diff] [blame] | 81 | ** YY_MIN_REDUCE Minimum value for reduce actions |
| 82 | ** YY_MAX_REDUCE Maximum value for reduce actions |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 83 | */ |
drh | 82415f2 | 2015-11-09 19:33:42 +0000 | [diff] [blame] | 84 | #ifndef INTERFACE |
| 85 | # define INTERFACE 1 |
| 86 | #endif |
| 87 | /************* Begin control #defines *****************************************/ |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 88 | %% |
drh | 82415f2 | 2015-11-09 19:33:42 +0000 | [diff] [blame] | 89 | /************* End control #defines *******************************************/ |
drh | 3773c25 | 2018-06-28 03:38:49 +0000 | [diff] [blame] | 90 | #define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0]))) |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 91 | |
drh | 8a415d3 | 2009-06-12 13:53:51 +0000 | [diff] [blame] | 92 | /* Define the yytestcase() macro to be a no-op if is not already defined |
| 93 | ** otherwise. |
| 94 | ** |
| 95 | ** Applications can choose to define yytestcase() in the %include section |
| 96 | ** to a macro that can assist in verifying code coverage. For production |
| 97 | ** code the yytestcase() macro should be turned off. But it is useful |
| 98 | ** for testing. |
| 99 | */ |
| 100 | #ifndef yytestcase |
| 101 | # define yytestcase(X) |
| 102 | #endif |
| 103 | |
drh | 26c9b5e | 2008-04-11 14:56:53 +0000 | [diff] [blame] | 104 | |
drh | 34ff57b | 2008-07-14 12:27:51 +0000 | [diff] [blame] | 105 | /* Next are the tables used to determine what action to take based on the |
drh | 8b58201 | 2003-10-21 13:16:03 +0000 | [diff] [blame] | 106 | ** current state and lookahead token. These tables are used to implement |
| 107 | ** functions that take a state number and lookahead value and return an |
| 108 | ** action integer. |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 109 | ** |
drh | 8548a05 | 2003-10-22 22:15:27 +0000 | [diff] [blame] | 110 | ** Suppose the action integer is N. Then the action is determined as |
| 111 | ** follows |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 112 | ** |
drh | 3bd48ab | 2015-09-07 18:23:37 +0000 | [diff] [blame] | 113 | ** 0 <= N <= YY_MAX_SHIFT Shift N. That is, push the lookahead |
drh | 8548a05 | 2003-10-22 22:15:27 +0000 | [diff] [blame] | 114 | ** token onto the stack and goto state N. |
| 115 | ** |
drh | 3bd48ab | 2015-09-07 18:23:37 +0000 | [diff] [blame] | 116 | ** N between YY_MIN_SHIFTREDUCE Shift to an arbitrary state then |
| 117 | ** and YY_MAX_SHIFTREDUCE reduce by rule N-YY_MIN_SHIFTREDUCE. |
drh | 8548a05 | 2003-10-22 22:15:27 +0000 | [diff] [blame] | 118 | ** |
drh | 3bd48ab | 2015-09-07 18:23:37 +0000 | [diff] [blame] | 119 | ** N == YY_ERROR_ACTION A syntax error has occurred. |
drh | 8548a05 | 2003-10-22 22:15:27 +0000 | [diff] [blame] | 120 | ** |
drh | 3bd48ab | 2015-09-07 18:23:37 +0000 | [diff] [blame] | 121 | ** N == YY_ACCEPT_ACTION The parser accepts its input. |
drh | 8548a05 | 2003-10-22 22:15:27 +0000 | [diff] [blame] | 122 | ** |
drh | 3bd48ab | 2015-09-07 18:23:37 +0000 | [diff] [blame] | 123 | ** N == YY_NO_ACTION No such action. Denotes unused |
drh | 8548a05 | 2003-10-22 22:15:27 +0000 | [diff] [blame] | 124 | ** slots in the yy_action[] table. |
| 125 | ** |
drh | 5c8241b | 2017-12-24 23:38:10 +0000 | [diff] [blame] | 126 | ** N between YY_MIN_REDUCE Reduce by rule N-YY_MIN_REDUCE |
| 127 | ** and YY_MAX_REDUCE |
| 128 | ** |
drh | 8548a05 | 2003-10-22 22:15:27 +0000 | [diff] [blame] | 129 | ** The action table is constructed as a single large table named yy_action[]. |
drh | 701b688 | 2016-08-10 13:30:43 +0000 | [diff] [blame] | 130 | ** Given state S and lookahead X, the action is computed as either: |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 131 | ** |
drh | 701b688 | 2016-08-10 13:30:43 +0000 | [diff] [blame] | 132 | ** (A) N = yy_action[ yy_shift_ofst[S] + X ] |
| 133 | ** (B) N = yy_default[S] |
drh | 8b58201 | 2003-10-21 13:16:03 +0000 | [diff] [blame] | 134 | ** |
drh | 3a9d6c7 | 2017-12-25 04:15:38 +0000 | [diff] [blame] | 135 | ** The (A) formula is preferred. The B formula is used instead if |
| 136 | ** yy_lookahead[yy_shift_ofst[S]+X] is not equal to X. |
drh | 8b58201 | 2003-10-21 13:16:03 +0000 | [diff] [blame] | 137 | ** |
drh | 701b688 | 2016-08-10 13:30:43 +0000 | [diff] [blame] | 138 | ** The formulas above are for computing the action when the lookahead is |
drh | 8b58201 | 2003-10-21 13:16:03 +0000 | [diff] [blame] | 139 | ** a terminal symbol. If the lookahead is a non-terminal (as occurs after |
| 140 | ** a reduce action) then the yy_reduce_ofst[] array is used in place of |
drh | 3a9d6c7 | 2017-12-25 04:15:38 +0000 | [diff] [blame] | 141 | ** the yy_shift_ofst[] array. |
drh | 8b58201 | 2003-10-21 13:16:03 +0000 | [diff] [blame] | 142 | ** |
| 143 | ** The following are the tables generated in this section: |
| 144 | ** |
| 145 | ** yy_action[] A single table containing all actions. |
| 146 | ** yy_lookahead[] A table containing the lookahead for each entry in |
| 147 | ** yy_action. Used to detect hash collisions. |
| 148 | ** yy_shift_ofst[] For each state, the offset into yy_action for |
| 149 | ** shifting terminals. |
| 150 | ** yy_reduce_ofst[] For each state, the offset into yy_action for |
| 151 | ** shifting non-terminals after a reduce. |
| 152 | ** yy_default[] Default action for each state. |
drh | 82415f2 | 2015-11-09 19:33:42 +0000 | [diff] [blame] | 153 | ** |
| 154 | *********** Begin parsing tables **********************************************/ |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 155 | %% |
drh | 82415f2 | 2015-11-09 19:33:42 +0000 | [diff] [blame] | 156 | /********** End of lemon-generated parsing tables *****************************/ |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 157 | |
drh | 82415f2 | 2015-11-09 19:33:42 +0000 | [diff] [blame] | 158 | /* The next table maps tokens (terminal symbols) into fallback tokens. |
| 159 | ** If a construct like the following: |
drh | 0bd1f4e | 2002-06-06 18:54:39 +0000 | [diff] [blame] | 160 | ** |
| 161 | ** %fallback ID X Y Z. |
| 162 | ** |
drh | 34ff57b | 2008-07-14 12:27:51 +0000 | [diff] [blame] | 163 | ** appears in the grammar, then ID becomes a fallback token for X, Y, |
drh | 0bd1f4e | 2002-06-06 18:54:39 +0000 | [diff] [blame] | 164 | ** and Z. Whenever one of the tokens X, Y, or Z is input to the parser |
| 165 | ** but it does not parse, the type of the token is changed to ID and |
| 166 | ** the parse is retried before an error is thrown. |
drh | 82415f2 | 2015-11-09 19:33:42 +0000 | [diff] [blame] | 167 | ** |
| 168 | ** This feature can be used, for example, to cause some keywords in a language |
| 169 | ** to revert to identifiers if they keyword does not apply in the context where |
| 170 | ** it appears. |
drh | 0bd1f4e | 2002-06-06 18:54:39 +0000 | [diff] [blame] | 171 | */ |
| 172 | #ifdef YYFALLBACK |
| 173 | static const YYCODETYPE yyFallback[] = { |
| 174 | %% |
| 175 | }; |
| 176 | #endif /* YYFALLBACK */ |
| 177 | |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 178 | /* The following structure represents a single element of the |
| 179 | ** parser's stack. Information stored includes: |
| 180 | ** |
| 181 | ** + The state number for the parser at this level of the stack. |
| 182 | ** |
| 183 | ** + The value of the token stored at this level of the stack. |
| 184 | ** (In other words, the "major" token.) |
| 185 | ** |
| 186 | ** + The semantic value stored at this level of the stack. This is |
| 187 | ** the information used by the action routines in the grammar. |
| 188 | ** It is sometimes called the "minor" token. |
drh | a248a72 | 2015-09-07 19:52:55 +0000 | [diff] [blame] | 189 | ** |
| 190 | ** After the "shift" half of a SHIFTREDUCE action, the stateno field |
| 191 | ** actually contains the reduce action for the second half of the |
| 192 | ** SHIFTREDUCE. |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 193 | */ |
| 194 | struct yyStackEntry { |
drh | a248a72 | 2015-09-07 19:52:55 +0000 | [diff] [blame] | 195 | YYACTIONTYPE stateno; /* The state-number, or reduce action in SHIFTREDUCE */ |
drh | 2abcd58 | 2008-07-24 23:34:07 +0000 | [diff] [blame] | 196 | YYCODETYPE major; /* The major token value. This is the code |
| 197 | ** number for the token at this stack level */ |
| 198 | YYMINORTYPE minor; /* The user-supplied minor token value. This |
| 199 | ** is the value of the token */ |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 200 | }; |
drh | 1f245e4 | 2002-03-11 13:55:50 +0000 | [diff] [blame] | 201 | typedef struct yyStackEntry yyStackEntry; |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 202 | |
| 203 | /* The state of the parser is completely contained in an instance of |
| 204 | ** the following structure */ |
| 205 | struct yyParser { |
drh | 118ab65 | 2016-05-23 21:56:24 +0000 | [diff] [blame] | 206 | yyStackEntry *yytos; /* Pointer to top element of the stack */ |
drh | ec424a5 | 2008-07-25 15:39:03 +0000 | [diff] [blame] | 207 | #ifdef YYTRACKMAXSTACKDEPTH |
drh | 118ab65 | 2016-05-23 21:56:24 +0000 | [diff] [blame] | 208 | int yyhwm; /* High-water mark of the stack */ |
drh | ec424a5 | 2008-07-25 15:39:03 +0000 | [diff] [blame] | 209 | #endif |
drh | dab943c | 2016-02-16 01:01:43 +0000 | [diff] [blame] | 210 | #ifndef YYNOERRORRECOVERY |
drh | 1f245e4 | 2002-03-11 13:55:50 +0000 | [diff] [blame] | 211 | int yyerrcnt; /* Shifts left before out of the error */ |
drh | dab943c | 2016-02-16 01:01:43 +0000 | [diff] [blame] | 212 | #endif |
drh | 1f245e4 | 2002-03-11 13:55:50 +0000 | [diff] [blame] | 213 | ParseARG_SDECL /* A place to hold %extra_argument */ |
drh | fb32c44 | 2018-04-21 13:51:42 +0000 | [diff] [blame] | 214 | ParseCTX_SDECL /* A place to hold %extra_context */ |
drh | b19fd01 | 2007-03-29 01:44:45 +0000 | [diff] [blame] | 215 | #if YYSTACKDEPTH<=0 |
| 216 | int yystksz; /* Current side of the stack */ |
| 217 | yyStackEntry *yystack; /* The parser's stack */ |
drh | 8dc8247 | 2016-05-27 04:10:47 +0000 | [diff] [blame] | 218 | yyStackEntry yystk0; /* First stack entry */ |
drh | b19fd01 | 2007-03-29 01:44:45 +0000 | [diff] [blame] | 219 | #else |
drh | 1f245e4 | 2002-03-11 13:55:50 +0000 | [diff] [blame] | 220 | yyStackEntry yystack[YYSTACKDEPTH]; /* The parser's stack */ |
drh | 8b471e7 | 2017-06-28 15:01:35 +0000 | [diff] [blame] | 221 | yyStackEntry *yystackEnd; /* Last entry in the stack */ |
drh | b19fd01 | 2007-03-29 01:44:45 +0000 | [diff] [blame] | 222 | #endif |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 223 | }; |
| 224 | typedef struct yyParser yyParser; |
| 225 | |
| 226 | #ifndef NDEBUG |
| 227 | #include <stdio.h> |
drh | 60c71b0 | 2020-09-01 11:20:03 +0000 | [diff] [blame] | 228 | #include <assert.h> |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 229 | static FILE *yyTraceFILE = 0; |
| 230 | static char *yyTracePrompt = 0; |
drh | 0bd1f4e | 2002-06-06 18:54:39 +0000 | [diff] [blame] | 231 | #endif /* NDEBUG */ |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 232 | |
drh | 0bd1f4e | 2002-06-06 18:54:39 +0000 | [diff] [blame] | 233 | #ifndef NDEBUG |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 234 | /* |
| 235 | ** Turn parser tracing on by giving a stream to which to write the trace |
| 236 | ** and a prompt to preface each trace message. Tracing is turned off |
| 237 | ** by making either argument NULL |
| 238 | ** |
| 239 | ** Inputs: |
| 240 | ** <ul> |
| 241 | ** <li> A FILE* to which trace output should be written. |
| 242 | ** If NULL, then tracing is turned off. |
| 243 | ** <li> A prefix string written at the beginning of every |
| 244 | ** line of trace output. If NULL, then tracing is |
| 245 | ** turned off. |
| 246 | ** </ul> |
| 247 | ** |
| 248 | ** Outputs: |
| 249 | ** None. |
| 250 | */ |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 251 | void ParseTrace(FILE *TraceFILE, char *zTracePrompt){ |
| 252 | yyTraceFILE = TraceFILE; |
| 253 | yyTracePrompt = zTracePrompt; |
| 254 | if( yyTraceFILE==0 ) yyTracePrompt = 0; |
| 255 | else if( yyTracePrompt==0 ) yyTraceFILE = 0; |
| 256 | } |
drh | 0bd1f4e | 2002-06-06 18:54:39 +0000 | [diff] [blame] | 257 | #endif /* NDEBUG */ |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 258 | |
drh | 0d9de99 | 2017-12-26 18:04:23 +0000 | [diff] [blame] | 259 | #if defined(YYCOVERAGE) || !defined(NDEBUG) |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 260 | /* For tracing shifts, the names of all terminals and nonterminals |
| 261 | ** are required. The following table supplies these names */ |
drh | 5719628 | 2004-10-06 15:41:16 +0000 | [diff] [blame] | 262 | static const char *const yyTokenName[] = { |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 263 | %% |
| 264 | }; |
drh | 0d9de99 | 2017-12-26 18:04:23 +0000 | [diff] [blame] | 265 | #endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */ |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 266 | |
drh | 0bd1f4e | 2002-06-06 18:54:39 +0000 | [diff] [blame] | 267 | #ifndef NDEBUG |
| 268 | /* For tracing reduce actions, the names of all rules are required. |
| 269 | */ |
drh | 5719628 | 2004-10-06 15:41:16 +0000 | [diff] [blame] | 270 | static const char *const yyRuleName[] = { |
drh | 0bd1f4e | 2002-06-06 18:54:39 +0000 | [diff] [blame] | 271 | %% |
| 272 | }; |
| 273 | #endif /* NDEBUG */ |
drh | a1b351a | 2001-09-14 16:42:12 +0000 | [diff] [blame] | 274 | |
drh | 960e8c6 | 2001-04-03 16:53:21 +0000 | [diff] [blame] | 275 | |
drh | b19fd01 | 2007-03-29 01:44:45 +0000 | [diff] [blame] | 276 | #if YYSTACKDEPTH<=0 |
| 277 | /* |
drh | 8dc8247 | 2016-05-27 04:10:47 +0000 | [diff] [blame] | 278 | ** Try to increase the size of the parser stack. Return the number |
| 279 | ** of errors. Return 0 on success. |
drh | b19fd01 | 2007-03-29 01:44:45 +0000 | [diff] [blame] | 280 | */ |
drh | 8dc8247 | 2016-05-27 04:10:47 +0000 | [diff] [blame] | 281 | static int yyGrowStack(yyParser *p){ |
drh | b19fd01 | 2007-03-29 01:44:45 +0000 | [diff] [blame] | 282 | int newSize; |
drh | abecc0b | 2016-05-24 00:40:54 +0000 | [diff] [blame] | 283 | int idx; |
drh | b19fd01 | 2007-03-29 01:44:45 +0000 | [diff] [blame] | 284 | yyStackEntry *pNew; |
| 285 | |
| 286 | newSize = p->yystksz*2 + 100; |
drh | abecc0b | 2016-05-24 00:40:54 +0000 | [diff] [blame] | 287 | idx = p->yytos ? (int)(p->yytos - p->yystack) : 0; |
drh | 8dc8247 | 2016-05-27 04:10:47 +0000 | [diff] [blame] | 288 | if( p->yystack==&p->yystk0 ){ |
| 289 | pNew = malloc(newSize*sizeof(pNew[0])); |
| 290 | if( pNew ) pNew[0] = p->yystk0; |
| 291 | }else{ |
| 292 | pNew = realloc(p->yystack, newSize*sizeof(pNew[0])); |
| 293 | } |
drh | b19fd01 | 2007-03-29 01:44:45 +0000 | [diff] [blame] | 294 | if( pNew ){ |
| 295 | p->yystack = pNew; |
drh | abecc0b | 2016-05-24 00:40:54 +0000 | [diff] [blame] | 296 | p->yytos = &p->yystack[idx]; |
drh | b19fd01 | 2007-03-29 01:44:45 +0000 | [diff] [blame] | 297 | #ifndef NDEBUG |
| 298 | if( yyTraceFILE ){ |
drh | 8dc8247 | 2016-05-27 04:10:47 +0000 | [diff] [blame] | 299 | fprintf(yyTraceFILE,"%sStack grows from %d to %d entries.\n", |
| 300 | yyTracePrompt, p->yystksz, newSize); |
drh | b19fd01 | 2007-03-29 01:44:45 +0000 | [diff] [blame] | 301 | } |
| 302 | #endif |
drh | 8dc8247 | 2016-05-27 04:10:47 +0000 | [diff] [blame] | 303 | p->yystksz = newSize; |
drh | b19fd01 | 2007-03-29 01:44:45 +0000 | [diff] [blame] | 304 | } |
drh | 8dc8247 | 2016-05-27 04:10:47 +0000 | [diff] [blame] | 305 | return pNew==0; |
drh | b19fd01 | 2007-03-29 01:44:45 +0000 | [diff] [blame] | 306 | } |
| 307 | #endif |
| 308 | |
drh | 82415f2 | 2015-11-09 19:33:42 +0000 | [diff] [blame] | 309 | /* Datatype of the argument to the memory allocated passed as the |
| 310 | ** second argument to ParseAlloc() below. This can be changed by |
| 311 | ** putting an appropriate #define in the %include section of the input |
| 312 | ** grammar. |
| 313 | */ |
| 314 | #ifndef YYMALLOCARGTYPE |
| 315 | # define YYMALLOCARGTYPE size_t |
| 316 | #endif |
| 317 | |
drh | d26cc54 | 2017-01-28 20:46:37 +0000 | [diff] [blame] | 318 | /* Initialize a new parser that has already been allocated. |
| 319 | */ |
drh | fb32c44 | 2018-04-21 13:51:42 +0000 | [diff] [blame] | 320 | void ParseInit(void *yypRawParser ParseCTX_PDECL){ |
| 321 | yyParser *yypParser = (yyParser*)yypRawParser; |
| 322 | ParseCTX_STORE |
drh | d26cc54 | 2017-01-28 20:46:37 +0000 | [diff] [blame] | 323 | #ifdef YYTRACKMAXSTACKDEPTH |
drh | fb32c44 | 2018-04-21 13:51:42 +0000 | [diff] [blame] | 324 | yypParser->yyhwm = 0; |
drh | d26cc54 | 2017-01-28 20:46:37 +0000 | [diff] [blame] | 325 | #endif |
| 326 | #if YYSTACKDEPTH<=0 |
drh | fb32c44 | 2018-04-21 13:51:42 +0000 | [diff] [blame] | 327 | yypParser->yytos = NULL; |
| 328 | yypParser->yystack = NULL; |
| 329 | yypParser->yystksz = 0; |
| 330 | if( yyGrowStack(yypParser) ){ |
| 331 | yypParser->yystack = &yypParser->yystk0; |
| 332 | yypParser->yystksz = 1; |
drh | d26cc54 | 2017-01-28 20:46:37 +0000 | [diff] [blame] | 333 | } |
| 334 | #endif |
| 335 | #ifndef YYNOERRORRECOVERY |
drh | fb32c44 | 2018-04-21 13:51:42 +0000 | [diff] [blame] | 336 | yypParser->yyerrcnt = -1; |
drh | d26cc54 | 2017-01-28 20:46:37 +0000 | [diff] [blame] | 337 | #endif |
drh | fb32c44 | 2018-04-21 13:51:42 +0000 | [diff] [blame] | 338 | yypParser->yytos = yypParser->yystack; |
| 339 | yypParser->yystack[0].stateno = 0; |
| 340 | yypParser->yystack[0].major = 0; |
drh | 92395c5 | 2017-07-04 12:50:00 +0000 | [diff] [blame] | 341 | #if YYSTACKDEPTH>0 |
drh | fb32c44 | 2018-04-21 13:51:42 +0000 | [diff] [blame] | 342 | yypParser->yystackEnd = &yypParser->yystack[YYSTACKDEPTH-1]; |
drh | 92395c5 | 2017-07-04 12:50:00 +0000 | [diff] [blame] | 343 | #endif |
drh | d26cc54 | 2017-01-28 20:46:37 +0000 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | #ifndef Parse_ENGINEALWAYSONSTACK |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 347 | /* |
| 348 | ** This function allocates a new parser. |
| 349 | ** The only argument is a pointer to a function which works like |
| 350 | ** malloc. |
| 351 | ** |
| 352 | ** Inputs: |
| 353 | ** A pointer to the function used to allocate memory. |
| 354 | ** |
| 355 | ** Outputs: |
| 356 | ** A pointer to a parser. This pointer is used in subsequent calls |
| 357 | ** to Parse and ParseFree. |
| 358 | */ |
drh | fb32c44 | 2018-04-21 13:51:42 +0000 | [diff] [blame] | 359 | void *ParseAlloc(void *(*mallocProc)(YYMALLOCARGTYPE) ParseCTX_PDECL){ |
| 360 | yyParser *yypParser; |
| 361 | yypParser = (yyParser*)(*mallocProc)( (YYMALLOCARGTYPE)sizeof(yyParser) ); |
| 362 | if( yypParser ){ |
| 363 | ParseCTX_STORE |
| 364 | ParseInit(yypParser ParseCTX_PARAM); |
| 365 | } |
| 366 | return (void*)yypParser; |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 367 | } |
drh | d26cc54 | 2017-01-28 20:46:37 +0000 | [diff] [blame] | 368 | #endif /* Parse_ENGINEALWAYSONSTACK */ |
| 369 | |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 370 | |
drh | 82415f2 | 2015-11-09 19:33:42 +0000 | [diff] [blame] | 371 | /* The following function deletes the "minor type" or semantic value |
| 372 | ** associated with a symbol. The symbol can be either a terminal |
| 373 | ** or nonterminal. "yymajor" is the symbol code, and "yypminor" is |
| 374 | ** a pointer to the value to be deleted. The code used to do the |
| 375 | ** deletions is derived from the %destructor and/or %token_destructor |
| 376 | ** directives of the input grammar. |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 377 | */ |
drh | 633e6d5 | 2008-07-28 19:34:53 +0000 | [diff] [blame] | 378 | static void yy_destructor( |
| 379 | yyParser *yypParser, /* The parser */ |
| 380 | YYCODETYPE yymajor, /* Type code for object to destroy */ |
| 381 | YYMINORTYPE *yypminor /* The object to be destroyed */ |
| 382 | ){ |
drh | fb32c44 | 2018-04-21 13:51:42 +0000 | [diff] [blame] | 383 | ParseARG_FETCH |
| 384 | ParseCTX_FETCH |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 385 | switch( yymajor ){ |
| 386 | /* Here is inserted the actions which take place when a |
| 387 | ** terminal or non-terminal is destroyed. This can happen |
| 388 | ** when the symbol is popped from the stack during a |
| 389 | ** reduce or during error processing or when a parser is |
| 390 | ** being destroyed before it is finished parsing. |
| 391 | ** |
| 392 | ** Note: during a reduce, the only symbols destroyed are those |
drh | 82415f2 | 2015-11-09 19:33:42 +0000 | [diff] [blame] | 393 | ** which appear on the RHS of the rule, but which are *not* used |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 394 | ** inside the C code. |
| 395 | */ |
drh | 82415f2 | 2015-11-09 19:33:42 +0000 | [diff] [blame] | 396 | /********* Begin destructor definitions ***************************************/ |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 397 | %% |
drh | 82415f2 | 2015-11-09 19:33:42 +0000 | [diff] [blame] | 398 | /********* End destructor definitions *****************************************/ |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 399 | default: break; /* If no destructor action specified: do nothing */ |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | /* |
| 404 | ** Pop the parser's stack once. |
| 405 | ** |
| 406 | ** If there is a destructor routine associated with the token which |
| 407 | ** is popped from the stack, then call it. |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 408 | */ |
drh | 3781f01 | 2015-11-09 14:11:37 +0000 | [diff] [blame] | 409 | static void yy_pop_parser_stack(yyParser *pParser){ |
| 410 | yyStackEntry *yytos; |
drh | 118ab65 | 2016-05-23 21:56:24 +0000 | [diff] [blame] | 411 | assert( pParser->yytos!=0 ); |
drh | 240c7fa | 2016-07-05 12:47:28 +0000 | [diff] [blame] | 412 | assert( pParser->yytos > pParser->yystack ); |
drh | 118ab65 | 2016-05-23 21:56:24 +0000 | [diff] [blame] | 413 | yytos = pParser->yytos--; |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 414 | #ifndef NDEBUG |
drh | 3781f01 | 2015-11-09 14:11:37 +0000 | [diff] [blame] | 415 | if( yyTraceFILE ){ |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 416 | fprintf(yyTraceFILE,"%sPopping %s\n", |
| 417 | yyTracePrompt, |
drh | 3ddfdf7 | 2003-12-22 14:53:19 +0000 | [diff] [blame] | 418 | yyTokenName[yytos->major]); |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 419 | } |
| 420 | #endif |
drh | 3781f01 | 2015-11-09 14:11:37 +0000 | [diff] [blame] | 421 | yy_destructor(pParser, yytos->major, &yytos->minor); |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 422 | } |
| 423 | |
drh | d26cc54 | 2017-01-28 20:46:37 +0000 | [diff] [blame] | 424 | /* |
| 425 | ** Clear all secondary memory allocations from the parser |
| 426 | */ |
| 427 | void ParseFinalize(void *p){ |
| 428 | yyParser *pParser = (yyParser*)p; |
| 429 | while( pParser->yytos>pParser->yystack ) yy_pop_parser_stack(pParser); |
| 430 | #if YYSTACKDEPTH<=0 |
| 431 | if( pParser->yystack!=&pParser->yystk0 ) free(pParser->yystack); |
| 432 | #endif |
| 433 | } |
| 434 | |
| 435 | #ifndef Parse_ENGINEALWAYSONSTACK |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 436 | /* |
drh | 82415f2 | 2015-11-09 19:33:42 +0000 | [diff] [blame] | 437 | ** Deallocate and destroy a parser. Destructors are called for |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 438 | ** all stack elements before shutting the parser down. |
| 439 | ** |
drh | 82415f2 | 2015-11-09 19:33:42 +0000 | [diff] [blame] | 440 | ** If the YYPARSEFREENEVERNULL macro exists (for example because it |
| 441 | ** is defined in a %include section of the input grammar) then it is |
| 442 | ** assumed that the input pointer is never NULL. |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 443 | */ |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 444 | void ParseFree( |
drh | 960e8c6 | 2001-04-03 16:53:21 +0000 | [diff] [blame] | 445 | void *p, /* The parser to be deleted */ |
| 446 | void (*freeProc)(void*) /* Function used to reclaim memory */ |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 447 | ){ |
drh | 82415f2 | 2015-11-09 19:33:42 +0000 | [diff] [blame] | 448 | #ifndef YYPARSEFREENEVERNULL |
drh | d26cc54 | 2017-01-28 20:46:37 +0000 | [diff] [blame] | 449 | if( p==0 ) return; |
drh | 82415f2 | 2015-11-09 19:33:42 +0000 | [diff] [blame] | 450 | #endif |
drh | d26cc54 | 2017-01-28 20:46:37 +0000 | [diff] [blame] | 451 | ParseFinalize(p); |
| 452 | (*freeProc)(p); |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 453 | } |
drh | d26cc54 | 2017-01-28 20:46:37 +0000 | [diff] [blame] | 454 | #endif /* Parse_ENGINEALWAYSONSTACK */ |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 455 | |
| 456 | /* |
drh | ec424a5 | 2008-07-25 15:39:03 +0000 | [diff] [blame] | 457 | ** Return the peak depth of the stack for a parser. |
| 458 | */ |
| 459 | #ifdef YYTRACKMAXSTACKDEPTH |
| 460 | int ParseStackPeak(void *p){ |
| 461 | yyParser *pParser = (yyParser*)p; |
drh | 118ab65 | 2016-05-23 21:56:24 +0000 | [diff] [blame] | 462 | return pParser->yyhwm; |
drh | ec424a5 | 2008-07-25 15:39:03 +0000 | [diff] [blame] | 463 | } |
| 464 | #endif |
| 465 | |
drh | 0d9de99 | 2017-12-26 18:04:23 +0000 | [diff] [blame] | 466 | /* This array of booleans keeps track of the parser statement |
| 467 | ** coverage. The element yycoverage[X][Y] is set when the parser |
| 468 | ** is in state X and has a lookahead token Y. In a well-tested |
| 469 | ** systems, every element of this matrix should end up being set. |
| 470 | */ |
| 471 | #if defined(YYCOVERAGE) |
| 472 | static unsigned char yycoverage[YYNSTATE][YYNTOKEN]; |
| 473 | #endif |
| 474 | |
| 475 | /* |
| 476 | ** Write into out a description of every state/lookahead combination that |
drh | 7038a99 | 2017-12-27 17:14:50 +0000 | [diff] [blame] | 477 | ** |
| 478 | ** (1) has not been used by the parser, and |
| 479 | ** (2) is not a syntax error. |
| 480 | ** |
| 481 | ** Return the number of missed state/lookahead combinations. |
drh | 0d9de99 | 2017-12-26 18:04:23 +0000 | [diff] [blame] | 482 | */ |
| 483 | #if defined(YYCOVERAGE) |
| 484 | int ParseCoverage(FILE *out){ |
drh | 7038a99 | 2017-12-27 17:14:50 +0000 | [diff] [blame] | 485 | int stateno, iLookAhead, i; |
drh | 0d9de99 | 2017-12-26 18:04:23 +0000 | [diff] [blame] | 486 | int nMissed = 0; |
drh | 7038a99 | 2017-12-27 17:14:50 +0000 | [diff] [blame] | 487 | for(stateno=0; stateno<YYNSTATE; stateno++){ |
| 488 | i = yy_shift_ofst[stateno]; |
| 489 | for(iLookAhead=0; iLookAhead<YYNTOKEN; iLookAhead++){ |
drh | cf8e0e9 | 2017-12-27 17:36:58 +0000 | [diff] [blame] | 490 | if( yy_lookahead[i+iLookAhead]!=iLookAhead ) continue; |
drh | 7038a99 | 2017-12-27 17:14:50 +0000 | [diff] [blame] | 491 | if( yycoverage[stateno][iLookAhead]==0 ) nMissed++; |
drh | 22716cb | 2017-12-26 18:32:06 +0000 | [diff] [blame] | 492 | if( out ){ |
drh | 7038a99 | 2017-12-27 17:14:50 +0000 | [diff] [blame] | 493 | fprintf(out,"State %d lookahead %s %s\n", stateno, |
| 494 | yyTokenName[iLookAhead], |
| 495 | yycoverage[stateno][iLookAhead] ? "ok" : "missed"); |
drh | 22716cb | 2017-12-26 18:32:06 +0000 | [diff] [blame] | 496 | } |
drh | 0d9de99 | 2017-12-26 18:04:23 +0000 | [diff] [blame] | 497 | } |
| 498 | } |
| 499 | return nMissed; |
| 500 | } |
| 501 | #endif |
| 502 | |
drh | ec424a5 | 2008-07-25 15:39:03 +0000 | [diff] [blame] | 503 | /* |
drh | 8b58201 | 2003-10-21 13:16:03 +0000 | [diff] [blame] | 504 | ** Find the appropriate action for a parser given the terminal |
| 505 | ** look-ahead token iLookAhead. |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 506 | */ |
drh | fd39c58 | 2018-04-21 22:40:08 +0000 | [diff] [blame] | 507 | static YYACTIONTYPE yy_find_shift_action( |
| 508 | YYCODETYPE iLookAhead, /* The look-ahead token */ |
| 509 | YYACTIONTYPE stateno /* Current state number */ |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 510 | ){ |
drh | 8b58201 | 2003-10-21 13:16:03 +0000 | [diff] [blame] | 511 | int i; |
drh | fd39c58 | 2018-04-21 22:40:08 +0000 | [diff] [blame] | 512 | |
drh | ef53a9f | 2017-12-25 00:10:05 +0000 | [diff] [blame] | 513 | if( stateno>YY_MAX_SHIFT ) return stateno; |
drh | ae2a408 | 2015-09-07 20:02:39 +0000 | [diff] [blame] | 514 | assert( stateno <= YY_SHIFT_COUNT ); |
drh | 0d9de99 | 2017-12-26 18:04:23 +0000 | [diff] [blame] | 515 | #if defined(YYCOVERAGE) |
| 516 | yycoverage[stateno][iLookAhead] = 1; |
| 517 | #endif |
drh | a441404 | 2015-11-09 15:06:26 +0000 | [diff] [blame] | 518 | do{ |
| 519 | i = yy_shift_ofst[stateno]; |
drh | 54cfb49 | 2018-02-09 15:04:51 +0000 | [diff] [blame] | 520 | assert( i>=0 ); |
drh | 2e51716 | 2019-08-28 02:09:47 +0000 | [diff] [blame] | 521 | assert( i<=YY_ACTTAB_COUNT ); |
| 522 | assert( i+YYNTOKEN<=(int)YY_NLOOKAHEAD ); |
drh | a441404 | 2015-11-09 15:06:26 +0000 | [diff] [blame] | 523 | assert( iLookAhead!=YYNOCODE ); |
drh | 7038a99 | 2017-12-27 17:14:50 +0000 | [diff] [blame] | 524 | assert( iLookAhead < YYNTOKEN ); |
drh | a441404 | 2015-11-09 15:06:26 +0000 | [diff] [blame] | 525 | i += iLookAhead; |
drh | 2e51716 | 2019-08-28 02:09:47 +0000 | [diff] [blame] | 526 | assert( i<(int)YY_NLOOKAHEAD ); |
| 527 | if( yy_lookahead[i]!=iLookAhead ){ |
drh | 4767d97 | 2006-06-14 15:03:49 +0000 | [diff] [blame] | 528 | #ifdef YYFALLBACK |
drh | c83db9e | 2016-08-10 01:43:30 +0000 | [diff] [blame] | 529 | YYCODETYPE iFallback; /* Fallback token */ |
drh | 010bdb4 | 2019-08-28 11:31:11 +0000 | [diff] [blame] | 530 | assert( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0]) ); |
| 531 | iFallback = yyFallback[iLookAhead]; |
| 532 | if( iFallback!=0 ){ |
drh | 4767d97 | 2006-06-14 15:03:49 +0000 | [diff] [blame] | 533 | #ifndef NDEBUG |
drh | c83db9e | 2016-08-10 01:43:30 +0000 | [diff] [blame] | 534 | if( yyTraceFILE ){ |
| 535 | fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n", |
| 536 | yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]); |
drh | e09daa9 | 2006-06-10 13:29:31 +0000 | [diff] [blame] | 537 | } |
drh | a441404 | 2015-11-09 15:06:26 +0000 | [diff] [blame] | 538 | #endif |
drh | c83db9e | 2016-08-10 01:43:30 +0000 | [diff] [blame] | 539 | assert( yyFallback[iFallback]==0 ); /* Fallback loop must terminate */ |
| 540 | iLookAhead = iFallback; |
| 541 | continue; |
| 542 | } |
| 543 | #endif |
drh | a441404 | 2015-11-09 15:06:26 +0000 | [diff] [blame] | 544 | #ifdef YYWILDCARD |
drh | c83db9e | 2016-08-10 01:43:30 +0000 | [diff] [blame] | 545 | { |
| 546 | int j = i - iLookAhead + YYWILDCARD; |
drh | 010bdb4 | 2019-08-28 11:31:11 +0000 | [diff] [blame] | 547 | assert( j<(int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0])) ); |
| 548 | if( yy_lookahead[j]==YYWILDCARD && iLookAhead>0 ){ |
drh | a441404 | 2015-11-09 15:06:26 +0000 | [diff] [blame] | 549 | #ifndef NDEBUG |
drh | c83db9e | 2016-08-10 01:43:30 +0000 | [diff] [blame] | 550 | if( yyTraceFILE ){ |
| 551 | fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n", |
| 552 | yyTracePrompt, yyTokenName[iLookAhead], |
| 553 | yyTokenName[YYWILDCARD]); |
drh | a441404 | 2015-11-09 15:06:26 +0000 | [diff] [blame] | 554 | } |
drh | c83db9e | 2016-08-10 01:43:30 +0000 | [diff] [blame] | 555 | #endif /* NDEBUG */ |
| 556 | return yy_action[j]; |
drh | a441404 | 2015-11-09 15:06:26 +0000 | [diff] [blame] | 557 | } |
drh | a441404 | 2015-11-09 15:06:26 +0000 | [diff] [blame] | 558 | } |
drh | c83db9e | 2016-08-10 01:43:30 +0000 | [diff] [blame] | 559 | #endif /* YYWILDCARD */ |
drh | a441404 | 2015-11-09 15:06:26 +0000 | [diff] [blame] | 560 | return yy_default[stateno]; |
| 561 | }else{ |
drh | 18ef40e | 2020-09-16 16:55:56 +0000 | [diff] [blame] | 562 | assert( i>=0 && i<(int)(sizeof(yy_action)/sizeof(yy_action[0])) ); |
drh | a441404 | 2015-11-09 15:06:26 +0000 | [diff] [blame] | 563 | return yy_action[i]; |
drh | 0bd1f4e | 2002-06-06 18:54:39 +0000 | [diff] [blame] | 564 | } |
drh | a441404 | 2015-11-09 15:06:26 +0000 | [diff] [blame] | 565 | }while(1); |
drh | 8b58201 | 2003-10-21 13:16:03 +0000 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | /* |
| 569 | ** Find the appropriate action for a parser given the non-terminal |
| 570 | ** look-ahead token iLookAhead. |
drh | 8b58201 | 2003-10-21 13:16:03 +0000 | [diff] [blame] | 571 | */ |
mistachkin | 709c822 | 2018-07-22 21:23:19 +0000 | [diff] [blame] | 572 | static YYACTIONTYPE yy_find_reduce_action( |
drh | fd39c58 | 2018-04-21 22:40:08 +0000 | [diff] [blame] | 573 | YYACTIONTYPE stateno, /* Current state number */ |
drh | d9f291e | 2006-06-13 11:15:47 +0000 | [diff] [blame] | 574 | YYCODETYPE iLookAhead /* The look-ahead token */ |
drh | 8b58201 | 2003-10-21 13:16:03 +0000 | [diff] [blame] | 575 | ){ |
| 576 | int i; |
drh | 7f7c257 | 2008-04-27 18:45:10 +0000 | [diff] [blame] | 577 | #ifdef YYERRORSYMBOL |
drh | f16371d | 2009-11-03 19:18:31 +0000 | [diff] [blame] | 578 | if( stateno>YY_REDUCE_COUNT ){ |
drh | 7f7c257 | 2008-04-27 18:45:10 +0000 | [diff] [blame] | 579 | return yy_default[stateno]; |
| 580 | } |
| 581 | #else |
drh | f16371d | 2009-11-03 19:18:31 +0000 | [diff] [blame] | 582 | assert( stateno<=YY_REDUCE_COUNT ); |
drh | 7f7c257 | 2008-04-27 18:45:10 +0000 | [diff] [blame] | 583 | #endif |
drh | 01495b9 | 2008-01-23 12:52:40 +0000 | [diff] [blame] | 584 | i = yy_reduce_ofst[stateno]; |
drh | 01495b9 | 2008-01-23 12:52:40 +0000 | [diff] [blame] | 585 | assert( iLookAhead!=YYNOCODE ); |
drh | 8b58201 | 2003-10-21 13:16:03 +0000 | [diff] [blame] | 586 | i += iLookAhead; |
drh | 7f7c257 | 2008-04-27 18:45:10 +0000 | [diff] [blame] | 587 | #ifdef YYERRORSYMBOL |
drh | f16371d | 2009-11-03 19:18:31 +0000 | [diff] [blame] | 588 | if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){ |
drh | 7f7c257 | 2008-04-27 18:45:10 +0000 | [diff] [blame] | 589 | return yy_default[stateno]; |
| 590 | } |
| 591 | #else |
drh | f16371d | 2009-11-03 19:18:31 +0000 | [diff] [blame] | 592 | assert( i>=0 && i<YY_ACTTAB_COUNT ); |
drh | 01495b9 | 2008-01-23 12:52:40 +0000 | [diff] [blame] | 593 | assert( yy_lookahead[i]==iLookAhead ); |
drh | 7f7c257 | 2008-04-27 18:45:10 +0000 | [diff] [blame] | 594 | #endif |
drh | 01495b9 | 2008-01-23 12:52:40 +0000 | [diff] [blame] | 595 | return yy_action[i]; |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | /* |
drh | b19fd01 | 2007-03-29 01:44:45 +0000 | [diff] [blame] | 599 | ** The following routine is called if the stack overflows. |
| 600 | */ |
drh | 45f31be | 2016-02-16 21:19:49 +0000 | [diff] [blame] | 601 | static void yyStackOverflow(yyParser *yypParser){ |
drh | fb32c44 | 2018-04-21 13:51:42 +0000 | [diff] [blame] | 602 | ParseARG_FETCH |
| 603 | ParseCTX_FETCH |
drh | b19fd01 | 2007-03-29 01:44:45 +0000 | [diff] [blame] | 604 | #ifndef NDEBUG |
| 605 | if( yyTraceFILE ){ |
| 606 | fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt); |
| 607 | } |
| 608 | #endif |
drh | abecc0b | 2016-05-24 00:40:54 +0000 | [diff] [blame] | 609 | while( yypParser->yytos>yypParser->yystack ) yy_pop_parser_stack(yypParser); |
drh | b19fd01 | 2007-03-29 01:44:45 +0000 | [diff] [blame] | 610 | /* Here code is inserted which will execute if the parser |
| 611 | ** stack every overflows */ |
drh | 82415f2 | 2015-11-09 19:33:42 +0000 | [diff] [blame] | 612 | /******** Begin %stack_overflow code ******************************************/ |
drh | b19fd01 | 2007-03-29 01:44:45 +0000 | [diff] [blame] | 613 | %% |
drh | 82415f2 | 2015-11-09 19:33:42 +0000 | [diff] [blame] | 614 | /******** End %stack_overflow code ********************************************/ |
drh | fb32c44 | 2018-04-21 13:51:42 +0000 | [diff] [blame] | 615 | ParseARG_STORE /* Suppress warning about unused %extra_argument var */ |
| 616 | ParseCTX_STORE |
drh | b19fd01 | 2007-03-29 01:44:45 +0000 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | /* |
drh | a248a72 | 2015-09-07 19:52:55 +0000 | [diff] [blame] | 620 | ** Print tracing information for a SHIFT action |
| 621 | */ |
| 622 | #ifndef NDEBUG |
drh | e58f74f | 2017-12-24 17:06:41 +0000 | [diff] [blame] | 623 | static void yyTraceShift(yyParser *yypParser, int yyNewState, const char *zTag){ |
drh | a248a72 | 2015-09-07 19:52:55 +0000 | [diff] [blame] | 624 | if( yyTraceFILE ){ |
drh | a248a72 | 2015-09-07 19:52:55 +0000 | [diff] [blame] | 625 | if( yyNewState<YYNSTATE ){ |
drh | e58f74f | 2017-12-24 17:06:41 +0000 | [diff] [blame] | 626 | fprintf(yyTraceFILE,"%s%s '%s', go to state %d\n", |
| 627 | yyTracePrompt, zTag, yyTokenName[yypParser->yytos->major], |
drh | 0c4105e | 2015-11-10 14:51:22 +0000 | [diff] [blame] | 628 | yyNewState); |
drh | a248a72 | 2015-09-07 19:52:55 +0000 | [diff] [blame] | 629 | }else{ |
drh | e58f74f | 2017-12-24 17:06:41 +0000 | [diff] [blame] | 630 | fprintf(yyTraceFILE,"%s%s '%s', pending reduce %d\n", |
| 631 | yyTracePrompt, zTag, yyTokenName[yypParser->yytos->major], |
| 632 | yyNewState - YY_MIN_REDUCE); |
drh | a248a72 | 2015-09-07 19:52:55 +0000 | [diff] [blame] | 633 | } |
| 634 | } |
| 635 | } |
| 636 | #else |
drh | e58f74f | 2017-12-24 17:06:41 +0000 | [diff] [blame] | 637 | # define yyTraceShift(X,Y,Z) |
drh | a248a72 | 2015-09-07 19:52:55 +0000 | [diff] [blame] | 638 | #endif |
| 639 | |
| 640 | /* |
drh | 82415f2 | 2015-11-09 19:33:42 +0000 | [diff] [blame] | 641 | ** Perform a shift action. |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 642 | */ |
drh | a248a72 | 2015-09-07 19:52:55 +0000 | [diff] [blame] | 643 | static void yy_shift( |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 644 | yyParser *yypParser, /* The parser to be shifted */ |
drh | fd39c58 | 2018-04-21 22:40:08 +0000 | [diff] [blame] | 645 | YYACTIONTYPE yyNewState, /* The new state to shift in */ |
| 646 | YYCODETYPE yyMajor, /* The major token to shift in */ |
drh | 45f31be | 2016-02-16 21:19:49 +0000 | [diff] [blame] | 647 | ParseTOKENTYPE yyMinor /* The minor token to shift in */ |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 648 | ){ |
drh | 3ddfdf7 | 2003-12-22 14:53:19 +0000 | [diff] [blame] | 649 | yyStackEntry *yytos; |
drh | 118ab65 | 2016-05-23 21:56:24 +0000 | [diff] [blame] | 650 | yypParser->yytos++; |
drh | ec424a5 | 2008-07-25 15:39:03 +0000 | [diff] [blame] | 651 | #ifdef YYTRACKMAXSTACKDEPTH |
drh | 118ab65 | 2016-05-23 21:56:24 +0000 | [diff] [blame] | 652 | if( (int)(yypParser->yytos - yypParser->yystack)>yypParser->yyhwm ){ |
| 653 | yypParser->yyhwm++; |
| 654 | assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack) ); |
drh | ec424a5 | 2008-07-25 15:39:03 +0000 | [diff] [blame] | 655 | } |
| 656 | #endif |
drh | b19fd01 | 2007-03-29 01:44:45 +0000 | [diff] [blame] | 657 | #if YYSTACKDEPTH>0 |
drh | 8b471e7 | 2017-06-28 15:01:35 +0000 | [diff] [blame] | 658 | if( yypParser->yytos>yypParser->yystackEnd ){ |
drh | 6341331 | 2016-12-06 17:59:05 +0000 | [diff] [blame] | 659 | yypParser->yytos--; |
drh | 45f31be | 2016-02-16 21:19:49 +0000 | [diff] [blame] | 660 | yyStackOverflow(yypParser); |
drh | a248a72 | 2015-09-07 19:52:55 +0000 | [diff] [blame] | 661 | return; |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 662 | } |
drh | b19fd01 | 2007-03-29 01:44:45 +0000 | [diff] [blame] | 663 | #else |
drh | 118ab65 | 2016-05-23 21:56:24 +0000 | [diff] [blame] | 664 | if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz] ){ |
drh | 8dc8247 | 2016-05-27 04:10:47 +0000 | [diff] [blame] | 665 | if( yyGrowStack(yypParser) ){ |
drh | 6341331 | 2016-12-06 17:59:05 +0000 | [diff] [blame] | 666 | yypParser->yytos--; |
drh | 45f31be | 2016-02-16 21:19:49 +0000 | [diff] [blame] | 667 | yyStackOverflow(yypParser); |
drh | a248a72 | 2015-09-07 19:52:55 +0000 | [diff] [blame] | 668 | return; |
drh | b19fd01 | 2007-03-29 01:44:45 +0000 | [diff] [blame] | 669 | } |
| 670 | } |
| 671 | #endif |
drh | 0efd37f | 2016-06-06 18:17:36 +0000 | [diff] [blame] | 672 | if( yyNewState > YY_MAX_SHIFT ){ |
| 673 | yyNewState += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE; |
| 674 | } |
drh | 118ab65 | 2016-05-23 21:56:24 +0000 | [diff] [blame] | 675 | yytos = yypParser->yytos; |
drh | fd39c58 | 2018-04-21 22:40:08 +0000 | [diff] [blame] | 676 | yytos->stateno = yyNewState; |
| 677 | yytos->major = yyMajor; |
drh | 45f31be | 2016-02-16 21:19:49 +0000 | [diff] [blame] | 678 | yytos->minor.yy0 = yyMinor; |
drh | e58f74f | 2017-12-24 17:06:41 +0000 | [diff] [blame] | 679 | yyTraceShift(yypParser, yyNewState, "Shift"); |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 680 | } |
| 681 | |
drh | cfc45b1 | 2018-12-03 23:57:27 +0000 | [diff] [blame] | 682 | /* For rule J, yyRuleInfoLhs[J] contains the symbol on the left-hand side |
| 683 | ** of that rule */ |
| 684 | static const YYCODETYPE yyRuleInfoLhs[] = { |
| 685 | %% |
| 686 | }; |
| 687 | |
| 688 | /* For rule J, yyRuleInfoNRhs[J] contains the negative of the number |
| 689 | ** of symbols on the right-hand side of that rule. */ |
| 690 | static const signed char yyRuleInfoNRhs[] = { |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 691 | %% |
| 692 | }; |
| 693 | |
drh | 1f245e4 | 2002-03-11 13:55:50 +0000 | [diff] [blame] | 694 | static void yy_accept(yyParser*); /* Forward Declaration */ |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 695 | |
| 696 | /* |
| 697 | ** Perform a reduce action and the shift that must immediately |
| 698 | ** follow the reduce. |
drh | 087316c | 2017-12-15 12:22:21 +0000 | [diff] [blame] | 699 | ** |
| 700 | ** The yyLookahead and yyLookaheadToken parameters provide reduce actions |
| 701 | ** access to the lookahead token (if any). The yyLookahead will be YYNOCODE |
| 702 | ** if the lookahead token has already been consumed. As this procedure is |
| 703 | ** only called from one place, optimizing compilers will in-line it, which |
| 704 | ** means that the extra parameters have no performance impact. |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 705 | */ |
drh | fd39c58 | 2018-04-21 22:40:08 +0000 | [diff] [blame] | 706 | static YYACTIONTYPE yy_reduce( |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 707 | yyParser *yypParser, /* The parser */ |
drh | 087316c | 2017-12-15 12:22:21 +0000 | [diff] [blame] | 708 | unsigned int yyruleno, /* Number of the rule by which to reduce */ |
| 709 | int yyLookahead, /* Lookahead token, or YYNOCODE if none */ |
| 710 | ParseTOKENTYPE yyLookaheadToken /* Value of the lookahead token */ |
drh | fb32c44 | 2018-04-21 13:51:42 +0000 | [diff] [blame] | 711 | ParseCTX_PDECL /* %extra_context */ |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 712 | ){ |
| 713 | int yygoto; /* The next state */ |
mistachkin | 709c822 | 2018-07-22 21:23:19 +0000 | [diff] [blame] | 714 | YYACTIONTYPE yyact; /* The next action */ |
drh | 1f245e4 | 2002-03-11 13:55:50 +0000 | [diff] [blame] | 715 | yyStackEntry *yymsp; /* The top of the parser's stack */ |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 716 | int yysize; /* Amount to pop the stack */ |
drh | fb32c44 | 2018-04-21 13:51:42 +0000 | [diff] [blame] | 717 | ParseARG_FETCH |
drh | b968518 | 2018-01-17 13:15:23 +0000 | [diff] [blame] | 718 | (void)yyLookahead; |
| 719 | (void)yyLookaheadToken; |
drh | 118ab65 | 2016-05-23 21:56:24 +0000 | [diff] [blame] | 720 | yymsp = yypParser->yytos; |
drh | cb6c565 | 2007-01-16 18:19:12 +0000 | [diff] [blame] | 721 | |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 722 | switch( yyruleno ){ |
| 723 | /* Beginning here are the reduction cases. A typical example |
| 724 | ** follows: |
| 725 | ** case 0: |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 726 | ** #line <lineno> <grammarfile> |
| 727 | ** { ... } // User supplied code |
| 728 | ** #line <lineno> <thisfile> |
| 729 | ** break; |
| 730 | */ |
drh | 82415f2 | 2015-11-09 19:33:42 +0000 | [diff] [blame] | 731 | /********** Begin reduce actions **********************************************/ |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 732 | %% |
drh | 82415f2 | 2015-11-09 19:33:42 +0000 | [diff] [blame] | 733 | /********** End reduce actions ************************************************/ |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 734 | }; |
drh | cfc45b1 | 2018-12-03 23:57:27 +0000 | [diff] [blame] | 735 | assert( yyruleno<sizeof(yyRuleInfoLhs)/sizeof(yyRuleInfoLhs[0]) ); |
| 736 | yygoto = yyRuleInfoLhs[yyruleno]; |
| 737 | yysize = yyRuleInfoNRhs[yyruleno]; |
drh | 6be9536 | 2017-06-28 13:47:56 +0000 | [diff] [blame] | 738 | yyact = yy_find_reduce_action(yymsp[yysize].stateno,(YYCODETYPE)yygoto); |
drh | bd8fcc1 | 2017-06-28 11:56:18 +0000 | [diff] [blame] | 739 | |
| 740 | /* There are no SHIFTREDUCE actions on nonterminals because the table |
| 741 | ** generator has simplified them to pure REDUCE actions. */ |
| 742 | assert( !(yyact>YY_MAX_SHIFT && yyact<=YY_MAX_SHIFTREDUCE) ); |
| 743 | |
| 744 | /* It is not possible for a REDUCE to be followed by an error */ |
| 745 | assert( yyact!=YY_ERROR_ACTION ); |
| 746 | |
drh | ef53a9f | 2017-12-25 00:10:05 +0000 | [diff] [blame] | 747 | yymsp += yysize+1; |
| 748 | yypParser->yytos = yymsp; |
| 749 | yymsp->stateno = (YYACTIONTYPE)yyact; |
| 750 | yymsp->major = (YYCODETYPE)yygoto; |
| 751 | yyTraceShift(yypParser, yyact, "... then shift"); |
drh | fd39c58 | 2018-04-21 22:40:08 +0000 | [diff] [blame] | 752 | return yyact; |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 753 | } |
| 754 | |
| 755 | /* |
| 756 | ** The following code executes when the parse fails |
| 757 | */ |
drh | d3ec02d | 2009-06-12 02:27:14 +0000 | [diff] [blame] | 758 | #ifndef YYNOERRORRECOVERY |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 759 | static void yy_parse_failed( |
| 760 | yyParser *yypParser /* The parser */ |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 761 | ){ |
drh | fb32c44 | 2018-04-21 13:51:42 +0000 | [diff] [blame] | 762 | ParseARG_FETCH |
| 763 | ParseCTX_FETCH |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 764 | #ifndef NDEBUG |
| 765 | if( yyTraceFILE ){ |
| 766 | fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt); |
| 767 | } |
| 768 | #endif |
drh | abecc0b | 2016-05-24 00:40:54 +0000 | [diff] [blame] | 769 | while( yypParser->yytos>yypParser->yystack ) yy_pop_parser_stack(yypParser); |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 770 | /* Here code is inserted which will be executed whenever the |
| 771 | ** parser fails */ |
drh | 82415f2 | 2015-11-09 19:33:42 +0000 | [diff] [blame] | 772 | /************ Begin %parse_failure code ***************************************/ |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 773 | %% |
drh | 82415f2 | 2015-11-09 19:33:42 +0000 | [diff] [blame] | 774 | /************ End %parse_failure code *****************************************/ |
drh | fb32c44 | 2018-04-21 13:51:42 +0000 | [diff] [blame] | 775 | ParseARG_STORE /* Suppress warning about unused %extra_argument variable */ |
| 776 | ParseCTX_STORE |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 777 | } |
drh | d3ec02d | 2009-06-12 02:27:14 +0000 | [diff] [blame] | 778 | #endif /* YYNOERRORRECOVERY */ |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 779 | |
| 780 | /* |
| 781 | ** The following code executes when a syntax error first occurs. |
| 782 | */ |
| 783 | static void yy_syntax_error( |
| 784 | yyParser *yypParser, /* The parser */ |
| 785 | int yymajor, /* The major type of the error token */ |
drh | 45f31be | 2016-02-16 21:19:49 +0000 | [diff] [blame] | 786 | ParseTOKENTYPE yyminor /* The minor type of the error token */ |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 787 | ){ |
drh | fb32c44 | 2018-04-21 13:51:42 +0000 | [diff] [blame] | 788 | ParseARG_FETCH |
| 789 | ParseCTX_FETCH |
drh | 45f31be | 2016-02-16 21:19:49 +0000 | [diff] [blame] | 790 | #define TOKEN yyminor |
drh | 82415f2 | 2015-11-09 19:33:42 +0000 | [diff] [blame] | 791 | /************ Begin %syntax_error code ****************************************/ |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 792 | %% |
drh | 82415f2 | 2015-11-09 19:33:42 +0000 | [diff] [blame] | 793 | /************ End %syntax_error code ******************************************/ |
drh | fb32c44 | 2018-04-21 13:51:42 +0000 | [diff] [blame] | 794 | ParseARG_STORE /* Suppress warning about unused %extra_argument variable */ |
| 795 | ParseCTX_STORE |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | /* |
| 799 | ** The following is executed when the parser accepts |
| 800 | */ |
| 801 | static void yy_accept( |
| 802 | yyParser *yypParser /* The parser */ |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 803 | ){ |
drh | fb32c44 | 2018-04-21 13:51:42 +0000 | [diff] [blame] | 804 | ParseARG_FETCH |
| 805 | ParseCTX_FETCH |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 806 | #ifndef NDEBUG |
| 807 | if( yyTraceFILE ){ |
| 808 | fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt); |
| 809 | } |
| 810 | #endif |
drh | dd703e2 | 2016-07-12 19:54:49 +0000 | [diff] [blame] | 811 | #ifndef YYNOERRORRECOVERY |
| 812 | yypParser->yyerrcnt = -1; |
| 813 | #endif |
drh | 756b41e | 2016-05-24 18:55:08 +0000 | [diff] [blame] | 814 | assert( yypParser->yytos==yypParser->yystack ); |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 815 | /* Here code is inserted which will be executed whenever the |
| 816 | ** parser accepts */ |
drh | 82415f2 | 2015-11-09 19:33:42 +0000 | [diff] [blame] | 817 | /*********** Begin %parse_accept code *****************************************/ |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 818 | %% |
drh | 82415f2 | 2015-11-09 19:33:42 +0000 | [diff] [blame] | 819 | /*********** End %parse_accept code *******************************************/ |
drh | fb32c44 | 2018-04-21 13:51:42 +0000 | [diff] [blame] | 820 | ParseARG_STORE /* Suppress warning about unused %extra_argument variable */ |
| 821 | ParseCTX_STORE |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 822 | } |
| 823 | |
| 824 | /* The main parser program. |
| 825 | ** The first argument is a pointer to a structure obtained from |
| 826 | ** "ParseAlloc" which describes the current state of the parser. |
| 827 | ** The second argument is the major token number. The third is |
| 828 | ** the minor token. The fourth optional argument is whatever the |
| 829 | ** user wants (and specified in the grammar) and is available for |
| 830 | ** use by the action routines. |
| 831 | ** |
| 832 | ** Inputs: |
| 833 | ** <ul> |
| 834 | ** <li> A pointer to the parser (an opaque structure.) |
| 835 | ** <li> The major token number. |
| 836 | ** <li> The minor token number. |
| 837 | ** <li> An option argument of a grammar-specified type. |
| 838 | ** </ul> |
| 839 | ** |
| 840 | ** Outputs: |
| 841 | ** None. |
| 842 | */ |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 843 | void Parse( |
| 844 | void *yyp, /* The parser */ |
| 845 | int yymajor, /* The major token code number */ |
| 846 | ParseTOKENTYPE yyminor /* The value for the token */ |
drh | 1f245e4 | 2002-03-11 13:55:50 +0000 | [diff] [blame] | 847 | ParseARG_PDECL /* Optional %extra_argument parameter */ |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 848 | ){ |
| 849 | YYMINORTYPE yyminorunion; |
drh | fd39c58 | 2018-04-21 22:40:08 +0000 | [diff] [blame] | 850 | YYACTIONTYPE yyact; /* The parser action. */ |
drh | a441404 | 2015-11-09 15:06:26 +0000 | [diff] [blame] | 851 | #if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY) |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 852 | int yyendofinput; /* True if we are at the end of input */ |
drh | a441404 | 2015-11-09 15:06:26 +0000 | [diff] [blame] | 853 | #endif |
drh | c4dd3fd | 2008-01-22 01:48:05 +0000 | [diff] [blame] | 854 | #ifdef YYERRORSYMBOL |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 855 | int yyerrorhit = 0; /* True if yymajor has invoked an error */ |
drh | c4dd3fd | 2008-01-22 01:48:05 +0000 | [diff] [blame] | 856 | #endif |
drh | fb32c44 | 2018-04-21 13:51:42 +0000 | [diff] [blame] | 857 | yyParser *yypParser = (yyParser*)yyp; /* The parser */ |
| 858 | ParseCTX_FETCH |
| 859 | ParseARG_STORE |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 860 | |
drh | abecc0b | 2016-05-24 00:40:54 +0000 | [diff] [blame] | 861 | assert( yypParser->yytos!=0 ); |
drh | a441404 | 2015-11-09 15:06:26 +0000 | [diff] [blame] | 862 | #if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY) |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 863 | yyendofinput = (yymajor==0); |
drh | a441404 | 2015-11-09 15:06:26 +0000 | [diff] [blame] | 864 | #endif |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 865 | |
drh | fd39c58 | 2018-04-21 22:40:08 +0000 | [diff] [blame] | 866 | yyact = yypParser->yytos->stateno; |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 867 | #ifndef NDEBUG |
| 868 | if( yyTraceFILE ){ |
drh | fd39c58 | 2018-04-21 22:40:08 +0000 | [diff] [blame] | 869 | if( yyact < YY_MIN_REDUCE ){ |
drh | e58f74f | 2017-12-24 17:06:41 +0000 | [diff] [blame] | 870 | fprintf(yyTraceFILE,"%sInput '%s' in state %d\n", |
drh | fd39c58 | 2018-04-21 22:40:08 +0000 | [diff] [blame] | 871 | yyTracePrompt,yyTokenName[yymajor],yyact); |
drh | e58f74f | 2017-12-24 17:06:41 +0000 | [diff] [blame] | 872 | }else{ |
| 873 | fprintf(yyTraceFILE,"%sInput '%s' with pending reduce %d\n", |
drh | fd39c58 | 2018-04-21 22:40:08 +0000 | [diff] [blame] | 874 | yyTracePrompt,yyTokenName[yymajor],yyact-YY_MIN_REDUCE); |
drh | e58f74f | 2017-12-24 17:06:41 +0000 | [diff] [blame] | 875 | } |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 876 | } |
| 877 | #endif |
| 878 | |
drh | e81f879 | 2021-01-02 23:56:37 +0000 | [diff] [blame] | 879 | while(1){ /* Exit by "break" */ |
| 880 | assert( yypParser->yytos>=yypParser->yystack ); |
drh | fd39c58 | 2018-04-21 22:40:08 +0000 | [diff] [blame] | 881 | assert( yyact==yypParser->yytos->stateno ); |
mistachkin | 709c822 | 2018-07-22 21:23:19 +0000 | [diff] [blame] | 882 | yyact = yy_find_shift_action((YYCODETYPE)yymajor,yyact); |
drh | 5c8241b | 2017-12-24 23:38:10 +0000 | [diff] [blame] | 883 | if( yyact >= YY_MIN_REDUCE ){ |
drh | e81f879 | 2021-01-02 23:56:37 +0000 | [diff] [blame] | 884 | unsigned int yyruleno = yyact - YY_MIN_REDUCE; /* Reduce by this rule */ |
| 885 | assert( yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ); |
| 886 | #ifndef NDEBUG |
| 887 | if( yyTraceFILE ){ |
| 888 | int yysize = yyRuleInfoNRhs[yyruleno]; |
| 889 | if( yysize ){ |
| 890 | fprintf(yyTraceFILE, "%sReduce %d [%s]%s, pop back to state %d.\n", |
| 891 | yyTracePrompt, |
| 892 | yyruleno, yyRuleName[yyruleno], |
| 893 | yyruleno<YYNRULE_WITH_ACTION ? "" : " without external action", |
| 894 | yypParser->yytos[yysize].stateno); |
| 895 | }else{ |
| 896 | fprintf(yyTraceFILE, "%sReduce %d [%s]%s.\n", |
| 897 | yyTracePrompt, yyruleno, yyRuleName[yyruleno], |
| 898 | yyruleno<YYNRULE_WITH_ACTION ? "" : " without external action"); |
| 899 | } |
| 900 | } |
| 901 | #endif /* NDEBUG */ |
| 902 | |
| 903 | /* Check that the stack is large enough to grow by a single entry |
| 904 | ** if the RHS of the rule is empty. This ensures that there is room |
| 905 | ** enough on the stack to push the LHS value */ |
| 906 | if( yyRuleInfoNRhs[yyruleno]==0 ){ |
| 907 | #ifdef YYTRACKMAXSTACKDEPTH |
| 908 | if( (int)(yypParser->yytos - yypParser->yystack)>yypParser->yyhwm ){ |
| 909 | yypParser->yyhwm++; |
| 910 | assert( yypParser->yyhwm == |
| 911 | (int)(yypParser->yytos - yypParser->yystack)); |
| 912 | } |
| 913 | #endif |
| 914 | #if YYSTACKDEPTH>0 |
| 915 | if( yypParser->yytos>=yypParser->yystackEnd ){ |
| 916 | yyStackOverflow(yypParser); |
| 917 | break; |
| 918 | } |
| 919 | #else |
| 920 | if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz-1] ){ |
| 921 | if( yyGrowStack(yypParser) ){ |
| 922 | yyStackOverflow(yypParser); |
| 923 | break; |
| 924 | } |
| 925 | } |
| 926 | #endif |
| 927 | } |
| 928 | yyact = yy_reduce(yypParser,yyruleno,yymajor,yyminor ParseCTX_PARAM); |
drh | 5c8241b | 2017-12-24 23:38:10 +0000 | [diff] [blame] | 929 | }else if( yyact <= YY_MAX_SHIFTREDUCE ){ |
mistachkin | 709c822 | 2018-07-22 21:23:19 +0000 | [diff] [blame] | 930 | yy_shift(yypParser,yyact,(YYCODETYPE)yymajor,yyminor); |
drh | dab943c | 2016-02-16 01:01:43 +0000 | [diff] [blame] | 931 | #ifndef YYNOERRORRECOVERY |
drh | a248a72 | 2015-09-07 19:52:55 +0000 | [diff] [blame] | 932 | yypParser->yyerrcnt--; |
drh | dab943c | 2016-02-16 01:01:43 +0000 | [diff] [blame] | 933 | #endif |
drh | fd39c58 | 2018-04-21 22:40:08 +0000 | [diff] [blame] | 934 | break; |
drh | ef53a9f | 2017-12-25 00:10:05 +0000 | [diff] [blame] | 935 | }else if( yyact==YY_ACCEPT_ACTION ){ |
drh | 05ef50d | 2018-04-23 00:25:31 +0000 | [diff] [blame] | 936 | yypParser->yytos--; |
| 937 | yy_accept(yypParser); |
drh | ef53a9f | 2017-12-25 00:10:05 +0000 | [diff] [blame] | 938 | return; |
drh | c4dd3fd | 2008-01-22 01:48:05 +0000 | [diff] [blame] | 939 | }else{ |
| 940 | assert( yyact == YY_ERROR_ACTION ); |
drh | 45f31be | 2016-02-16 21:19:49 +0000 | [diff] [blame] | 941 | yyminorunion.yy0 = yyminor; |
drh | c4dd3fd | 2008-01-22 01:48:05 +0000 | [diff] [blame] | 942 | #ifdef YYERRORSYMBOL |
drh | 3ddfdf7 | 2003-12-22 14:53:19 +0000 | [diff] [blame] | 943 | int yymx; |
drh | c4dd3fd | 2008-01-22 01:48:05 +0000 | [diff] [blame] | 944 | #endif |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 945 | #ifndef NDEBUG |
| 946 | if( yyTraceFILE ){ |
| 947 | fprintf(yyTraceFILE,"%sSyntax Error!\n",yyTracePrompt); |
| 948 | } |
| 949 | #endif |
| 950 | #ifdef YYERRORSYMBOL |
| 951 | /* A syntax error has occurred. |
| 952 | ** The response to an error depends upon whether or not the |
| 953 | ** grammar defines an error token "ERROR". |
| 954 | ** |
| 955 | ** This is what we do if the grammar does define ERROR: |
| 956 | ** |
| 957 | ** * Call the %syntax_error function. |
| 958 | ** |
| 959 | ** * Begin popping the stack until we enter a state where |
| 960 | ** it is legal to shift the error symbol, then shift |
| 961 | ** the error symbol. |
| 962 | ** |
| 963 | ** * Set the error count to three. |
| 964 | ** |
| 965 | ** * Begin accepting and shifting new tokens. No new error |
| 966 | ** processing will occur until three tokens have been |
| 967 | ** shifted successfully. |
| 968 | ** |
| 969 | */ |
drh | 1f245e4 | 2002-03-11 13:55:50 +0000 | [diff] [blame] | 970 | if( yypParser->yyerrcnt<0 ){ |
drh | 45f31be | 2016-02-16 21:19:49 +0000 | [diff] [blame] | 971 | yy_syntax_error(yypParser,yymajor,yyminor); |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 972 | } |
drh | 118ab65 | 2016-05-23 21:56:24 +0000 | [diff] [blame] | 973 | yymx = yypParser->yytos->major; |
drh | 3ddfdf7 | 2003-12-22 14:53:19 +0000 | [diff] [blame] | 974 | if( yymx==YYERRORSYMBOL || yyerrorhit ){ |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 975 | #ifndef NDEBUG |
| 976 | if( yyTraceFILE ){ |
| 977 | fprintf(yyTraceFILE,"%sDiscard input token %s\n", |
| 978 | yyTracePrompt,yyTokenName[yymajor]); |
| 979 | } |
| 980 | #endif |
drh | 45f31be | 2016-02-16 21:19:49 +0000 | [diff] [blame] | 981 | yy_destructor(yypParser, (YYCODETYPE)yymajor, &yyminorunion); |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 982 | yymajor = YYNOCODE; |
| 983 | }else{ |
drh | 4eda15e | 2016-10-04 12:20:12 +0000 | [diff] [blame] | 984 | while( yypParser->yytos >= yypParser->yystack |
drh | 118ab65 | 2016-05-23 21:56:24 +0000 | [diff] [blame] | 985 | && (yyact = yy_find_reduce_action( |
| 986 | yypParser->yytos->stateno, |
drh | b8a7628 | 2018-11-27 14:03:11 +0000 | [diff] [blame] | 987 | YYERRORSYMBOL)) > YY_MAX_SHIFTREDUCE |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 988 | ){ |
| 989 | yy_pop_parser_stack(yypParser); |
| 990 | } |
drh | 118ab65 | 2016-05-23 21:56:24 +0000 | [diff] [blame] | 991 | if( yypParser->yytos < yypParser->yystack || yymajor==0 ){ |
drh | b27b7f5 | 2008-12-10 18:03:45 +0000 | [diff] [blame] | 992 | yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion); |
drh | 1f245e4 | 2002-03-11 13:55:50 +0000 | [diff] [blame] | 993 | yy_parse_failed(yypParser); |
drh | 240c7fa | 2016-07-05 12:47:28 +0000 | [diff] [blame] | 994 | #ifndef YYNOERRORRECOVERY |
| 995 | yypParser->yyerrcnt = -1; |
| 996 | #endif |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 997 | yymajor = YYNOCODE; |
drh | 3ddfdf7 | 2003-12-22 14:53:19 +0000 | [diff] [blame] | 998 | }else if( yymx!=YYERRORSYMBOL ){ |
drh | 45f31be | 2016-02-16 21:19:49 +0000 | [diff] [blame] | 999 | yy_shift(yypParser,yyact,YYERRORSYMBOL,yyminor); |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 1000 | } |
| 1001 | } |
drh | 1f245e4 | 2002-03-11 13:55:50 +0000 | [diff] [blame] | 1002 | yypParser->yyerrcnt = 3; |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 1003 | yyerrorhit = 1; |
drh | fd39c58 | 2018-04-21 22:40:08 +0000 | [diff] [blame] | 1004 | if( yymajor==YYNOCODE ) break; |
| 1005 | yyact = yypParser->yytos->stateno; |
drh | d3ec02d | 2009-06-12 02:27:14 +0000 | [diff] [blame] | 1006 | #elif defined(YYNOERRORRECOVERY) |
| 1007 | /* If the YYNOERRORRECOVERY macro is defined, then do not attempt to |
| 1008 | ** do any kind of error recovery. Instead, simply invoke the syntax |
| 1009 | ** error routine and continue going as if nothing had happened. |
| 1010 | ** |
| 1011 | ** Applications can set this macro (for example inside %include) if |
| 1012 | ** they intend to abandon the parse upon the first syntax error seen. |
| 1013 | */ |
drh | 45f31be | 2016-02-16 21:19:49 +0000 | [diff] [blame] | 1014 | yy_syntax_error(yypParser,yymajor, yyminor); |
drh | d3ec02d | 2009-06-12 02:27:14 +0000 | [diff] [blame] | 1015 | yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion); |
drh | fd39c58 | 2018-04-21 22:40:08 +0000 | [diff] [blame] | 1016 | break; |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 1017 | #else /* YYERRORSYMBOL is not defined */ |
| 1018 | /* This is what we do if the grammar does not define ERROR: |
| 1019 | ** |
| 1020 | ** * Report an error message, and throw away the input token. |
| 1021 | ** |
| 1022 | ** * If the input token is $, then fail the parse. |
| 1023 | ** |
| 1024 | ** As before, subsequent error messages are suppressed until |
| 1025 | ** three input tokens have been successfully shifted. |
| 1026 | */ |
drh | 1f245e4 | 2002-03-11 13:55:50 +0000 | [diff] [blame] | 1027 | if( yypParser->yyerrcnt<=0 ){ |
drh | 45f31be | 2016-02-16 21:19:49 +0000 | [diff] [blame] | 1028 | yy_syntax_error(yypParser,yymajor, yyminor); |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 1029 | } |
drh | 1f245e4 | 2002-03-11 13:55:50 +0000 | [diff] [blame] | 1030 | yypParser->yyerrcnt = 3; |
drh | b27b7f5 | 2008-12-10 18:03:45 +0000 | [diff] [blame] | 1031 | yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion); |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 1032 | if( yyendofinput ){ |
drh | 1f245e4 | 2002-03-11 13:55:50 +0000 | [diff] [blame] | 1033 | yy_parse_failed(yypParser); |
drh | d3d4b3c | 2016-07-08 19:54:38 +0000 | [diff] [blame] | 1034 | #ifndef YYNOERRORRECOVERY |
| 1035 | yypParser->yyerrcnt = -1; |
| 1036 | #endif |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 1037 | } |
drh | fd39c58 | 2018-04-21 22:40:08 +0000 | [diff] [blame] | 1038 | break; |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 1039 | #endif |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 1040 | } |
drh | e81f879 | 2021-01-02 23:56:37 +0000 | [diff] [blame] | 1041 | } |
drh | 3bd48ab | 2015-09-07 18:23:37 +0000 | [diff] [blame] | 1042 | #ifndef NDEBUG |
| 1043 | if( yyTraceFILE ){ |
drh | 118ab65 | 2016-05-23 21:56:24 +0000 | [diff] [blame] | 1044 | yyStackEntry *i; |
| 1045 | char cDiv = '['; |
drh | 0c4105e | 2015-11-10 14:51:22 +0000 | [diff] [blame] | 1046 | fprintf(yyTraceFILE,"%sReturn. Stack=",yyTracePrompt); |
drh | 118ab65 | 2016-05-23 21:56:24 +0000 | [diff] [blame] | 1047 | for(i=&yypParser->yystack[1]; i<=yypParser->yytos; i++){ |
| 1048 | fprintf(yyTraceFILE,"%c%s", cDiv, yyTokenName[i->major]); |
| 1049 | cDiv = ' '; |
| 1050 | } |
drh | 0c4105e | 2015-11-10 14:51:22 +0000 | [diff] [blame] | 1051 | fprintf(yyTraceFILE,"]\n"); |
drh | 3bd48ab | 2015-09-07 18:23:37 +0000 | [diff] [blame] | 1052 | } |
| 1053 | #endif |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 1054 | return; |
| 1055 | } |
dan | 59ff425 | 2018-06-29 17:44:52 +0000 | [diff] [blame] | 1056 | |
| 1057 | /* |
| 1058 | ** Return the fallback token corresponding to canonical token iToken, or |
| 1059 | ** 0 if iToken has no fallback. |
| 1060 | */ |
| 1061 | int ParseFallback(int iToken){ |
| 1062 | #ifdef YYFALLBACK |
drh | 6ee3fa8 | 2019-08-28 11:49:45 +0000 | [diff] [blame] | 1063 | assert( iToken<(int)(sizeof(yyFallback)/sizeof(yyFallback[0])) ); |
| 1064 | return yyFallback[iToken]; |
drh | c7bf571 | 2018-07-09 22:49:01 +0000 | [diff] [blame] | 1065 | #else |
| 1066 | (void)iToken; |
dan | 59ff425 | 2018-06-29 17:44:52 +0000 | [diff] [blame] | 1067 | return 0; |
drh | 276d7f7 | 2019-10-21 16:15:57 +0000 | [diff] [blame] | 1068 | #endif |
dan | 59ff425 | 2018-06-29 17:44:52 +0000 | [diff] [blame] | 1069 | } |