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