Debian Codegraph @

misc/lempar.c

raw symbols SCIP
1 /*
2 * My changes over the original lempar.c from SQLite are encased in
3 * #if __MOJOSHADER__ blocks. --ryan.
4 */
5 #ifndef __MOJOSHADER__
6 #define __MOJOSHADER__ 1
7 #endif
8
9 #if !__MOJOSHADER__
10 #define LEMON_SUPPORT_TRACING (!defined(NDEBUG))
11 #endif
12
13 #if __MOJOSHADER__
14 /* Driver template for the LEMON parser generator.
15 ** The original author(s) of lempar.c disclaim copyright to this source code.
16 ** However, changes made for MojoShader fall under the same license as the
17 ** rest of MojoShader. Please see the file LICENSE.txt in the source's root
18 ** directory.
19 */
20 #endif
21
22 /*
23 ** 2000-05-29
24 **
25 ** The author disclaims copyright to this source code. In place of
26 ** a legal notice, here is a blessing:
27 **
28 ** May you do good and not evil.
29 ** May you find forgiveness for yourself and forgive others.
30 ** May you share freely, never taking more than you give.
31 **
32 *************************************************************************
33 ** Driver template for the LEMON parser generator.
34 **
35 ** The "lemon" program processes an LALR(1) input grammar file, then uses
36 ** this template to construct a parser. The "lemon" program inserts text
37 ** at each "%%" line. Also, any "P-a-r-s-e" identifer prefix (without the
38 ** interstitial "-" characters) contained in this template is changed into
39 ** the value of the %name directive from the grammar. Otherwise, the content
40 ** of this template is copied straight through into the generate parser
41 ** source file.
42 **
43 ** The following is the concatenation of all %include directives from the
44 ** input grammar file:
45 */
46 /************ Begin %include sections from the grammar ************************/
47 %%
48 /**************** End of %include directives **********************************/
49 /* These constants specify the various numeric values for terminal symbols.
50 ***************** Begin token definitions *************************************/
51 %%
52 /**************** End token definitions ***************************************/
53
54 /* The next sections is a series of control #defines.
55 ** various aspects of the generated parser.
56 ** YYCODETYPE is the data type used to store the integer codes
57 ** that represent terminal and non-terminal symbols.
58 ** "unsigned char" is used if there are fewer than
59 ** 256 symbols. Larger types otherwise.
60 ** YYNOCODE is a number of type YYCODETYPE that is not used for
61 ** any terminal or nonterminal symbol.
62 ** YYFALLBACK If defined, this indicates that one or more tokens
63 ** (also known as: "terminal symbols") have fall-back
64 ** values which should be used if the original symbol
65 ** would not parse. This permits keywords to sometimes
66 ** be used as identifiers, for example.
67 ** YYACTIONTYPE is the data type used for "action codes" - numbers
68 ** that indicate what to do in response to the next
69 ** token.
70 ** ParseTOKENTYPE is the data type used for minor type for terminal
71 ** symbols. Background: A "minor type" is a semantic
72 ** value associated with a terminal or non-terminal
73 ** symbols. For example, for an "ID" terminal symbol,
74 ** the minor type might be the name of the identifier.
75 ** Each non-terminal can have a different minor type.
76 ** Terminal symbols all have the same minor type, though.
77 ** This macros defines the minor type for terminal
78 ** symbols.
79 ** YYMINORTYPE is the data type used for all minor types.
80 ** This is typically a union of many types, one of
81 ** which is ParseTOKENTYPE. The entry in the union
82 ** for terminal symbols is called "yy0".
83 ** YYSTACKDEPTH is the maximum depth of the parser's stack. If
84 ** zero the stack is dynamically sized using realloc()
85 ** ParseARG_SDECL A static variable declaration for the %extra_argument
86 ** ParseARG_PDECL A parameter declaration for the %extra_argument
87 ** ParseARG_PARAM Code to pass %extra_argument as a subroutine parameter
88 ** ParseARG_STORE Code to store %extra_argument into yypParser
89 ** ParseARG_FETCH Code to extract %extra_argument from yypParser
90 ** ParseCTX_* As ParseARG_ except for %extra_context
91 ** YYERRORSYMBOL is the code number of the error symbol. If not
92 ** defined, then do no error processing.
93 ** YYNSTATE the combined number of states.
94 ** YYNRULE the number of rules in the grammar
95 ** YYNTOKEN Number of terminal symbols
96 ** YY_MAX_SHIFT Maximum value for shift actions
97 ** YY_MIN_SHIFTREDUCE Minimum value for shift-reduce actions
98 ** YY_MAX_SHIFTREDUCE Maximum value for shift-reduce actions
99 ** YY_ERROR_ACTION The yy_action[] code for syntax error
100 ** YY_ACCEPT_ACTION The yy_action[] code for accept
101 ** YY_NO_ACTION The yy_action[] code for no-op
102 ** YY_MIN_REDUCE Minimum value for reduce actions
103 ** YY_MAX_REDUCE Maximum value for reduce actions
104 */
105 #ifndef INTERFACE
106 # define INTERFACE 1
107 #endif
108 /************* Begin control #defines *****************************************/
109 %%
110 /************* End control #defines *******************************************/
111 #define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0])))
112
113 /* Define the yytestcase() macro to be a no-op if is not already defined
114 ** otherwise.
115 **
116 ** Applications can choose to define yytestcase() in the %include section
117 ** to a macro that can assist in verifying code coverage. For production
118 ** code the yytestcase() macro should be turned off. But it is useful
119 ** for testing.
120 */
121 #ifndef yytestcase
122 # define yytestcase(X)
123 #endif
124
125
126 /* Next are the tables used to determine what action to take based on the
127 ** current state and lookahead token. These tables are used to implement
128 ** functions that take a state number and lookahead value and return an
129 ** action integer.
130 **
131 ** Suppose the action integer is N. Then the action is determined as
132 ** follows
133 **
134 ** 0 <= N <= YY_MAX_SHIFT Shift N. That is, push the lookahead
135 ** token onto the stack and goto state N.
136 **
137 ** N between YY_MIN_SHIFTREDUCE Shift to an arbitrary state then
138 ** and YY_MAX_SHIFTREDUCE reduce by rule N-YY_MIN_SHIFTREDUCE.
139 **
140 ** N == YY_ERROR_ACTION A syntax error has occurred.
141 **
142 ** N == YY_ACCEPT_ACTION The parser accepts its input.
143 **
144 ** N == YY_NO_ACTION No such action. Denotes unused
145 ** slots in the yy_action[] table.
146 **
147 ** N between YY_MIN_REDUCE Reduce by rule N-YY_MIN_REDUCE
148 ** and YY_MAX_REDUCE
149 **
150 ** The action table is constructed as a single large table named yy_action[].
151 ** Given state S and lookahead X, the action is computed as either:
152 **
153 ** (A) N = yy_action[ yy_shift_ofst[S] + X ]
154 ** (B) N = yy_default[S]
155 **
156 ** The (A) formula is preferred. The B formula is used instead if
157 ** yy_lookahead[yy_shift_ofst[S]+X] is not equal to X.
158 **
159 ** The formulas above are for computing the action when the lookahead is
160 ** a terminal symbol. If the lookahead is a non-terminal (as occurs after
161 ** a reduce action) then the yy_reduce_ofst[] array is used in place of
162 ** the yy_shift_ofst[] array.
163 **
164 ** The following are the tables generated in this section:
165 **
166 ** yy_action[] A single table containing all actions.
167 ** yy_lookahead[] A table containing the lookahead for each entry in
168 ** yy_action. Used to detect hash collisions.
169 ** yy_shift_ofst[] For each state, the offset into yy_action for
170 ** shifting terminals.
171 ** yy_reduce_ofst[] For each state, the offset into yy_action for
172 ** shifting non-terminals after a reduce.
173 ** yy_default[] Default action for each state.
174 **
175 *********** Begin parsing tables **********************************************/
176 %%
177 /********** End of lemon-generated parsing tables *****************************/
178
179 /* The next table maps tokens (terminal symbols) into fallback tokens.
180 ** If a construct like the following:
181 **
182 ** %fallback ID X Y Z.
183 **
184 ** appears in the grammar, then ID becomes a fallback token for X, Y,
185 ** and Z. Whenever one of the tokens X, Y, or Z is input to the parser
186 ** but it does not parse, the type of the token is changed to ID and
187 ** the parse is retried before an error is thrown.
188 **
189 ** This feature can be used, for example, to cause some keywords in a language
190 ** to revert to identifiers if they keyword does not apply in the context where
191 ** it appears.
192 */
193 #ifdef YYFALLBACK
194 static const YYCODETYPE yyFallback[] = {
195 %%
196 };
197 #endif /* YYFALLBACK */
198
199 /* The following structure represents a single element of the
200 ** parser's stack. Information stored includes:
201 **
202 ** + The state number for the parser at this level of the stack.
203 **
204 ** + The value of the token stored at this level of the stack.
205 ** (In other words, the "major" token.)
206 **
207 ** + The semantic value stored at this level of the stack. This is
208 ** the information used by the action routines in the grammar.
209 ** It is sometimes called the "minor" token.
210 **
211 ** After the "shift" half of a SHIFTREDUCE action, the stateno field
212 ** actually contains the reduce action for the second half of the
213 ** SHIFTREDUCE.
214 */
215 struct yyStackEntry {
216 YYACTIONTYPE stateno; /* The state-number, or reduce action in SHIFTREDUCE */
217 YYCODETYPE major; /* The major token value. This is the code
218 ** number for the token at this stack level */
219 YYMINORTYPE minor; /* The user-supplied minor token value. This
220 ** is the value of the token */
221 };
222 typedef struct yyStackEntry yyStackEntry;
223
224 /* The state of the parser is completely contained in an instance of
225 ** the following structure */
226 struct yyParser {
227 yyStackEntry *yytos; /* Pointer to top element of the stack */
228 #ifdef YYTRACKMAXSTACKDEPTH
229 int yyhwm; /* High-water mark of the stack */
230 #endif
231 #ifndef YYNOERRORRECOVERY
232 int yyerrcnt; /* Shifts left before out of the error */
233 #endif
234 ParseARG_SDECL /* A place to hold %extra_argument */
235 ParseCTX_SDECL /* A place to hold %extra_context */
236 #if YYSTACKDEPTH<=0
237 int yystksz; /* Current side of the stack */
238 yyStackEntry *yystack; /* The parser's stack */
239 yyStackEntry yystk0; /* First stack entry */
240 #else
241 yyStackEntry yystack[YYSTACKDEPTH]; /* The parser's stack */
242 yyStackEntry *yystackEnd; /* Last entry in the stack */
243 #endif
244 };
245 typedef struct yyParser yyParser;
246
247 #include <assert.h>
248 #if LEMON_SUPPORT_TRACING /* __MOJOSHADER__ */
249 #include <stdio.h>
250 static FILE *yyTraceFILE = 0;
251 static char *yyTracePrompt = 0;
252 #endif /* NDEBUG */
253
254 #if LEMON_SUPPORT_TRACING /* __MOJOSHADER__ */
255 /*
256 ** Turn parser tracing on by giving a stream to which to write the trace
257 ** and a prompt to preface each trace message. Tracing is turned off
258 ** by making either argument NULL
259 **
260 ** Inputs:
261 ** <ul>
262 ** <li> A FILE* to which trace output should be written.
263 ** If NULL, then tracing is turned off.
264 ** <li> A prefix string written at the beginning of every
265 ** line of trace output. If NULL, then tracing is
266 ** turned off.
267 ** </ul>
268 **
269 ** Outputs:
270 ** None.
271 */
272 #if __MOJOSHADER__
273 static
274 #endif
275 void ParseTrace(FILE *TraceFILE, char *zTracePrompt){
276 yyTraceFILE = TraceFILE;
277 yyTracePrompt = zTracePrompt;
278 if( yyTraceFILE==0 ) yyTracePrompt = 0;
279 else if( yyTracePrompt==0 ) yyTraceFILE = 0;
280 }
281 #endif /* NDEBUG */
282
283 #if defined(YYCOVERAGE) || LEMON_SUPPORT_TRACING /* __MOJOSHADER__ */
284 /* For tracing shifts, the names of all terminals and nonterminals
285 ** are required. The following table supplies these names */
286 static const char *const yyTokenName[] = {
287 %%
288 };
289 #endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */
290
291 #if LEMON_SUPPORT_TRACING /* __MOJOSHADER__ */
292 /* For tracing reduce actions, the names of all rules are required.
293 */
294 static const char *const yyRuleName[] = {
295 %%
296 };
297 #endif /* NDEBUG */
298
299
300 #if YYSTACKDEPTH<=0
301 /*
302 ** Try to increase the size of the parser stack. Return the number
303 ** of errors. Return 0 on success.
304 */
305 static int yyGrowStack(yyParser *p){
306 int newSize;
307 int idx;
308 yyStackEntry *pNew;
309
310 newSize = p->yystksz*2 + 100;
311 idx = p->yytos ? (int)(p->yytos - p->yystack) : 0;
312 if( p->yystack==&p->yystk0 ){
313 pNew = malloc(newSize*sizeof(pNew[0]));
314 if( pNew ) pNew[0] = p->yystk0;
315 }else{
316 pNew = realloc(p->yystack, newSize*sizeof(pNew[0]));
317 }
318 if( pNew ){
319 p->yystack = pNew;
320 p->yytos = &p->yystack[idx];
321 #if LEMON_SUPPORT_TRACING /* __MOJOSHADER__ */
322 if( yyTraceFILE ){
323 fprintf(yyTraceFILE,"%sStack grows from %d to %d entries.\n",
324 yyTracePrompt, p->yystksz, newSize);
325 }
326 #endif
327 p->yystksz = newSize;
328 }
329 return pNew==0;
330 }
331 #endif
332
333 /* Datatype of the argument to the memory allocated passed as the
334 ** second argument to ParseAlloc() below. This can be changed by
335 ** putting an appropriate #define in the %include section of the input
336 ** grammar.
337 */
338 #ifndef YYMALLOCARGTYPE
339 # define YYMALLOCARGTYPE size_t
340 #endif
341
342 /* Initialize a new parser that has already been allocated.
343 */
344 void ParseInit(void *yypRawParser ParseCTX_PDECL){
345 yyParser *yypParser = (yyParser*)yypRawParser;
346 ParseCTX_STORE
347 #ifdef YYTRACKMAXSTACKDEPTH
348 yypParser->yyhwm = 0;
349 #endif
350 #if YYSTACKDEPTH<=0
351 yypParser->yytos = NULL;
352 yypParser->yystack = NULL;
353 yypParser->yystksz = 0;
354 if( yyGrowStack(yypParser) ){
355 yypParser->yystack = &yypParser->yystk0;
356 yypParser->yystksz = 1;
357 }
358 #endif
359 #ifndef YYNOERRORRECOVERY
360 yypParser->yyerrcnt = -1;
361 #endif
362 yypParser->yytos = yypParser->yystack;
363 yypParser->yystack[0].stateno = 0;
364 yypParser->yystack[0].major = 0;
365 #if YYSTACKDEPTH>0
366 yypParser->yystackEnd = &yypParser->yystack[YYSTACKDEPTH-1];
367 #endif
368 }
369
370 #ifndef Parse_ENGINEALWAYSONSTACK
371 /*
372 ** This function allocates a new parser.
373 ** The only argument is a pointer to a function which works like
374 ** malloc.
375 **
376 ** Inputs:
377 ** A pointer to the function used to allocate memory.
378 **
379 ** Outputs:
380 ** A pointer to a parser. This pointer is used in subsequent calls
381 ** to Parse and ParseFree.
382 */
383 #if __MOJOSHADER__
384 static void *ParseAlloc(void *(*mallocProc)(int,void *), void *malloc_data ParseCTX_PDECL){
385 yyParser *yypParser;
386 yypParser = (yyParser*)(*mallocProc)( (YYMALLOCARGTYPE)sizeof(yyParser), malloc_data );
387 if( yypParser ){
388 ParseCTX_STORE
389 ParseInit(yypParser ParseCTX_PARAM);
390 }
391 return (void*)yypParser;
392 }
393 #else
394 void *ParseAlloc(void *(*mallocProc)(YYMALLOCARGTYPE) ParseCTX_PDECL){
395 yyParser *yypParser;
396 yypParser = (yyParser*)(*mallocProc)( (YYMALLOCARGTYPE)sizeof(yyParser) );
397 if( yypParser ){
398 ParseCTX_STORE
399 ParseInit(yypParser ParseCTX_PARAM);
400 }
401 return (void*)yypParser;
402 }
403 #endif
404 #endif /* Parse_ENGINEALWAYSONSTACK */
405
406
407 /* The following function deletes the "minor type" or semantic value
408 ** associated with a symbol. The symbol can be either a terminal
409 ** or nonterminal. "yymajor" is the symbol code, and "yypminor" is
410 ** a pointer to the value to be deleted. The code used to do the
411 ** deletions is derived from the %destructor and/or %token_destructor
412 ** directives of the input grammar.
413 */
414 static void yy_destructor(
415 yyParser *yypParser, /* The parser */
416 YYCODETYPE yymajor, /* Type code for object to destroy */
417 YYMINORTYPE *yypminor /* The object to be destroyed */
418 ){
419 ParseARG_FETCH
420 ParseCTX_FETCH
421 switch( yymajor ){
422 /* Here is inserted the actions which take place when a
423 ** terminal or non-terminal is destroyed. This can happen
424 ** when the symbol is popped from the stack during a
425 ** reduce or during error processing or when a parser is
426 ** being destroyed before it is finished parsing.
427 **
428 ** Note: during a reduce, the only symbols destroyed are those
429 ** which appear on the RHS of the rule, but which are *not* used
430 ** inside the C code.
431 */
432 /********* Begin destructor definitions ***************************************/
433 %%
434 /********* End destructor definitions *****************************************/
435 default: break; /* If no destructor action specified: do nothing */
436 }
437 }
438
439 /*
440 ** Pop the parser's stack once.
441 **
442 ** If there is a destructor routine associated with the token which
443 ** is popped from the stack, then call it.
444 */
445 static void yy_pop_parser_stack(yyParser *pParser){
446 yyStackEntry *yytos;
447 assert( pParser->yytos!=0 );
448 assert( pParser->yytos > pParser->yystack );
449 yytos = pParser->yytos--;
450 #if LEMON_SUPPORT_TRACING /* __MOJOSHADER__ */
451 if( yyTraceFILE ){
452 fprintf(yyTraceFILE,"%sPopping %s\n",
453 yyTracePrompt,
454 yyTokenName[yytos->major]);
455 }
456 #endif
457 yy_destructor(pParser, yytos->major, &yytos->minor);
458 }
459
460 /*
461 ** Clear all secondary memory allocations from the parser
462 */
463 void ParseFinalize(void *p){
464 yyParser *pParser = (yyParser*)p;
465 while( pParser->yytos>pParser->yystack ) yy_pop_parser_stack(pParser);
466 #if YYSTACKDEPTH<=0
467 if( pParser->yystack!=&pParser->yystk0 ) free(pParser->yystack);
468 #endif
469 }
470
471 #ifndef Parse_ENGINEALWAYSONSTACK
472 /*
473 ** Deallocate and destroy a parser. Destructors are called for
474 ** all stack elements before shutting the parser down.
475 **
476 ** If the YYPARSEFREENEVERNULL macro exists (for example because it
477 ** is defined in a %include section of the input grammar) then it is
478 ** assumed that the input pointer is never NULL.
479 */
480 #if __MOJOSHADER__
481 static void ParseFree(
482 void *p, /* The parser to be deleted */
483 void (*freeProc)(void*,void*), /* Function used to reclaim memory */
484 void *malloc_data
485 ){
486 #ifndef YYPARSEFREENEVERNULL
487 if( p==0 ) return;
488 #endif
489 ParseFinalize(p);
490 (*freeProc)(p,malloc_data);
491 }
492 #else
493 void ParseFree(
494 void *p, /* The parser to be deleted */
495 void (*freeProc)(void*) /* Function used to reclaim memory */
496 ){
497 #ifndef YYPARSEFREENEVERNULL
498 if( p==0 ) return;
499 #endif
500 ParseFinalize(p);
501 (*freeProc)(p);
502 }
503 #endif
504 #endif /* Parse_ENGINEALWAYSONSTACK */
505
506 /*
507 ** Return the peak depth of the stack for a parser.
508 */
509 #ifdef YYTRACKMAXSTACKDEPTH
510 int ParseStackPeak(void *p){
511 yyParser *pParser = (yyParser*)p;
512 return pParser->yyhwm;
513 }
514 #endif
515
516 /* This array of booleans keeps track of the parser statement
517 ** coverage. The element yycoverage[X][Y] is set when the parser
518 ** is in state X and has a lookahead token Y. In a well-tested
519 ** systems, every element of this matrix should end up being set.
520 */
521 #if defined(YYCOVERAGE)
522 static unsigned char yycoverage[YYNSTATE][YYNTOKEN];
523 #endif
524
525 /*
526 ** Write into out a description of every state/lookahead combination that
527 **
528 ** (1) has not been used by the parser, and
529 ** (2) is not a syntax error.
530 **
531 ** Return the number of missed state/lookahead combinations.
532 */
533 #if defined(YYCOVERAGE)
534 int ParseCoverage(FILE *out){
535 int stateno, iLookAhead, i;
536 int nMissed = 0;
537 for(stateno=0; stateno<YYNSTATE; stateno++){
538 i = yy_shift_ofst[stateno];
539 for(iLookAhead=0; iLookAhead<YYNTOKEN; iLookAhead++){
540 if( yy_lookahead[i+iLookAhead]!=iLookAhead ) continue;
541 if( yycoverage[stateno][iLookAhead]==0 ) nMissed++;
542 if( out ){
543 fprintf(out,"State %d lookahead %s %s\n", stateno,
544 yyTokenName[iLookAhead],
545 yycoverage[stateno][iLookAhead] ? "ok" : "missed");
546 }
547 }
548 }
549 return nMissed;
550 }
551 #endif
552
553 /*
554 ** Find the appropriate action for a parser given the terminal
555 ** look-ahead token iLookAhead.
556 */
557 static YYACTIONTYPE yy_find_shift_action(
558 YYCODETYPE iLookAhead, /* The look-ahead token */
559 YYACTIONTYPE stateno /* Current state number */
560 ){
561 int i;
562
563 if( stateno>YY_MAX_SHIFT ) return stateno;
564 assert( stateno <= YY_SHIFT_COUNT );
565 #if defined(YYCOVERAGE)
566 yycoverage[stateno][iLookAhead] = 1;
567 #endif
568 do{
569 i = yy_shift_ofst[stateno];
570 assert( i>=0 );
571 assert( i<=YY_ACTTAB_COUNT );
572 assert( i+YYNTOKEN<=(int)YY_NLOOKAHEAD );
573 assert( iLookAhead!=YYNOCODE );
574 assert( iLookAhead < YYNTOKEN );
575 i += iLookAhead;
576 assert( i<(int)YY_NLOOKAHEAD );
577 if( yy_lookahead[i]!=iLookAhead ){
578 #ifdef YYFALLBACK
579 YYCODETYPE iFallback; /* Fallback token */
580 assert( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0]) );
581 iFallback = yyFallback[iLookAhead];
582 if( iFallback!=0 ){
583 #if LEMON_SUPPORT_TRACING /* __MOJOSHADER__ */
584 if( yyTraceFILE ){
585 fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n",
586 yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]);
587 }
588 #endif
589 assert( yyFallback[iFallback]==0 ); /* Fallback loop must terminate */
590 iLookAhead = iFallback;
591 continue;
592 }
593 #endif
594 #ifdef YYWILDCARD
595 {
596 int j = i - iLookAhead + YYWILDCARD;
597 assert( j<(int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0])) );
598 if( yy_lookahead[j]==YYWILDCARD && iLookAhead>0 ){
599 #if LEMON_SUPPORT_TRACING /* __MOJOSHADER__ */
600 if( yyTraceFILE ){
601 fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n",
602 yyTracePrompt, yyTokenName[iLookAhead],
603 yyTokenName[YYWILDCARD]);
604 }
605 #endif /* NDEBUG */
606 return yy_action[j];
607 }
608 }
609 #endif /* YYWILDCARD */
610 return yy_default[stateno];
611 }else{
612 assert( i>=0 && i<(int)(sizeof(yy_action)/sizeof(yy_action[0])) );
613 return yy_action[i];
614 }
615 }while(1);
616 }
617
618 /*
619 ** Find the appropriate action for a parser given the non-terminal
620 ** look-ahead token iLookAhead.
621 */
622 static YYACTIONTYPE yy_find_reduce_action(
623 YYACTIONTYPE stateno, /* Current state number */
624 YYCODETYPE iLookAhead /* The look-ahead token */
625 ){
626 int i;
627 #ifdef YYERRORSYMBOL
628 if( stateno>YY_REDUCE_COUNT ){
629 return yy_default[stateno];
630 }
631 #else
632 assert( stateno<=YY_REDUCE_COUNT );
633 #endif
634 i = yy_reduce_ofst[stateno];
635 assert( iLookAhead!=YYNOCODE );
636 i += iLookAhead;
637 #ifdef YYERRORSYMBOL
638 if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){
639 return yy_default[stateno];
640 }
641 #else
642 assert( i>=0 && i<YY_ACTTAB_COUNT );
643 assert( yy_lookahead[i]==iLookAhead );
644 #endif
645 return yy_action[i];
646 }
647
648 /*
649 ** The following routine is called if the stack overflows.
650 */
651 static void yyStackOverflow(yyParser *yypParser){
652 ParseARG_FETCH
653 ParseCTX_FETCH
654 #if LEMON_SUPPORT_TRACING /* __MOJOSHADER__ */
655 if( yyTraceFILE ){
656 fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt);
657 }
658 #endif
659 while( yypParser->yytos>yypParser->yystack ) yy_pop_parser_stack(yypParser);
660 /* Here code is inserted which will execute if the parser
661 ** stack every overflows */
662 /******** Begin %stack_overflow code ******************************************/
663 %%
664 /******** End %stack_overflow code ********************************************/
665 ParseARG_STORE /* Suppress warning about unused %extra_argument var */
666 ParseCTX_STORE
667 }
668
669 /*
670 ** Print tracing information for a SHIFT action
671 */
672 #if LEMON_SUPPORT_TRACING /* __MOJOSHADER__ */
673 static void yyTraceShift(yyParser *yypParser, int yyNewState, const char *zTag){
674 if( yyTraceFILE ){
675 if( yyNewState<YYNSTATE ){
676 fprintf(yyTraceFILE,"%s%s '%s', go to state %d\n",
677 yyTracePrompt, zTag, yyTokenName[yypParser->yytos->major],
678 yyNewState);
679 }else{
680 fprintf(yyTraceFILE,"%s%s '%s', pending reduce %d\n",
681 yyTracePrompt, zTag, yyTokenName[yypParser->yytos->major],
682 yyNewState - YY_MIN_REDUCE);
683 }
684 }
685 }
686 #else
687 # define yyTraceShift(X,Y,Z)
688 #endif
689
690 /*
691 ** Perform a shift action.
692 */
693 static void yy_shift(
694 yyParser *yypParser, /* The parser to be shifted */
695 YYACTIONTYPE yyNewState, /* The new state to shift in */
696 YYCODETYPE yyMajor, /* The major token to shift in */
697 ParseTOKENTYPE yyMinor /* The minor token to shift in */
698 ){
699 yyStackEntry *yytos;
700 yypParser->yytos++;
701 #ifdef YYTRACKMAXSTACKDEPTH
702 if( (int)(yypParser->yytos - yypParser->yystack)>yypParser->yyhwm ){
703 yypParser->yyhwm++;
704 assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack) );
705 }
706 #endif
707 #if YYSTACKDEPTH>0
708 if( yypParser->yytos>yypParser->yystackEnd ){
709 yypParser->yytos--;
710 yyStackOverflow(yypParser);
711 return;
712 }
713 #else
714 if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz] ){
715 if( yyGrowStack(yypParser) ){
716 yypParser->yytos--;
717 yyStackOverflow(yypParser);
718 return;
719 }
720 }
721 #endif
722 if( yyNewState > YY_MAX_SHIFT ){
723 yyNewState += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE;
724 }
725 yytos = yypParser->yytos;
726 yytos->stateno = yyNewState;
727 yytos->major = yyMajor;
728 yytos->minor.yy0 = yyMinor;
729 yyTraceShift(yypParser, yyNewState, "Shift");
730 }
731
732 /* For rule J, yyRuleInfoLhs[J] contains the symbol on the left-hand side
733 ** of that rule */
734 static const YYCODETYPE yyRuleInfoLhs[] = {
735 %%
736 };
737
738 /* For rule J, yyRuleInfoNRhs[J] contains the negative of the number
739 ** of symbols on the right-hand side of that rule. */
740 static const signed char yyRuleInfoNRhs[] = {
741 %%
742 };
743
744 static void yy_accept(yyParser*); /* Forward Declaration */
745
746 /*
747 ** Perform a reduce action and the shift that must immediately
748 ** follow the reduce.
749 **
750 ** The yyLookahead and yyLookaheadToken parameters provide reduce actions
751 ** access to the lookahead token (if any). The yyLookahead will be YYNOCODE
752 ** if the lookahead token has already been consumed. As this procedure is
753 ** only called from one place, optimizing compilers will in-line it, which
754 ** means that the extra parameters have no performance impact.
755 */
756 static YYACTIONTYPE yy_reduce(
757 yyParser *yypParser, /* The parser */
758 unsigned int yyruleno, /* Number of the rule by which to reduce */
759 int yyLookahead, /* Lookahead token, or YYNOCODE if none */
760 ParseTOKENTYPE yyLookaheadToken /* Value of the lookahead token */
761 ParseCTX_PDECL /* %extra_context */
762 ){
763 int yygoto; /* The next state */
764 YYACTIONTYPE yyact; /* The next action */
765 yyStackEntry *yymsp; /* The top of the parser's stack */
766 int yysize; /* Amount to pop the stack */
767 ParseARG_FETCH
768 (void)yyLookahead;
769 (void)yyLookaheadToken;
770 yymsp = yypParser->yytos;
771
772 switch( yyruleno ){
773 /* Beginning here are the reduction cases. A typical example
774 ** follows:
775 ** case 0:
776 ** #line <lineno> <grammarfile>
777 ** { ... } // User supplied code
778 ** #line <lineno> <thisfile>
779 ** break;
780 */
781 /********** Begin reduce actions **********************************************/
782 %%
783 /********** End reduce actions ************************************************/
784 };
785 assert( yyruleno<sizeof(yyRuleInfoLhs)/sizeof(yyRuleInfoLhs[0]) );
786 yygoto = yyRuleInfoLhs[yyruleno];
787 yysize = yyRuleInfoNRhs[yyruleno];
788 yyact = yy_find_reduce_action(yymsp[yysize].stateno,(YYCODETYPE)yygoto);
789
790 /* There are no SHIFTREDUCE actions on nonterminals because the table
791 ** generator has simplified them to pure REDUCE actions. */
792 assert( !(yyact>YY_MAX_SHIFT && yyact<=YY_MAX_SHIFTREDUCE) );
793
794 /* It is not possible for a REDUCE to be followed by an error */
795 assert( yyact!=YY_ERROR_ACTION );
796
797 yymsp += yysize+1;
798 yypParser->yytos = yymsp;
799 yymsp->stateno = (YYACTIONTYPE)yyact;
800 yymsp->major = (YYCODETYPE)yygoto;
801 yyTraceShift(yypParser, yyact, "... then shift");
802 return yyact;
803 }
804
805 /*
806 ** The following code executes when the parse fails
807 */
808 #ifndef YYNOERRORRECOVERY
809 static void yy_parse_failed(
810 yyParser *yypParser /* The parser */
811 ){
812 ParseARG_FETCH
813 ParseCTX_FETCH
814 #if LEMON_SUPPORT_TRACING /* __MOJOSHADER__ */
815 if( yyTraceFILE ){
816 fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt);
817 }
818 #endif
819 while( yypParser->yytos>yypParser->yystack ) yy_pop_parser_stack(yypParser);
820 /* Here code is inserted which will be executed whenever the
821 ** parser fails */
822 /************ Begin %parse_failure code ***************************************/
823 %%
824 /************ End %parse_failure code *****************************************/
825 ParseARG_STORE /* Suppress warning about unused %extra_argument variable */
826 ParseCTX_STORE
827 }
828 #endif /* YYNOERRORRECOVERY */
829
830 /*
831 ** The following code executes when a syntax error first occurs.
832 */
833 static void yy_syntax_error(
834 yyParser *yypParser, /* The parser */
835 int yymajor, /* The major type of the error token */
836 ParseTOKENTYPE yyminor /* The minor type of the error token */
837 ){
838 ParseARG_FETCH
839 ParseCTX_FETCH
840 #define TOKEN yyminor
841 /************ Begin %syntax_error code ****************************************/
842 %%
843 /************ End %syntax_error code ******************************************/
844 ParseARG_STORE /* Suppress warning about unused %extra_argument variable */
845 ParseCTX_STORE
846 }
847
848 /*
849 ** The following is executed when the parser accepts
850 */
851 static void yy_accept(
852 yyParser *yypParser /* The parser */
853 ){
854 ParseARG_FETCH
855 ParseCTX_FETCH
856 #if LEMON_SUPPORT_TRACING /* __MOJOSHADER__ */
857 if( yyTraceFILE ){
858 fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt);
859 }
860 #endif
861 #ifndef YYNOERRORRECOVERY
862 yypParser->yyerrcnt = -1;
863 #endif
864 assert( yypParser->yytos==yypParser->yystack );
865 /* Here code is inserted which will be executed whenever the
866 ** parser accepts */
867 /*********** Begin %parse_accept code *****************************************/
868 %%
869 /*********** End %parse_accept code *******************************************/
870 ParseARG_STORE /* Suppress warning about unused %extra_argument variable */
871 ParseCTX_STORE
872 }
873
874 /* The main parser program.
875 ** The first argument is a pointer to a structure obtained from
876 ** "ParseAlloc" which describes the current state of the parser.
877 ** The second argument is the major token number. The third is
878 ** the minor token. The fourth optional argument is whatever the
879 ** user wants (and specified in the grammar) and is available for
880 ** use by the action routines.
881 **
882 ** Inputs:
883 ** <ul>
884 ** <li> A pointer to the parser (an opaque structure.)
885 ** <li> The major token number.
886 ** <li> The minor token number.
887 ** <li> An option argument of a grammar-specified type.
888 ** </ul>
889 **
890 ** Outputs:
891 ** None.
892 */
893 #if __MOJOSHADER__
894 static
895 #endif
896 void Parse(
897 void *yyp, /* The parser */
898 int yymajor, /* The major token code number */
899 ParseTOKENTYPE yyminor /* The value for the token */
900 ParseARG_PDECL /* Optional %extra_argument parameter */
901 ){
902 YYMINORTYPE yyminorunion;
903 YYACTIONTYPE yyact; /* The parser action. */
904 #if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY)
905 int yyendofinput; /* True if we are at the end of input */
906 #endif
907 #ifdef YYERRORSYMBOL
908 int yyerrorhit = 0; /* True if yymajor has invoked an error */
909 #endif
910 yyParser *yypParser = (yyParser*)yyp; /* The parser */
911 ParseCTX_FETCH
912 ParseARG_STORE
913
914 assert( yypParser->yytos!=0 );
915 #if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY)
916 yyendofinput = (yymajor==0);
917 #endif
918
919 yyact = yypParser->yytos->stateno;
920 #if LEMON_SUPPORT_TRACING /* __MOJOSHADER__ */
921 if( yyTraceFILE ){
922 if( yyact < YY_MIN_REDUCE ){
923 fprintf(yyTraceFILE,"%sInput '%s' in state %d\n",
924 yyTracePrompt,yyTokenName[yymajor],yyact);
925 }else{
926 fprintf(yyTraceFILE,"%sInput '%s' with pending reduce %d\n",
927 yyTracePrompt,yyTokenName[yymajor],yyact-YY_MIN_REDUCE);
928 }
929 }
930 #endif
931
932 while(1){ /* Exit by "break" */
933 assert( yypParser->yytos>=yypParser->yystack );
934 assert( yyact==yypParser->yytos->stateno );
935 yyact = yy_find_shift_action((YYCODETYPE)yymajor,yyact);
936 if( yyact >= YY_MIN_REDUCE ){
937 unsigned int yyruleno = yyact - YY_MIN_REDUCE; /* Reduce by this rule */
938 #if LEMON_SUPPORT_TRACING /* __MOJOSHADER__ */
939 assert( yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) );
940 if( yyTraceFILE ){
941 int yysize = yyRuleInfoNRhs[yyruleno];
942 if( yysize ){
943 fprintf(yyTraceFILE, "%sReduce %d [%s]%s, pop back to state %d.\n",
944 yyTracePrompt,
945 yyruleno, yyRuleName[yyruleno],
946 yyruleno<YYNRULE_WITH_ACTION ? "" : " without external action",
947 yypParser->yytos[yysize].stateno);
948 }else{
949 fprintf(yyTraceFILE, "%sReduce %d [%s]%s.\n",
950 yyTracePrompt, yyruleno, yyRuleName[yyruleno],
951 yyruleno<YYNRULE_WITH_ACTION ? "" : " without external action");
952 }
953 }
954 #endif /* NDEBUG */
955
956 /* Check that the stack is large enough to grow by a single entry
957 ** if the RHS of the rule is empty. This ensures that there is room
958 ** enough on the stack to push the LHS value */
959 if( yyRuleInfoNRhs[yyruleno]==0 ){
960 #ifdef YYTRACKMAXSTACKDEPTH
961 if( (int)(yypParser->yytos - yypParser->yystack)>yypParser->yyhwm ){
962 yypParser->yyhwm++;
963 assert( yypParser->yyhwm ==
964 (int)(yypParser->yytos - yypParser->yystack));
965 }
966 #endif
967 #if YYSTACKDEPTH>0
968 if( yypParser->yytos>=yypParser->yystackEnd ){
969 yyStackOverflow(yypParser);
970 break;
971 }
972 #else
973 if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz-1] ){
974 if( yyGrowStack(yypParser) ){
975 yyStackOverflow(yypParser);
976 break;
977 }
978 }
979 #endif
980 }
981 yyact = yy_reduce(yypParser,yyruleno,yymajor,yyminor ParseCTX_PARAM);
982 }else if( yyact <= YY_MAX_SHIFTREDUCE ){
983 yy_shift(yypParser,yyact,(YYCODETYPE)yymajor,yyminor);
984 #ifndef YYNOERRORRECOVERY
985 yypParser->yyerrcnt--;
986 #endif
987 break;
988 }else if( yyact==YY_ACCEPT_ACTION ){
989 yypParser->yytos--;
990 yy_accept(yypParser);
991 return;
992 }else{
993 assert( yyact == YY_ERROR_ACTION );
994 yyminorunion.yy0 = yyminor;
995 #ifdef YYERRORSYMBOL
996 int yymx;
997 #endif
998 #if LEMON_SUPPORT_TRACING /* __MOJOSHADER__ */
999 if( yyTraceFILE ){
1000 fprintf(yyTraceFILE,"%sSyntax Error!\n",yyTracePrompt);
1001 }
1002 #endif
1003 #ifdef YYERRORSYMBOL
1004 /* A syntax error has occurred.
1005 ** The response to an error depends upon whether or not the
1006 ** grammar defines an error token "ERROR".
1007 **
1008 ** This is what we do if the grammar does define ERROR:
1009 **
1010 ** * Call the %syntax_error function.
1011 **
1012 ** * Begin popping the stack until we enter a state where
1013 ** it is legal to shift the error symbol, then shift
1014 ** the error symbol.
1015 **
1016 ** * Set the error count to three.
1017 **
1018 ** * Begin accepting and shifting new tokens. No new error
1019 ** processing will occur until three tokens have been
1020 ** shifted successfully.
1021 **
1022 */
1023 if( yypParser->yyerrcnt<0 ){
1024 yy_syntax_error(yypParser,yymajor,yyminor);
1025 }
1026 yymx = yypParser->yytos->major;
1027 if( yymx==YYERRORSYMBOL || yyerrorhit ){
1028 #if LEMON_SUPPORT_TRACING /* __MOJOSHADER__ */
1029 if( yyTraceFILE ){
1030 fprintf(yyTraceFILE,"%sDiscard input token %s\n",
1031 yyTracePrompt,yyTokenName[yymajor]);
1032 }
1033 #endif
1034 yy_destructor(yypParser, (YYCODETYPE)yymajor, &yyminorunion);
1035 yymajor = YYNOCODE;
1036 }else{
1037 while( yypParser->yytos > yypParser->yystack ){
1038 yyact = yy_find_reduce_action(yypParser->yytos->stateno,
1039 YYERRORSYMBOL);
1040 if( yyact<=YY_MAX_SHIFTREDUCE ) break;
1041 yy_pop_parser_stack(yypParser);
1042 }
1043 if( yypParser->yytos <= yypParser->yystack || yymajor==0 ){
1044 yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
1045 yy_parse_failed(yypParser);
1046 #ifndef YYNOERRORRECOVERY
1047 yypParser->yyerrcnt = -1;
1048 #endif
1049 yymajor = YYNOCODE;
1050 }else if( yymx!=YYERRORSYMBOL ){
1051 yy_shift(yypParser,yyact,YYERRORSYMBOL,yyminor);
1052 }
1053 }
1054 yypParser->yyerrcnt = 3;
1055 yyerrorhit = 1;
1056 if( yymajor==YYNOCODE ) break;
1057 yyact = yypParser->yytos->stateno;
1058 #elif defined(YYNOERRORRECOVERY)
1059 /* If the YYNOERRORRECOVERY macro is defined, then do not attempt to
1060 ** do any kind of error recovery. Instead, simply invoke the syntax
1061 ** error routine and continue going as if nothing had happened.
1062 **
1063 ** Applications can set this macro (for example inside %include) if
1064 ** they intend to abandon the parse upon the first syntax error seen.
1065 */
1066 yy_syntax_error(yypParser,yymajor, yyminor);
1067 yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
1068 break;
1069 #else /* YYERRORSYMBOL is not defined */
1070 /* This is what we do if the grammar does not define ERROR:
1071 **
1072 ** * Report an error message, and throw away the input token.
1073 **
1074 ** * If the input token is $, then fail the parse.
1075 **
1076 ** As before, subsequent error messages are suppressed until
1077 ** three input tokens have been successfully shifted.
1078 */
1079 if( yypParser->yyerrcnt<=0 ){
1080 yy_syntax_error(yypParser,yymajor, yyminor);
1081 }
1082 yypParser->yyerrcnt = 3;
1083 yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
1084 if( yyendofinput ){
1085 yy_parse_failed(yypParser);
1086 #ifndef YYNOERRORRECOVERY
1087 yypParser->yyerrcnt = -1;
1088 #endif
1089 }
1090 break;
1091 #endif
1092 }
1093 }
1094 #if LEMON_SUPPORT_TRACING /* __MOJOSHADER__ */
1095 if( yyTraceFILE ){
1096 yyStackEntry *i;
1097 char cDiv = '[';
1098 fprintf(yyTraceFILE,"%sReturn. Stack=",yyTracePrompt);
1099 for(i=&yypParser->yystack[1]; i<=yypParser->yytos; i++){
1100 fprintf(yyTraceFILE,"%c%s", cDiv, yyTokenName[i->major]);
1101 cDiv = ' ';
1102 }
1103 fprintf(yyTraceFILE,"]\n");
1104 }
1105 #endif
1106 return;
1107 }
1108
1109 /*
1110 ** Return the fallback token corresponding to canonical token iToken, or
1111 ** 0 if iToken has no fallback.
1112 */
1113 #if __MOJOSHADER__
1114 static
1115 #endif
1116 int ParseFallback(int iToken){
1117 #ifdef YYFALLBACK
1118 assert( iToken<(int)(sizeof(yyFallback)/sizeof(yyFallback[0])) );
1119 return yyFallback[iToken];
1120 #else
1121 (void)iToken;
1122 return 0;
1123 #endif
1124 }