blob: aede437faba6cd06581c3f18471ce571665e98da [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.
34** YYACTIONTYPE is the data type used for storing terminal
35** and nonterminal numbers. "unsigned char" is
36** used if there are fewer than 250 rules and
37** states combined. "int" is used otherwise.
38** ParseTOKENTYPE is the data type used for minor tokens given
39** directly to the parser from the tokenizer.
40** YYMINORTYPE is the data type used for all minor tokens.
41** This is typically a union of many types, one of
42** which is ParseTOKENTYPE. The entry in the union
43** for base tokens is called "yy0".
44** YYSTACKDEPTH is the maximum depth of the parser's stack.
drh1f245e42002-03-11 13:55:50 +000045** ParseARG_SDECL A static variable declaration for the %extra_argument
46** ParseARG_PDECL A parameter declaration for the %extra_argument
47** ParseARG_STORE Code to store %extra_argument into yypParser
48** ParseARG_FETCH Code to extract %extra_argument from yypParser
drh75897232000-05-29 14:26:00 +000049** YYNSTATE the combined number of states.
50** YYNRULE the number of rules in the grammar
51** YYERRORSYMBOL is the code number of the error symbol. If not
52** defined, then do no error processing.
53*/
54%%
55#define YY_NO_ACTION (YYNSTATE+YYNRULE+2)
56#define YY_ACCEPT_ACTION (YYNSTATE+YYNRULE+1)
57#define YY_ERROR_ACTION (YYNSTATE+YYNRULE)
58/* Next is the action table. Each entry in this table contains
59**
60** + An integer which is the number representing the look-ahead
61** token
62**
63** + An integer indicating what action to take. Number (N) between
64** 0 and YYNSTATE-1 mean shift the look-ahead and go to state N.
65** Numbers between YYNSTATE and YYNSTATE+YYNRULE-1 mean reduce by
66** rule N-YYNSTATE. Number YYNSTATE+YYNRULE means that a syntax
67** error has occurred. Number YYNSTATE+YYNRULE+1 means the parser
68** accepts its input.
69**
70** + A pointer to the next entry with the same hash value.
71**
72** The action table is really a series of hash tables. Each hash
73** table contains a number of entries which is a power of two. The
74** "state" table (which follows) contains information about the starting
75** point and size of each hash table.
76*/
77struct yyActionEntry {
78 YYCODETYPE lookahead; /* The value of the look-ahead token */
drhb29b0a52002-02-23 19:39:46 +000079 YYCODETYPE next; /* Next entry + 1. Zero at end of collision chain */
drh75897232000-05-29 14:26:00 +000080 YYACTIONTYPE action; /* Action to take for this look-ahead */
drh75897232000-05-29 14:26:00 +000081};
drh1f245e42002-03-11 13:55:50 +000082typedef struct yyActionEntry yyActionEntry;
83static const yyActionEntry yyActionTable[] = {
drh75897232000-05-29 14:26:00 +000084%%
85};
86
87/* The state table contains information needed to look up the correct
88** action in the action table, given the current state of the parser.
89** Information needed includes:
90**
91** + A pointer to the start of the action hash table in yyActionTable.
92**
drhb29b0a52002-02-23 19:39:46 +000093** + The number of entries in the action hash table.
drh75897232000-05-29 14:26:00 +000094**
95** + The default action. This is the action to take if no entry for
96** the given look-ahead is found in the action hash table.
97*/
98struct yyStateEntry {
drh1f245e42002-03-11 13:55:50 +000099 const yyActionEntry *hashtbl; /* Start of the hash table in yyActionTable */
drhb29b0a52002-02-23 19:39:46 +0000100 YYCODETYPE nEntry; /* Number of entries in action hash table */
drh75897232000-05-29 14:26:00 +0000101 YYACTIONTYPE actionDefault; /* Default action if look-ahead not found */
102};
drh1f245e42002-03-11 13:55:50 +0000103typedef struct yyStateEntry yyStateEntry;
104static const yyStateEntry yyStateTable[] = {
drh75897232000-05-29 14:26:00 +0000105%%
106};
107
108/* The following structure represents a single element of the
109** parser's stack. Information stored includes:
110**
111** + The state number for the parser at this level of the stack.
112**
113** + The value of the token stored at this level of the stack.
114** (In other words, the "major" token.)
115**
116** + The semantic value stored at this level of the stack. This is
117** the information used by the action routines in the grammar.
118** It is sometimes called the "minor" token.
119*/
120struct yyStackEntry {
121 int stateno; /* The state-number */
122 int major; /* The major token value. This is the code
123 ** number for the token at this stack level */
124 YYMINORTYPE minor; /* The user-supplied minor token value. This
125 ** is the value of the token */
126};
drh1f245e42002-03-11 13:55:50 +0000127typedef struct yyStackEntry yyStackEntry;
drh75897232000-05-29 14:26:00 +0000128
129/* The state of the parser is completely contained in an instance of
130** the following structure */
131struct yyParser {
drh1f245e42002-03-11 13:55:50 +0000132 int yyidx; /* Index of top element in stack */
133 int yyerrcnt; /* Shifts left before out of the error */
134 yyStackEntry *yytop; /* Pointer to the top stack element */
135 ParseARG_SDECL /* A place to hold %extra_argument */
136 yyStackEntry yystack[YYSTACKDEPTH]; /* The parser's stack */
drh75897232000-05-29 14:26:00 +0000137};
138typedef struct yyParser yyParser;
139
140#ifndef NDEBUG
141#include <stdio.h>
142static FILE *yyTraceFILE = 0;
143static char *yyTracePrompt = 0;
144
145/*
146** Turn parser tracing on by giving a stream to which to write the trace
147** and a prompt to preface each trace message. Tracing is turned off
148** by making either argument NULL
149**
150** Inputs:
151** <ul>
152** <li> A FILE* to which trace output should be written.
153** If NULL, then tracing is turned off.
154** <li> A prefix string written at the beginning of every
155** line of trace output. If NULL, then tracing is
156** turned off.
157** </ul>
158**
159** Outputs:
160** None.
161*/
drh75897232000-05-29 14:26:00 +0000162void ParseTrace(FILE *TraceFILE, char *zTracePrompt){
163 yyTraceFILE = TraceFILE;
164 yyTracePrompt = zTracePrompt;
165 if( yyTraceFILE==0 ) yyTracePrompt = 0;
166 else if( yyTracePrompt==0 ) yyTraceFILE = 0;
167}
168
169/* For tracing shifts, the names of all terminals and nonterminals
170** are required. The following table supplies these names */
drh1f245e42002-03-11 13:55:50 +0000171static const char *yyTokenName[] = {
drh75897232000-05-29 14:26:00 +0000172%%
173};
174#define YYTRACE(X) if( yyTraceFILE ) fprintf(yyTraceFILE,"%sReduce [%s].\n",yyTracePrompt,X);
175#else
176#define YYTRACE(X)
177#endif
178
drha1b351a2001-09-14 16:42:12 +0000179
drh960e8c62001-04-03 16:53:21 +0000180/*
181** This function returns the symbolic name associated with a token
182** value.
183*/
184const char *ParseTokenName(int tokenType){
drha1b351a2001-09-14 16:42:12 +0000185#ifndef NDEBUG
drh960e8c62001-04-03 16:53:21 +0000186 if( tokenType>0 && tokenType<(sizeof(yyTokenName)/sizeof(yyTokenName[0])) ){
187 return yyTokenName[tokenType];
188 }else{
189 return "Unknown";
190 }
drha1b351a2001-09-14 16:42:12 +0000191#else
192 return "";
193#endif
drh960e8c62001-04-03 16:53:21 +0000194}
195
drh75897232000-05-29 14:26:00 +0000196/*
197** This function allocates a new parser.
198** The only argument is a pointer to a function which works like
199** malloc.
200**
201** Inputs:
202** A pointer to the function used to allocate memory.
203**
204** Outputs:
205** A pointer to a parser. This pointer is used in subsequent calls
206** to Parse and ParseFree.
207*/
drh7218ac72002-03-10 21:21:00 +0000208void *ParseAlloc(void *(*mallocProc)(size_t)){
drh75897232000-05-29 14:26:00 +0000209 yyParser *pParser;
drh7218ac72002-03-10 21:21:00 +0000210 pParser = (yyParser*)(*mallocProc)( (size_t)sizeof(yyParser) );
drh75897232000-05-29 14:26:00 +0000211 if( pParser ){
drh1f245e42002-03-11 13:55:50 +0000212 pParser->yyidx = -1;
drh75897232000-05-29 14:26:00 +0000213 }
214 return pParser;
215}
216
217/* The following function deletes the value associated with a
218** symbol. The symbol can be either a terminal or nonterminal.
219** "yymajor" is the symbol code, and "yypminor" is a pointer to
220** the value.
221*/
222static void yy_destructor(YYCODETYPE yymajor, YYMINORTYPE *yypminor){
223 switch( yymajor ){
224 /* Here is inserted the actions which take place when a
225 ** terminal or non-terminal is destroyed. This can happen
226 ** when the symbol is popped from the stack during a
227 ** reduce or during error processing or when a parser is
228 ** being destroyed before it is finished parsing.
229 **
230 ** Note: during a reduce, the only symbols destroyed are those
231 ** which appear on the RHS of the rule, but which are not used
232 ** inside the C code.
233 */
234%%
235 default: break; /* If no destructor action specified: do nothing */
236 }
237}
238
239/*
240** Pop the parser's stack once.
241**
242** If there is a destructor routine associated with the token which
243** is popped from the stack, then call it.
244**
245** Return the major token number for the symbol popped.
246*/
247static int yy_pop_parser_stack(yyParser *pParser){
248 YYCODETYPE yymajor;
249
drh1f245e42002-03-11 13:55:50 +0000250 if( pParser->yyidx<0 ) return 0;
drh75897232000-05-29 14:26:00 +0000251#ifndef NDEBUG
drh1f245e42002-03-11 13:55:50 +0000252 if( yyTraceFILE && pParser->yyidx>=0 ){
drh75897232000-05-29 14:26:00 +0000253 fprintf(yyTraceFILE,"%sPopping %s\n",
254 yyTracePrompt,
drh1f245e42002-03-11 13:55:50 +0000255 yyTokenName[pParser->yytop->major]);
drh75897232000-05-29 14:26:00 +0000256 }
257#endif
drh1f245e42002-03-11 13:55:50 +0000258 yymajor = pParser->yytop->major;
259 yy_destructor( yymajor, &pParser->yytop->minor);
260 pParser->yyidx--;
261 pParser->yytop--;
drh75897232000-05-29 14:26:00 +0000262 return yymajor;
263}
264
265/*
266** Deallocate and destroy a parser. Destructors are all called for
267** all stack elements before shutting the parser down.
268**
269** Inputs:
270** <ul>
271** <li> A pointer to the parser. This should be a pointer
272** obtained from ParseAlloc.
273** <li> A pointer to a function used to reclaim memory obtained
274** from malloc.
275** </ul>
276*/
drh75897232000-05-29 14:26:00 +0000277void ParseFree(
drh960e8c62001-04-03 16:53:21 +0000278 void *p, /* The parser to be deleted */
279 void (*freeProc)(void*) /* Function used to reclaim memory */
drh75897232000-05-29 14:26:00 +0000280){
281 yyParser *pParser = (yyParser*)p;
282 if( pParser==0 ) return;
drh1f245e42002-03-11 13:55:50 +0000283 while( pParser->yyidx>=0 ) yy_pop_parser_stack(pParser);
drh960e8c62001-04-03 16:53:21 +0000284 (*freeProc)((void*)pParser);
drh75897232000-05-29 14:26:00 +0000285}
286
287/*
288** Find the appropriate action for a parser given the look-ahead token.
289**
290** If the look-ahead token is YYNOCODE, then check to see if the action is
291** independent of the look-ahead. If it is, return the action, otherwise
292** return YY_NO_ACTION.
293*/
294static int yy_find_parser_action(
295 yyParser *pParser, /* The parser */
296 int iLookAhead /* The look-ahead token */
297){
drh1f245e42002-03-11 13:55:50 +0000298 const yyStateEntry *pState; /* Appropriate entry in the state table */
299 const yyActionEntry *pAction; /* Action appropriate for the look-ahead */
drh75897232000-05-29 14:26:00 +0000300
drh1f245e42002-03-11 13:55:50 +0000301 /* if( pParser->yyidx<0 ) return YY_NO_ACTION; */
302 pState = &yyStateTable[pParser->yytop->stateno];
drhb29b0a52002-02-23 19:39:46 +0000303 if( pState->nEntry==0 ){
304 return pState->actionDefault;
305 }else if( iLookAhead!=YYNOCODE ){
306 pAction = &pState->hashtbl[iLookAhead % pState->nEntry];
307 while( 1 ){
drh75897232000-05-29 14:26:00 +0000308 if( pAction->lookahead==iLookAhead ) return pAction->action;
drhb29b0a52002-02-23 19:39:46 +0000309 if( pAction->next==0 ) return pState->actionDefault;
310 pAction = &pState->hashtbl[pAction->next-1];
drh75897232000-05-29 14:26:00 +0000311 }
drhb29b0a52002-02-23 19:39:46 +0000312 }else if( pState->hashtbl->lookahead!=YYNOCODE ){
drh75897232000-05-29 14:26:00 +0000313 return YY_NO_ACTION;
314 }
315 return pState->actionDefault;
316}
317
318/*
319** Perform a shift action.
320*/
321static void yy_shift(
322 yyParser *yypParser, /* The parser to be shifted */
323 int yyNewState, /* The new state to shift in */
324 int yyMajor, /* The major token to shift in */
325 YYMINORTYPE *yypMinor /* Pointer ot the minor token to shift in */
326){
drh1f245e42002-03-11 13:55:50 +0000327 yypParser->yyidx++;
328 yypParser->yytop++;
329 if( yypParser->yyidx>=YYSTACKDEPTH ){
330 ParseARG_FETCH;
331 yypParser->yyidx--;
332 yypParser->yytop--;
drh75897232000-05-29 14:26:00 +0000333#ifndef NDEBUG
334 if( yyTraceFILE ){
335 fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt);
336 }
337#endif
drh1f245e42002-03-11 13:55:50 +0000338 while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
drh75897232000-05-29 14:26:00 +0000339 /* Here code is inserted which will execute if the parser
340 ** stack every overflows */
341%%
drh1f245e42002-03-11 13:55:50 +0000342 ParseARG_STORE; /* Suppress warning about unused %extra_argument var */
drh75897232000-05-29 14:26:00 +0000343 return;
344 }
drh1f245e42002-03-11 13:55:50 +0000345 yypParser->yytop->stateno = yyNewState;
346 yypParser->yytop->major = yyMajor;
347 yypParser->yytop->minor = *yypMinor;
drh75897232000-05-29 14:26:00 +0000348#ifndef NDEBUG
drh1f245e42002-03-11 13:55:50 +0000349 if( yyTraceFILE && yypParser->yyidx>0 ){
drh75897232000-05-29 14:26:00 +0000350 int i;
351 fprintf(yyTraceFILE,"%sShift %d\n",yyTracePrompt,yyNewState);
352 fprintf(yyTraceFILE,"%sStack:",yyTracePrompt);
drh1f245e42002-03-11 13:55:50 +0000353 for(i=1; i<=yypParser->yyidx; i++)
354 fprintf(yyTraceFILE," %s",yyTokenName[yypParser->yystack[i].major]);
drh75897232000-05-29 14:26:00 +0000355 fprintf(yyTraceFILE,"\n");
356 }
357#endif
358}
359
360/* The following table contains information about every rule that
361** is used during the reduce.
362*/
363static struct {
364 YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */
365 unsigned char nrhs; /* Number of right-hand side symbols in the rule */
366} yyRuleInfo[] = {
367%%
368};
369
drh1f245e42002-03-11 13:55:50 +0000370static void yy_accept(yyParser*); /* Forward Declaration */
drh75897232000-05-29 14:26:00 +0000371
372/*
373** Perform a reduce action and the shift that must immediately
374** follow the reduce.
375*/
376static void yy_reduce(
377 yyParser *yypParser, /* The parser */
378 int yyruleno /* Number of the rule by which to reduce */
drh75897232000-05-29 14:26:00 +0000379){
380 int yygoto; /* The next state */
381 int yyact; /* The next action */
382 YYMINORTYPE yygotominor; /* The LHS of the rule reduced */
drh1f245e42002-03-11 13:55:50 +0000383 yyStackEntry *yymsp; /* The top of the parser's stack */
drh75897232000-05-29 14:26:00 +0000384 int yysize; /* Amount to pop the stack */
drh1f245e42002-03-11 13:55:50 +0000385 ParseARG_FETCH;
386 yymsp = yypParser->yytop;
drh75897232000-05-29 14:26:00 +0000387 switch( yyruleno ){
388 /* Beginning here are the reduction cases. A typical example
389 ** follows:
390 ** case 0:
391 ** YYTRACE("<text of the rule>");
392 ** #line <lineno> <grammarfile>
393 ** { ... } // User supplied code
394 ** #line <lineno> <thisfile>
395 ** break;
396 */
397%%
398 };
399 yygoto = yyRuleInfo[yyruleno].lhs;
400 yysize = yyRuleInfo[yyruleno].nrhs;
drh1f245e42002-03-11 13:55:50 +0000401 yypParser->yyidx -= yysize;
402 yypParser->yytop -= yysize;
drh75897232000-05-29 14:26:00 +0000403 yyact = yy_find_parser_action(yypParser,yygoto);
404 if( yyact < YYNSTATE ){
405 yy_shift(yypParser,yyact,yygoto,&yygotominor);
406 }else if( yyact == YYNSTATE + YYNRULE + 1 ){
drh1f245e42002-03-11 13:55:50 +0000407 yy_accept(yypParser);
drh75897232000-05-29 14:26:00 +0000408 }
409}
410
411/*
412** The following code executes when the parse fails
413*/
414static void yy_parse_failed(
415 yyParser *yypParser /* The parser */
drh75897232000-05-29 14:26:00 +0000416){
drh1f245e42002-03-11 13:55:50 +0000417 ParseARG_FETCH;
drh75897232000-05-29 14:26:00 +0000418#ifndef NDEBUG
419 if( yyTraceFILE ){
420 fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt);
421 }
422#endif
drh1f245e42002-03-11 13:55:50 +0000423 while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
drh75897232000-05-29 14:26:00 +0000424 /* Here code is inserted which will be executed whenever the
425 ** parser fails */
426%%
drh1f245e42002-03-11 13:55:50 +0000427 ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
drh75897232000-05-29 14:26:00 +0000428}
429
430/*
431** The following code executes when a syntax error first occurs.
432*/
433static void yy_syntax_error(
434 yyParser *yypParser, /* The parser */
435 int yymajor, /* The major type of the error token */
436 YYMINORTYPE yyminor /* The minor type of the error token */
drh75897232000-05-29 14:26:00 +0000437){
drh1f245e42002-03-11 13:55:50 +0000438 ParseARG_FETCH;
drh75897232000-05-29 14:26:00 +0000439#define TOKEN (yyminor.yy0)
440%%
drh1f245e42002-03-11 13:55:50 +0000441 ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
drh75897232000-05-29 14:26:00 +0000442}
443
444/*
445** The following is executed when the parser accepts
446*/
447static void yy_accept(
448 yyParser *yypParser /* The parser */
drh75897232000-05-29 14:26:00 +0000449){
drh1f245e42002-03-11 13:55:50 +0000450 ParseARG_FETCH;
drh75897232000-05-29 14:26:00 +0000451#ifndef NDEBUG
452 if( yyTraceFILE ){
453 fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt);
454 }
455#endif
drh1f245e42002-03-11 13:55:50 +0000456 while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
drh75897232000-05-29 14:26:00 +0000457 /* Here code is inserted which will be executed whenever the
458 ** parser accepts */
459%%
drh1f245e42002-03-11 13:55:50 +0000460 ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
drh75897232000-05-29 14:26:00 +0000461}
462
463/* The main parser program.
464** The first argument is a pointer to a structure obtained from
465** "ParseAlloc" which describes the current state of the parser.
466** The second argument is the major token number. The third is
467** the minor token. The fourth optional argument is whatever the
468** user wants (and specified in the grammar) and is available for
469** use by the action routines.
470**
471** Inputs:
472** <ul>
473** <li> A pointer to the parser (an opaque structure.)
474** <li> The major token number.
475** <li> The minor token number.
476** <li> An option argument of a grammar-specified type.
477** </ul>
478**
479** Outputs:
480** None.
481*/
drh75897232000-05-29 14:26:00 +0000482void Parse(
483 void *yyp, /* The parser */
484 int yymajor, /* The major token code number */
485 ParseTOKENTYPE yyminor /* The value for the token */
drh1f245e42002-03-11 13:55:50 +0000486 ParseARG_PDECL /* Optional %extra_argument parameter */
drh75897232000-05-29 14:26:00 +0000487){
488 YYMINORTYPE yyminorunion;
489 int yyact; /* The parser action. */
490 int yyendofinput; /* True if we are at the end of input */
491 int yyerrorhit = 0; /* True if yymajor has invoked an error */
492 yyParser *yypParser; /* The parser */
493
494 /* (re)initialize the parser, if necessary */
495 yypParser = (yyParser*)yyp;
drh1f245e42002-03-11 13:55:50 +0000496 if( yypParser->yyidx<0 ){
drh75897232000-05-29 14:26:00 +0000497 if( yymajor==0 ) return;
drh1f245e42002-03-11 13:55:50 +0000498 yypParser->yyidx = 0;
499 yypParser->yyerrcnt = -1;
500 yypParser->yytop = &yypParser->yystack[0];
501 yypParser->yytop->stateno = 0;
502 yypParser->yytop->major = 0;
drh75897232000-05-29 14:26:00 +0000503 }
504 yyminorunion.yy0 = yyminor;
505 yyendofinput = (yymajor==0);
drh1f245e42002-03-11 13:55:50 +0000506 ParseARG_STORE;
drh75897232000-05-29 14:26:00 +0000507
508#ifndef NDEBUG
509 if( yyTraceFILE ){
510 fprintf(yyTraceFILE,"%sInput %s\n",yyTracePrompt,yyTokenName[yymajor]);
511 }
512#endif
513
514 do{
515 yyact = yy_find_parser_action(yypParser,yymajor);
516 if( yyact<YYNSTATE ){
517 yy_shift(yypParser,yyact,yymajor,&yyminorunion);
drh1f245e42002-03-11 13:55:50 +0000518 yypParser->yyerrcnt--;
519 if( yyendofinput && yypParser->yyidx>=0 ){
drh75897232000-05-29 14:26:00 +0000520 yymajor = 0;
521 }else{
522 yymajor = YYNOCODE;
523 }
524 }else if( yyact < YYNSTATE + YYNRULE ){
drh1f245e42002-03-11 13:55:50 +0000525 yy_reduce(yypParser,yyact-YYNSTATE);
drh75897232000-05-29 14:26:00 +0000526 }else if( yyact == YY_ERROR_ACTION ){
527#ifndef NDEBUG
528 if( yyTraceFILE ){
529 fprintf(yyTraceFILE,"%sSyntax Error!\n",yyTracePrompt);
530 }
531#endif
532#ifdef YYERRORSYMBOL
533 /* A syntax error has occurred.
534 ** The response to an error depends upon whether or not the
535 ** grammar defines an error token "ERROR".
536 **
537 ** This is what we do if the grammar does define ERROR:
538 **
539 ** * Call the %syntax_error function.
540 **
541 ** * Begin popping the stack until we enter a state where
542 ** it is legal to shift the error symbol, then shift
543 ** the error symbol.
544 **
545 ** * Set the error count to three.
546 **
547 ** * Begin accepting and shifting new tokens. No new error
548 ** processing will occur until three tokens have been
549 ** shifted successfully.
550 **
551 */
drh1f245e42002-03-11 13:55:50 +0000552 if( yypParser->yyerrcnt<0 ){
553 yy_syntax_error(yypParser,yymajor,yyminorunion);
drh75897232000-05-29 14:26:00 +0000554 }
drh1f245e42002-03-11 13:55:50 +0000555 if( yypParser->yytop->major==YYERRORSYMBOL || yyerrorhit ){
drh75897232000-05-29 14:26:00 +0000556#ifndef NDEBUG
557 if( yyTraceFILE ){
558 fprintf(yyTraceFILE,"%sDiscard input token %s\n",
559 yyTracePrompt,yyTokenName[yymajor]);
560 }
561#endif
562 yy_destructor(yymajor,&yyminorunion);
563 yymajor = YYNOCODE;
564 }else{
565 while(
drh1f245e42002-03-11 13:55:50 +0000566 yypParser->yyidx >= 0 &&
567 yypParser->yytop->major != YYERRORSYMBOL &&
drh75897232000-05-29 14:26:00 +0000568 (yyact = yy_find_parser_action(yypParser,YYERRORSYMBOL)) >= YYNSTATE
569 ){
570 yy_pop_parser_stack(yypParser);
571 }
drh1f245e42002-03-11 13:55:50 +0000572 if( yypParser->yyidx < 0 || yymajor==0 ){
drh75897232000-05-29 14:26:00 +0000573 yy_destructor(yymajor,&yyminorunion);
drh1f245e42002-03-11 13:55:50 +0000574 yy_parse_failed(yypParser);
drh75897232000-05-29 14:26:00 +0000575 yymajor = YYNOCODE;
drh1f245e42002-03-11 13:55:50 +0000576 }else if( yypParser->yytop->major!=YYERRORSYMBOL ){
drh75897232000-05-29 14:26:00 +0000577 YYMINORTYPE u2;
578 u2.YYERRSYMDT = 0;
579 yy_shift(yypParser,yyact,YYERRORSYMBOL,&u2);
580 }
581 }
drh1f245e42002-03-11 13:55:50 +0000582 yypParser->yyerrcnt = 3;
drh75897232000-05-29 14:26:00 +0000583 yyerrorhit = 1;
584#else /* YYERRORSYMBOL is not defined */
585 /* This is what we do if the grammar does not define ERROR:
586 **
587 ** * Report an error message, and throw away the input token.
588 **
589 ** * If the input token is $, then fail the parse.
590 **
591 ** As before, subsequent error messages are suppressed until
592 ** three input tokens have been successfully shifted.
593 */
drh1f245e42002-03-11 13:55:50 +0000594 if( yypParser->yyerrcnt<=0 ){
595 yy_syntax_error(yypParser,yymajor,yyminorunion);
drh75897232000-05-29 14:26:00 +0000596 }
drh1f245e42002-03-11 13:55:50 +0000597 yypParser->yyerrcnt = 3;
drh75897232000-05-29 14:26:00 +0000598 yy_destructor(yymajor,&yyminorunion);
599 if( yyendofinput ){
drh1f245e42002-03-11 13:55:50 +0000600 yy_parse_failed(yypParser);
drh75897232000-05-29 14:26:00 +0000601 }
602 yymajor = YYNOCODE;
603#endif
604 }else{
drh1f245e42002-03-11 13:55:50 +0000605 yy_accept(yypParser);
drh75897232000-05-29 14:26:00 +0000606 yymajor = YYNOCODE;
607 }
drh1f245e42002-03-11 13:55:50 +0000608 }while( yymajor!=YYNOCODE && yypParser->yyidx>=0 );
drh75897232000-05-29 14:26:00 +0000609 return;
610}