xref: /onnv-gate/usr/src/lib/libsqlite/tool/lempar.c (revision 4520:7dbeadedd7fe)
1*4520Snw141292 
2*4520Snw141292 #pragma ident	"%Z%%M%	%I%	%E% SMI"
3*4520Snw141292 
4*4520Snw141292 /* Driver template for the LEMON parser generator.
5*4520Snw141292 ** The author disclaims copyright to this source code.
6*4520Snw141292 */
7*4520Snw141292 /* First off, code is include which follows the "include" declaration
8*4520Snw141292 ** in the input file. */
9*4520Snw141292 #include <stdio.h>
10*4520Snw141292 %%
11*4520Snw141292 /* Next is all token values, in a form suitable for use by makeheaders.
12*4520Snw141292 ** This section will be null unless lemon is run with the -m switch.
13*4520Snw141292 */
14*4520Snw141292 /*
15*4520Snw141292 ** These constants (all generated automatically by the parser generator)
16*4520Snw141292 ** specify the various kinds of tokens (terminals) that the parser
17*4520Snw141292 ** understands.
18*4520Snw141292 **
19*4520Snw141292 ** Each symbol here is a terminal symbol in the grammar.
20*4520Snw141292 */
21*4520Snw141292 %%
22*4520Snw141292 /* Make sure the INTERFACE macro is defined.
23*4520Snw141292 */
24*4520Snw141292 #ifndef INTERFACE
25*4520Snw141292 # define INTERFACE 1
26*4520Snw141292 #endif
27*4520Snw141292 /* The next thing included is series of defines which control
28*4520Snw141292 ** various aspects of the generated parser.
29*4520Snw141292 **    YYCODETYPE         is the data type used for storing terminal
30*4520Snw141292 **                       and nonterminal numbers.  "unsigned char" is
31*4520Snw141292 **                       used if there are fewer than 250 terminals
32*4520Snw141292 **                       and nonterminals.  "int" is used otherwise.
33*4520Snw141292 **    YYNOCODE           is a number of type YYCODETYPE which corresponds
34*4520Snw141292 **                       to no legal terminal or nonterminal number.  This
35*4520Snw141292 **                       number is used to fill in empty slots of the hash
36*4520Snw141292 **                       table.
37*4520Snw141292 **    YYFALLBACK         If defined, this indicates that one or more tokens
38*4520Snw141292 **                       have fall-back values which should be used if the
39*4520Snw141292 **                       original value of the token will not parse.
40*4520Snw141292 **    YYACTIONTYPE       is the data type used for storing terminal
41*4520Snw141292 **                       and nonterminal numbers.  "unsigned char" is
42*4520Snw141292 **                       used if there are fewer than 250 rules and
43*4520Snw141292 **                       states combined.  "int" is used otherwise.
44*4520Snw141292 **    ParseTOKENTYPE     is the data type used for minor tokens given
45*4520Snw141292 **                       directly to the parser from the tokenizer.
46*4520Snw141292 **    YYMINORTYPE        is the data type used for all minor tokens.
47*4520Snw141292 **                       This is typically a union of many types, one of
48*4520Snw141292 **                       which is ParseTOKENTYPE.  The entry in the union
49*4520Snw141292 **                       for base tokens is called "yy0".
50*4520Snw141292 **    YYSTACKDEPTH       is the maximum depth of the parser's stack.
51*4520Snw141292 **    ParseARG_SDECL     A static variable declaration for the %extra_argument
52*4520Snw141292 **    ParseARG_PDECL     A parameter declaration for the %extra_argument
53*4520Snw141292 **    ParseARG_STORE     Code to store %extra_argument into yypParser
54*4520Snw141292 **    ParseARG_FETCH     Code to extract %extra_argument from yypParser
55*4520Snw141292 **    YYNSTATE           the combined number of states.
56*4520Snw141292 **    YYNRULE            the number of rules in the grammar
57*4520Snw141292 **    YYERRORSYMBOL      is the code number of the error symbol.  If not
58*4520Snw141292 **                       defined, then do no error processing.
59*4520Snw141292 */
60*4520Snw141292 %%
61*4520Snw141292 #define YY_NO_ACTION      (YYNSTATE+YYNRULE+2)
62*4520Snw141292 #define YY_ACCEPT_ACTION  (YYNSTATE+YYNRULE+1)
63*4520Snw141292 #define YY_ERROR_ACTION   (YYNSTATE+YYNRULE)
64*4520Snw141292 
65*4520Snw141292 /* Next are that tables used to determine what action to take based on the
66*4520Snw141292 ** current state and lookahead token.  These tables are used to implement
67*4520Snw141292 ** functions that take a state number and lookahead value and return an
68*4520Snw141292 ** action integer.
69*4520Snw141292 **
70*4520Snw141292 ** Suppose the action integer is N.  Then the action is determined as
71*4520Snw141292 ** follows
72*4520Snw141292 **
73*4520Snw141292 **   0 <= N < YYNSTATE                  Shift N.  That is, push the lookahead
74*4520Snw141292 **                                      token onto the stack and goto state N.
75*4520Snw141292 **
76*4520Snw141292 **   YYNSTATE <= N < YYNSTATE+YYNRULE   Reduce by rule N-YYNSTATE.
77*4520Snw141292 **
78*4520Snw141292 **   N == YYNSTATE+YYNRULE              A syntax error has occurred.
79*4520Snw141292 **
80*4520Snw141292 **   N == YYNSTATE+YYNRULE+1            The parser accepts its input.
81*4520Snw141292 **
82*4520Snw141292 **   N == YYNSTATE+YYNRULE+2            No such action.  Denotes unused
83*4520Snw141292 **                                      slots in the yy_action[] table.
84*4520Snw141292 **
85*4520Snw141292 ** The action table is constructed as a single large table named yy_action[].
86*4520Snw141292 ** Given state S and lookahead X, the action is computed as
87*4520Snw141292 **
88*4520Snw141292 **      yy_action[ yy_shift_ofst[S] + X ]
89*4520Snw141292 **
90*4520Snw141292 ** If the index value yy_shift_ofst[S]+X is out of range or if the value
91*4520Snw141292 ** yy_lookahead[yy_shift_ofst[S]+X] is not equal to X or if yy_shift_ofst[S]
92*4520Snw141292 ** is equal to YY_SHIFT_USE_DFLT, it means that the action is not in the table
93*4520Snw141292 ** and that yy_default[S] should be used instead.
94*4520Snw141292 **
95*4520Snw141292 ** The formula above is for computing the action when the lookahead is
96*4520Snw141292 ** a terminal symbol.  If the lookahead is a non-terminal (as occurs after
97*4520Snw141292 ** a reduce action) then the yy_reduce_ofst[] array is used in place of
98*4520Snw141292 ** the yy_shift_ofst[] array and YY_REDUCE_USE_DFLT is used in place of
99*4520Snw141292 ** YY_SHIFT_USE_DFLT.
100*4520Snw141292 **
101*4520Snw141292 ** The following are the tables generated in this section:
102*4520Snw141292 **
103*4520Snw141292 **  yy_action[]        A single table containing all actions.
104*4520Snw141292 **  yy_lookahead[]     A table containing the lookahead for each entry in
105*4520Snw141292 **                     yy_action.  Used to detect hash collisions.
106*4520Snw141292 **  yy_shift_ofst[]    For each state, the offset into yy_action for
107*4520Snw141292 **                     shifting terminals.
108*4520Snw141292 **  yy_reduce_ofst[]   For each state, the offset into yy_action for
109*4520Snw141292 **                     shifting non-terminals after a reduce.
110*4520Snw141292 **  yy_default[]       Default action for each state.
111*4520Snw141292 */
112*4520Snw141292 %%
113*4520Snw141292 #define YY_SZ_ACTTAB (sizeof(yy_action)/sizeof(yy_action[0]))
114*4520Snw141292 
115*4520Snw141292 /* The next table maps tokens into fallback tokens.  If a construct
116*4520Snw141292 ** like the following:
117*4520Snw141292 **
118*4520Snw141292 **      %fallback ID X Y Z.
119*4520Snw141292 **
120*4520Snw141292 ** appears in the grammer, then ID becomes a fallback token for X, Y,
121*4520Snw141292 ** and Z.  Whenever one of the tokens X, Y, or Z is input to the parser
122*4520Snw141292 ** but it does not parse, the type of the token is changed to ID and
123*4520Snw141292 ** the parse is retried before an error is thrown.
124*4520Snw141292 */
125*4520Snw141292 #ifdef YYFALLBACK
126*4520Snw141292 static const YYCODETYPE yyFallback[] = {
127*4520Snw141292 %%
128*4520Snw141292 };
129*4520Snw141292 #endif /* YYFALLBACK */
130*4520Snw141292 
131*4520Snw141292 /* The following structure represents a single element of the
132*4520Snw141292 ** parser's stack.  Information stored includes:
133*4520Snw141292 **
134*4520Snw141292 **   +  The state number for the parser at this level of the stack.
135*4520Snw141292 **
136*4520Snw141292 **   +  The value of the token stored at this level of the stack.
137*4520Snw141292 **      (In other words, the "major" token.)
138*4520Snw141292 **
139*4520Snw141292 **   +  The semantic value stored at this level of the stack.  This is
140*4520Snw141292 **      the information used by the action routines in the grammar.
141*4520Snw141292 **      It is sometimes called the "minor" token.
142*4520Snw141292 */
143*4520Snw141292 struct yyStackEntry {
144*4520Snw141292   int stateno;       /* The state-number */
145*4520Snw141292   int major;         /* The major token value.  This is the code
146*4520Snw141292                      ** number for the token at this stack level */
147*4520Snw141292   YYMINORTYPE minor; /* The user-supplied minor token value.  This
148*4520Snw141292                      ** is the value of the token  */
149*4520Snw141292 };
150*4520Snw141292 typedef struct yyStackEntry yyStackEntry;
151*4520Snw141292 
152*4520Snw141292 /* The state of the parser is completely contained in an instance of
153*4520Snw141292 ** the following structure */
154*4520Snw141292 struct yyParser {
155*4520Snw141292   int yyidx;                    /* Index of top element in stack */
156*4520Snw141292   int yyerrcnt;                 /* Shifts left before out of the error */
157*4520Snw141292   ParseARG_SDECL                /* A place to hold %extra_argument */
158*4520Snw141292   yyStackEntry yystack[YYSTACKDEPTH];  /* The parser's stack */
159*4520Snw141292 };
160*4520Snw141292 typedef struct yyParser yyParser;
161*4520Snw141292 
162*4520Snw141292 #ifndef NDEBUG
163*4520Snw141292 #include <stdio.h>
164*4520Snw141292 static FILE *yyTraceFILE = 0;
165*4520Snw141292 static char *yyTracePrompt = 0;
166*4520Snw141292 #endif /* NDEBUG */
167*4520Snw141292 
168*4520Snw141292 #ifndef NDEBUG
169*4520Snw141292 /*
170*4520Snw141292 ** Turn parser tracing on by giving a stream to which to write the trace
171*4520Snw141292 ** and a prompt to preface each trace message.  Tracing is turned off
172*4520Snw141292 ** by making either argument NULL
173*4520Snw141292 **
174*4520Snw141292 ** Inputs:
175*4520Snw141292 ** <ul>
176*4520Snw141292 ** <li> A FILE* to which trace output should be written.
177*4520Snw141292 **      If NULL, then tracing is turned off.
178*4520Snw141292 ** <li> A prefix string written at the beginning of every
179*4520Snw141292 **      line of trace output.  If NULL, then tracing is
180*4520Snw141292 **      turned off.
181*4520Snw141292 ** </ul>
182*4520Snw141292 **
183*4520Snw141292 ** Outputs:
184*4520Snw141292 ** None.
185*4520Snw141292 */
ParseTrace(FILE * TraceFILE,char * zTracePrompt)186*4520Snw141292 void ParseTrace(FILE *TraceFILE, char *zTracePrompt){
187*4520Snw141292   yyTraceFILE = TraceFILE;
188*4520Snw141292   yyTracePrompt = zTracePrompt;
189*4520Snw141292   if( yyTraceFILE==0 ) yyTracePrompt = 0;
190*4520Snw141292   else if( yyTracePrompt==0 ) yyTraceFILE = 0;
191*4520Snw141292 }
192*4520Snw141292 #endif /* NDEBUG */
193*4520Snw141292 
194*4520Snw141292 #ifndef NDEBUG
195*4520Snw141292 /* For tracing shifts, the names of all terminals and nonterminals
196*4520Snw141292 ** are required.  The following table supplies these names */
197*4520Snw141292 static const char *yyTokenName[] = {
198*4520Snw141292 %%
199*4520Snw141292 };
200*4520Snw141292 #endif /* NDEBUG */
201*4520Snw141292 
202*4520Snw141292 #ifndef NDEBUG
203*4520Snw141292 /* For tracing reduce actions, the names of all rules are required.
204*4520Snw141292 */
205*4520Snw141292 static const char *yyRuleName[] = {
206*4520Snw141292 %%
207*4520Snw141292 };
208*4520Snw141292 #endif /* NDEBUG */
209*4520Snw141292 
210*4520Snw141292 /*
211*4520Snw141292 ** This function returns the symbolic name associated with a token
212*4520Snw141292 ** value.
213*4520Snw141292 */
ParseTokenName(int tokenType)214*4520Snw141292 const char *ParseTokenName(int tokenType){
215*4520Snw141292 #ifndef NDEBUG
216*4520Snw141292   if( tokenType>0 && tokenType<(sizeof(yyTokenName)/sizeof(yyTokenName[0])) ){
217*4520Snw141292     return yyTokenName[tokenType];
218*4520Snw141292   }else{
219*4520Snw141292     return "Unknown";
220*4520Snw141292   }
221*4520Snw141292 #else
222*4520Snw141292   return "";
223*4520Snw141292 #endif
224*4520Snw141292 }
225*4520Snw141292 
226*4520Snw141292 /*
227*4520Snw141292 ** This function allocates a new parser.
228*4520Snw141292 ** The only argument is a pointer to a function which works like
229*4520Snw141292 ** malloc.
230*4520Snw141292 **
231*4520Snw141292 ** Inputs:
232*4520Snw141292 ** A pointer to the function used to allocate memory.
233*4520Snw141292 **
234*4520Snw141292 ** Outputs:
235*4520Snw141292 ** A pointer to a parser.  This pointer is used in subsequent calls
236*4520Snw141292 ** to Parse and ParseFree.
237*4520Snw141292 */
ParseAlloc(void * (* mallocProc)(size_t))238*4520Snw141292 void *ParseAlloc(void *(*mallocProc)(size_t)){
239*4520Snw141292   yyParser *pParser;
240*4520Snw141292   pParser = (yyParser*)(*mallocProc)( (size_t)sizeof(yyParser) );
241*4520Snw141292   if( pParser ){
242*4520Snw141292     pParser->yyidx = -1;
243*4520Snw141292   }
244*4520Snw141292   return pParser;
245*4520Snw141292 }
246*4520Snw141292 
247*4520Snw141292 /* The following function deletes the value associated with a
248*4520Snw141292 ** symbol.  The symbol can be either a terminal or nonterminal.
249*4520Snw141292 ** "yymajor" is the symbol code, and "yypminor" is a pointer to
250*4520Snw141292 ** the value.
251*4520Snw141292 */
yy_destructor(YYCODETYPE yymajor,YYMINORTYPE * yypminor)252*4520Snw141292 static void yy_destructor(YYCODETYPE yymajor, YYMINORTYPE *yypminor){
253*4520Snw141292   switch( yymajor ){
254*4520Snw141292     /* Here is inserted the actions which take place when a
255*4520Snw141292     ** terminal or non-terminal is destroyed.  This can happen
256*4520Snw141292     ** when the symbol is popped from the stack during a
257*4520Snw141292     ** reduce or during error processing or when a parser is
258*4520Snw141292     ** being destroyed before it is finished parsing.
259*4520Snw141292     **
260*4520Snw141292     ** Note: during a reduce, the only symbols destroyed are those
261*4520Snw141292     ** which appear on the RHS of the rule, but which are not used
262*4520Snw141292     ** inside the C code.
263*4520Snw141292     */
264*4520Snw141292 %%
265*4520Snw141292     default:  break;   /* If no destructor action specified: do nothing */
266*4520Snw141292   }
267*4520Snw141292 }
268*4520Snw141292 
269*4520Snw141292 /*
270*4520Snw141292 ** Pop the parser's stack once.
271*4520Snw141292 **
272*4520Snw141292 ** If there is a destructor routine associated with the token which
273*4520Snw141292 ** is popped from the stack, then call it.
274*4520Snw141292 **
275*4520Snw141292 ** Return the major token number for the symbol popped.
276*4520Snw141292 */
yy_pop_parser_stack(yyParser * pParser)277*4520Snw141292 static int yy_pop_parser_stack(yyParser *pParser){
278*4520Snw141292   YYCODETYPE yymajor;
279*4520Snw141292   yyStackEntry *yytos = &pParser->yystack[pParser->yyidx];
280*4520Snw141292 
281*4520Snw141292   if( pParser->yyidx<0 ) return 0;
282*4520Snw141292 #ifndef NDEBUG
283*4520Snw141292   if( yyTraceFILE && pParser->yyidx>=0 ){
284*4520Snw141292     fprintf(yyTraceFILE,"%sPopping %s\n",
285*4520Snw141292       yyTracePrompt,
286*4520Snw141292       yyTokenName[yytos->major]);
287*4520Snw141292   }
288*4520Snw141292 #endif
289*4520Snw141292   yymajor = yytos->major;
290*4520Snw141292   yy_destructor( yymajor, &yytos->minor);
291*4520Snw141292   pParser->yyidx--;
292*4520Snw141292   return yymajor;
293*4520Snw141292 }
294*4520Snw141292 
295*4520Snw141292 /*
296*4520Snw141292 ** Deallocate and destroy a parser.  Destructors are all called for
297*4520Snw141292 ** all stack elements before shutting the parser down.
298*4520Snw141292 **
299*4520Snw141292 ** Inputs:
300*4520Snw141292 ** <ul>
301*4520Snw141292 ** <li>  A pointer to the parser.  This should be a pointer
302*4520Snw141292 **       obtained from ParseAlloc.
303*4520Snw141292 ** <li>  A pointer to a function used to reclaim memory obtained
304*4520Snw141292 **       from malloc.
305*4520Snw141292 ** </ul>
306*4520Snw141292 */
ParseFree(void * p,void (* freeProc)(void *))307*4520Snw141292 void ParseFree(
308*4520Snw141292   void *p,                    /* The parser to be deleted */
309*4520Snw141292   void (*freeProc)(void*)     /* Function used to reclaim memory */
310*4520Snw141292 ){
311*4520Snw141292   yyParser *pParser = (yyParser*)p;
312*4520Snw141292   if( pParser==0 ) return;
313*4520Snw141292   while( pParser->yyidx>=0 ) yy_pop_parser_stack(pParser);
314*4520Snw141292   (*freeProc)((void*)pParser);
315*4520Snw141292 }
316*4520Snw141292 
317*4520Snw141292 /*
318*4520Snw141292 ** Find the appropriate action for a parser given the terminal
319*4520Snw141292 ** look-ahead token iLookAhead.
320*4520Snw141292 **
321*4520Snw141292 ** If the look-ahead token is YYNOCODE, then check to see if the action is
322*4520Snw141292 ** independent of the look-ahead.  If it is, return the action, otherwise
323*4520Snw141292 ** return YY_NO_ACTION.
324*4520Snw141292 */
yy_find_shift_action(yyParser * pParser,int iLookAhead)325*4520Snw141292 static int yy_find_shift_action(
326*4520Snw141292   yyParser *pParser,        /* The parser */
327*4520Snw141292   int iLookAhead            /* The look-ahead token */
328*4520Snw141292 ){
329*4520Snw141292   int i;
330*4520Snw141292   int stateno = pParser->yystack[pParser->yyidx].stateno;
331*4520Snw141292 
332*4520Snw141292   /* if( pParser->yyidx<0 ) return YY_NO_ACTION;  */
333*4520Snw141292   i = yy_shift_ofst[stateno];
334*4520Snw141292   if( i==YY_SHIFT_USE_DFLT ){
335*4520Snw141292     return yy_default[stateno];
336*4520Snw141292   }
337*4520Snw141292   if( iLookAhead==YYNOCODE ){
338*4520Snw141292     return YY_NO_ACTION;
339*4520Snw141292   }
340*4520Snw141292   i += iLookAhead;
341*4520Snw141292   if( i<0 || i>=YY_SZ_ACTTAB || yy_lookahead[i]!=iLookAhead ){
342*4520Snw141292 #ifdef YYFALLBACK
343*4520Snw141292     int iFallback;            /* Fallback token */
344*4520Snw141292     if( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0])
345*4520Snw141292            && (iFallback = yyFallback[iLookAhead])!=0 ){
346*4520Snw141292 #ifndef NDEBUG
347*4520Snw141292       if( yyTraceFILE ){
348*4520Snw141292         fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n",
349*4520Snw141292            yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]);
350*4520Snw141292       }
351*4520Snw141292 #endif
352*4520Snw141292       return yy_find_shift_action(pParser, iFallback);
353*4520Snw141292     }
354*4520Snw141292 #endif
355*4520Snw141292     return yy_default[stateno];
356*4520Snw141292   }else{
357*4520Snw141292     return yy_action[i];
358*4520Snw141292   }
359*4520Snw141292 }
360*4520Snw141292 
361*4520Snw141292 /*
362*4520Snw141292 ** Find the appropriate action for a parser given the non-terminal
363*4520Snw141292 ** look-ahead token iLookAhead.
364*4520Snw141292 **
365*4520Snw141292 ** If the look-ahead token is YYNOCODE, then check to see if the action is
366*4520Snw141292 ** independent of the look-ahead.  If it is, return the action, otherwise
367*4520Snw141292 ** return YY_NO_ACTION.
368*4520Snw141292 */
yy_find_reduce_action(yyParser * pParser,int iLookAhead)369*4520Snw141292 static int yy_find_reduce_action(
370*4520Snw141292   yyParser *pParser,        /* The parser */
371*4520Snw141292   int iLookAhead            /* The look-ahead token */
372*4520Snw141292 ){
373*4520Snw141292   int i;
374*4520Snw141292   int stateno = pParser->yystack[pParser->yyidx].stateno;
375*4520Snw141292 
376*4520Snw141292   i = yy_reduce_ofst[stateno];
377*4520Snw141292   if( i==YY_REDUCE_USE_DFLT ){
378*4520Snw141292     return yy_default[stateno];
379*4520Snw141292   }
380*4520Snw141292   if( iLookAhead==YYNOCODE ){
381*4520Snw141292     return YY_NO_ACTION;
382*4520Snw141292   }
383*4520Snw141292   i += iLookAhead;
384*4520Snw141292   if( i<0 || i>=YY_SZ_ACTTAB || yy_lookahead[i]!=iLookAhead ){
385*4520Snw141292     return yy_default[stateno];
386*4520Snw141292   }else{
387*4520Snw141292     return yy_action[i];
388*4520Snw141292   }
389*4520Snw141292 }
390*4520Snw141292 
391*4520Snw141292 /*
392*4520Snw141292 ** Perform a shift action.
393*4520Snw141292 */
yy_shift(yyParser * yypParser,int yyNewState,int yyMajor,YYMINORTYPE * yypMinor)394*4520Snw141292 static void yy_shift(
395*4520Snw141292   yyParser *yypParser,          /* The parser to be shifted */
396*4520Snw141292   int yyNewState,               /* The new state to shift in */
397*4520Snw141292   int yyMajor,                  /* The major token to shift in */
398*4520Snw141292   YYMINORTYPE *yypMinor         /* Pointer ot the minor token to shift in */
399*4520Snw141292 ){
400*4520Snw141292   yyStackEntry *yytos;
401*4520Snw141292   yypParser->yyidx++;
402*4520Snw141292   if( yypParser->yyidx>=YYSTACKDEPTH ){
403*4520Snw141292      ParseARG_FETCH;
404*4520Snw141292      yypParser->yyidx--;
405*4520Snw141292 #ifndef NDEBUG
406*4520Snw141292      if( yyTraceFILE ){
407*4520Snw141292        fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt);
408*4520Snw141292      }
409*4520Snw141292 #endif
410*4520Snw141292      while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
411*4520Snw141292      /* Here code is inserted which will execute if the parser
412*4520Snw141292      ** stack every overflows */
413*4520Snw141292 %%
414*4520Snw141292      ParseARG_STORE; /* Suppress warning about unused %extra_argument var */
415*4520Snw141292      return;
416*4520Snw141292   }
417*4520Snw141292   yytos = &yypParser->yystack[yypParser->yyidx];
418*4520Snw141292   yytos->stateno = yyNewState;
419*4520Snw141292   yytos->major = yyMajor;
420*4520Snw141292   yytos->minor = *yypMinor;
421*4520Snw141292 #ifndef NDEBUG
422*4520Snw141292   if( yyTraceFILE && yypParser->yyidx>0 ){
423*4520Snw141292     int i;
424*4520Snw141292     fprintf(yyTraceFILE,"%sShift %d\n",yyTracePrompt,yyNewState);
425*4520Snw141292     fprintf(yyTraceFILE,"%sStack:",yyTracePrompt);
426*4520Snw141292     for(i=1; i<=yypParser->yyidx; i++)
427*4520Snw141292       fprintf(yyTraceFILE," %s",yyTokenName[yypParser->yystack[i].major]);
428*4520Snw141292     fprintf(yyTraceFILE,"\n");
429*4520Snw141292   }
430*4520Snw141292 #endif
431*4520Snw141292 }
432*4520Snw141292 
433*4520Snw141292 /* The following table contains information about every rule that
434*4520Snw141292 ** is used during the reduce.
435*4520Snw141292 */
436*4520Snw141292 static struct {
437*4520Snw141292   YYCODETYPE lhs;         /* Symbol on the left-hand side of the rule */
438*4520Snw141292   unsigned char nrhs;     /* Number of right-hand side symbols in the rule */
439*4520Snw141292 } yyRuleInfo[] = {
440*4520Snw141292 %%
441*4520Snw141292 };
442*4520Snw141292 
443*4520Snw141292 static void yy_accept(yyParser*);  /* Forward Declaration */
444*4520Snw141292 
445*4520Snw141292 /*
446*4520Snw141292 ** Perform a reduce action and the shift that must immediately
447*4520Snw141292 ** follow the reduce.
448*4520Snw141292 */
yy_reduce(yyParser * yypParser,int yyruleno)449*4520Snw141292 static void yy_reduce(
450*4520Snw141292   yyParser *yypParser,         /* The parser */
451*4520Snw141292   int yyruleno                 /* Number of the rule by which to reduce */
452*4520Snw141292 ){
453*4520Snw141292   int yygoto;                     /* The next state */
454*4520Snw141292   int yyact;                      /* The next action */
455*4520Snw141292   YYMINORTYPE yygotominor;        /* The LHS of the rule reduced */
456*4520Snw141292   yyStackEntry *yymsp;            /* The top of the parser's stack */
457*4520Snw141292   int yysize;                     /* Amount to pop the stack */
458*4520Snw141292   ParseARG_FETCH;
459*4520Snw141292   yymsp = &yypParser->yystack[yypParser->yyidx];
460*4520Snw141292 #ifndef NDEBUG
461*4520Snw141292   if( yyTraceFILE && yyruleno>=0
462*4520Snw141292         && yyruleno<sizeof(yyRuleName)/sizeof(yyRuleName[0]) ){
463*4520Snw141292     fprintf(yyTraceFILE, "%sReduce [%s].\n", yyTracePrompt,
464*4520Snw141292       yyRuleName[yyruleno]);
465*4520Snw141292   }
466*4520Snw141292 #endif /* NDEBUG */
467*4520Snw141292 
468*4520Snw141292   switch( yyruleno ){
469*4520Snw141292   /* Beginning here are the reduction cases.  A typical example
470*4520Snw141292   ** follows:
471*4520Snw141292   **   case 0:
472*4520Snw141292   **  #line <lineno> <grammarfile>
473*4520Snw141292   **     { ... }           // User supplied code
474*4520Snw141292   **  #line <lineno> <thisfile>
475*4520Snw141292   **     break;
476*4520Snw141292   */
477*4520Snw141292 %%
478*4520Snw141292   };
479*4520Snw141292   yygoto = yyRuleInfo[yyruleno].lhs;
480*4520Snw141292   yysize = yyRuleInfo[yyruleno].nrhs;
481*4520Snw141292   yypParser->yyidx -= yysize;
482*4520Snw141292   yyact = yy_find_reduce_action(yypParser,yygoto);
483*4520Snw141292   if( yyact < YYNSTATE ){
484*4520Snw141292     yy_shift(yypParser,yyact,yygoto,&yygotominor);
485*4520Snw141292   }else if( yyact == YYNSTATE + YYNRULE + 1 ){
486*4520Snw141292     yy_accept(yypParser);
487*4520Snw141292   }
488*4520Snw141292 }
489*4520Snw141292 
490*4520Snw141292 /*
491*4520Snw141292 ** The following code executes when the parse fails
492*4520Snw141292 */
yy_parse_failed(yyParser * yypParser)493*4520Snw141292 static void yy_parse_failed(
494*4520Snw141292   yyParser *yypParser           /* The parser */
495*4520Snw141292 ){
496*4520Snw141292   ParseARG_FETCH;
497*4520Snw141292 #ifndef NDEBUG
498*4520Snw141292   if( yyTraceFILE ){
499*4520Snw141292     fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt);
500*4520Snw141292   }
501*4520Snw141292 #endif
502*4520Snw141292   while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
503*4520Snw141292   /* Here code is inserted which will be executed whenever the
504*4520Snw141292   ** parser fails */
505*4520Snw141292 %%
506*4520Snw141292   ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
507*4520Snw141292 }
508*4520Snw141292 
509*4520Snw141292 /*
510*4520Snw141292 ** The following code executes when a syntax error first occurs.
511*4520Snw141292 */
yy_syntax_error(yyParser * yypParser,int yymajor,YYMINORTYPE yyminor)512*4520Snw141292 static void yy_syntax_error(
513*4520Snw141292   yyParser *yypParser,           /* The parser */
514*4520Snw141292   int yymajor,                   /* The major type of the error token */
515*4520Snw141292   YYMINORTYPE yyminor            /* The minor type of the error token */
516*4520Snw141292 ){
517*4520Snw141292   ParseARG_FETCH;
518*4520Snw141292 #define TOKEN (yyminor.yy0)
519*4520Snw141292 %%
520*4520Snw141292   ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
521*4520Snw141292 }
522*4520Snw141292 
523*4520Snw141292 /*
524*4520Snw141292 ** The following is executed when the parser accepts
525*4520Snw141292 */
yy_accept(yyParser * yypParser)526*4520Snw141292 static void yy_accept(
527*4520Snw141292   yyParser *yypParser           /* The parser */
528*4520Snw141292 ){
529*4520Snw141292   ParseARG_FETCH;
530*4520Snw141292 #ifndef NDEBUG
531*4520Snw141292   if( yyTraceFILE ){
532*4520Snw141292     fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt);
533*4520Snw141292   }
534*4520Snw141292 #endif
535*4520Snw141292   while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
536*4520Snw141292   /* Here code is inserted which will be executed whenever the
537*4520Snw141292   ** parser accepts */
538*4520Snw141292 %%
539*4520Snw141292   ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
540*4520Snw141292 }
541*4520Snw141292 
542*4520Snw141292 /* The main parser program.
543*4520Snw141292 ** The first argument is a pointer to a structure obtained from
544*4520Snw141292 ** "ParseAlloc" which describes the current state of the parser.
545*4520Snw141292 ** The second argument is the major token number.  The third is
546*4520Snw141292 ** the minor token.  The fourth optional argument is whatever the
547*4520Snw141292 ** user wants (and specified in the grammar) and is available for
548*4520Snw141292 ** use by the action routines.
549*4520Snw141292 **
550*4520Snw141292 ** Inputs:
551*4520Snw141292 ** <ul>
552*4520Snw141292 ** <li> A pointer to the parser (an opaque structure.)
553*4520Snw141292 ** <li> The major token number.
554*4520Snw141292 ** <li> The minor token number.
555*4520Snw141292 ** <li> An option argument of a grammar-specified type.
556*4520Snw141292 ** </ul>
557*4520Snw141292 **
558*4520Snw141292 ** Outputs:
559*4520Snw141292 ** None.
560*4520Snw141292 */
Parse(void * yyp,int yymajor,ParseTOKENTYPE yyminor ParseARG_PDECL)561*4520Snw141292 void Parse(
562*4520Snw141292   void *yyp,                   /* The parser */
563*4520Snw141292   int yymajor,                 /* The major token code number */
564*4520Snw141292   ParseTOKENTYPE yyminor       /* The value for the token */
565*4520Snw141292   ParseARG_PDECL               /* Optional %extra_argument parameter */
566*4520Snw141292 ){
567*4520Snw141292   YYMINORTYPE yyminorunion;
568*4520Snw141292   int yyact;            /* The parser action. */
569*4520Snw141292   int yyendofinput;     /* True if we are at the end of input */
570*4520Snw141292   int yyerrorhit = 0;   /* True if yymajor has invoked an error */
571*4520Snw141292   yyParser *yypParser;  /* The parser */
572*4520Snw141292 
573*4520Snw141292   /* (re)initialize the parser, if necessary */
574*4520Snw141292   yypParser = (yyParser*)yyp;
575*4520Snw141292   if( yypParser->yyidx<0 ){
576*4520Snw141292     if( yymajor==0 ) return;
577*4520Snw141292     yypParser->yyidx = 0;
578*4520Snw141292     yypParser->yyerrcnt = -1;
579*4520Snw141292     yypParser->yystack[0].stateno = 0;
580*4520Snw141292     yypParser->yystack[0].major = 0;
581*4520Snw141292   }
582*4520Snw141292   yyminorunion.yy0 = yyminor;
583*4520Snw141292   yyendofinput = (yymajor==0);
584*4520Snw141292   ParseARG_STORE;
585*4520Snw141292 
586*4520Snw141292 #ifndef NDEBUG
587*4520Snw141292   if( yyTraceFILE ){
588*4520Snw141292     fprintf(yyTraceFILE,"%sInput %s\n",yyTracePrompt,yyTokenName[yymajor]);
589*4520Snw141292   }
590*4520Snw141292 #endif
591*4520Snw141292 
592*4520Snw141292   do{
593*4520Snw141292     yyact = yy_find_shift_action(yypParser,yymajor);
594*4520Snw141292     if( yyact<YYNSTATE ){
595*4520Snw141292       yy_shift(yypParser,yyact,yymajor,&yyminorunion);
596*4520Snw141292       yypParser->yyerrcnt--;
597*4520Snw141292       if( yyendofinput && yypParser->yyidx>=0 ){
598*4520Snw141292         yymajor = 0;
599*4520Snw141292       }else{
600*4520Snw141292         yymajor = YYNOCODE;
601*4520Snw141292       }
602*4520Snw141292     }else if( yyact < YYNSTATE + YYNRULE ){
603*4520Snw141292       yy_reduce(yypParser,yyact-YYNSTATE);
604*4520Snw141292     }else if( yyact == YY_ERROR_ACTION ){
605*4520Snw141292       int yymx;
606*4520Snw141292 #ifndef NDEBUG
607*4520Snw141292       if( yyTraceFILE ){
608*4520Snw141292         fprintf(yyTraceFILE,"%sSyntax Error!\n",yyTracePrompt);
609*4520Snw141292       }
610*4520Snw141292 #endif
611*4520Snw141292 #ifdef YYERRORSYMBOL
612*4520Snw141292       /* A syntax error has occurred.
613*4520Snw141292       ** The response to an error depends upon whether or not the
614*4520Snw141292       ** grammar defines an error token "ERROR".
615*4520Snw141292       **
616*4520Snw141292       ** This is what we do if the grammar does define ERROR:
617*4520Snw141292       **
618*4520Snw141292       **  * Call the %syntax_error function.
619*4520Snw141292       **
620*4520Snw141292       **  * Begin popping the stack until we enter a state where
621*4520Snw141292       **    it is legal to shift the error symbol, then shift
622*4520Snw141292       **    the error symbol.
623*4520Snw141292       **
624*4520Snw141292       **  * Set the error count to three.
625*4520Snw141292       **
626*4520Snw141292       **  * Begin accepting and shifting new tokens.  No new error
627*4520Snw141292       **    processing will occur until three tokens have been
628*4520Snw141292       **    shifted successfully.
629*4520Snw141292       **
630*4520Snw141292       */
631*4520Snw141292       if( yypParser->yyerrcnt<0 ){
632*4520Snw141292         yy_syntax_error(yypParser,yymajor,yyminorunion);
633*4520Snw141292       }
634*4520Snw141292       yymx = yypParser->yystack[yypParser->yyidx].major;
635*4520Snw141292       if( yymx==YYERRORSYMBOL || yyerrorhit ){
636*4520Snw141292 #ifndef NDEBUG
637*4520Snw141292         if( yyTraceFILE ){
638*4520Snw141292           fprintf(yyTraceFILE,"%sDiscard input token %s\n",
639*4520Snw141292              yyTracePrompt,yyTokenName[yymajor]);
640*4520Snw141292         }
641*4520Snw141292 #endif
642*4520Snw141292         yy_destructor(yymajor,&yyminorunion);
643*4520Snw141292         yymajor = YYNOCODE;
644*4520Snw141292       }else{
645*4520Snw141292          while(
646*4520Snw141292           yypParser->yyidx >= 0 &&
647*4520Snw141292           yymx != YYERRORSYMBOL &&
648*4520Snw141292           (yyact = yy_find_shift_action(yypParser,YYERRORSYMBOL)) >= YYNSTATE
649*4520Snw141292         ){
650*4520Snw141292           yy_pop_parser_stack(yypParser);
651*4520Snw141292         }
652*4520Snw141292         if( yypParser->yyidx < 0 || yymajor==0 ){
653*4520Snw141292           yy_destructor(yymajor,&yyminorunion);
654*4520Snw141292           yy_parse_failed(yypParser);
655*4520Snw141292           yymajor = YYNOCODE;
656*4520Snw141292         }else if( yymx!=YYERRORSYMBOL ){
657*4520Snw141292           YYMINORTYPE u2;
658*4520Snw141292           u2.YYERRSYMDT = 0;
659*4520Snw141292           yy_shift(yypParser,yyact,YYERRORSYMBOL,&u2);
660*4520Snw141292         }
661*4520Snw141292       }
662*4520Snw141292       yypParser->yyerrcnt = 3;
663*4520Snw141292       yyerrorhit = 1;
664*4520Snw141292 #else  /* YYERRORSYMBOL is not defined */
665*4520Snw141292       /* This is what we do if the grammar does not define ERROR:
666*4520Snw141292       **
667*4520Snw141292       **  * Report an error message, and throw away the input token.
668*4520Snw141292       **
669*4520Snw141292       **  * If the input token is $, then fail the parse.
670*4520Snw141292       **
671*4520Snw141292       ** As before, subsequent error messages are suppressed until
672*4520Snw141292       ** three input tokens have been successfully shifted.
673*4520Snw141292       */
674*4520Snw141292       if( yypParser->yyerrcnt<=0 ){
675*4520Snw141292         yy_syntax_error(yypParser,yymajor,yyminorunion);
676*4520Snw141292       }
677*4520Snw141292       yypParser->yyerrcnt = 3;
678*4520Snw141292       yy_destructor(yymajor,&yyminorunion);
679*4520Snw141292       if( yyendofinput ){
680*4520Snw141292         yy_parse_failed(yypParser);
681*4520Snw141292       }
682*4520Snw141292       yymajor = YYNOCODE;
683*4520Snw141292 #endif
684*4520Snw141292     }else{
685*4520Snw141292       yy_accept(yypParser);
686*4520Snw141292       yymajor = YYNOCODE;
687*4520Snw141292     }
688*4520Snw141292   }while( yymajor!=YYNOCODE && yypParser->yyidx>=0 );
689*4520Snw141292   return;
690*4520Snw141292 }
691