MSWSP: use GuidPropertySet_find_guid() in parse_CFullPropSpec()
[wireshark-wip.git] / tools / lemon / lempar.c
blob848c43b3d2e7ae08fdee4c3a3d06eebbc763b9c3
1 /* Driver template for the LEMON parser generator.
2 * $Id$
4 ** Copyright 1991-1995 by D. Richard Hipp.
5 **
6 ** This library is free software; you can redistribute it and/or
7 ** modify it under the terms of the GNU Library General Public
8 ** License as published by the Free Software Foundation; either
9 ** version 2 of the License, or (at your option) any later version.
11 ** This library is distributed in the hope that it will be useful,
12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ** Library General Public License for more details.
16 ** You should have received a copy of the GNU General Public License
17 ** along with this program; if not, write to the Free Software
18 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 ** Modified 1997 to make it suitable for use with makeheaders.
21 * Updated to sqlite lemon version 1.36
23 /* First off, code is included that follows the "include" declaration
24 ** in the input grammar file. */
25 #include <stdio.h>
27 /* Next is all token values, in a form suitable for use by makeheaders.
28 ** This section will be null unless lemon is run with the -m switch.
31 ** These constants (all generated automatically by the parser generator)
32 ** specify the various kinds of tokens (terminals) that the parser
33 ** understands.
35 ** Each symbol here is a terminal symbol in the grammar.
38 /* Make sure the INTERFACE macro is defined.
40 #ifndef INTERFACE
41 # define INTERFACE 1
42 #endif
43 /* The next thing included is series of defines which control
44 ** various aspects of the generated parser.
45 ** YYCODETYPE is the data type used for storing terminal
46 ** and nonterminal numbers. "unsigned char" is
47 ** used if there are fewer than 250 terminals
48 ** and nonterminals. "int" is used otherwise.
49 ** YYNOCODE is a number of type YYCODETYPE which corresponds
50 ** to no legal terminal or nonterminal number. This
51 ** number is used to fill in empty slots of the hash
52 ** table.
53 ** YYFALLBACK If defined, this indicates that one or more tokens
54 ** have fall-back values which should be used if the
55 ** original value of the token will not parse.
56 ** YYACTIONTYPE is the data type used for storing terminal
57 ** and nonterminal numbers. "unsigned char" is
58 ** used if there are fewer than 250 rules and
59 ** states combined. "int" is used otherwise.
60 ** ParseTOKENTYPE is the data type used for minor tokens given
61 ** directly to the parser from the tokenizer.
62 ** YYMINORTYPE is the data type used for all minor tokens.
63 ** This is typically a union of many types, one of
64 ** which is ParseTOKENTYPE. The entry in the union
65 ** for base tokens is called "yy0".
66 ** YYSTACKDEPTH is the maximum depth of the parser's stack. If
67 ** zero the stack is dynamically sized using realloc()
68 ** ParseARG_SDECL A static variable declaration for the %extra_argument
69 ** ParseARG_PDECL A parameter declaration for the %extra_argument
70 ** ParseARG_STORE Code to store %extra_argument into yypParser
71 ** ParseARG_FETCH Code to extract %extra_argument from yypParser
72 ** YYNSTATE the combined number of states.
73 ** YYNRULE the number of rules in the grammar
74 ** YYERRORSYMBOL is the code number of the error symbol. If not
75 ** defined, then do no error processing.
78 #define YY_NO_ACTION (YYNSTATE+YYNRULE+2)
79 #define YY_ACCEPT_ACTION (YYNSTATE+YYNRULE+1)
80 #define YY_ERROR_ACTION (YYNSTATE+YYNRULE)
82 /* The yyzerominor constant is used to initialize instances of
83 ** YYMINORTYPE objects to zero. */
84 static const YYMINORTYPE yyzerominor = { 0 };
86 /* Define the yytestcase() macro to be a no-op if is not already defined
87 ** otherwise.
89 ** Applications can choose to define yytestcase() in the %include section
90 ** to a macro that can assist in verifying code coverage. For production
91 ** code the yytestcase() macro should be turned off. But it is useful
92 ** for testing.
94 #ifndef yytestcase
95 # define yytestcase(X)
96 #endif
98 /* Next are the tables used to determine what action to take based on the
99 ** current state and lookahead token. These tables are used to implement
100 ** functions that take a state number and lookahead value and return an
101 ** action integer.
103 ** Suppose the action integer is N. Then the action is determined as
104 ** follows
106 ** 0 <= N < YYNSTATE Shift N. That is, push the lookahead
107 ** token onto the stack and goto state N.
109 ** YYNSTATE <= N < YYNSTATE+YYNRULE Reduce by rule N-YYNSTATE.
111 ** N == YYNSTATE+YYNRULE A syntax error has occurred.
113 ** N == YYNSTATE+YYNRULE+1 The parser accepts its input.
115 ** N == YYNSTATE+YYNRULE+2 No such action. Denotes unused
116 ** slots in the yy_action[] table.
118 ** The action table is constructed as a single large table named yy_action[].
119 ** Given state S and lookahead X, the action is computed as
121 ** yy_action[ yy_shift_ofst[S] + X ]
123 ** If the index value yy_shift_ofst[S]+X is out of range or if the value
124 ** yy_lookahead[yy_shift_ofst[S]+X] is not equal to X or if yy_shift_ofst[S]
125 ** is equal to YY_SHIFT_USE_DFLT, it means that the action is not in the table
126 ** and that yy_default[S] should be used instead.
128 ** The formula above is for computing the action when the lookahead is
129 ** a terminal symbol. If the lookahead is a non-terminal (as occurs after
130 ** a reduce action) then the yy_reduce_ofst[] array is used in place of
131 ** the yy_shift_ofst[] array and YY_REDUCE_USE_DFLT is used in place of
132 ** YY_SHIFT_USE_DFLT.
134 ** The following are the tables generated in this section:
136 ** yy_action[] A single table containing all actions.
137 ** yy_lookahead[] A table containing the lookahead for each entry in
138 ** yy_action. Used to detect hash collisions.
139 ** yy_shift_ofst[] For each state, the offset into yy_action for
140 ** shifting terminals.
141 ** yy_reduce_ofst[] For each state, the offset into yy_action for
142 ** shifting non-terminals after a reduce.
143 ** yy_default[] Default action for each state.
146 #define YY_SZ_ACTTAB (int)(sizeof(yy_action)/sizeof(yy_action[0]))
148 /* The next table maps tokens into fallback tokens. If a construct
149 ** like the following:
151 ** %fallback ID X Y Z.
153 ** appears in the grammar, then ID becomes a fallback token for X, Y,
154 ** and Z. Whenever one of the tokens X, Y, or Z is input to the parser
155 ** but it does not parse, the type of the token is changed to ID and
156 ** the parse is retried before an error is thrown.
158 #ifdef YYFALLBACK
159 static const YYCODETYPE yyFallback[] = {
162 #endif /* YYFALLBACK */
164 /* The following structure represents a single element of the
165 ** parser's stack. Information stored includes:
167 ** + The state number for the parser at this level of the stack.
169 ** + The value of the token stored at this level of the stack.
170 ** (In other words, the "major" token.)
172 ** + The semantic value stored at this level of the stack. This is
173 ** the information used by the action routines in the grammar.
174 ** It is sometimes called the "minor" token.
176 struct yyStackEntry {
177 YYACTIONTYPE stateno; /* The state-number */
178 YYCODETYPE major; /* The major token value. This is the code
179 ** number for the token at this stack level */
180 YYMINORTYPE minor; /* The user-supplied minor token value. This
181 ** is the value of the token */
183 typedef struct yyStackEntry yyStackEntry;
185 /* The state of the parser is completely contained in an instance of
186 ** the following structure */
187 struct yyParser {
188 int yyidx; /* Index of top element in stack */
189 #ifdef YYTRACKMAXSTACKDEPTH
190 int yyidxMax; /* Maximum value of yyidx */
191 #endif
192 int yyerrcnt; /* Shifts left before out of the error */
193 ParseARG_SDECL /* A place to hold %extra_argument */
194 #if YYSTACKDEPTH<=0
195 int yystksz; /* Current side of the stack */
196 yyStackEntry *yystack; /* The parser's stack */
197 #else
198 yyStackEntry yystack[YYSTACKDEPTH]; /* The parser's stack */
199 #endif
201 typedef struct yyParser yyParser;
203 #ifndef NDEBUG
204 #include <stdio.h>
205 static FILE *yyTraceFILE = 0;
206 static char *yyTracePrompt = 0;
207 #endif /* NDEBUG */
209 #ifndef NDEBUG
211 ** Turn parser tracing on by giving a stream to which to write the trace
212 ** and a prompt to preface each trace message. Tracing is turned off
213 ** by making either argument NULL
215 ** Inputs:
216 ** <ul>
217 ** <li> A FILE* to which trace output should be written.
218 ** If NULL, then tracing is turned off.
219 ** <li> A prefix string written at the beginning of every
220 ** line of trace output. If NULL, then tracing is
221 ** turned off.
222 ** </ul>
224 ** Outputs:
225 ** None.
227 void ParseTrace(FILE *TraceFILE, char *zTracePrompt){
228 yyTraceFILE = TraceFILE;
229 yyTracePrompt = zTracePrompt;
230 if( yyTraceFILE==0 ){
231 yyTracePrompt = 0;
232 }else if( yyTracePrompt==0 ){
233 yyTraceFILE = 0;
236 #endif /* NDEBUG */
238 #ifndef NDEBUG
239 /* For tracing shifts, the names of all terminals and nonterminals
240 ** are required. The following table supplies these names */
241 static const char *const yyTokenName[] = {
244 #endif /* NDEBUG */
246 #ifndef NDEBUG
247 /* For tracing reduce actions, the names of all rules are required.
249 static const char *const yyRuleName[] = {
252 #endif /* NDEBUG */
255 #if YYSTACKDEPTH<=0
257 ** Try to increase the size of the parser stack.
259 static void yyGrowStack(yyParser *p){
260 int newSize;
261 yyStackEntry *pNew;
263 newSize = p->yystksz*2 + 100;
264 pNew = realloc(p->yystack, newSize*sizeof(pNew[0]));
265 if( pNew ){
266 p->yystack = pNew;
267 p->yystksz = newSize;
268 #ifndef NDEBUG
269 if( yyTraceFILE ){
270 fprintf(yyTraceFILE,"%sStack grows to %d entries!\n",
271 yyTracePrompt, p->yystksz);
273 #endif
276 #endif
279 ** This function allocates a new parser.
280 ** The only argument is a pointer to a function which works like
281 ** malloc.
283 ** Inputs:
284 ** A pointer to the function used to allocate memory.
286 ** Outputs:
287 ** A pointer to a parser. This pointer is used in subsequent calls
288 ** to Parse and ParseFree.
290 void *ParseAlloc(void *(*mallocProc)(gsize)){
291 yyParser *pParser;
292 pParser = (yyParser*)(*mallocProc)( (gsize)sizeof(yyParser) );
293 if( pParser ){
294 pParser->yyidx = -1;
295 #ifdef YYTRACKMAXSTACKDEPTH
296 pParser->yyidxMax = 0;
297 #endif
298 #if YYSTACKDEPTH<=0
299 pParser->yystack = NULL;
300 pParser->yystksz = 0;
301 yyGrowStack(pParser);
302 #endif
304 return pParser;
307 /* The following function deletes the value associated with a
308 ** symbol. The symbol can be either a terminal or nonterminal.
309 ** "yymajor" is the symbol code, and "yypminor" is a pointer to
310 ** the value.
312 static void yy_destructor(yyParser *yypParser, YYCODETYPE yymajor, YYMINORTYPE *yypminor){
313 ParseARG_FETCH;
314 switch( yymajor ){
315 /* Here is inserted the actions which take place when a
316 ** terminal or non-terminal is destroyed. This can happen
317 ** when the symbol is popped from the stack during a
318 ** reduce or during error processing or when a parser is
319 ** being destroyed before it is finished parsing.
321 ** Note: during a reduce, the only symbols destroyed are those
322 ** which appear on the RHS of the rule, but which are not used
323 ** inside the C code.
326 default: break; /* If no destructor action specified: do nothing */
331 ** Pop the parser's stack once.
333 ** If there is a destructor routine associated with the token which
334 ** is popped from the stack, then call it.
336 ** Return the major token number for the symbol popped.
338 static int yy_pop_parser_stack(yyParser *pParser){
339 YYCODETYPE yymajor;
340 yyStackEntry *yytos;
342 if( pParser->yyidx<0 ){
343 return 0;
345 yytos = &pParser->yystack[pParser->yyidx];
346 #ifndef NDEBUG
347 if( yyTraceFILE && pParser->yyidx>=0 ){
348 fprintf(yyTraceFILE,"%sPopping %s\n",
349 yyTracePrompt,
350 yyTokenName[yytos->major]);
352 #endif
353 yymajor = yytos->major;
354 yy_destructor(pParser, yymajor, &yytos->minor);
355 pParser->yyidx--;
356 return yymajor;
360 ** Deallocate and destroy a parser. Destructors are all called for
361 ** all stack elements before shutting the parser down.
363 ** Inputs:
364 ** <ul>
365 ** <li> A pointer to the parser. This should be a pointer
366 ** obtained from ParseAlloc.
367 ** <li> A pointer to a function used to reclaim memory obtained
368 ** from malloc.
369 ** </ul>
371 void ParseFree(
372 void *p, /* The parser to be deleted */
373 void (*freeProc)(void*) /* Function used to reclaim memory */
375 yyParser *pParser = (yyParser*)p;
376 if( pParser==0 ){
377 return;
379 while( pParser->yyidx>=0 ){
380 yy_pop_parser_stack(pParser);
382 #if YYSTACKDEPTH<=0
383 free(pParser->yystack);
384 #endif
385 (*freeProc)((void*)pParser);
389 ** Return the peak depth of the stack for a parser.
391 #ifdef YYTRACKMAXSTACKDEPTH
392 int ParseStackPeak(void *p){
393 yyParser *pParser = (yyParser*)p;
394 return pParser->yyidxMax;
396 #endif
399 ** Find the appropriate action for a parser given the terminal
400 ** look-ahead token iLookAhead.
402 ** If the look-ahead token is YYNOCODE, then check to see if the action is
403 ** independent of the look-ahead. If it is, return the action, otherwise
404 ** return YY_NO_ACTION.
406 static int yy_find_shift_action(
407 yyParser *pParser, /* The parser */
408 YYCODETYPE iLookAhead /* The look-ahead token */
410 int i;
411 int stateno = pParser->yystack[pParser->yyidx].stateno;
413 if( stateno>YY_SHIFT_MAX
414 || (i = yy_shift_ofst[stateno])==YY_SHIFT_USE_DFLT ){
415 return yy_default[stateno];
417 assert( iLookAhead!=YYNOCODE );
418 i += iLookAhead;
419 if( i<0 || i>=YY_SZ_ACTTAB || yy_lookahead[i]!=iLookAhead ){
420 if( iLookAhead>0 ){
421 #ifdef YYFALLBACK
422 YYCODETYPE iFallback; /* Fallback token */
423 if( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0])
424 && (iFallback = yyFallback[iLookAhead])!=0 ){
425 #ifndef NDEBUG
426 if( yyTraceFILE ){
427 fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n",
428 yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]);
430 #endif
431 return yy_find_shift_action(pParser, iFallback);
433 #endif
434 #ifdef YYWILDCARD
436 int j = i - iLookAhead + YYWILDCARD;
437 if( j>=0 && j<YY_SZ_ACTTAB && yy_lookahead[j]==YYWILDCARD ){
438 #ifndef NDEBUG
439 if( yyTraceFILE ){
440 fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n",
441 yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[YYWILDCARD]);
443 #endif /* NDEBUG */
444 return yy_action[j];
447 #endif /* YYWILDCARD */
449 return yy_default[stateno];
450 }else{
451 return yy_action[i];
456 ** Find the appropriate action for a parser given the non-terminal
457 ** look-ahead token iLookAhead.
459 ** If the look-ahead token is YYNOCODE, then check to see if the action is
460 ** independent of the look-ahead. If it is, return the action, otherwise
461 ** return YY_NO_ACTION.
463 static int yy_find_reduce_action(
464 int stateno, /* Current state number */
465 YYCODETYPE iLookAhead /* The look-ahead token */
467 int i;
468 #ifdef YYERRORSYMBOL
469 if( stateno>YY_REDUCE_MAX ){
470 return yy_default[stateno];
472 #else
473 assert( stateno<=YY_REDUCE_MAX );
474 #endif
475 i = yy_reduce_ofst[stateno];
476 assert( i!=YY_REDUCE_USE_DFLT );
477 assert( iLookAhead!=YYNOCODE );
478 i += iLookAhead;
479 #ifdef YYERRORSYMBOL
480 if( i<0 || i>=YY_SZ_ACTTAB || yy_lookahead[i]!=iLookAhead ){
481 return yy_default[stateno];
483 #else
484 assert( i>=0 && i<YY_SZ_ACTTAB );
485 assert( yy_lookahead[i]==iLookAhead );
486 #endif
487 return yy_action[i];
491 ** The following routine is called if the stack overflows.
493 static void yyStackOverflow(yyParser *yypParser, YYMINORTYPE *yypMinor _U_){
494 ParseARG_FETCH;
495 yypParser->yyidx--;
496 #ifndef NDEBUG
497 if( yyTraceFILE ){
498 fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt);
500 #endif
501 while( yypParser->yyidx>=0 ) {
502 yy_pop_parser_stack(yypParser);
504 /* Here code is inserted which will execute if the parser
505 ** stack every overflows */
507 ParseARG_STORE; /* Suppress warning about unused %extra_argument var */
511 ** Perform a shift action.
513 static void yy_shift(
514 yyParser *yypParser, /* The parser to be shifted */
515 int yyNewState, /* The new state to shift in */
516 int yyMajor, /* The major token to shift in */
517 YYMINORTYPE *yypMinor /* Pointer to the minor token to shift in */
519 yyStackEntry *yytos;
520 yypParser->yyidx++;
521 #ifdef YYTRACKMAXSTACKDEPTH
522 if( yypParser->yyidx>yypParser->yyidxMax ){
523 yypParser->yyidxMax = yypParser->yyidx;
525 #endif
526 #if YYSTACKDEPTH>0
527 if( yypParser->yyidx>=YYSTACKDEPTH ){
528 yyStackOverflow(yypParser, yypMinor);
529 return;
531 #else
532 if( yypParser->yyidx>=yypParser->yystksz ){
533 yyGrowStack(yypParser);
534 if( yypParser->yyidx>=yypParser->yystksz ){
535 yyStackOverflow(yypParser, yypMinor);
536 return;
539 #endif
540 yytos = &yypParser->yystack[yypParser->yyidx];
541 yytos->stateno = (YYACTIONTYPE)yyNewState;
542 yytos->major = (YYCODETYPE)yyMajor;
543 yytos->minor = *yypMinor;
544 #ifndef NDEBUG
545 if( yyTraceFILE && yypParser->yyidx>0 ){
546 int i;
547 fprintf(yyTraceFILE,"%sShift %d\n",yyTracePrompt,yyNewState);
548 fprintf(yyTraceFILE,"%sStack:",yyTracePrompt);
549 for(i=1; i<=yypParser->yyidx; i++)
550 fprintf(yyTraceFILE," %s",yyTokenName[yypParser->yystack[i].major]);
551 fprintf(yyTraceFILE,"\n");
553 #endif
556 /* The following table contains information about every rule that
557 ** is used during the reduce.
559 static const struct {
560 YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */
561 unsigned char nrhs; /* Number of right-hand side symbols in the rule */
562 } yyRuleInfo[] = {
566 static void yy_accept(yyParser *yypParser); /* Forward declaration */
569 ** Perform a reduce action and the shift that must immediately
570 ** follow the reduce.
572 static void yy_reduce(
573 yyParser *yypParser, /* The parser */
574 int yyruleno /* Number of the rule by which to reduce */
576 int yygoto; /* The next state */
577 int yyact; /* The next action */
578 YYMINORTYPE yygotominor; /* The LHS of the rule reduced */
579 yyStackEntry *yymsp; /* The top of the parser's stack */
580 int yysize; /* Amount to pop the stack */
581 ParseARG_FETCH;
582 yymsp = &yypParser->yystack[yypParser->yyidx];
583 #ifndef NDEBUG
584 if( yyTraceFILE && yyruleno>=0
585 && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){
586 fprintf(yyTraceFILE, "%sReduce [%s].\n", yyTracePrompt,
587 yyRuleName[yyruleno]);
589 #endif /* NDEBUG */
591 /* Silence complaints from purify about yygotominor being uninitialized
592 ** in some cases when it is copied into the stack after the following
593 ** switch. yygotominor is uninitialized when a rule reduces that does
594 ** not set the value of its left-hand side nonterminal. Leaving the
595 ** value of the nonterminal uninitialized is utterly harmless as long
596 ** as the value is never used. So really the only thing this code
597 ** accomplishes is to quieten purify.
599 ** 2007-01-16: The wireshark project (www.wireshark.org) reports that
600 ** without this code, their parser segfaults. I'm not sure what there
601 ** parser is doing to make this happen. This is the second bug report
602 ** from wireshark this week. Clearly they are stressing Lemon in ways
603 ** that it has not been previously stressed... (SQLite ticket #2172)
605 /*memset(&yygotominor, 0, sizeof(yygotominor));*/
606 yygotominor = yyzerominor;
607 switch( yyruleno ){
608 /* Beginning here are the reduction cases. A typical example
609 ** follows:
610 ** case 0:
611 ** #line <lineno> <grammarfile>
612 ** { ... } // User supplied code
613 ** #line <lineno> <thisfile>
614 ** break;
618 yygoto = yyRuleInfo[yyruleno].lhs;
619 yysize = yyRuleInfo[yyruleno].nrhs;
620 yypParser->yyidx -= yysize;
621 yyact = yy_find_reduce_action(yymsp[-yysize].stateno,(YYCODETYPE)yygoto);
622 if( yyact < YYNSTATE ){
623 #ifdef NDEBUG
624 /* If we are not debugging and the reduce action popped at least
625 ** one element off the stack, then we can push the new element back
626 ** onto the stack here, and skip the stack overflow test in yy_shift().
627 ** That gives a significant speed improvement. */
628 if( yysize ){
629 yypParser->yyidx++;
630 yymsp -= yysize-1;
631 yymsp->stateno = (YYACTIONTYPE)yyact;
632 yymsp->major = (YYCODETYPE)yygoto;
633 yymsp->minor = yygotominor;
634 }else
635 #endif
637 yy_shift(yypParser,yyact,yygoto,&yygotominor);
639 }else{
640 assert( yyact == YYNSTATE + YYNRULE + 1 );
641 yy_accept(yypParser);
646 ** The following code executes when the parse fails
648 static void yy_parse_failed(
649 yyParser *yypParser /* The parser */
651 ParseARG_FETCH;
652 #ifndef NDEBUG
653 if( yyTraceFILE ){
654 fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt);
656 #endif
657 while( yypParser->yyidx>=0 ) {
658 yy_pop_parser_stack(yypParser);
660 /* Here code is inserted which will be executed whenever the
661 ** parser fails */
663 ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
667 ** The following code executes when a syntax error first occurs.
669 static void yy_syntax_error(
670 yyParser *yypParser _U_, /* The parser */
671 int yymajor _U_, /* The major type of the error token */
672 YYMINORTYPE yyminor /* The minor type of the error token */
674 ParseARG_FETCH;
675 #define TOKEN (yyminor.yy0)
677 ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
681 ** The following is executed when the parser accepts
683 static void yy_accept(
684 yyParser *yypParser /* The parser */
686 ParseARG_FETCH;
687 #ifndef NDEBUG
688 if( yyTraceFILE ){
689 fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt);
691 #endif
692 while( yypParser->yyidx>=0 ){
693 yy_pop_parser_stack(yypParser);
695 /* Here code is inserted which will be executed whenever the
696 ** parser accepts */
698 ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
701 /* The main parser program.
702 ** The first argument is a pointer to a structure obtained from
703 ** "ParseAlloc" which describes the current state of the parser.
704 ** The second argument is the major token number. The third is
705 ** the minor token. The fourth optional argument is whatever the
706 ** user wants (and specified in the grammar) and is available for
707 ** use by the action routines.
709 ** Inputs:
710 ** <ul>
711 ** <li> A pointer to the parser (an opaque structure.)
712 ** <li> The major token number.
713 ** <li> The minor token number.
714 ** <li> An option argument of a grammar-specified type.
715 ** </ul>
717 ** Outputs:
718 ** None.
720 void Parse(
721 void *yyp, /* The parser */
722 int yymajor, /* The major token code number */
723 ParseTOKENTYPE yyminor /* The value for the token */
724 ParseARG_PDECL /* Optional %extra_argument parameter */
726 YYMINORTYPE yyminorunion;
727 int yyact; /* The parser action. */
728 int yyendofinput; /* True if we are at the end of input */
729 #ifdef YYERRORSYMBOL
730 int yyerrorhit = 0; /* True if yymajor has invoked an error */
731 #endif
732 yyParser *yypParser; /* The parser */
734 /* (re)initialize the parser, if necessary */
735 yypParser = (yyParser*)yyp;
736 if( yypParser->yyidx<0 ){
737 #if YYSTACKDEPTH<=0
738 if( yypParser->yystksz <=0 ){
739 /*memset(&yyminorunion, 0, sizeof(yyminorunion));*/
740 yyminorunion = yyzerominor;
741 yyStackOverflow(yypParser, &yyminorunion);
742 return;
744 #endif
745 yypParser->yyidx = 0;
746 yypParser->yyerrcnt = -1;
747 yypParser->yystack[0].stateno = 0;
748 yypParser->yystack[0].major = 0;
750 yyminorunion.yy0 = yyminor;
751 yyendofinput = (yymajor==0);
752 ParseARG_STORE;
754 #ifndef NDEBUG
755 if( yyTraceFILE ){
756 fprintf(yyTraceFILE,"%sInput %s\n",yyTracePrompt,yyTokenName[yymajor]);
758 #endif
761 yyact = yy_find_shift_action(yypParser,(YYCODETYPE)yymajor);
762 if( yyact<YYNSTATE ){
763 assert( !yyendofinput ); /* Impossible to shift the $ token */
764 yy_shift(yypParser,yyact,yymajor,&yyminorunion);
765 yypParser->yyerrcnt--;
766 yymajor = YYNOCODE;
767 }else if( yyact < YYNSTATE + YYNRULE ){
768 yy_reduce(yypParser,yyact-YYNSTATE);
769 }else{
770 #ifdef YYERRORSYMBOL
771 int yymx;
772 #endif
773 assert( yyact == YY_ERROR_ACTION );
774 #ifndef NDEBUG
775 if( yyTraceFILE ){
776 fprintf(yyTraceFILE,"%sSyntax Error!\n",yyTracePrompt);
778 #endif
779 #ifdef YYERRORSYMBOL
780 /* A syntax error has occurred.
781 ** The response to an error depends upon whether or not the
782 ** grammar defines an error token "ERROR".
784 ** This is what we do if the grammar does define ERROR:
786 ** * Call the %syntax_error function.
788 ** * Begin popping the stack until we enter a state where
789 ** it is legal to shift the error symbol, then shift
790 ** the error symbol.
792 ** * Set the error count to three.
794 ** * Begin accepting and shifting new tokens. No new error
795 ** processing will occur until three tokens have been
796 ** shifted successfully.
799 if( yypParser->yyerrcnt<0 ){
800 yy_syntax_error(yypParser,yymajor,yyminorunion);
802 yymx = yypParser->yystack[yypParser->yyidx].major;
803 if( yymx==YYERRORSYMBOL || yyerrorhit ){
804 #ifndef NDEBUG
805 if( yyTraceFILE ){
806 fprintf(yyTraceFILE,"%sDiscard input token %s\n",
807 yyTracePrompt,yyTokenName[yymajor]);
809 #endif
810 yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
811 yymajor = YYNOCODE;
812 }else{
813 while(
814 yypParser->yyidx >= 0 &&
815 yymx != YYERRORSYMBOL &&
816 (yyact = yy_find_reduce_action(
817 yypParser->yystack[yypParser->yyidx].stateno,
818 YYERRORSYMBOL)) >= YYNSTATE
820 yy_pop_parser_stack(yypParser);
822 if( yypParser->yyidx < 0 || yymajor==0 ){
823 yy_destructor(yypParser, (YYCODETYPE)yymajor,&yyminorunion);
824 yy_parse_failed(yypParser);
825 yymajor = YYNOCODE;
826 }else if( yymx!=YYERRORSYMBOL ){
827 YYMINORTYPE u2;
828 u2.YYERRSYMDT = 0;
829 yy_shift(yypParser,yyact,YYERRORSYMBOL,&u2);
832 yypParser->yyerrcnt = 3;
833 yyerrorhit = 1;
834 #else /* YYERRORSYMBOL is not defined */
835 /* This is what we do if the grammar does not define ERROR:
837 ** * Report an error message, and throw away the input token.
839 ** * If the input token is $, then fail the parse.
841 ** As before, subsequent error messages are suppressed until
842 ** three input tokens have been successfully shifted.
844 if( yypParser->yyerrcnt<=0 ){
845 yy_syntax_error(yypParser,yymajor,yyminorunion);
847 yypParser->yyerrcnt = 3;
848 yy_destructor(yypParser, (YYCODETYPE)yymajor,&yyminorunion);
849 if( yyendofinput ){
850 yy_parse_failed(yypParser);
852 yymajor = YYNOCODE;
853 #endif
855 }while( yymajor!=YYNOCODE && yypParser->yyidx>=0 );
856 return;