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