blob: 5195d9c31b3c22eab7e3589619c3cfaa465e7ecb [file] [log] [blame]
drh82415f22015-11-09 19:33:42 +00001/*
2** 2000-05-29
drh75897232000-05-29 14:26:00 +00003**
drh82415f22015-11-09 19:33:42 +00004** The author disclaims copyright to this source code. In place of
5** a legal notice, here is a blessing:
6**
7** May you do good and not evil.
8** May you find forgiveness for yourself and forgive others.
9** May you share freely, never taking more than you give.
10**
11*************************************************************************
12** Driver template for the LEMON parser generator.
13**
14** The "lemon" program processes an LALR(1) input grammar file, then uses
15** this template to construct a parser. The "lemon" program inserts text
16** at each "%%" line. Also, any "P-a-r-s-e" identifer prefix (without the
17** interstitial "-" characters) contained in this template is changed into
18** the value of the %name directive from the grammar. Otherwise, the content
19** of this template is copied straight through into the generate parser
20** source file.
21**
22** The following is the concatenation of all %include directives from the
23** input grammar file:
drh75897232000-05-29 14:26:00 +000024*/
drh82415f22015-11-09 19:33:42 +000025#include <stdio.h>
26/************ Begin %include sections from the grammar ************************/
drh75897232000-05-29 14:26:00 +000027%%
drh82415f22015-11-09 19:33:42 +000028/**************** End of %include directives **********************************/
29/* These constants specify the various numeric values for terminal symbols
30** in a format understandable to "makeheaders". This section is blank unless
31** "lemon" is run with the "-m" command-line option.
32***************** Begin makeheaders token definitions *************************/
33%%
34/**************** End makeheaders token definitions ***************************/
drh822a62f2015-11-09 19:35:18 +000035
36/* The next sections is a series of control #defines.
drh75897232000-05-29 14:26:00 +000037** various aspects of the generated parser.
drh82415f22015-11-09 19:33:42 +000038** YYCODETYPE is the data type used to store the integer codes
39** that represent terminal and non-terminal symbols.
40** "unsigned char" is used if there are fewer than
41** 256 symbols. Larger types otherwise.
42** YYNOCODE is a number of type YYCODETYPE that is not used for
43** any terminal or nonterminal symbol.
drh0bd1f4e2002-06-06 18:54:39 +000044** YYFALLBACK If defined, this indicates that one or more tokens
drh82415f22015-11-09 19:33:42 +000045** (also known as: "terminal symbols") have fall-back
46** values which should be used if the original symbol
47** would not parse. This permits keywords to sometimes
48** be used as identifiers, for example.
49** YYACTIONTYPE is the data type used for "action codes" - numbers
50** that indicate what to do in response to the next
51** token.
52** ParseTOKENTYPE is the data type used for minor type for terminal
53** symbols. Background: A "minor type" is a semantic
54** value associated with a terminal or non-terminal
55** symbols. For example, for an "ID" terminal symbol,
56** the minor type might be the name of the identifier.
57** Each non-terminal can have a different minor type.
58** Terminal symbols all have the same minor type, though.
59** This macros defines the minor type for terminal
60** symbols.
61** YYMINORTYPE is the data type used for all minor types.
drh75897232000-05-29 14:26:00 +000062** This is typically a union of many types, one of
63** which is ParseTOKENTYPE. The entry in the union
drh82415f22015-11-09 19:33:42 +000064** for terminal symbols is called "yy0".
drhb19fd012007-03-29 01:44:45 +000065** YYSTACKDEPTH is the maximum depth of the parser's stack. If
66** zero the stack is dynamically sized using realloc()
drh1f245e42002-03-11 13:55:50 +000067** ParseARG_SDECL A static variable declaration for the %extra_argument
68** ParseARG_PDECL A parameter declaration for the %extra_argument
69** ParseARG_STORE Code to store %extra_argument into yypParser
70** ParseARG_FETCH Code to extract %extra_argument from yypParser
drh75897232000-05-29 14:26:00 +000071** YYERRORSYMBOL is the code number of the error symbol. If not
72** defined, then do no error processing.
drh3bd48ab2015-09-07 18:23:37 +000073** YYNSTATE the combined number of states.
74** YYNRULE the number of rules in the grammar
75** YY_MAX_SHIFT Maximum value for shift actions
76** YY_MIN_SHIFTREDUCE Minimum value for shift-reduce actions
77** YY_MAX_SHIFTREDUCE Maximum value for shift-reduce actions
78** YY_MIN_REDUCE Maximum value for reduce actions
79** YY_ERROR_ACTION The yy_action[] code for syntax error
80** YY_ACCEPT_ACTION The yy_action[] code for accept
81** YY_NO_ACTION The yy_action[] code for no-op
drh75897232000-05-29 14:26:00 +000082*/
drh82415f22015-11-09 19:33:42 +000083#ifndef INTERFACE
84# define INTERFACE 1
85#endif
86/************* Begin control #defines *****************************************/
drh75897232000-05-29 14:26:00 +000087%%
drh82415f22015-11-09 19:33:42 +000088/************* End control #defines *******************************************/
drh75897232000-05-29 14:26:00 +000089
drh8a415d32009-06-12 13:53:51 +000090/* Define the yytestcase() macro to be a no-op if is not already defined
91** otherwise.
92**
93** Applications can choose to define yytestcase() in the %include section
94** to a macro that can assist in verifying code coverage. For production
95** code the yytestcase() macro should be turned off. But it is useful
96** for testing.
97*/
98#ifndef yytestcase
99# define yytestcase(X)
100#endif
101
drh26c9b5e2008-04-11 14:56:53 +0000102
drh34ff57b2008-07-14 12:27:51 +0000103/* Next are the tables used to determine what action to take based on the
drh8b582012003-10-21 13:16:03 +0000104** current state and lookahead token. These tables are used to implement
105** functions that take a state number and lookahead value and return an
106** action integer.
drh75897232000-05-29 14:26:00 +0000107**
drh8548a052003-10-22 22:15:27 +0000108** Suppose the action integer is N. Then the action is determined as
109** follows
drh75897232000-05-29 14:26:00 +0000110**
drh3bd48ab2015-09-07 18:23:37 +0000111** 0 <= N <= YY_MAX_SHIFT Shift N. That is, push the lookahead
drh8548a052003-10-22 22:15:27 +0000112** token onto the stack and goto state N.
113**
drh3bd48ab2015-09-07 18:23:37 +0000114** N between YY_MIN_SHIFTREDUCE Shift to an arbitrary state then
115** and YY_MAX_SHIFTREDUCE reduce by rule N-YY_MIN_SHIFTREDUCE.
drh8548a052003-10-22 22:15:27 +0000116**
drh3bd48ab2015-09-07 18:23:37 +0000117** N between YY_MIN_REDUCE Reduce by rule N-YY_MIN_REDUCE
118** and YY_MAX_REDUCE
drh701b6882016-08-10 13:30:43 +0000119**
drh3bd48ab2015-09-07 18:23:37 +0000120** N == YY_ERROR_ACTION A syntax error has occurred.
drh8548a052003-10-22 22:15:27 +0000121**
drh3bd48ab2015-09-07 18:23:37 +0000122** N == YY_ACCEPT_ACTION The parser accepts its input.
drh8548a052003-10-22 22:15:27 +0000123**
drh3bd48ab2015-09-07 18:23:37 +0000124** N == YY_NO_ACTION No such action. Denotes unused
drh8548a052003-10-22 22:15:27 +0000125** slots in the yy_action[] table.
126**
127** The action table is constructed as a single large table named yy_action[].
drh701b6882016-08-10 13:30:43 +0000128** Given state S and lookahead X, the action is computed as either:
drh75897232000-05-29 14:26:00 +0000129**
drh701b6882016-08-10 13:30:43 +0000130** (A) N = yy_action[ yy_shift_ofst[S] + X ]
131** (B) N = yy_default[S]
drh8b582012003-10-21 13:16:03 +0000132**
drh701b6882016-08-10 13:30:43 +0000133** The (A) formula is preferred. The B formula is used instead if:
134** (1) The yy_shift_ofst[S]+X value is out of range, or
135** (2) yy_lookahead[yy_shift_ofst[S]+X] is not equal to X, or
136** (3) yy_shift_ofst[S] equal YY_SHIFT_USE_DFLT.
137** (Implementation note: YY_SHIFT_USE_DFLT is chosen so that
138** YY_SHIFT_USE_DFLT+X will be out of range for all possible lookaheads X.
139** Hence only tests (1) and (2) need to be evaluated.)
drh8b582012003-10-21 13:16:03 +0000140**
drh701b6882016-08-10 13:30:43 +0000141** The formulas above are for computing the action when the lookahead is
drh8b582012003-10-21 13:16:03 +0000142** a terminal symbol. If the lookahead is a non-terminal (as occurs after
143** a reduce action) then the yy_reduce_ofst[] array is used in place of
144** the yy_shift_ofst[] array and YY_REDUCE_USE_DFLT is used in place of
145** YY_SHIFT_USE_DFLT.
146**
147** The following are the tables generated in this section:
148**
149** yy_action[] A single table containing all actions.
150** yy_lookahead[] A table containing the lookahead for each entry in
151** yy_action. Used to detect hash collisions.
152** yy_shift_ofst[] For each state, the offset into yy_action for
153** shifting terminals.
154** yy_reduce_ofst[] For each state, the offset into yy_action for
155** shifting non-terminals after a reduce.
156** yy_default[] Default action for each state.
drh82415f22015-11-09 19:33:42 +0000157**
158*********** Begin parsing tables **********************************************/
drh75897232000-05-29 14:26:00 +0000159%%
drh82415f22015-11-09 19:33:42 +0000160/********** End of lemon-generated parsing tables *****************************/
drh75897232000-05-29 14:26:00 +0000161
drh82415f22015-11-09 19:33:42 +0000162/* The next table maps tokens (terminal symbols) into fallback tokens.
163** If a construct like the following:
drh0bd1f4e2002-06-06 18:54:39 +0000164**
165** %fallback ID X Y Z.
166**
drh34ff57b2008-07-14 12:27:51 +0000167** appears in the grammar, then ID becomes a fallback token for X, Y,
drh0bd1f4e2002-06-06 18:54:39 +0000168** and Z. Whenever one of the tokens X, Y, or Z is input to the parser
169** but it does not parse, the type of the token is changed to ID and
170** the parse is retried before an error is thrown.
drh82415f22015-11-09 19:33:42 +0000171**
172** This feature can be used, for example, to cause some keywords in a language
173** to revert to identifiers if they keyword does not apply in the context where
174** it appears.
drh0bd1f4e2002-06-06 18:54:39 +0000175*/
176#ifdef YYFALLBACK
177static const YYCODETYPE yyFallback[] = {
178%%
179};
180#endif /* YYFALLBACK */
181
drh75897232000-05-29 14:26:00 +0000182/* The following structure represents a single element of the
183** parser's stack. Information stored includes:
184**
185** + The state number for the parser at this level of the stack.
186**
187** + The value of the token stored at this level of the stack.
188** (In other words, the "major" token.)
189**
190** + The semantic value stored at this level of the stack. This is
191** the information used by the action routines in the grammar.
192** It is sometimes called the "minor" token.
drha248a722015-09-07 19:52:55 +0000193**
194** After the "shift" half of a SHIFTREDUCE action, the stateno field
195** actually contains the reduce action for the second half of the
196** SHIFTREDUCE.
drh75897232000-05-29 14:26:00 +0000197*/
198struct yyStackEntry {
drha248a722015-09-07 19:52:55 +0000199 YYACTIONTYPE stateno; /* The state-number, or reduce action in SHIFTREDUCE */
drh2abcd582008-07-24 23:34:07 +0000200 YYCODETYPE major; /* The major token value. This is the code
201 ** number for the token at this stack level */
202 YYMINORTYPE minor; /* The user-supplied minor token value. This
203 ** is the value of the token */
drh75897232000-05-29 14:26:00 +0000204};
drh1f245e42002-03-11 13:55:50 +0000205typedef struct yyStackEntry yyStackEntry;
drh75897232000-05-29 14:26:00 +0000206
207/* The state of the parser is completely contained in an instance of
208** the following structure */
209struct yyParser {
drh118ab652016-05-23 21:56:24 +0000210 yyStackEntry *yytos; /* Pointer to top element of the stack */
drhec424a52008-07-25 15:39:03 +0000211#ifdef YYTRACKMAXSTACKDEPTH
drh118ab652016-05-23 21:56:24 +0000212 int yyhwm; /* High-water mark of the stack */
drhec424a52008-07-25 15:39:03 +0000213#endif
drhdab943c2016-02-16 01:01:43 +0000214#ifndef YYNOERRORRECOVERY
drh1f245e42002-03-11 13:55:50 +0000215 int yyerrcnt; /* Shifts left before out of the error */
drhdab943c2016-02-16 01:01:43 +0000216#endif
drh1f245e42002-03-11 13:55:50 +0000217 ParseARG_SDECL /* A place to hold %extra_argument */
drhb19fd012007-03-29 01:44:45 +0000218#if YYSTACKDEPTH<=0
219 int yystksz; /* Current side of the stack */
220 yyStackEntry *yystack; /* The parser's stack */
drh8dc82472016-05-27 04:10:47 +0000221 yyStackEntry yystk0; /* First stack entry */
drhb19fd012007-03-29 01:44:45 +0000222#else
drh1f245e42002-03-11 13:55:50 +0000223 yyStackEntry yystack[YYSTACKDEPTH]; /* The parser's stack */
drhb19fd012007-03-29 01:44:45 +0000224#endif
drh75897232000-05-29 14:26:00 +0000225};
226typedef struct yyParser yyParser;
227
228#ifndef NDEBUG
229#include <stdio.h>
230static FILE *yyTraceFILE = 0;
231static char *yyTracePrompt = 0;
drh0bd1f4e2002-06-06 18:54:39 +0000232#endif /* NDEBUG */
drh75897232000-05-29 14:26:00 +0000233
drh0bd1f4e2002-06-06 18:54:39 +0000234#ifndef NDEBUG
drh75897232000-05-29 14:26:00 +0000235/*
236** Turn parser tracing on by giving a stream to which to write the trace
237** and a prompt to preface each trace message. Tracing is turned off
238** by making either argument NULL
239**
240** Inputs:
241** <ul>
242** <li> A FILE* to which trace output should be written.
243** If NULL, then tracing is turned off.
244** <li> A prefix string written at the beginning of every
245** line of trace output. If NULL, then tracing is
246** turned off.
247** </ul>
248**
249** Outputs:
250** None.
251*/
drh75897232000-05-29 14:26:00 +0000252void ParseTrace(FILE *TraceFILE, char *zTracePrompt){
253 yyTraceFILE = TraceFILE;
254 yyTracePrompt = zTracePrompt;
255 if( yyTraceFILE==0 ) yyTracePrompt = 0;
256 else if( yyTracePrompt==0 ) yyTraceFILE = 0;
257}
drh0bd1f4e2002-06-06 18:54:39 +0000258#endif /* NDEBUG */
drh75897232000-05-29 14:26:00 +0000259
drh0bd1f4e2002-06-06 18:54:39 +0000260#ifndef NDEBUG
drh75897232000-05-29 14:26:00 +0000261/* For tracing shifts, the names of all terminals and nonterminals
262** are required. The following table supplies these names */
drh57196282004-10-06 15:41:16 +0000263static const char *const yyTokenName[] = {
drh75897232000-05-29 14:26:00 +0000264%%
265};
drh0bd1f4e2002-06-06 18:54:39 +0000266#endif /* NDEBUG */
drh75897232000-05-29 14:26:00 +0000267
drh0bd1f4e2002-06-06 18:54:39 +0000268#ifndef NDEBUG
269/* For tracing reduce actions, the names of all rules are required.
270*/
drh57196282004-10-06 15:41:16 +0000271static const char *const yyRuleName[] = {
drh0bd1f4e2002-06-06 18:54:39 +0000272%%
273};
274#endif /* NDEBUG */
drha1b351a2001-09-14 16:42:12 +0000275
drh960e8c62001-04-03 16:53:21 +0000276
drhb19fd012007-03-29 01:44:45 +0000277#if YYSTACKDEPTH<=0
278/*
drh8dc82472016-05-27 04:10:47 +0000279** Try to increase the size of the parser stack. Return the number
280** of errors. Return 0 on success.
drhb19fd012007-03-29 01:44:45 +0000281*/
drh8dc82472016-05-27 04:10:47 +0000282static int yyGrowStack(yyParser *p){
drhb19fd012007-03-29 01:44:45 +0000283 int newSize;
drhabecc0b2016-05-24 00:40:54 +0000284 int idx;
drhb19fd012007-03-29 01:44:45 +0000285 yyStackEntry *pNew;
286
287 newSize = p->yystksz*2 + 100;
drhabecc0b2016-05-24 00:40:54 +0000288 idx = p->yytos ? (int)(p->yytos - p->yystack) : 0;
drh8dc82472016-05-27 04:10:47 +0000289 if( p->yystack==&p->yystk0 ){
290 pNew = malloc(newSize*sizeof(pNew[0]));
291 if( pNew ) pNew[0] = p->yystk0;
292 }else{
293 pNew = realloc(p->yystack, newSize*sizeof(pNew[0]));
294 }
drhb19fd012007-03-29 01:44:45 +0000295 if( pNew ){
296 p->yystack = pNew;
drhabecc0b2016-05-24 00:40:54 +0000297 p->yytos = &p->yystack[idx];
drhb19fd012007-03-29 01:44:45 +0000298#ifndef NDEBUG
299 if( yyTraceFILE ){
drh8dc82472016-05-27 04:10:47 +0000300 fprintf(yyTraceFILE,"%sStack grows from %d to %d entries.\n",
301 yyTracePrompt, p->yystksz, newSize);
drhb19fd012007-03-29 01:44:45 +0000302 }
303#endif
drh8dc82472016-05-27 04:10:47 +0000304 p->yystksz = newSize;
drhb19fd012007-03-29 01:44:45 +0000305 }
drh8dc82472016-05-27 04:10:47 +0000306 return pNew==0;
drhb19fd012007-03-29 01:44:45 +0000307}
308#endif
309
drh82415f22015-11-09 19:33:42 +0000310/* Datatype of the argument to the memory allocated passed as the
311** second argument to ParseAlloc() below. This can be changed by
312** putting an appropriate #define in the %include section of the input
313** grammar.
314*/
315#ifndef YYMALLOCARGTYPE
316# define YYMALLOCARGTYPE size_t
317#endif
318
drh75897232000-05-29 14:26:00 +0000319/*
320** This function allocates a new parser.
321** The only argument is a pointer to a function which works like
322** malloc.
323**
324** Inputs:
325** A pointer to the function used to allocate memory.
326**
327** Outputs:
328** A pointer to a parser. This pointer is used in subsequent calls
329** to Parse and ParseFree.
330*/
drh82415f22015-11-09 19:33:42 +0000331void *ParseAlloc(void *(*mallocProc)(YYMALLOCARGTYPE)){
drh75897232000-05-29 14:26:00 +0000332 yyParser *pParser;
drh82415f22015-11-09 19:33:42 +0000333 pParser = (yyParser*)(*mallocProc)( (YYMALLOCARGTYPE)sizeof(yyParser) );
drh75897232000-05-29 14:26:00 +0000334 if( pParser ){
drhec424a52008-07-25 15:39:03 +0000335#ifdef YYTRACKMAXSTACKDEPTH
drh118ab652016-05-23 21:56:24 +0000336 pParser->yyhwm = 0;
drhec424a52008-07-25 15:39:03 +0000337#endif
drhb19fd012007-03-29 01:44:45 +0000338#if YYSTACKDEPTH<=0
drhabecc0b2016-05-24 00:40:54 +0000339 pParser->yytos = NULL;
drh4c651782008-11-18 23:25:54 +0000340 pParser->yystack = NULL;
341 pParser->yystksz = 0;
drh8dc82472016-05-27 04:10:47 +0000342 if( yyGrowStack(pParser) ){
343 pParser->yystack = &pParser->yystk0;
344 pParser->yystksz = 1;
345 }
drhb19fd012007-03-29 01:44:45 +0000346#endif
drh4335ad02016-06-06 13:24:57 +0000347#ifndef YYNOERRORRECOVERY
348 pParser->yyerrcnt = -1;
349#endif
drhabecc0b2016-05-24 00:40:54 +0000350 pParser->yytos = pParser->yystack;
351 pParser->yystack[0].stateno = 0;
352 pParser->yystack[0].major = 0;
drh75897232000-05-29 14:26:00 +0000353 }
354 return pParser;
355}
356
drh82415f22015-11-09 19:33:42 +0000357/* The following function deletes the "minor type" or semantic value
358** associated with a symbol. The symbol can be either a terminal
359** or nonterminal. "yymajor" is the symbol code, and "yypminor" is
360** a pointer to the value to be deleted. The code used to do the
361** deletions is derived from the %destructor and/or %token_destructor
362** directives of the input grammar.
drh75897232000-05-29 14:26:00 +0000363*/
drh633e6d52008-07-28 19:34:53 +0000364static void yy_destructor(
365 yyParser *yypParser, /* The parser */
366 YYCODETYPE yymajor, /* Type code for object to destroy */
367 YYMINORTYPE *yypminor /* The object to be destroyed */
368){
369 ParseARG_FETCH;
drh75897232000-05-29 14:26:00 +0000370 switch( yymajor ){
371 /* Here is inserted the actions which take place when a
372 ** terminal or non-terminal is destroyed. This can happen
373 ** when the symbol is popped from the stack during a
374 ** reduce or during error processing or when a parser is
375 ** being destroyed before it is finished parsing.
376 **
377 ** Note: during a reduce, the only symbols destroyed are those
drh82415f22015-11-09 19:33:42 +0000378 ** which appear on the RHS of the rule, but which are *not* used
drh75897232000-05-29 14:26:00 +0000379 ** inside the C code.
380 */
drh82415f22015-11-09 19:33:42 +0000381/********* Begin destructor definitions ***************************************/
drh75897232000-05-29 14:26:00 +0000382%%
drh82415f22015-11-09 19:33:42 +0000383/********* End destructor definitions *****************************************/
drh75897232000-05-29 14:26:00 +0000384 default: break; /* If no destructor action specified: do nothing */
385 }
386}
387
388/*
389** Pop the parser's stack once.
390**
391** If there is a destructor routine associated with the token which
392** is popped from the stack, then call it.
drh75897232000-05-29 14:26:00 +0000393*/
drh3781f012015-11-09 14:11:37 +0000394static void yy_pop_parser_stack(yyParser *pParser){
395 yyStackEntry *yytos;
drh118ab652016-05-23 21:56:24 +0000396 assert( pParser->yytos!=0 );
drh240c7fa2016-07-05 12:47:28 +0000397 assert( pParser->yytos > pParser->yystack );
drh118ab652016-05-23 21:56:24 +0000398 yytos = pParser->yytos--;
drh75897232000-05-29 14:26:00 +0000399#ifndef NDEBUG
drh3781f012015-11-09 14:11:37 +0000400 if( yyTraceFILE ){
drh75897232000-05-29 14:26:00 +0000401 fprintf(yyTraceFILE,"%sPopping %s\n",
402 yyTracePrompt,
drh3ddfdf72003-12-22 14:53:19 +0000403 yyTokenName[yytos->major]);
drh75897232000-05-29 14:26:00 +0000404 }
405#endif
drh3781f012015-11-09 14:11:37 +0000406 yy_destructor(pParser, yytos->major, &yytos->minor);
drh75897232000-05-29 14:26:00 +0000407}
408
409/*
drh82415f22015-11-09 19:33:42 +0000410** Deallocate and destroy a parser. Destructors are called for
drh75897232000-05-29 14:26:00 +0000411** all stack elements before shutting the parser down.
412**
drh82415f22015-11-09 19:33:42 +0000413** If the YYPARSEFREENEVERNULL macro exists (for example because it
414** is defined in a %include section of the input grammar) then it is
415** assumed that the input pointer is never NULL.
drh75897232000-05-29 14:26:00 +0000416*/
drh75897232000-05-29 14:26:00 +0000417void ParseFree(
drh960e8c62001-04-03 16:53:21 +0000418 void *p, /* The parser to be deleted */
419 void (*freeProc)(void*) /* Function used to reclaim memory */
drh75897232000-05-29 14:26:00 +0000420){
421 yyParser *pParser = (yyParser*)p;
drh82415f22015-11-09 19:33:42 +0000422#ifndef YYPARSEFREENEVERNULL
drh75897232000-05-29 14:26:00 +0000423 if( pParser==0 ) return;
drh82415f22015-11-09 19:33:42 +0000424#endif
drhabecc0b2016-05-24 00:40:54 +0000425 while( pParser->yytos>pParser->yystack ) yy_pop_parser_stack(pParser);
drhb19fd012007-03-29 01:44:45 +0000426#if YYSTACKDEPTH<=0
drh8dc82472016-05-27 04:10:47 +0000427 if( pParser->yystack!=&pParser->yystk0 ) free(pParser->yystack);
drhb19fd012007-03-29 01:44:45 +0000428#endif
drh960e8c62001-04-03 16:53:21 +0000429 (*freeProc)((void*)pParser);
drh75897232000-05-29 14:26:00 +0000430}
431
432/*
drhec424a52008-07-25 15:39:03 +0000433** Return the peak depth of the stack for a parser.
434*/
435#ifdef YYTRACKMAXSTACKDEPTH
436int ParseStackPeak(void *p){
437 yyParser *pParser = (yyParser*)p;
drh118ab652016-05-23 21:56:24 +0000438 return pParser->yyhwm;
drhec424a52008-07-25 15:39:03 +0000439}
440#endif
441
442/*
drh8b582012003-10-21 13:16:03 +0000443** Find the appropriate action for a parser given the terminal
444** look-ahead token iLookAhead.
drh75897232000-05-29 14:26:00 +0000445*/
drh4ef07702016-03-16 19:45:54 +0000446static unsigned int yy_find_shift_action(
drh75897232000-05-29 14:26:00 +0000447 yyParser *pParser, /* The parser */
drhd9f291e2006-06-13 11:15:47 +0000448 YYCODETYPE iLookAhead /* The look-ahead token */
drh75897232000-05-29 14:26:00 +0000449){
drh8b582012003-10-21 13:16:03 +0000450 int i;
drh118ab652016-05-23 21:56:24 +0000451 int stateno = pParser->yytos->stateno;
drha4414042015-11-09 15:06:26 +0000452
453 if( stateno>=YY_MIN_REDUCE ) return stateno;
drhae2a4082015-09-07 20:02:39 +0000454 assert( stateno <= YY_SHIFT_COUNT );
drha4414042015-11-09 15:06:26 +0000455 do{
456 i = yy_shift_ofst[stateno];
drha4414042015-11-09 15:06:26 +0000457 assert( iLookAhead!=YYNOCODE );
458 i += iLookAhead;
459 if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){
drh4767d972006-06-14 15:03:49 +0000460#ifdef YYFALLBACK
drhc83db9e2016-08-10 01:43:30 +0000461 YYCODETYPE iFallback; /* Fallback token */
462 if( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0])
463 && (iFallback = yyFallback[iLookAhead])!=0 ){
drh4767d972006-06-14 15:03:49 +0000464#ifndef NDEBUG
drhc83db9e2016-08-10 01:43:30 +0000465 if( yyTraceFILE ){
466 fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n",
467 yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]);
drhe09daa92006-06-10 13:29:31 +0000468 }
drha4414042015-11-09 15:06:26 +0000469#endif
drhc83db9e2016-08-10 01:43:30 +0000470 assert( yyFallback[iFallback]==0 ); /* Fallback loop must terminate */
471 iLookAhead = iFallback;
472 continue;
473 }
474#endif
drha4414042015-11-09 15:06:26 +0000475#ifdef YYWILDCARD
drhc83db9e2016-08-10 01:43:30 +0000476 {
477 int j = i - iLookAhead + YYWILDCARD;
478 if(
drha4414042015-11-09 15:06:26 +0000479#if YY_SHIFT_MIN+YYWILDCARD<0
drhc83db9e2016-08-10 01:43:30 +0000480 j>=0 &&
drha4414042015-11-09 15:06:26 +0000481#endif
482#if YY_SHIFT_MAX+YYWILDCARD>=YY_ACTTAB_COUNT
drhc83db9e2016-08-10 01:43:30 +0000483 j<YY_ACTTAB_COUNT &&
drha4414042015-11-09 15:06:26 +0000484#endif
drhc83db9e2016-08-10 01:43:30 +0000485 yy_lookahead[j]==YYWILDCARD && iLookAhead>0
486 ){
drha4414042015-11-09 15:06:26 +0000487#ifndef NDEBUG
drhc83db9e2016-08-10 01:43:30 +0000488 if( yyTraceFILE ){
489 fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n",
490 yyTracePrompt, yyTokenName[iLookAhead],
491 yyTokenName[YYWILDCARD]);
drha4414042015-11-09 15:06:26 +0000492 }
drhc83db9e2016-08-10 01:43:30 +0000493#endif /* NDEBUG */
494 return yy_action[j];
drha4414042015-11-09 15:06:26 +0000495 }
drha4414042015-11-09 15:06:26 +0000496 }
drhc83db9e2016-08-10 01:43:30 +0000497#endif /* YYWILDCARD */
drha4414042015-11-09 15:06:26 +0000498 return yy_default[stateno];
499 }else{
500 return yy_action[i];
drh0bd1f4e2002-06-06 18:54:39 +0000501 }
drha4414042015-11-09 15:06:26 +0000502 }while(1);
drh8b582012003-10-21 13:16:03 +0000503}
504
505/*
506** Find the appropriate action for a parser given the non-terminal
507** look-ahead token iLookAhead.
drh8b582012003-10-21 13:16:03 +0000508*/
509static int yy_find_reduce_action(
drh161aba32005-02-01 04:09:36 +0000510 int stateno, /* Current state number */
drhd9f291e2006-06-13 11:15:47 +0000511 YYCODETYPE iLookAhead /* The look-ahead token */
drh8b582012003-10-21 13:16:03 +0000512){
513 int i;
drh7f7c2572008-04-27 18:45:10 +0000514#ifdef YYERRORSYMBOL
drhf16371d2009-11-03 19:18:31 +0000515 if( stateno>YY_REDUCE_COUNT ){
drh7f7c2572008-04-27 18:45:10 +0000516 return yy_default[stateno];
517 }
518#else
drhf16371d2009-11-03 19:18:31 +0000519 assert( stateno<=YY_REDUCE_COUNT );
drh7f7c2572008-04-27 18:45:10 +0000520#endif
drh01495b92008-01-23 12:52:40 +0000521 i = yy_reduce_ofst[stateno];
522 assert( i!=YY_REDUCE_USE_DFLT );
523 assert( iLookAhead!=YYNOCODE );
drh8b582012003-10-21 13:16:03 +0000524 i += iLookAhead;
drh7f7c2572008-04-27 18:45:10 +0000525#ifdef YYERRORSYMBOL
drhf16371d2009-11-03 19:18:31 +0000526 if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){
drh7f7c2572008-04-27 18:45:10 +0000527 return yy_default[stateno];
528 }
529#else
drhf16371d2009-11-03 19:18:31 +0000530 assert( i>=0 && i<YY_ACTTAB_COUNT );
drh01495b92008-01-23 12:52:40 +0000531 assert( yy_lookahead[i]==iLookAhead );
drh7f7c2572008-04-27 18:45:10 +0000532#endif
drh01495b92008-01-23 12:52:40 +0000533 return yy_action[i];
drh75897232000-05-29 14:26:00 +0000534}
535
536/*
drhb19fd012007-03-29 01:44:45 +0000537** The following routine is called if the stack overflows.
538*/
drh45f31be2016-02-16 21:19:49 +0000539static void yyStackOverflow(yyParser *yypParser){
drhb19fd012007-03-29 01:44:45 +0000540 ParseARG_FETCH;
drh118ab652016-05-23 21:56:24 +0000541 yypParser->yytos--;
drhb19fd012007-03-29 01:44:45 +0000542#ifndef NDEBUG
543 if( yyTraceFILE ){
544 fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt);
545 }
546#endif
drhabecc0b2016-05-24 00:40:54 +0000547 while( yypParser->yytos>yypParser->yystack ) yy_pop_parser_stack(yypParser);
drhb19fd012007-03-29 01:44:45 +0000548 /* Here code is inserted which will execute if the parser
549 ** stack every overflows */
drh82415f22015-11-09 19:33:42 +0000550/******** Begin %stack_overflow code ******************************************/
drhb19fd012007-03-29 01:44:45 +0000551%%
drh82415f22015-11-09 19:33:42 +0000552/******** End %stack_overflow code ********************************************/
drhb19fd012007-03-29 01:44:45 +0000553 ParseARG_STORE; /* Suppress warning about unused %extra_argument var */
554}
555
556/*
drha248a722015-09-07 19:52:55 +0000557** Print tracing information for a SHIFT action
558*/
559#ifndef NDEBUG
560static void yyTraceShift(yyParser *yypParser, int yyNewState){
561 if( yyTraceFILE ){
drha248a722015-09-07 19:52:55 +0000562 if( yyNewState<YYNSTATE ){
drh0c4105e2015-11-10 14:51:22 +0000563 fprintf(yyTraceFILE,"%sShift '%s', go to state %d\n",
drh118ab652016-05-23 21:56:24 +0000564 yyTracePrompt,yyTokenName[yypParser->yytos->major],
drh0c4105e2015-11-10 14:51:22 +0000565 yyNewState);
drha248a722015-09-07 19:52:55 +0000566 }else{
drh0c4105e2015-11-10 14:51:22 +0000567 fprintf(yyTraceFILE,"%sShift '%s'\n",
drh118ab652016-05-23 21:56:24 +0000568 yyTracePrompt,yyTokenName[yypParser->yytos->major]);
drha248a722015-09-07 19:52:55 +0000569 }
570 }
571}
572#else
573# define yyTraceShift(X,Y)
574#endif
575
576/*
drh82415f22015-11-09 19:33:42 +0000577** Perform a shift action.
drh75897232000-05-29 14:26:00 +0000578*/
drha248a722015-09-07 19:52:55 +0000579static void yy_shift(
drh75897232000-05-29 14:26:00 +0000580 yyParser *yypParser, /* The parser to be shifted */
581 int yyNewState, /* The new state to shift in */
582 int yyMajor, /* The major token to shift in */
drh45f31be2016-02-16 21:19:49 +0000583 ParseTOKENTYPE yyMinor /* The minor token to shift in */
drh75897232000-05-29 14:26:00 +0000584){
drh3ddfdf72003-12-22 14:53:19 +0000585 yyStackEntry *yytos;
drh118ab652016-05-23 21:56:24 +0000586 yypParser->yytos++;
drhec424a52008-07-25 15:39:03 +0000587#ifdef YYTRACKMAXSTACKDEPTH
drh118ab652016-05-23 21:56:24 +0000588 if( (int)(yypParser->yytos - yypParser->yystack)>yypParser->yyhwm ){
589 yypParser->yyhwm++;
590 assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack) );
drhec424a52008-07-25 15:39:03 +0000591 }
592#endif
drhb19fd012007-03-29 01:44:45 +0000593#if YYSTACKDEPTH>0
drh118ab652016-05-23 21:56:24 +0000594 if( yypParser->yytos>=&yypParser->yystack[YYSTACKDEPTH] ){
drh45f31be2016-02-16 21:19:49 +0000595 yyStackOverflow(yypParser);
drha248a722015-09-07 19:52:55 +0000596 return;
drh75897232000-05-29 14:26:00 +0000597 }
drhb19fd012007-03-29 01:44:45 +0000598#else
drh118ab652016-05-23 21:56:24 +0000599 if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz] ){
drh8dc82472016-05-27 04:10:47 +0000600 if( yyGrowStack(yypParser) ){
drh45f31be2016-02-16 21:19:49 +0000601 yyStackOverflow(yypParser);
drha248a722015-09-07 19:52:55 +0000602 return;
drhb19fd012007-03-29 01:44:45 +0000603 }
604 }
605#endif
drh0efd37f2016-06-06 18:17:36 +0000606 if( yyNewState > YY_MAX_SHIFT ){
607 yyNewState += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE;
608 }
drh118ab652016-05-23 21:56:24 +0000609 yytos = yypParser->yytos;
drhb27b7f52008-12-10 18:03:45 +0000610 yytos->stateno = (YYACTIONTYPE)yyNewState;
611 yytos->major = (YYCODETYPE)yyMajor;
drh45f31be2016-02-16 21:19:49 +0000612 yytos->minor.yy0 = yyMinor;
drha248a722015-09-07 19:52:55 +0000613 yyTraceShift(yypParser, yyNewState);
drh75897232000-05-29 14:26:00 +0000614}
615
616/* The following table contains information about every rule that
617** is used during the reduce.
618*/
drh57196282004-10-06 15:41:16 +0000619static const struct {
drh75897232000-05-29 14:26:00 +0000620 YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */
621 unsigned char nrhs; /* Number of right-hand side symbols in the rule */
622} yyRuleInfo[] = {
623%%
624};
625
drh1f245e42002-03-11 13:55:50 +0000626static void yy_accept(yyParser*); /* Forward Declaration */
drh75897232000-05-29 14:26:00 +0000627
628/*
629** Perform a reduce action and the shift that must immediately
630** follow the reduce.
631*/
632static void yy_reduce(
633 yyParser *yypParser, /* The parser */
drh4ef07702016-03-16 19:45:54 +0000634 unsigned int yyruleno /* Number of the rule by which to reduce */
drh75897232000-05-29 14:26:00 +0000635){
636 int yygoto; /* The next state */
637 int yyact; /* The next action */
drh1f245e42002-03-11 13:55:50 +0000638 yyStackEntry *yymsp; /* The top of the parser's stack */
drh75897232000-05-29 14:26:00 +0000639 int yysize; /* Amount to pop the stack */
drh1f245e42002-03-11 13:55:50 +0000640 ParseARG_FETCH;
drh118ab652016-05-23 21:56:24 +0000641 yymsp = yypParser->yytos;
drh0bd1f4e2002-06-06 18:54:39 +0000642#ifndef NDEBUG
drh4ef07702016-03-16 19:45:54 +0000643 if( yyTraceFILE && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){
drh3bd48ab2015-09-07 18:23:37 +0000644 yysize = yyRuleInfo[yyruleno].nrhs;
drh0c4105e2015-11-10 14:51:22 +0000645 fprintf(yyTraceFILE, "%sReduce [%s], go to state %d.\n", yyTracePrompt,
drh3bd48ab2015-09-07 18:23:37 +0000646 yyRuleName[yyruleno], yymsp[-yysize].stateno);
drh0bd1f4e2002-06-06 18:54:39 +0000647 }
648#endif /* NDEBUG */
drh45f31be2016-02-16 21:19:49 +0000649
650 /* Check that the stack is large enough to grow by a single entry
651 ** if the RHS of the rule is empty. This ensures that there is room
652 ** enough on the stack to push the LHS value */
653 if( yyRuleInfo[yyruleno].nrhs==0 ){
654#ifdef YYTRACKMAXSTACKDEPTH
drh118ab652016-05-23 21:56:24 +0000655 if( (int)(yypParser->yytos - yypParser->yystack)>yypParser->yyhwm ){
656 yypParser->yyhwm++;
657 assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack));
drh45f31be2016-02-16 21:19:49 +0000658 }
659#endif
660#if YYSTACKDEPTH>0
drh118ab652016-05-23 21:56:24 +0000661 if( yypParser->yytos>=&yypParser->yystack[YYSTACKDEPTH-1] ){
drh45f31be2016-02-16 21:19:49 +0000662 yyStackOverflow(yypParser);
663 return;
664 }
665#else
drh118ab652016-05-23 21:56:24 +0000666 if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz-1] ){
drh8dc82472016-05-27 04:10:47 +0000667 if( yyGrowStack(yypParser) ){
drh45f31be2016-02-16 21:19:49 +0000668 yyStackOverflow(yypParser);
669 return;
670 }
drh8dc82472016-05-27 04:10:47 +0000671 yymsp = yypParser->yytos;
drh45f31be2016-02-16 21:19:49 +0000672 }
673#endif
674 }
drhcb6c5652007-01-16 18:19:12 +0000675
drh75897232000-05-29 14:26:00 +0000676 switch( yyruleno ){
677 /* Beginning here are the reduction cases. A typical example
678 ** follows:
679 ** case 0:
drh75897232000-05-29 14:26:00 +0000680 ** #line <lineno> <grammarfile>
681 ** { ... } // User supplied code
682 ** #line <lineno> <thisfile>
683 ** break;
684 */
drh82415f22015-11-09 19:33:42 +0000685/********** Begin reduce actions **********************************************/
drh75897232000-05-29 14:26:00 +0000686%%
drh82415f22015-11-09 19:33:42 +0000687/********** End reduce actions ************************************************/
drh75897232000-05-29 14:26:00 +0000688 };
drh4ef07702016-03-16 19:45:54 +0000689 assert( yyruleno<sizeof(yyRuleInfo)/sizeof(yyRuleInfo[0]) );
drh75897232000-05-29 14:26:00 +0000690 yygoto = yyRuleInfo[yyruleno].lhs;
691 yysize = yyRuleInfo[yyruleno].nrhs;
drh3abbd392008-12-10 23:04:13 +0000692 yyact = yy_find_reduce_action(yymsp[-yysize].stateno,(YYCODETYPE)yygoto);
drha248a722015-09-07 19:52:55 +0000693 if( yyact <= YY_MAX_SHIFTREDUCE ){
drh118ab652016-05-23 21:56:24 +0000694 if( yyact>YY_MAX_SHIFT ){
695 yyact += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE;
696 }
drh45f31be2016-02-16 21:19:49 +0000697 yymsp -= yysize-1;
drh118ab652016-05-23 21:56:24 +0000698 yypParser->yytos = yymsp;
drh45f31be2016-02-16 21:19:49 +0000699 yymsp->stateno = (YYACTIONTYPE)yyact;
700 yymsp->major = (YYCODETYPE)yygoto;
drh45f31be2016-02-16 21:19:49 +0000701 yyTraceShift(yypParser, yyact);
drh4b2f9362008-01-22 23:37:09 +0000702 }else{
drh3bd48ab2015-09-07 18:23:37 +0000703 assert( yyact == YY_ACCEPT_ACTION );
drh118ab652016-05-23 21:56:24 +0000704 yypParser->yytos -= yysize;
drh1f245e42002-03-11 13:55:50 +0000705 yy_accept(yypParser);
drh75897232000-05-29 14:26:00 +0000706 }
707}
708
709/*
710** The following code executes when the parse fails
711*/
drhd3ec02d2009-06-12 02:27:14 +0000712#ifndef YYNOERRORRECOVERY
drh75897232000-05-29 14:26:00 +0000713static void yy_parse_failed(
714 yyParser *yypParser /* The parser */
drh75897232000-05-29 14:26:00 +0000715){
drh1f245e42002-03-11 13:55:50 +0000716 ParseARG_FETCH;
drh75897232000-05-29 14:26:00 +0000717#ifndef NDEBUG
718 if( yyTraceFILE ){
719 fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt);
720 }
721#endif
drhabecc0b2016-05-24 00:40:54 +0000722 while( yypParser->yytos>yypParser->yystack ) yy_pop_parser_stack(yypParser);
drh75897232000-05-29 14:26:00 +0000723 /* Here code is inserted which will be executed whenever the
724 ** parser fails */
drh82415f22015-11-09 19:33:42 +0000725/************ Begin %parse_failure code ***************************************/
drh75897232000-05-29 14:26:00 +0000726%%
drh82415f22015-11-09 19:33:42 +0000727/************ End %parse_failure code *****************************************/
drh1f245e42002-03-11 13:55:50 +0000728 ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
drh75897232000-05-29 14:26:00 +0000729}
drhd3ec02d2009-06-12 02:27:14 +0000730#endif /* YYNOERRORRECOVERY */
drh75897232000-05-29 14:26:00 +0000731
732/*
733** The following code executes when a syntax error first occurs.
734*/
735static void yy_syntax_error(
736 yyParser *yypParser, /* The parser */
737 int yymajor, /* The major type of the error token */
drh45f31be2016-02-16 21:19:49 +0000738 ParseTOKENTYPE yyminor /* The minor type of the error token */
drh75897232000-05-29 14:26:00 +0000739){
drh1f245e42002-03-11 13:55:50 +0000740 ParseARG_FETCH;
drh45f31be2016-02-16 21:19:49 +0000741#define TOKEN yyminor
drh82415f22015-11-09 19:33:42 +0000742/************ Begin %syntax_error code ****************************************/
drh75897232000-05-29 14:26:00 +0000743%%
drh82415f22015-11-09 19:33:42 +0000744/************ End %syntax_error code ******************************************/
drh1f245e42002-03-11 13:55:50 +0000745 ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
drh75897232000-05-29 14:26:00 +0000746}
747
748/*
749** The following is executed when the parser accepts
750*/
751static void yy_accept(
752 yyParser *yypParser /* The parser */
drh75897232000-05-29 14:26:00 +0000753){
drh1f245e42002-03-11 13:55:50 +0000754 ParseARG_FETCH;
drh75897232000-05-29 14:26:00 +0000755#ifndef NDEBUG
756 if( yyTraceFILE ){
757 fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt);
758 }
759#endif
drhdd703e22016-07-12 19:54:49 +0000760#ifndef YYNOERRORRECOVERY
761 yypParser->yyerrcnt = -1;
762#endif
drh756b41e2016-05-24 18:55:08 +0000763 assert( yypParser->yytos==yypParser->yystack );
drh75897232000-05-29 14:26:00 +0000764 /* Here code is inserted which will be executed whenever the
765 ** parser accepts */
drh82415f22015-11-09 19:33:42 +0000766/*********** Begin %parse_accept code *****************************************/
drh75897232000-05-29 14:26:00 +0000767%%
drh82415f22015-11-09 19:33:42 +0000768/*********** End %parse_accept code *******************************************/
drh1f245e42002-03-11 13:55:50 +0000769 ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
drh75897232000-05-29 14:26:00 +0000770}
771
772/* The main parser program.
773** The first argument is a pointer to a structure obtained from
774** "ParseAlloc" which describes the current state of the parser.
775** The second argument is the major token number. The third is
776** the minor token. The fourth optional argument is whatever the
777** user wants (and specified in the grammar) and is available for
778** use by the action routines.
779**
780** Inputs:
781** <ul>
782** <li> A pointer to the parser (an opaque structure.)
783** <li> The major token number.
784** <li> The minor token number.
785** <li> An option argument of a grammar-specified type.
786** </ul>
787**
788** Outputs:
789** None.
790*/
drh75897232000-05-29 14:26:00 +0000791void Parse(
792 void *yyp, /* The parser */
793 int yymajor, /* The major token code number */
794 ParseTOKENTYPE yyminor /* The value for the token */
drh1f245e42002-03-11 13:55:50 +0000795 ParseARG_PDECL /* Optional %extra_argument parameter */
drh75897232000-05-29 14:26:00 +0000796){
797 YYMINORTYPE yyminorunion;
drh4ef07702016-03-16 19:45:54 +0000798 unsigned int yyact; /* The parser action. */
drha4414042015-11-09 15:06:26 +0000799#if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY)
drh75897232000-05-29 14:26:00 +0000800 int yyendofinput; /* True if we are at the end of input */
drha4414042015-11-09 15:06:26 +0000801#endif
drhc4dd3fd2008-01-22 01:48:05 +0000802#ifdef YYERRORSYMBOL
drh75897232000-05-29 14:26:00 +0000803 int yyerrorhit = 0; /* True if yymajor has invoked an error */
drhc4dd3fd2008-01-22 01:48:05 +0000804#endif
drh75897232000-05-29 14:26:00 +0000805 yyParser *yypParser; /* The parser */
806
drh75897232000-05-29 14:26:00 +0000807 yypParser = (yyParser*)yyp;
drhabecc0b2016-05-24 00:40:54 +0000808 assert( yypParser->yytos!=0 );
drha4414042015-11-09 15:06:26 +0000809#if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY)
drh75897232000-05-29 14:26:00 +0000810 yyendofinput = (yymajor==0);
drha4414042015-11-09 15:06:26 +0000811#endif
drh1f245e42002-03-11 13:55:50 +0000812 ParseARG_STORE;
drh75897232000-05-29 14:26:00 +0000813
814#ifndef NDEBUG
815 if( yyTraceFILE ){
drh0c4105e2015-11-10 14:51:22 +0000816 fprintf(yyTraceFILE,"%sInput '%s'\n",yyTracePrompt,yyTokenName[yymajor]);
drh75897232000-05-29 14:26:00 +0000817 }
818#endif
819
820 do{
drh3abbd392008-12-10 23:04:13 +0000821 yyact = yy_find_shift_action(yypParser,(YYCODETYPE)yymajor);
drh3bd48ab2015-09-07 18:23:37 +0000822 if( yyact <= YY_MAX_SHIFTREDUCE ){
drh45f31be2016-02-16 21:19:49 +0000823 yy_shift(yypParser,yyact,yymajor,yyminor);
drhdab943c2016-02-16 01:01:43 +0000824#ifndef YYNOERRORRECOVERY
drha248a722015-09-07 19:52:55 +0000825 yypParser->yyerrcnt--;
drhdab943c2016-02-16 01:01:43 +0000826#endif
drha248a722015-09-07 19:52:55 +0000827 yymajor = YYNOCODE;
drh3bd48ab2015-09-07 18:23:37 +0000828 }else if( yyact <= YY_MAX_REDUCE ){
829 yy_reduce(yypParser,yyact-YY_MIN_REDUCE);
drhc4dd3fd2008-01-22 01:48:05 +0000830 }else{
831 assert( yyact == YY_ERROR_ACTION );
drh45f31be2016-02-16 21:19:49 +0000832 yyminorunion.yy0 = yyminor;
drhc4dd3fd2008-01-22 01:48:05 +0000833#ifdef YYERRORSYMBOL
drh3ddfdf72003-12-22 14:53:19 +0000834 int yymx;
drhc4dd3fd2008-01-22 01:48:05 +0000835#endif
drh75897232000-05-29 14:26:00 +0000836#ifndef NDEBUG
837 if( yyTraceFILE ){
838 fprintf(yyTraceFILE,"%sSyntax Error!\n",yyTracePrompt);
839 }
840#endif
841#ifdef YYERRORSYMBOL
842 /* A syntax error has occurred.
843 ** The response to an error depends upon whether or not the
844 ** grammar defines an error token "ERROR".
845 **
846 ** This is what we do if the grammar does define ERROR:
847 **
848 ** * Call the %syntax_error function.
849 **
850 ** * Begin popping the stack until we enter a state where
851 ** it is legal to shift the error symbol, then shift
852 ** the error symbol.
853 **
854 ** * Set the error count to three.
855 **
856 ** * Begin accepting and shifting new tokens. No new error
857 ** processing will occur until three tokens have been
858 ** shifted successfully.
859 **
860 */
drh1f245e42002-03-11 13:55:50 +0000861 if( yypParser->yyerrcnt<0 ){
drh45f31be2016-02-16 21:19:49 +0000862 yy_syntax_error(yypParser,yymajor,yyminor);
drh75897232000-05-29 14:26:00 +0000863 }
drh118ab652016-05-23 21:56:24 +0000864 yymx = yypParser->yytos->major;
drh3ddfdf72003-12-22 14:53:19 +0000865 if( yymx==YYERRORSYMBOL || yyerrorhit ){
drh75897232000-05-29 14:26:00 +0000866#ifndef NDEBUG
867 if( yyTraceFILE ){
868 fprintf(yyTraceFILE,"%sDiscard input token %s\n",
869 yyTracePrompt,yyTokenName[yymajor]);
870 }
871#endif
drh45f31be2016-02-16 21:19:49 +0000872 yy_destructor(yypParser, (YYCODETYPE)yymajor, &yyminorunion);
drh75897232000-05-29 14:26:00 +0000873 yymajor = YYNOCODE;
874 }else{
drh4eda15e2016-10-04 12:20:12 +0000875 while( yypParser->yytos >= yypParser->yystack
drh118ab652016-05-23 21:56:24 +0000876 && yymx != YYERRORSYMBOL
877 && (yyact = yy_find_reduce_action(
878 yypParser->yytos->stateno,
drh3bd48ab2015-09-07 18:23:37 +0000879 YYERRORSYMBOL)) >= YY_MIN_REDUCE
drh75897232000-05-29 14:26:00 +0000880 ){
881 yy_pop_parser_stack(yypParser);
882 }
drh118ab652016-05-23 21:56:24 +0000883 if( yypParser->yytos < yypParser->yystack || yymajor==0 ){
drhb27b7f52008-12-10 18:03:45 +0000884 yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
drh1f245e42002-03-11 13:55:50 +0000885 yy_parse_failed(yypParser);
drh240c7fa2016-07-05 12:47:28 +0000886#ifndef YYNOERRORRECOVERY
887 yypParser->yyerrcnt = -1;
888#endif
drh75897232000-05-29 14:26:00 +0000889 yymajor = YYNOCODE;
drh3ddfdf72003-12-22 14:53:19 +0000890 }else if( yymx!=YYERRORSYMBOL ){
drh45f31be2016-02-16 21:19:49 +0000891 yy_shift(yypParser,yyact,YYERRORSYMBOL,yyminor);
drh75897232000-05-29 14:26:00 +0000892 }
893 }
drh1f245e42002-03-11 13:55:50 +0000894 yypParser->yyerrcnt = 3;
drh75897232000-05-29 14:26:00 +0000895 yyerrorhit = 1;
drhd3ec02d2009-06-12 02:27:14 +0000896#elif defined(YYNOERRORRECOVERY)
897 /* If the YYNOERRORRECOVERY macro is defined, then do not attempt to
898 ** do any kind of error recovery. Instead, simply invoke the syntax
899 ** error routine and continue going as if nothing had happened.
900 **
901 ** Applications can set this macro (for example inside %include) if
902 ** they intend to abandon the parse upon the first syntax error seen.
903 */
drh45f31be2016-02-16 21:19:49 +0000904 yy_syntax_error(yypParser,yymajor, yyminor);
drhd3ec02d2009-06-12 02:27:14 +0000905 yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
906 yymajor = YYNOCODE;
907
drh75897232000-05-29 14:26:00 +0000908#else /* YYERRORSYMBOL is not defined */
909 /* This is what we do if the grammar does not define ERROR:
910 **
911 ** * Report an error message, and throw away the input token.
912 **
913 ** * If the input token is $, then fail the parse.
914 **
915 ** As before, subsequent error messages are suppressed until
916 ** three input tokens have been successfully shifted.
917 */
drh1f245e42002-03-11 13:55:50 +0000918 if( yypParser->yyerrcnt<=0 ){
drh45f31be2016-02-16 21:19:49 +0000919 yy_syntax_error(yypParser,yymajor, yyminor);
drh75897232000-05-29 14:26:00 +0000920 }
drh1f245e42002-03-11 13:55:50 +0000921 yypParser->yyerrcnt = 3;
drhb27b7f52008-12-10 18:03:45 +0000922 yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
drh75897232000-05-29 14:26:00 +0000923 if( yyendofinput ){
drh1f245e42002-03-11 13:55:50 +0000924 yy_parse_failed(yypParser);
drhd3d4b3c2016-07-08 19:54:38 +0000925#ifndef YYNOERRORRECOVERY
926 yypParser->yyerrcnt = -1;
927#endif
drh75897232000-05-29 14:26:00 +0000928 }
929 yymajor = YYNOCODE;
930#endif
drh75897232000-05-29 14:26:00 +0000931 }
drhabecc0b2016-05-24 00:40:54 +0000932 }while( yymajor!=YYNOCODE && yypParser->yytos>yypParser->yystack );
drh3bd48ab2015-09-07 18:23:37 +0000933#ifndef NDEBUG
934 if( yyTraceFILE ){
drh118ab652016-05-23 21:56:24 +0000935 yyStackEntry *i;
936 char cDiv = '[';
drh0c4105e2015-11-10 14:51:22 +0000937 fprintf(yyTraceFILE,"%sReturn. Stack=",yyTracePrompt);
drh118ab652016-05-23 21:56:24 +0000938 for(i=&yypParser->yystack[1]; i<=yypParser->yytos; i++){
939 fprintf(yyTraceFILE,"%c%s", cDiv, yyTokenName[i->major]);
940 cDiv = ' ';
941 }
drh0c4105e2015-11-10 14:51:22 +0000942 fprintf(yyTraceFILE,"]\n");
drh3bd48ab2015-09-07 18:23:37 +0000943 }
944#endif
drh75897232000-05-29 14:26:00 +0000945 return;
946}