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