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