blob: 0ede04a2252ad9751a55b20f17d7390720ba4799 [file] [log] [blame]
drh75897232000-05-29 14:26:00 +00001/* Driver template for the LEMON parser generator.
drhb19a2bc2001-09-16 00:13:26 +00002** The author disclaims copyright to this source code.
drh75897232000-05-29 14:26:00 +00003*/
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.
drh0bd1f4e2002-06-06 18:54:39 +000034** 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.
drh75897232000-05-29 14:26:00 +000037** 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".
47** YYSTACKDEPTH is the maximum depth of the parser's stack.
drh1f245e42002-03-11 13:55:50 +000048** ParseARG_SDECL A static variable declaration for the %extra_argument
49** ParseARG_PDECL A parameter declaration for the %extra_argument
50** ParseARG_STORE Code to store %extra_argument into yypParser
51** ParseARG_FETCH Code to extract %extra_argument from yypParser
drh75897232000-05-29 14:26:00 +000052** YYNSTATE the combined number of states.
53** YYNRULE the number of rules in the grammar
54** YYERRORSYMBOL is the code number of the error symbol. If not
55** defined, then do no error processing.
56*/
57%%
58#define YY_NO_ACTION (YYNSTATE+YYNRULE+2)
59#define YY_ACCEPT_ACTION (YYNSTATE+YYNRULE+1)
60#define YY_ERROR_ACTION (YYNSTATE+YYNRULE)
drh75897232000-05-29 14:26:00 +000061
drhfdbf9282003-10-21 16:34:41 +000062/* Next are that tables used to determine what action to take based on the
drh8b582012003-10-21 13:16:03 +000063** current state and lookahead token. These tables are used to implement
64** functions that take a state number and lookahead value and return an
65** action integer.
drh75897232000-05-29 14:26:00 +000066**
drh8548a052003-10-22 22:15:27 +000067** Suppose the action integer is N. Then the action is determined as
68** follows
drh75897232000-05-29 14:26:00 +000069**
drh8548a052003-10-22 22:15:27 +000070** 0 <= N < YYNSTATE Shift N. That is, push the lookahead
71** token onto the stack and goto state N.
72**
73** YYNSTATE <= N < YYNSTATE+YYNRULE Reduce by rule N-YYNSTATE.
74**
75** N == YYNSTATE+YYNRULE A syntax error has occurred.
76**
77** N == YYNSTATE+YYNRULE+1 The parser accepts its input.
78**
79** N == YYNSTATE+YYNRULE+2 No such action. Denotes unused
80** slots in the yy_action[] table.
81**
82** The action table is constructed as a single large table named yy_action[].
83** Given state S and lookahead X, the action is computed as
drh75897232000-05-29 14:26:00 +000084**
drh8b582012003-10-21 13:16:03 +000085** yy_action[ yy_shift_ofst[S] + X ]
86**
drh8548a052003-10-22 22:15:27 +000087** If the index value yy_shift_ofst[S]+X is out of range or if the value
drh8b582012003-10-21 13:16:03 +000088** yy_lookahead[yy_shift_ofst[S]+X] is not equal to X or if yy_shift_ofst[S]
89** is equal to YY_SHIFT_USE_DFLT, it means that the action is not in the table
90** and that yy_default[S] should be used instead.
91**
92** The formula above is for computing the action when the lookahead is
93** a terminal symbol. If the lookahead is a non-terminal (as occurs after
94** a reduce action) then the yy_reduce_ofst[] array is used in place of
95** the yy_shift_ofst[] array and YY_REDUCE_USE_DFLT is used in place of
96** YY_SHIFT_USE_DFLT.
97**
98** The following are the tables generated in this section:
99**
100** yy_action[] A single table containing all actions.
101** yy_lookahead[] A table containing the lookahead for each entry in
102** yy_action. Used to detect hash collisions.
103** yy_shift_ofst[] For each state, the offset into yy_action for
104** shifting terminals.
105** yy_reduce_ofst[] For each state, the offset into yy_action for
106** shifting non-terminals after a reduce.
107** yy_default[] Default action for each state.
drh75897232000-05-29 14:26:00 +0000108*/
drh75897232000-05-29 14:26:00 +0000109%%
drhd9f291e2006-06-13 11:15:47 +0000110#define YY_SZ_ACTTAB (int)(sizeof(yy_action)/sizeof(yy_action[0]))
drh75897232000-05-29 14:26:00 +0000111
drh0bd1f4e2002-06-06 18:54:39 +0000112/* The next table maps tokens into fallback tokens. If a construct
113** like the following:
114**
115** %fallback ID X Y Z.
116**
117** appears in the grammer, then ID becomes a fallback token for X, Y,
118** and Z. Whenever one of the tokens X, Y, or Z is input to the parser
119** but it does not parse, the type of the token is changed to ID and
120** the parse is retried before an error is thrown.
121*/
122#ifdef YYFALLBACK
123static const YYCODETYPE yyFallback[] = {
124%%
125};
126#endif /* YYFALLBACK */
127
drh75897232000-05-29 14:26:00 +0000128/* The following structure represents a single element of the
129** parser's stack. Information stored includes:
130**
131** + The state number for the parser at this level of the stack.
132**
133** + The value of the token stored at this level of the stack.
134** (In other words, the "major" token.)
135**
136** + The semantic value stored at this level of the stack. This is
137** the information used by the action routines in the grammar.
138** It is sometimes called the "minor" token.
139*/
140struct yyStackEntry {
141 int stateno; /* The state-number */
142 int major; /* The major token value. This is the code
143 ** number for the token at this stack level */
144 YYMINORTYPE minor; /* The user-supplied minor token value. This
145 ** is the value of the token */
146};
drh1f245e42002-03-11 13:55:50 +0000147typedef struct yyStackEntry yyStackEntry;
drh75897232000-05-29 14:26:00 +0000148
149/* The state of the parser is completely contained in an instance of
150** the following structure */
151struct yyParser {
drh1f245e42002-03-11 13:55:50 +0000152 int yyidx; /* Index of top element in stack */
153 int yyerrcnt; /* Shifts left before out of the error */
drh1f245e42002-03-11 13:55:50 +0000154 ParseARG_SDECL /* A place to hold %extra_argument */
155 yyStackEntry yystack[YYSTACKDEPTH]; /* The parser's stack */
drh75897232000-05-29 14:26:00 +0000156};
157typedef struct yyParser yyParser;
158
159#ifndef NDEBUG
160#include <stdio.h>
161static FILE *yyTraceFILE = 0;
162static char *yyTracePrompt = 0;
drh0bd1f4e2002-06-06 18:54:39 +0000163#endif /* NDEBUG */
drh75897232000-05-29 14:26:00 +0000164
drh0bd1f4e2002-06-06 18:54:39 +0000165#ifndef NDEBUG
drh75897232000-05-29 14:26:00 +0000166/*
167** Turn parser tracing on by giving a stream to which to write the trace
168** and a prompt to preface each trace message. Tracing is turned off
169** by making either argument NULL
170**
171** Inputs:
172** <ul>
173** <li> A FILE* to which trace output should be written.
174** If NULL, then tracing is turned off.
175** <li> A prefix string written at the beginning of every
176** line of trace output. If NULL, then tracing is
177** turned off.
178** </ul>
179**
180** Outputs:
181** None.
182*/
drh75897232000-05-29 14:26:00 +0000183void ParseTrace(FILE *TraceFILE, char *zTracePrompt){
184 yyTraceFILE = TraceFILE;
185 yyTracePrompt = zTracePrompt;
186 if( yyTraceFILE==0 ) yyTracePrompt = 0;
187 else if( yyTracePrompt==0 ) yyTraceFILE = 0;
188}
drh0bd1f4e2002-06-06 18:54:39 +0000189#endif /* NDEBUG */
drh75897232000-05-29 14:26:00 +0000190
drh0bd1f4e2002-06-06 18:54:39 +0000191#ifndef NDEBUG
drh75897232000-05-29 14:26:00 +0000192/* For tracing shifts, the names of all terminals and nonterminals
193** are required. The following table supplies these names */
drh57196282004-10-06 15:41:16 +0000194static const char *const yyTokenName[] = {
drh75897232000-05-29 14:26:00 +0000195%%
196};
drh0bd1f4e2002-06-06 18:54:39 +0000197#endif /* NDEBUG */
drh75897232000-05-29 14:26:00 +0000198
drh0bd1f4e2002-06-06 18:54:39 +0000199#ifndef NDEBUG
200/* For tracing reduce actions, the names of all rules are required.
201*/
drh57196282004-10-06 15:41:16 +0000202static const char *const yyRuleName[] = {
drh0bd1f4e2002-06-06 18:54:39 +0000203%%
204};
205#endif /* NDEBUG */
drha1b351a2001-09-14 16:42:12 +0000206
drh960e8c62001-04-03 16:53:21 +0000207/*
208** This function returns the symbolic name associated with a token
209** value.
210*/
211const char *ParseTokenName(int tokenType){
drha1b351a2001-09-14 16:42:12 +0000212#ifndef NDEBUG
drh960e8c62001-04-03 16:53:21 +0000213 if( tokenType>0 && tokenType<(sizeof(yyTokenName)/sizeof(yyTokenName[0])) ){
214 return yyTokenName[tokenType];
215 }else{
216 return "Unknown";
217 }
drha1b351a2001-09-14 16:42:12 +0000218#else
219 return "";
220#endif
drh960e8c62001-04-03 16:53:21 +0000221}
222
drh75897232000-05-29 14:26:00 +0000223/*
224** This function allocates a new parser.
225** The only argument is a pointer to a function which works like
226** malloc.
227**
228** Inputs:
229** A pointer to the function used to allocate memory.
230**
231** Outputs:
232** A pointer to a parser. This pointer is used in subsequent calls
233** to Parse and ParseFree.
234*/
drh7218ac72002-03-10 21:21:00 +0000235void *ParseAlloc(void *(*mallocProc)(size_t)){
drh75897232000-05-29 14:26:00 +0000236 yyParser *pParser;
drh7218ac72002-03-10 21:21:00 +0000237 pParser = (yyParser*)(*mallocProc)( (size_t)sizeof(yyParser) );
drh75897232000-05-29 14:26:00 +0000238 if( pParser ){
drh1f245e42002-03-11 13:55:50 +0000239 pParser->yyidx = -1;
drh75897232000-05-29 14:26:00 +0000240 }
241 return pParser;
242}
243
244/* The following function deletes the value associated with a
245** symbol. The symbol can be either a terminal or nonterminal.
246** "yymajor" is the symbol code, and "yypminor" is a pointer to
247** the value.
248*/
249static void yy_destructor(YYCODETYPE yymajor, YYMINORTYPE *yypminor){
250 switch( yymajor ){
251 /* Here is inserted the actions which take place when a
252 ** terminal or non-terminal is destroyed. This can happen
253 ** when the symbol is popped from the stack during a
254 ** reduce or during error processing or when a parser is
255 ** being destroyed before it is finished parsing.
256 **
257 ** Note: during a reduce, the only symbols destroyed are those
258 ** which appear on the RHS of the rule, but which are not used
259 ** inside the C code.
260 */
261%%
262 default: break; /* If no destructor action specified: do nothing */
263 }
264}
265
266/*
267** Pop the parser's stack once.
268**
269** If there is a destructor routine associated with the token which
270** is popped from the stack, then call it.
271**
272** Return the major token number for the symbol popped.
273*/
274static int yy_pop_parser_stack(yyParser *pParser){
275 YYCODETYPE yymajor;
drh3ddfdf72003-12-22 14:53:19 +0000276 yyStackEntry *yytos = &pParser->yystack[pParser->yyidx];
drh75897232000-05-29 14:26:00 +0000277
drh1f245e42002-03-11 13:55:50 +0000278 if( pParser->yyidx<0 ) return 0;
drh75897232000-05-29 14:26:00 +0000279#ifndef NDEBUG
drh1f245e42002-03-11 13:55:50 +0000280 if( yyTraceFILE && pParser->yyidx>=0 ){
drh75897232000-05-29 14:26:00 +0000281 fprintf(yyTraceFILE,"%sPopping %s\n",
282 yyTracePrompt,
drh3ddfdf72003-12-22 14:53:19 +0000283 yyTokenName[yytos->major]);
drh75897232000-05-29 14:26:00 +0000284 }
285#endif
drh3ddfdf72003-12-22 14:53:19 +0000286 yymajor = yytos->major;
287 yy_destructor( yymajor, &yytos->minor);
drh1f245e42002-03-11 13:55:50 +0000288 pParser->yyidx--;
drh75897232000-05-29 14:26:00 +0000289 return yymajor;
290}
291
292/*
293** Deallocate and destroy a parser. Destructors are all called for
294** all stack elements before shutting the parser down.
295**
296** Inputs:
297** <ul>
298** <li> A pointer to the parser. This should be a pointer
299** obtained from ParseAlloc.
300** <li> A pointer to a function used to reclaim memory obtained
301** from malloc.
302** </ul>
303*/
drh75897232000-05-29 14:26:00 +0000304void ParseFree(
drh960e8c62001-04-03 16:53:21 +0000305 void *p, /* The parser to be deleted */
306 void (*freeProc)(void*) /* Function used to reclaim memory */
drh75897232000-05-29 14:26:00 +0000307){
308 yyParser *pParser = (yyParser*)p;
309 if( pParser==0 ) return;
drh1f245e42002-03-11 13:55:50 +0000310 while( pParser->yyidx>=0 ) yy_pop_parser_stack(pParser);
drh960e8c62001-04-03 16:53:21 +0000311 (*freeProc)((void*)pParser);
drh75897232000-05-29 14:26:00 +0000312}
313
314/*
drh8b582012003-10-21 13:16:03 +0000315** Find the appropriate action for a parser given the terminal
316** look-ahead token iLookAhead.
drh75897232000-05-29 14:26:00 +0000317**
318** If the look-ahead token is YYNOCODE, then check to see if the action is
319** independent of the look-ahead. If it is, return the action, otherwise
320** return YY_NO_ACTION.
321*/
drh8b582012003-10-21 13:16:03 +0000322static int yy_find_shift_action(
drh75897232000-05-29 14:26:00 +0000323 yyParser *pParser, /* The parser */
drhd9f291e2006-06-13 11:15:47 +0000324 YYCODETYPE iLookAhead /* The look-ahead token */
drh75897232000-05-29 14:26:00 +0000325){
drh8b582012003-10-21 13:16:03 +0000326 int i;
drh3ddfdf72003-12-22 14:53:19 +0000327 int stateno = pParser->yystack[pParser->yyidx].stateno;
drh75897232000-05-29 14:26:00 +0000328
drhada354d2005-11-05 15:03:59 +0000329 if( stateno>YY_SHIFT_MAX || (i = yy_shift_ofst[stateno])==YY_SHIFT_USE_DFLT ){
drh3ddfdf72003-12-22 14:53:19 +0000330 return yy_default[stateno];
drh8b582012003-10-21 13:16:03 +0000331 }
332 if( iLookAhead==YYNOCODE ){
333 return YY_NO_ACTION;
334 }
335 i += iLookAhead;
336 if( i<0 || i>=YY_SZ_ACTTAB || yy_lookahead[i]!=iLookAhead ){
drhe09daa92006-06-10 13:29:31 +0000337 if( iLookAhead>0 ){
338 #ifdef YYFALLBACK
339 int iFallback; /* Fallback token */
340 if( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0])
341 && (iFallback = yyFallback[iLookAhead])!=0 ){
342 #ifndef NDEBUG
343 if( yyTraceFILE ){
344 fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n",
345 yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]);
346 }
347 #endif
348 return yy_find_shift_action(pParser, iFallback);
drh0bd1f4e2002-06-06 18:54:39 +0000349 }
drhe09daa92006-06-10 13:29:31 +0000350 #endif
351 #ifdef YYWILDCARD
352 int j = i - iLookAhead + YYWILDCARD;
353 if( j>=0 && j<YY_SZ_ACTTAB && yy_lookahead[j]==YYWILDCARD ){
354 #ifndef NDEBUG
355 if( yyTraceFILE ){
356 fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n",
357 yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[YYWILDCARD]);
358 }
359 #endif
360 return yy_action[j];
361 }
362 #endif
drh0bd1f4e2002-06-06 18:54:39 +0000363 }
drh3ddfdf72003-12-22 14:53:19 +0000364 return yy_default[stateno];
drh8b582012003-10-21 13:16:03 +0000365 }else{
366 return yy_action[i];
367 }
368}
369
370/*
371** Find the appropriate action for a parser given the non-terminal
372** look-ahead token iLookAhead.
373**
374** If the look-ahead token is YYNOCODE, then check to see if the action is
375** independent of the look-ahead. If it is, return the action, otherwise
376** return YY_NO_ACTION.
377*/
378static int yy_find_reduce_action(
drh161aba32005-02-01 04:09:36 +0000379 int stateno, /* Current state number */
drhd9f291e2006-06-13 11:15:47 +0000380 YYCODETYPE iLookAhead /* The look-ahead token */
drh8b582012003-10-21 13:16:03 +0000381){
382 int i;
drh161aba32005-02-01 04:09:36 +0000383 /* int stateno = pParser->yystack[pParser->yyidx].stateno; */
drh8b582012003-10-21 13:16:03 +0000384
drhada354d2005-11-05 15:03:59 +0000385 if( stateno>YY_REDUCE_MAX ||
386 (i = yy_reduce_ofst[stateno])==YY_REDUCE_USE_DFLT ){
drh3ddfdf72003-12-22 14:53:19 +0000387 return yy_default[stateno];
drh8b582012003-10-21 13:16:03 +0000388 }
389 if( iLookAhead==YYNOCODE ){
drh75897232000-05-29 14:26:00 +0000390 return YY_NO_ACTION;
391 }
drh8b582012003-10-21 13:16:03 +0000392 i += iLookAhead;
393 if( i<0 || i>=YY_SZ_ACTTAB || yy_lookahead[i]!=iLookAhead ){
drh3ddfdf72003-12-22 14:53:19 +0000394 return yy_default[stateno];
drh8b582012003-10-21 13:16:03 +0000395 }else{
396 return yy_action[i];
397 }
drh75897232000-05-29 14:26:00 +0000398}
399
400/*
401** Perform a shift action.
402*/
403static void yy_shift(
404 yyParser *yypParser, /* The parser to be shifted */
405 int yyNewState, /* The new state to shift in */
406 int yyMajor, /* The major token to shift in */
407 YYMINORTYPE *yypMinor /* Pointer ot the minor token to shift in */
408){
drh3ddfdf72003-12-22 14:53:19 +0000409 yyStackEntry *yytos;
drh1f245e42002-03-11 13:55:50 +0000410 yypParser->yyidx++;
drh1f245e42002-03-11 13:55:50 +0000411 if( yypParser->yyidx>=YYSTACKDEPTH ){
412 ParseARG_FETCH;
413 yypParser->yyidx--;
drh75897232000-05-29 14:26:00 +0000414#ifndef NDEBUG
415 if( yyTraceFILE ){
416 fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt);
417 }
418#endif
drh1f245e42002-03-11 13:55:50 +0000419 while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
drh75897232000-05-29 14:26:00 +0000420 /* Here code is inserted which will execute if the parser
421 ** stack every overflows */
422%%
drh1f245e42002-03-11 13:55:50 +0000423 ParseARG_STORE; /* Suppress warning about unused %extra_argument var */
drh75897232000-05-29 14:26:00 +0000424 return;
425 }
drh3ddfdf72003-12-22 14:53:19 +0000426 yytos = &yypParser->yystack[yypParser->yyidx];
427 yytos->stateno = yyNewState;
428 yytos->major = yyMajor;
429 yytos->minor = *yypMinor;
drh75897232000-05-29 14:26:00 +0000430#ifndef NDEBUG
drh1f245e42002-03-11 13:55:50 +0000431 if( yyTraceFILE && yypParser->yyidx>0 ){
drh75897232000-05-29 14:26:00 +0000432 int i;
433 fprintf(yyTraceFILE,"%sShift %d\n",yyTracePrompt,yyNewState);
434 fprintf(yyTraceFILE,"%sStack:",yyTracePrompt);
drh1f245e42002-03-11 13:55:50 +0000435 for(i=1; i<=yypParser->yyidx; i++)
436 fprintf(yyTraceFILE," %s",yyTokenName[yypParser->yystack[i].major]);
drh75897232000-05-29 14:26:00 +0000437 fprintf(yyTraceFILE,"\n");
438 }
439#endif
440}
441
442/* The following table contains information about every rule that
443** is used during the reduce.
444*/
drh57196282004-10-06 15:41:16 +0000445static const struct {
drh75897232000-05-29 14:26:00 +0000446 YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */
447 unsigned char nrhs; /* Number of right-hand side symbols in the rule */
448} yyRuleInfo[] = {
449%%
450};
451
drh1f245e42002-03-11 13:55:50 +0000452static void yy_accept(yyParser*); /* Forward Declaration */
drh75897232000-05-29 14:26:00 +0000453
454/*
455** Perform a reduce action and the shift that must immediately
456** follow the reduce.
457*/
458static void yy_reduce(
459 yyParser *yypParser, /* The parser */
460 int yyruleno /* Number of the rule by which to reduce */
drh75897232000-05-29 14:26:00 +0000461){
462 int yygoto; /* The next state */
463 int yyact; /* The next action */
464 YYMINORTYPE yygotominor; /* The LHS of the rule reduced */
drh1f245e42002-03-11 13:55:50 +0000465 yyStackEntry *yymsp; /* The top of the parser's stack */
drh75897232000-05-29 14:26:00 +0000466 int yysize; /* Amount to pop the stack */
drh1f245e42002-03-11 13:55:50 +0000467 ParseARG_FETCH;
drh3ddfdf72003-12-22 14:53:19 +0000468 yymsp = &yypParser->yystack[yypParser->yyidx];
drh0bd1f4e2002-06-06 18:54:39 +0000469#ifndef NDEBUG
470 if( yyTraceFILE && yyruleno>=0
drhd9f291e2006-06-13 11:15:47 +0000471 && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){
drh0bd1f4e2002-06-06 18:54:39 +0000472 fprintf(yyTraceFILE, "%sReduce [%s].\n", yyTracePrompt,
473 yyRuleName[yyruleno]);
474 }
475#endif /* NDEBUG */
476
drh7bec5052005-02-06 02:45:41 +0000477#ifndef NDEBUG
478 /* Silence complaints from purify about yygotominor being uninitialized
479 ** in some cases when it is copied into the stack after the following
480 ** switch. yygotominor is uninitialized when a rule reduces that does
481 ** not set the value of its left-hand side nonterminal. Leaving the
482 ** value of the nonterminal uninitialized is utterly harmless as long
483 ** as the value is never used. So really the only thing this code
484 ** accomplishes is to quieten purify.
485 */
486 memset(&yygotominor, 0, sizeof(yygotominor));
487#endif
488
drh75897232000-05-29 14:26:00 +0000489 switch( yyruleno ){
490 /* Beginning here are the reduction cases. A typical example
491 ** follows:
492 ** case 0:
drh75897232000-05-29 14:26:00 +0000493 ** #line <lineno> <grammarfile>
494 ** { ... } // User supplied code
495 ** #line <lineno> <thisfile>
496 ** break;
497 */
498%%
499 };
500 yygoto = yyRuleInfo[yyruleno].lhs;
501 yysize = yyRuleInfo[yyruleno].nrhs;
drh1f245e42002-03-11 13:55:50 +0000502 yypParser->yyidx -= yysize;
drh161aba32005-02-01 04:09:36 +0000503 yyact = yy_find_reduce_action(yymsp[-yysize].stateno,yygoto);
drh75897232000-05-29 14:26:00 +0000504 if( yyact < YYNSTATE ){
drh490a73b2005-02-01 03:20:00 +0000505#ifdef NDEBUG
506 /* If we are not debugging and the reduce action popped at least
507 ** one element off the stack, then we can push the new element back
508 ** onto the stack here, and skip the stack overflow test in yy_shift().
509 ** That gives a significant speed improvement. */
510 if( yysize ){
511 yypParser->yyidx++;
512 yymsp -= yysize-1;
513 yymsp->stateno = yyact;
514 yymsp->major = yygoto;
515 yymsp->minor = yygotominor;
516 }else
517#endif
518 {
519 yy_shift(yypParser,yyact,yygoto,&yygotominor);
520 }
drh75897232000-05-29 14:26:00 +0000521 }else if( yyact == YYNSTATE + YYNRULE + 1 ){
drh1f245e42002-03-11 13:55:50 +0000522 yy_accept(yypParser);
drh75897232000-05-29 14:26:00 +0000523 }
524}
525
526/*
527** The following code executes when the parse fails
528*/
529static void yy_parse_failed(
530 yyParser *yypParser /* The parser */
drh75897232000-05-29 14:26:00 +0000531){
drh1f245e42002-03-11 13:55:50 +0000532 ParseARG_FETCH;
drh75897232000-05-29 14:26:00 +0000533#ifndef NDEBUG
534 if( yyTraceFILE ){
535 fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt);
536 }
537#endif
drh1f245e42002-03-11 13:55:50 +0000538 while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
drh75897232000-05-29 14:26:00 +0000539 /* Here code is inserted which will be executed whenever the
540 ** parser fails */
541%%
drh1f245e42002-03-11 13:55:50 +0000542 ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
drh75897232000-05-29 14:26:00 +0000543}
544
545/*
546** The following code executes when a syntax error first occurs.
547*/
548static void yy_syntax_error(
549 yyParser *yypParser, /* The parser */
550 int yymajor, /* The major type of the error token */
551 YYMINORTYPE yyminor /* The minor type of the error token */
drh75897232000-05-29 14:26:00 +0000552){
drh1f245e42002-03-11 13:55:50 +0000553 ParseARG_FETCH;
drh75897232000-05-29 14:26:00 +0000554#define TOKEN (yyminor.yy0)
555%%
drh1f245e42002-03-11 13:55:50 +0000556 ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
drh75897232000-05-29 14:26:00 +0000557}
558
559/*
560** The following is executed when the parser accepts
561*/
562static void yy_accept(
563 yyParser *yypParser /* The parser */
drh75897232000-05-29 14:26:00 +0000564){
drh1f245e42002-03-11 13:55:50 +0000565 ParseARG_FETCH;
drh75897232000-05-29 14:26:00 +0000566#ifndef NDEBUG
567 if( yyTraceFILE ){
568 fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt);
569 }
570#endif
drh1f245e42002-03-11 13:55:50 +0000571 while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
drh75897232000-05-29 14:26:00 +0000572 /* Here code is inserted which will be executed whenever the
573 ** parser accepts */
574%%
drh1f245e42002-03-11 13:55:50 +0000575 ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
drh75897232000-05-29 14:26:00 +0000576}
577
578/* The main parser program.
579** The first argument is a pointer to a structure obtained from
580** "ParseAlloc" which describes the current state of the parser.
581** The second argument is the major token number. The third is
582** the minor token. The fourth optional argument is whatever the
583** user wants (and specified in the grammar) and is available for
584** use by the action routines.
585**
586** Inputs:
587** <ul>
588** <li> A pointer to the parser (an opaque structure.)
589** <li> The major token number.
590** <li> The minor token number.
591** <li> An option argument of a grammar-specified type.
592** </ul>
593**
594** Outputs:
595** None.
596*/
drh75897232000-05-29 14:26:00 +0000597void Parse(
598 void *yyp, /* The parser */
599 int yymajor, /* The major token code number */
600 ParseTOKENTYPE yyminor /* The value for the token */
drh1f245e42002-03-11 13:55:50 +0000601 ParseARG_PDECL /* Optional %extra_argument parameter */
drh75897232000-05-29 14:26:00 +0000602){
603 YYMINORTYPE yyminorunion;
604 int yyact; /* The parser action. */
605 int yyendofinput; /* True if we are at the end of input */
606 int yyerrorhit = 0; /* True if yymajor has invoked an error */
607 yyParser *yypParser; /* The parser */
608
609 /* (re)initialize the parser, if necessary */
610 yypParser = (yyParser*)yyp;
drh1f245e42002-03-11 13:55:50 +0000611 if( yypParser->yyidx<0 ){
drh29f214b2005-05-11 14:28:14 +0000612 /* if( yymajor==0 ) return; // not sure why this was here... */
drh1f245e42002-03-11 13:55:50 +0000613 yypParser->yyidx = 0;
614 yypParser->yyerrcnt = -1;
drh3ddfdf72003-12-22 14:53:19 +0000615 yypParser->yystack[0].stateno = 0;
616 yypParser->yystack[0].major = 0;
drh75897232000-05-29 14:26:00 +0000617 }
618 yyminorunion.yy0 = yyminor;
619 yyendofinput = (yymajor==0);
drh1f245e42002-03-11 13:55:50 +0000620 ParseARG_STORE;
drh75897232000-05-29 14:26:00 +0000621
622#ifndef NDEBUG
623 if( yyTraceFILE ){
624 fprintf(yyTraceFILE,"%sInput %s\n",yyTracePrompt,yyTokenName[yymajor]);
625 }
626#endif
627
628 do{
drh8b582012003-10-21 13:16:03 +0000629 yyact = yy_find_shift_action(yypParser,yymajor);
drh75897232000-05-29 14:26:00 +0000630 if( yyact<YYNSTATE ){
631 yy_shift(yypParser,yyact,yymajor,&yyminorunion);
drh1f245e42002-03-11 13:55:50 +0000632 yypParser->yyerrcnt--;
633 if( yyendofinput && yypParser->yyidx>=0 ){
drh75897232000-05-29 14:26:00 +0000634 yymajor = 0;
635 }else{
636 yymajor = YYNOCODE;
637 }
638 }else if( yyact < YYNSTATE + YYNRULE ){
drh1f245e42002-03-11 13:55:50 +0000639 yy_reduce(yypParser,yyact-YYNSTATE);
drh75897232000-05-29 14:26:00 +0000640 }else if( yyact == YY_ERROR_ACTION ){
drh3ddfdf72003-12-22 14:53:19 +0000641 int yymx;
drh75897232000-05-29 14:26:00 +0000642#ifndef NDEBUG
643 if( yyTraceFILE ){
644 fprintf(yyTraceFILE,"%sSyntax Error!\n",yyTracePrompt);
645 }
646#endif
647#ifdef YYERRORSYMBOL
648 /* A syntax error has occurred.
649 ** The response to an error depends upon whether or not the
650 ** grammar defines an error token "ERROR".
651 **
652 ** This is what we do if the grammar does define ERROR:
653 **
654 ** * Call the %syntax_error function.
655 **
656 ** * Begin popping the stack until we enter a state where
657 ** it is legal to shift the error symbol, then shift
658 ** the error symbol.
659 **
660 ** * Set the error count to three.
661 **
662 ** * Begin accepting and shifting new tokens. No new error
663 ** processing will occur until three tokens have been
664 ** shifted successfully.
665 **
666 */
drh1f245e42002-03-11 13:55:50 +0000667 if( yypParser->yyerrcnt<0 ){
668 yy_syntax_error(yypParser,yymajor,yyminorunion);
drh75897232000-05-29 14:26:00 +0000669 }
drh3ddfdf72003-12-22 14:53:19 +0000670 yymx = yypParser->yystack[yypParser->yyidx].major;
671 if( yymx==YYERRORSYMBOL || yyerrorhit ){
drh75897232000-05-29 14:26:00 +0000672#ifndef NDEBUG
673 if( yyTraceFILE ){
674 fprintf(yyTraceFILE,"%sDiscard input token %s\n",
675 yyTracePrompt,yyTokenName[yymajor]);
676 }
677#endif
678 yy_destructor(yymajor,&yyminorunion);
679 yymajor = YYNOCODE;
680 }else{
681 while(
drh1f245e42002-03-11 13:55:50 +0000682 yypParser->yyidx >= 0 &&
drh3ddfdf72003-12-22 14:53:19 +0000683 yymx != YYERRORSYMBOL &&
drhf3a58882006-05-08 15:14:19 +0000684 (yyact = yy_find_reduce_action(
685 yypParser->yystack[yypParser->yyidx].stateno,
686 YYERRORSYMBOL)) >= YYNSTATE
drh75897232000-05-29 14:26:00 +0000687 ){
688 yy_pop_parser_stack(yypParser);
689 }
drh1f245e42002-03-11 13:55:50 +0000690 if( yypParser->yyidx < 0 || yymajor==0 ){
drh75897232000-05-29 14:26:00 +0000691 yy_destructor(yymajor,&yyminorunion);
drh1f245e42002-03-11 13:55:50 +0000692 yy_parse_failed(yypParser);
drh75897232000-05-29 14:26:00 +0000693 yymajor = YYNOCODE;
drh3ddfdf72003-12-22 14:53:19 +0000694 }else if( yymx!=YYERRORSYMBOL ){
drh75897232000-05-29 14:26:00 +0000695 YYMINORTYPE u2;
696 u2.YYERRSYMDT = 0;
697 yy_shift(yypParser,yyact,YYERRORSYMBOL,&u2);
698 }
699 }
drh1f245e42002-03-11 13:55:50 +0000700 yypParser->yyerrcnt = 3;
drh75897232000-05-29 14:26:00 +0000701 yyerrorhit = 1;
702#else /* YYERRORSYMBOL is not defined */
703 /* This is what we do if the grammar does not define ERROR:
704 **
705 ** * Report an error message, and throw away the input token.
706 **
707 ** * If the input token is $, then fail the parse.
708 **
709 ** As before, subsequent error messages are suppressed until
710 ** three input tokens have been successfully shifted.
711 */
drh1f245e42002-03-11 13:55:50 +0000712 if( yypParser->yyerrcnt<=0 ){
713 yy_syntax_error(yypParser,yymajor,yyminorunion);
drh75897232000-05-29 14:26:00 +0000714 }
drh1f245e42002-03-11 13:55:50 +0000715 yypParser->yyerrcnt = 3;
drh75897232000-05-29 14:26:00 +0000716 yy_destructor(yymajor,&yyminorunion);
717 if( yyendofinput ){
drh1f245e42002-03-11 13:55:50 +0000718 yy_parse_failed(yypParser);
drh75897232000-05-29 14:26:00 +0000719 }
720 yymajor = YYNOCODE;
721#endif
722 }else{
drh1f245e42002-03-11 13:55:50 +0000723 yy_accept(yypParser);
drh75897232000-05-29 14:26:00 +0000724 yymajor = YYNOCODE;
725 }
drh1f245e42002-03-11 13:55:50 +0000726 }while( yymajor!=YYNOCODE && yypParser->yyidx>=0 );
drh75897232000-05-29 14:26:00 +0000727 return;
728}