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