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