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