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