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