blob: e0d0e88565f0fff5691386a941485aad27b81989 [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
119
120** 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[].
128** Given state S and lookahead X, the action is computed as
drh75897232000-05-29 14:26:00 +0000129**
drh8b582012003-10-21 13:16:03 +0000130** yy_action[ yy_shift_ofst[S] + X ]
131**
drh8548a052003-10-22 22:15:27 +0000132** If the index value yy_shift_ofst[S]+X is out of range or if the value
drh8b582012003-10-21 13:16:03 +0000133** yy_lookahead[yy_shift_ofst[S]+X] is not equal to X or if yy_shift_ofst[S]
134** is equal to YY_SHIFT_USE_DFLT, it means that the action is not in the table
135** and that yy_default[S] should be used instead.
136**
137** The formula above is for computing the action when the lookahead is
138** a terminal symbol. If the lookahead is a non-terminal (as occurs after
139** a reduce action) then the yy_reduce_ofst[] array is used in place of
140** the yy_shift_ofst[] array and YY_REDUCE_USE_DFLT is used in place of
141** YY_SHIFT_USE_DFLT.
142**
143** The following are the tables generated in this section:
144**
145** yy_action[] A single table containing all actions.
146** yy_lookahead[] A table containing the lookahead for each entry in
147** yy_action. Used to detect hash collisions.
148** yy_shift_ofst[] For each state, the offset into yy_action for
149** shifting terminals.
150** yy_reduce_ofst[] For each state, the offset into yy_action for
151** shifting non-terminals after a reduce.
152** yy_default[] Default action for each state.
drh82415f22015-11-09 19:33:42 +0000153**
154*********** Begin parsing tables **********************************************/
drh75897232000-05-29 14:26:00 +0000155%%
drh82415f22015-11-09 19:33:42 +0000156/********** End of lemon-generated parsing tables *****************************/
drh75897232000-05-29 14:26:00 +0000157
drh82415f22015-11-09 19:33:42 +0000158/* The next table maps tokens (terminal symbols) into fallback tokens.
159** If a construct like the following:
drh0bd1f4e2002-06-06 18:54:39 +0000160**
161** %fallback ID X Y Z.
162**
drh34ff57b2008-07-14 12:27:51 +0000163** appears in the grammar, then ID becomes a fallback token for X, Y,
drh0bd1f4e2002-06-06 18:54:39 +0000164** and Z. Whenever one of the tokens X, Y, or Z is input to the parser
165** but it does not parse, the type of the token is changed to ID and
166** the parse is retried before an error is thrown.
drh82415f22015-11-09 19:33:42 +0000167**
168** This feature can be used, for example, to cause some keywords in a language
169** to revert to identifiers if they keyword does not apply in the context where
170** it appears.
drh0bd1f4e2002-06-06 18:54:39 +0000171*/
172#ifdef YYFALLBACK
173static const YYCODETYPE yyFallback[] = {
174%%
175};
176#endif /* YYFALLBACK */
177
drh75897232000-05-29 14:26:00 +0000178/* The following structure represents a single element of the
179** parser's stack. Information stored includes:
180**
181** + The state number for the parser at this level of the stack.
182**
183** + The value of the token stored at this level of the stack.
184** (In other words, the "major" token.)
185**
186** + The semantic value stored at this level of the stack. This is
187** the information used by the action routines in the grammar.
188** It is sometimes called the "minor" token.
drha248a722015-09-07 19:52:55 +0000189**
190** After the "shift" half of a SHIFTREDUCE action, the stateno field
191** actually contains the reduce action for the second half of the
192** SHIFTREDUCE.
drh75897232000-05-29 14:26:00 +0000193*/
194struct yyStackEntry {
drha248a722015-09-07 19:52:55 +0000195 YYACTIONTYPE stateno; /* The state-number, or reduce action in SHIFTREDUCE */
drh2abcd582008-07-24 23:34:07 +0000196 YYCODETYPE major; /* The major token value. This is the code
197 ** number for the token at this stack level */
198 YYMINORTYPE minor; /* The user-supplied minor token value. This
199 ** is the value of the token */
drh75897232000-05-29 14:26:00 +0000200};
drh1f245e42002-03-11 13:55:50 +0000201typedef struct yyStackEntry yyStackEntry;
drh75897232000-05-29 14:26:00 +0000202
203/* The state of the parser is completely contained in an instance of
204** the following structure */
205struct yyParser {
drh118ab652016-05-23 21:56:24 +0000206 yyStackEntry *yytos; /* Pointer to top element of the stack */
drhec424a52008-07-25 15:39:03 +0000207#ifdef YYTRACKMAXSTACKDEPTH
drh118ab652016-05-23 21:56:24 +0000208 int yyhwm; /* High-water mark of the stack */
drhec424a52008-07-25 15:39:03 +0000209#endif
drhdab943c2016-02-16 01:01:43 +0000210#ifndef YYNOERRORRECOVERY
drh1f245e42002-03-11 13:55:50 +0000211 int yyerrcnt; /* Shifts left before out of the error */
drhdab943c2016-02-16 01:01:43 +0000212#endif
drh1f245e42002-03-11 13:55:50 +0000213 ParseARG_SDECL /* A place to hold %extra_argument */
drhb19fd012007-03-29 01:44:45 +0000214#if YYSTACKDEPTH<=0
215 int yystksz; /* Current side of the stack */
216 yyStackEntry *yystack; /* The parser's stack */
drh8dc82472016-05-27 04:10:47 +0000217 yyStackEntry yystk0; /* First stack entry */
drhb19fd012007-03-29 01:44:45 +0000218#else
drh1f245e42002-03-11 13:55:50 +0000219 yyStackEntry yystack[YYSTACKDEPTH]; /* The parser's stack */
drhb19fd012007-03-29 01:44:45 +0000220#endif
drh75897232000-05-29 14:26:00 +0000221};
222typedef struct yyParser yyParser;
223
224#ifndef NDEBUG
225#include <stdio.h>
226static FILE *yyTraceFILE = 0;
227static char *yyTracePrompt = 0;
drh0bd1f4e2002-06-06 18:54:39 +0000228#endif /* NDEBUG */
drh75897232000-05-29 14:26:00 +0000229
drh0bd1f4e2002-06-06 18:54:39 +0000230#ifndef NDEBUG
drh75897232000-05-29 14:26:00 +0000231/*
232** Turn parser tracing on by giving a stream to which to write the trace
233** and a prompt to preface each trace message. Tracing is turned off
234** by making either argument NULL
235**
236** Inputs:
237** <ul>
238** <li> A FILE* to which trace output should be written.
239** If NULL, then tracing is turned off.
240** <li> A prefix string written at the beginning of every
241** line of trace output. If NULL, then tracing is
242** turned off.
243** </ul>
244**
245** Outputs:
246** None.
247*/
drh75897232000-05-29 14:26:00 +0000248void ParseTrace(FILE *TraceFILE, char *zTracePrompt){
249 yyTraceFILE = TraceFILE;
250 yyTracePrompt = zTracePrompt;
251 if( yyTraceFILE==0 ) yyTracePrompt = 0;
252 else if( yyTracePrompt==0 ) yyTraceFILE = 0;
253}
drh0bd1f4e2002-06-06 18:54:39 +0000254#endif /* NDEBUG */
drh75897232000-05-29 14:26:00 +0000255
drh0bd1f4e2002-06-06 18:54:39 +0000256#ifndef NDEBUG
drh75897232000-05-29 14:26:00 +0000257/* For tracing shifts, the names of all terminals and nonterminals
258** are required. The following table supplies these names */
drh57196282004-10-06 15:41:16 +0000259static const char *const yyTokenName[] = {
drh75897232000-05-29 14:26:00 +0000260%%
261};
drh0bd1f4e2002-06-06 18:54:39 +0000262#endif /* NDEBUG */
drh75897232000-05-29 14:26:00 +0000263
drh0bd1f4e2002-06-06 18:54:39 +0000264#ifndef NDEBUG
265/* For tracing reduce actions, the names of all rules are required.
266*/
drh57196282004-10-06 15:41:16 +0000267static const char *const yyRuleName[] = {
drh0bd1f4e2002-06-06 18:54:39 +0000268%%
269};
270#endif /* NDEBUG */
drha1b351a2001-09-14 16:42:12 +0000271
drh960e8c62001-04-03 16:53:21 +0000272
drhb19fd012007-03-29 01:44:45 +0000273#if YYSTACKDEPTH<=0
274/*
drh8dc82472016-05-27 04:10:47 +0000275** Try to increase the size of the parser stack. Return the number
276** of errors. Return 0 on success.
drhb19fd012007-03-29 01:44:45 +0000277*/
drh8dc82472016-05-27 04:10:47 +0000278static int yyGrowStack(yyParser *p){
drhb19fd012007-03-29 01:44:45 +0000279 int newSize;
drhabecc0b2016-05-24 00:40:54 +0000280 int idx;
drhb19fd012007-03-29 01:44:45 +0000281 yyStackEntry *pNew;
282
283 newSize = p->yystksz*2 + 100;
drhabecc0b2016-05-24 00:40:54 +0000284 idx = p->yytos ? (int)(p->yytos - p->yystack) : 0;
drh8dc82472016-05-27 04:10:47 +0000285 if( p->yystack==&p->yystk0 ){
286 pNew = malloc(newSize*sizeof(pNew[0]));
287 if( pNew ) pNew[0] = p->yystk0;
288 }else{
289 pNew = realloc(p->yystack, newSize*sizeof(pNew[0]));
290 }
drhb19fd012007-03-29 01:44:45 +0000291 if( pNew ){
292 p->yystack = pNew;
drhabecc0b2016-05-24 00:40:54 +0000293 p->yytos = &p->yystack[idx];
drhb19fd012007-03-29 01:44:45 +0000294#ifndef NDEBUG
295 if( yyTraceFILE ){
drh8dc82472016-05-27 04:10:47 +0000296 fprintf(yyTraceFILE,"%sStack grows from %d to %d entries.\n",
297 yyTracePrompt, p->yystksz, newSize);
drhb19fd012007-03-29 01:44:45 +0000298 }
299#endif
drh8dc82472016-05-27 04:10:47 +0000300 p->yystksz = newSize;
drhb19fd012007-03-29 01:44:45 +0000301 }
drh8dc82472016-05-27 04:10:47 +0000302 return pNew==0;
drhb19fd012007-03-29 01:44:45 +0000303}
304#endif
305
drh82415f22015-11-09 19:33:42 +0000306/* Datatype of the argument to the memory allocated passed as the
307** second argument to ParseAlloc() below. This can be changed by
308** putting an appropriate #define in the %include section of the input
309** grammar.
310*/
311#ifndef YYMALLOCARGTYPE
312# define YYMALLOCARGTYPE size_t
313#endif
314
drh75897232000-05-29 14:26:00 +0000315/*
316** This function allocates a new parser.
317** The only argument is a pointer to a function which works like
318** malloc.
319**
320** Inputs:
321** A pointer to the function used to allocate memory.
322**
323** Outputs:
324** A pointer to a parser. This pointer is used in subsequent calls
325** to Parse and ParseFree.
326*/
drh82415f22015-11-09 19:33:42 +0000327void *ParseAlloc(void *(*mallocProc)(YYMALLOCARGTYPE)){
drh75897232000-05-29 14:26:00 +0000328 yyParser *pParser;
drh82415f22015-11-09 19:33:42 +0000329 pParser = (yyParser*)(*mallocProc)( (YYMALLOCARGTYPE)sizeof(yyParser) );
drh75897232000-05-29 14:26:00 +0000330 if( pParser ){
drhec424a52008-07-25 15:39:03 +0000331#ifdef YYTRACKMAXSTACKDEPTH
drh118ab652016-05-23 21:56:24 +0000332 pParser->yyhwm = 0;
drhec424a52008-07-25 15:39:03 +0000333#endif
drhb19fd012007-03-29 01:44:45 +0000334#if YYSTACKDEPTH<=0
drhabecc0b2016-05-24 00:40:54 +0000335 pParser->yytos = NULL;
drh4c651782008-11-18 23:25:54 +0000336 pParser->yystack = NULL;
337 pParser->yystksz = 0;
drh8dc82472016-05-27 04:10:47 +0000338 if( yyGrowStack(pParser) ){
339 pParser->yystack = &pParser->yystk0;
340 pParser->yystksz = 1;
341 }
drhb19fd012007-03-29 01:44:45 +0000342#endif
drh4335ad02016-06-06 13:24:57 +0000343#ifndef YYNOERRORRECOVERY
344 pParser->yyerrcnt = -1;
345#endif
drhabecc0b2016-05-24 00:40:54 +0000346 pParser->yytos = pParser->yystack;
347 pParser->yystack[0].stateno = 0;
348 pParser->yystack[0].major = 0;
drh75897232000-05-29 14:26:00 +0000349 }
350 return pParser;
351}
352
drh82415f22015-11-09 19:33:42 +0000353/* The following function deletes the "minor type" or semantic value
354** associated with a symbol. The symbol can be either a terminal
355** or nonterminal. "yymajor" is the symbol code, and "yypminor" is
356** a pointer to the value to be deleted. The code used to do the
357** deletions is derived from the %destructor and/or %token_destructor
358** directives of the input grammar.
drh75897232000-05-29 14:26:00 +0000359*/
drh633e6d52008-07-28 19:34:53 +0000360static void yy_destructor(
361 yyParser *yypParser, /* The parser */
362 YYCODETYPE yymajor, /* Type code for object to destroy */
363 YYMINORTYPE *yypminor /* The object to be destroyed */
364){
365 ParseARG_FETCH;
drh75897232000-05-29 14:26:00 +0000366 switch( yymajor ){
367 /* Here is inserted the actions which take place when a
368 ** terminal or non-terminal is destroyed. This can happen
369 ** when the symbol is popped from the stack during a
370 ** reduce or during error processing or when a parser is
371 ** being destroyed before it is finished parsing.
372 **
373 ** Note: during a reduce, the only symbols destroyed are those
drh82415f22015-11-09 19:33:42 +0000374 ** which appear on the RHS of the rule, but which are *not* used
drh75897232000-05-29 14:26:00 +0000375 ** inside the C code.
376 */
drh82415f22015-11-09 19:33:42 +0000377/********* Begin destructor definitions ***************************************/
drh75897232000-05-29 14:26:00 +0000378%%
drh82415f22015-11-09 19:33:42 +0000379/********* End destructor definitions *****************************************/
drh75897232000-05-29 14:26:00 +0000380 default: break; /* If no destructor action specified: do nothing */
381 }
382}
383
384/*
385** Pop the parser's stack once.
386**
387** If there is a destructor routine associated with the token which
388** is popped from the stack, then call it.
drh75897232000-05-29 14:26:00 +0000389*/
drh3781f012015-11-09 14:11:37 +0000390static void yy_pop_parser_stack(yyParser *pParser){
391 yyStackEntry *yytos;
drh118ab652016-05-23 21:56:24 +0000392 assert( pParser->yytos!=0 );
drh240c7fa2016-07-05 12:47:28 +0000393 assert( pParser->yytos > pParser->yystack );
drh118ab652016-05-23 21:56:24 +0000394 yytos = pParser->yytos--;
drh75897232000-05-29 14:26:00 +0000395#ifndef NDEBUG
drh3781f012015-11-09 14:11:37 +0000396 if( yyTraceFILE ){
drh75897232000-05-29 14:26:00 +0000397 fprintf(yyTraceFILE,"%sPopping %s\n",
398 yyTracePrompt,
drh3ddfdf72003-12-22 14:53:19 +0000399 yyTokenName[yytos->major]);
drh75897232000-05-29 14:26:00 +0000400 }
401#endif
drh3781f012015-11-09 14:11:37 +0000402 yy_destructor(pParser, yytos->major, &yytos->minor);
drh75897232000-05-29 14:26:00 +0000403}
404
405/*
drh82415f22015-11-09 19:33:42 +0000406** Deallocate and destroy a parser. Destructors are called for
drh75897232000-05-29 14:26:00 +0000407** all stack elements before shutting the parser down.
408**
drh82415f22015-11-09 19:33:42 +0000409** If the YYPARSEFREENEVERNULL macro exists (for example because it
410** is defined in a %include section of the input grammar) then it is
411** assumed that the input pointer is never NULL.
drh75897232000-05-29 14:26:00 +0000412*/
drh75897232000-05-29 14:26:00 +0000413void ParseFree(
drh960e8c62001-04-03 16:53:21 +0000414 void *p, /* The parser to be deleted */
415 void (*freeProc)(void*) /* Function used to reclaim memory */
drh75897232000-05-29 14:26:00 +0000416){
417 yyParser *pParser = (yyParser*)p;
drh82415f22015-11-09 19:33:42 +0000418#ifndef YYPARSEFREENEVERNULL
drh75897232000-05-29 14:26:00 +0000419 if( pParser==0 ) return;
drh82415f22015-11-09 19:33:42 +0000420#endif
drhabecc0b2016-05-24 00:40:54 +0000421 while( pParser->yytos>pParser->yystack ) yy_pop_parser_stack(pParser);
drhb19fd012007-03-29 01:44:45 +0000422#if YYSTACKDEPTH<=0
drh8dc82472016-05-27 04:10:47 +0000423 if( pParser->yystack!=&pParser->yystk0 ) free(pParser->yystack);
drhb19fd012007-03-29 01:44:45 +0000424#endif
drh960e8c62001-04-03 16:53:21 +0000425 (*freeProc)((void*)pParser);
drh75897232000-05-29 14:26:00 +0000426}
427
428/*
drhec424a52008-07-25 15:39:03 +0000429** Return the peak depth of the stack for a parser.
430*/
431#ifdef YYTRACKMAXSTACKDEPTH
432int ParseStackPeak(void *p){
433 yyParser *pParser = (yyParser*)p;
drh118ab652016-05-23 21:56:24 +0000434 return pParser->yyhwm;
drhec424a52008-07-25 15:39:03 +0000435}
436#endif
437
438/*
drh8b582012003-10-21 13:16:03 +0000439** Find the appropriate action for a parser given the terminal
440** look-ahead token iLookAhead.
drh75897232000-05-29 14:26:00 +0000441*/
drh4ef07702016-03-16 19:45:54 +0000442static unsigned int yy_find_shift_action(
drh75897232000-05-29 14:26:00 +0000443 yyParser *pParser, /* The parser */
drhd9f291e2006-06-13 11:15:47 +0000444 YYCODETYPE iLookAhead /* The look-ahead token */
drh75897232000-05-29 14:26:00 +0000445){
drh8b582012003-10-21 13:16:03 +0000446 int i;
drh118ab652016-05-23 21:56:24 +0000447 int stateno = pParser->yytos->stateno;
drha4414042015-11-09 15:06:26 +0000448
449 if( stateno>=YY_MIN_REDUCE ) return stateno;
drhae2a4082015-09-07 20:02:39 +0000450 assert( stateno <= YY_SHIFT_COUNT );
drha4414042015-11-09 15:06:26 +0000451 do{
452 i = yy_shift_ofst[stateno];
453 if( i==YY_SHIFT_USE_DFLT ) return yy_default[stateno];
454 assert( iLookAhead!=YYNOCODE );
455 i += iLookAhead;
456 if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){
457 if( iLookAhead>0 ){
drh4767d972006-06-14 15:03:49 +0000458#ifdef YYFALLBACK
drha4414042015-11-09 15:06:26 +0000459 YYCODETYPE iFallback; /* Fallback token */
460 if( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0])
461 && (iFallback = yyFallback[iLookAhead])!=0 ){
drh4767d972006-06-14 15:03:49 +0000462#ifndef NDEBUG
463 if( yyTraceFILE ){
drha4414042015-11-09 15:06:26 +0000464 fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n",
465 yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]);
drh4767d972006-06-14 15:03:49 +0000466 }
drha4414042015-11-09 15:06:26 +0000467#endif
468 assert( yyFallback[iFallback]==0 ); /* Fallback loop must terminate */
469 iLookAhead = iFallback;
470 continue;
drhe09daa92006-06-10 13:29:31 +0000471 }
drha4414042015-11-09 15:06:26 +0000472#endif
473#ifdef YYWILDCARD
474 {
475 int j = i - iLookAhead + YYWILDCARD;
476 if(
477#if YY_SHIFT_MIN+YYWILDCARD<0
478 j>=0 &&
479#endif
480#if YY_SHIFT_MAX+YYWILDCARD>=YY_ACTTAB_COUNT
481 j<YY_ACTTAB_COUNT &&
482#endif
483 yy_lookahead[j]==YYWILDCARD
484 ){
485#ifndef NDEBUG
486 if( yyTraceFILE ){
487 fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n",
488 yyTracePrompt, yyTokenName[iLookAhead],
489 yyTokenName[YYWILDCARD]);
490 }
491#endif /* NDEBUG */
492 return yy_action[j];
493 }
494 }
drh4767d972006-06-14 15:03:49 +0000495#endif /* YYWILDCARD */
drha4414042015-11-09 15:06:26 +0000496 }
497 return yy_default[stateno];
498 }else{
499 return yy_action[i];
drh0bd1f4e2002-06-06 18:54:39 +0000500 }
drha4414042015-11-09 15:06:26 +0000501 }while(1);
drh8b582012003-10-21 13:16:03 +0000502}
503
504/*
505** Find the appropriate action for a parser given the non-terminal
506** look-ahead token iLookAhead.
drh8b582012003-10-21 13:16:03 +0000507*/
508static int yy_find_reduce_action(
drh161aba32005-02-01 04:09:36 +0000509 int stateno, /* Current state number */
drhd9f291e2006-06-13 11:15:47 +0000510 YYCODETYPE iLookAhead /* The look-ahead token */
drh8b582012003-10-21 13:16:03 +0000511){
512 int i;
drh7f7c2572008-04-27 18:45:10 +0000513#ifdef YYERRORSYMBOL
drhf16371d2009-11-03 19:18:31 +0000514 if( stateno>YY_REDUCE_COUNT ){
drh7f7c2572008-04-27 18:45:10 +0000515 return yy_default[stateno];
516 }
517#else
drhf16371d2009-11-03 19:18:31 +0000518 assert( stateno<=YY_REDUCE_COUNT );
drh7f7c2572008-04-27 18:45:10 +0000519#endif
drh01495b92008-01-23 12:52:40 +0000520 i = yy_reduce_ofst[stateno];
521 assert( i!=YY_REDUCE_USE_DFLT );
522 assert( iLookAhead!=YYNOCODE );
drh8b582012003-10-21 13:16:03 +0000523 i += iLookAhead;
drh7f7c2572008-04-27 18:45:10 +0000524#ifdef YYERRORSYMBOL
drhf16371d2009-11-03 19:18:31 +0000525 if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){
drh7f7c2572008-04-27 18:45:10 +0000526 return yy_default[stateno];
527 }
528#else
drhf16371d2009-11-03 19:18:31 +0000529 assert( i>=0 && i<YY_ACTTAB_COUNT );
drh01495b92008-01-23 12:52:40 +0000530 assert( yy_lookahead[i]==iLookAhead );
drh7f7c2572008-04-27 18:45:10 +0000531#endif
drh01495b92008-01-23 12:52:40 +0000532 return yy_action[i];
drh75897232000-05-29 14:26:00 +0000533}
534
535/*
drhb19fd012007-03-29 01:44:45 +0000536** The following routine is called if the stack overflows.
537*/
drh45f31be2016-02-16 21:19:49 +0000538static void yyStackOverflow(yyParser *yypParser){
drhb19fd012007-03-29 01:44:45 +0000539 ParseARG_FETCH;
drh118ab652016-05-23 21:56:24 +0000540 yypParser->yytos--;
drhb19fd012007-03-29 01:44:45 +0000541#ifndef NDEBUG
542 if( yyTraceFILE ){
543 fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt);
544 }
545#endif
drhabecc0b2016-05-24 00:40:54 +0000546 while( yypParser->yytos>yypParser->yystack ) yy_pop_parser_stack(yypParser);
drhb19fd012007-03-29 01:44:45 +0000547 /* Here code is inserted which will execute if the parser
548 ** stack every overflows */
drh82415f22015-11-09 19:33:42 +0000549/******** Begin %stack_overflow code ******************************************/
drhb19fd012007-03-29 01:44:45 +0000550%%
drh82415f22015-11-09 19:33:42 +0000551/******** End %stack_overflow code ********************************************/
drhb19fd012007-03-29 01:44:45 +0000552 ParseARG_STORE; /* Suppress warning about unused %extra_argument var */
553}
554
555/*
drha248a722015-09-07 19:52:55 +0000556** Print tracing information for a SHIFT action
557*/
558#ifndef NDEBUG
559static void yyTraceShift(yyParser *yypParser, int yyNewState){
560 if( yyTraceFILE ){
drha248a722015-09-07 19:52:55 +0000561 if( yyNewState<YYNSTATE ){
drh0c4105e2015-11-10 14:51:22 +0000562 fprintf(yyTraceFILE,"%sShift '%s', go to state %d\n",
drh118ab652016-05-23 21:56:24 +0000563 yyTracePrompt,yyTokenName[yypParser->yytos->major],
drh0c4105e2015-11-10 14:51:22 +0000564 yyNewState);
drha248a722015-09-07 19:52:55 +0000565 }else{
drh0c4105e2015-11-10 14:51:22 +0000566 fprintf(yyTraceFILE,"%sShift '%s'\n",
drh118ab652016-05-23 21:56:24 +0000567 yyTracePrompt,yyTokenName[yypParser->yytos->major]);
drha248a722015-09-07 19:52:55 +0000568 }
569 }
570}
571#else
572# define yyTraceShift(X,Y)
573#endif
574
575/*
drh82415f22015-11-09 19:33:42 +0000576** Perform a shift action.
drh75897232000-05-29 14:26:00 +0000577*/
drha248a722015-09-07 19:52:55 +0000578static void yy_shift(
drh75897232000-05-29 14:26:00 +0000579 yyParser *yypParser, /* The parser to be shifted */
580 int yyNewState, /* The new state to shift in */
581 int yyMajor, /* The major token to shift in */
drh45f31be2016-02-16 21:19:49 +0000582 ParseTOKENTYPE yyMinor /* The minor token to shift in */
drh75897232000-05-29 14:26:00 +0000583){
drh3ddfdf72003-12-22 14:53:19 +0000584 yyStackEntry *yytos;
drh118ab652016-05-23 21:56:24 +0000585 yypParser->yytos++;
drhec424a52008-07-25 15:39:03 +0000586#ifdef YYTRACKMAXSTACKDEPTH
drh118ab652016-05-23 21:56:24 +0000587 if( (int)(yypParser->yytos - yypParser->yystack)>yypParser->yyhwm ){
588 yypParser->yyhwm++;
589 assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack) );
drhec424a52008-07-25 15:39:03 +0000590 }
591#endif
drhb19fd012007-03-29 01:44:45 +0000592#if YYSTACKDEPTH>0
drh118ab652016-05-23 21:56:24 +0000593 if( yypParser->yytos>=&yypParser->yystack[YYSTACKDEPTH] ){
drh45f31be2016-02-16 21:19:49 +0000594 yyStackOverflow(yypParser);
drha248a722015-09-07 19:52:55 +0000595 return;
drh75897232000-05-29 14:26:00 +0000596 }
drhb19fd012007-03-29 01:44:45 +0000597#else
drh118ab652016-05-23 21:56:24 +0000598 if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz] ){
drh8dc82472016-05-27 04:10:47 +0000599 if( yyGrowStack(yypParser) ){
drh45f31be2016-02-16 21:19:49 +0000600 yyStackOverflow(yypParser);
drha248a722015-09-07 19:52:55 +0000601 return;
drhb19fd012007-03-29 01:44:45 +0000602 }
603 }
604#endif
drh0efd37f2016-06-06 18:17:36 +0000605 if( yyNewState > YY_MAX_SHIFT ){
606 yyNewState += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE;
607 }
drh118ab652016-05-23 21:56:24 +0000608 yytos = yypParser->yytos;
drhb27b7f52008-12-10 18:03:45 +0000609 yytos->stateno = (YYACTIONTYPE)yyNewState;
610 yytos->major = (YYCODETYPE)yyMajor;
drh45f31be2016-02-16 21:19:49 +0000611 yytos->minor.yy0 = yyMinor;
drha248a722015-09-07 19:52:55 +0000612 yyTraceShift(yypParser, yyNewState);
drh75897232000-05-29 14:26:00 +0000613}
614
615/* The following table contains information about every rule that
616** is used during the reduce.
617*/
drh57196282004-10-06 15:41:16 +0000618static const struct {
drh75897232000-05-29 14:26:00 +0000619 YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */
620 unsigned char nrhs; /* Number of right-hand side symbols in the rule */
621} yyRuleInfo[] = {
622%%
623};
624
drh1f245e42002-03-11 13:55:50 +0000625static void yy_accept(yyParser*); /* Forward Declaration */
drh75897232000-05-29 14:26:00 +0000626
627/*
628** Perform a reduce action and the shift that must immediately
629** follow the reduce.
630*/
631static void yy_reduce(
632 yyParser *yypParser, /* The parser */
drh4ef07702016-03-16 19:45:54 +0000633 unsigned int yyruleno /* Number of the rule by which to reduce */
drh75897232000-05-29 14:26:00 +0000634){
635 int yygoto; /* The next state */
636 int yyact; /* The next action */
drh1f245e42002-03-11 13:55:50 +0000637 yyStackEntry *yymsp; /* The top of the parser's stack */
drh75897232000-05-29 14:26:00 +0000638 int yysize; /* Amount to pop the stack */
drh1f245e42002-03-11 13:55:50 +0000639 ParseARG_FETCH;
drh118ab652016-05-23 21:56:24 +0000640 yymsp = yypParser->yytos;
drh0bd1f4e2002-06-06 18:54:39 +0000641#ifndef NDEBUG
drh4ef07702016-03-16 19:45:54 +0000642 if( yyTraceFILE && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){
drh3bd48ab2015-09-07 18:23:37 +0000643 yysize = yyRuleInfo[yyruleno].nrhs;
drh0c4105e2015-11-10 14:51:22 +0000644 fprintf(yyTraceFILE, "%sReduce [%s], go to state %d.\n", yyTracePrompt,
drh3bd48ab2015-09-07 18:23:37 +0000645 yyRuleName[yyruleno], yymsp[-yysize].stateno);
drh0bd1f4e2002-06-06 18:54:39 +0000646 }
647#endif /* NDEBUG */
drh45f31be2016-02-16 21:19:49 +0000648
649 /* Check that the stack is large enough to grow by a single entry
650 ** if the RHS of the rule is empty. This ensures that there is room
651 ** enough on the stack to push the LHS value */
652 if( yyRuleInfo[yyruleno].nrhs==0 ){
653#ifdef YYTRACKMAXSTACKDEPTH
drh118ab652016-05-23 21:56:24 +0000654 if( (int)(yypParser->yytos - yypParser->yystack)>yypParser->yyhwm ){
655 yypParser->yyhwm++;
656 assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack));
drh45f31be2016-02-16 21:19:49 +0000657 }
658#endif
659#if YYSTACKDEPTH>0
drh118ab652016-05-23 21:56:24 +0000660 if( yypParser->yytos>=&yypParser->yystack[YYSTACKDEPTH-1] ){
drh45f31be2016-02-16 21:19:49 +0000661 yyStackOverflow(yypParser);
662 return;
663 }
664#else
drh118ab652016-05-23 21:56:24 +0000665 if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz-1] ){
drh8dc82472016-05-27 04:10:47 +0000666 if( yyGrowStack(yypParser) ){
drh45f31be2016-02-16 21:19:49 +0000667 yyStackOverflow(yypParser);
668 return;
669 }
drh8dc82472016-05-27 04:10:47 +0000670 yymsp = yypParser->yytos;
drh45f31be2016-02-16 21:19:49 +0000671 }
672#endif
673 }
drhcb6c5652007-01-16 18:19:12 +0000674
drh75897232000-05-29 14:26:00 +0000675 switch( yyruleno ){
676 /* Beginning here are the reduction cases. A typical example
677 ** follows:
678 ** case 0:
drh75897232000-05-29 14:26:00 +0000679 ** #line <lineno> <grammarfile>
680 ** { ... } // User supplied code
681 ** #line <lineno> <thisfile>
682 ** break;
683 */
drh82415f22015-11-09 19:33:42 +0000684/********** Begin reduce actions **********************************************/
drh75897232000-05-29 14:26:00 +0000685%%
drh82415f22015-11-09 19:33:42 +0000686/********** End reduce actions ************************************************/
drh75897232000-05-29 14:26:00 +0000687 };
drh4ef07702016-03-16 19:45:54 +0000688 assert( yyruleno<sizeof(yyRuleInfo)/sizeof(yyRuleInfo[0]) );
drh75897232000-05-29 14:26:00 +0000689 yygoto = yyRuleInfo[yyruleno].lhs;
690 yysize = yyRuleInfo[yyruleno].nrhs;
drh3abbd392008-12-10 23:04:13 +0000691 yyact = yy_find_reduce_action(yymsp[-yysize].stateno,(YYCODETYPE)yygoto);
drha248a722015-09-07 19:52:55 +0000692 if( yyact <= YY_MAX_SHIFTREDUCE ){
drh118ab652016-05-23 21:56:24 +0000693 if( yyact>YY_MAX_SHIFT ){
694 yyact += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE;
695 }
drh45f31be2016-02-16 21:19:49 +0000696 yymsp -= yysize-1;
drh118ab652016-05-23 21:56:24 +0000697 yypParser->yytos = yymsp;
drh45f31be2016-02-16 21:19:49 +0000698 yymsp->stateno = (YYACTIONTYPE)yyact;
699 yymsp->major = (YYCODETYPE)yygoto;
drh45f31be2016-02-16 21:19:49 +0000700 yyTraceShift(yypParser, yyact);
drh4b2f9362008-01-22 23:37:09 +0000701 }else{
drh3bd48ab2015-09-07 18:23:37 +0000702 assert( yyact == YY_ACCEPT_ACTION );
drh118ab652016-05-23 21:56:24 +0000703 yypParser->yytos -= yysize;
drh1f245e42002-03-11 13:55:50 +0000704 yy_accept(yypParser);
drh75897232000-05-29 14:26:00 +0000705 }
706}
707
708/*
709** The following code executes when the parse fails
710*/
drhd3ec02d2009-06-12 02:27:14 +0000711#ifndef YYNOERRORRECOVERY
drh75897232000-05-29 14:26:00 +0000712static void yy_parse_failed(
713 yyParser *yypParser /* The parser */
drh75897232000-05-29 14:26:00 +0000714){
drh1f245e42002-03-11 13:55:50 +0000715 ParseARG_FETCH;
drh75897232000-05-29 14:26:00 +0000716#ifndef NDEBUG
717 if( yyTraceFILE ){
718 fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt);
719 }
720#endif
drhabecc0b2016-05-24 00:40:54 +0000721 while( yypParser->yytos>yypParser->yystack ) yy_pop_parser_stack(yypParser);
drh75897232000-05-29 14:26:00 +0000722 /* Here code is inserted which will be executed whenever the
723 ** parser fails */
drh82415f22015-11-09 19:33:42 +0000724/************ Begin %parse_failure code ***************************************/
drh75897232000-05-29 14:26:00 +0000725%%
drh82415f22015-11-09 19:33:42 +0000726/************ End %parse_failure code *****************************************/
drh1f245e42002-03-11 13:55:50 +0000727 ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
drh75897232000-05-29 14:26:00 +0000728}
drhd3ec02d2009-06-12 02:27:14 +0000729#endif /* YYNOERRORRECOVERY */
drh75897232000-05-29 14:26:00 +0000730
731/*
732** The following code executes when a syntax error first occurs.
733*/
734static void yy_syntax_error(
735 yyParser *yypParser, /* The parser */
736 int yymajor, /* The major type of the error token */
drh45f31be2016-02-16 21:19:49 +0000737 ParseTOKENTYPE yyminor /* The minor type of the error token */
drh75897232000-05-29 14:26:00 +0000738){
drh1f245e42002-03-11 13:55:50 +0000739 ParseARG_FETCH;
drh45f31be2016-02-16 21:19:49 +0000740#define TOKEN yyminor
drh82415f22015-11-09 19:33:42 +0000741/************ Begin %syntax_error code ****************************************/
drh75897232000-05-29 14:26:00 +0000742%%
drh82415f22015-11-09 19:33:42 +0000743/************ End %syntax_error code ******************************************/
drh1f245e42002-03-11 13:55:50 +0000744 ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
drh75897232000-05-29 14:26:00 +0000745}
746
747/*
748** The following is executed when the parser accepts
749*/
750static void yy_accept(
751 yyParser *yypParser /* The parser */
drh75897232000-05-29 14:26:00 +0000752){
drh1f245e42002-03-11 13:55:50 +0000753 ParseARG_FETCH;
drh75897232000-05-29 14:26:00 +0000754#ifndef NDEBUG
755 if( yyTraceFILE ){
756 fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt);
757 }
758#endif
drhdd703e22016-07-12 19:54:49 +0000759#ifndef YYNOERRORRECOVERY
760 yypParser->yyerrcnt = -1;
761#endif
drh756b41e2016-05-24 18:55:08 +0000762 assert( yypParser->yytos==yypParser->yystack );
drh75897232000-05-29 14:26:00 +0000763 /* Here code is inserted which will be executed whenever the
764 ** parser accepts */
drh82415f22015-11-09 19:33:42 +0000765/*********** Begin %parse_accept code *****************************************/
drh75897232000-05-29 14:26:00 +0000766%%
drh82415f22015-11-09 19:33:42 +0000767/*********** End %parse_accept code *******************************************/
drh1f245e42002-03-11 13:55:50 +0000768 ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
drh75897232000-05-29 14:26:00 +0000769}
770
771/* The main parser program.
772** The first argument is a pointer to a structure obtained from
773** "ParseAlloc" which describes the current state of the parser.
774** The second argument is the major token number. The third is
775** the minor token. The fourth optional argument is whatever the
776** user wants (and specified in the grammar) and is available for
777** use by the action routines.
778**
779** Inputs:
780** <ul>
781** <li> A pointer to the parser (an opaque structure.)
782** <li> The major token number.
783** <li> The minor token number.
784** <li> An option argument of a grammar-specified type.
785** </ul>
786**
787** Outputs:
788** None.
789*/
drh75897232000-05-29 14:26:00 +0000790void Parse(
791 void *yyp, /* The parser */
792 int yymajor, /* The major token code number */
793 ParseTOKENTYPE yyminor /* The value for the token */
drh1f245e42002-03-11 13:55:50 +0000794 ParseARG_PDECL /* Optional %extra_argument parameter */
drh75897232000-05-29 14:26:00 +0000795){
796 YYMINORTYPE yyminorunion;
drh4ef07702016-03-16 19:45:54 +0000797 unsigned int yyact; /* The parser action. */
drha4414042015-11-09 15:06:26 +0000798#if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY)
drh75897232000-05-29 14:26:00 +0000799 int yyendofinput; /* True if we are at the end of input */
drha4414042015-11-09 15:06:26 +0000800#endif
drhc4dd3fd2008-01-22 01:48:05 +0000801#ifdef YYERRORSYMBOL
drh75897232000-05-29 14:26:00 +0000802 int yyerrorhit = 0; /* True if yymajor has invoked an error */
drhc4dd3fd2008-01-22 01:48:05 +0000803#endif
drh75897232000-05-29 14:26:00 +0000804 yyParser *yypParser; /* The parser */
805
drh75897232000-05-29 14:26:00 +0000806 yypParser = (yyParser*)yyp;
drhabecc0b2016-05-24 00:40:54 +0000807 assert( yypParser->yytos!=0 );
drha4414042015-11-09 15:06:26 +0000808#if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY)
drh75897232000-05-29 14:26:00 +0000809 yyendofinput = (yymajor==0);
drha4414042015-11-09 15:06:26 +0000810#endif
drh1f245e42002-03-11 13:55:50 +0000811 ParseARG_STORE;
drh75897232000-05-29 14:26:00 +0000812
813#ifndef NDEBUG
814 if( yyTraceFILE ){
drh0c4105e2015-11-10 14:51:22 +0000815 fprintf(yyTraceFILE,"%sInput '%s'\n",yyTracePrompt,yyTokenName[yymajor]);
drh75897232000-05-29 14:26:00 +0000816 }
817#endif
818
819 do{
drh3abbd392008-12-10 23:04:13 +0000820 yyact = yy_find_shift_action(yypParser,(YYCODETYPE)yymajor);
drh3bd48ab2015-09-07 18:23:37 +0000821 if( yyact <= YY_MAX_SHIFTREDUCE ){
drh45f31be2016-02-16 21:19:49 +0000822 yy_shift(yypParser,yyact,yymajor,yyminor);
drhdab943c2016-02-16 01:01:43 +0000823#ifndef YYNOERRORRECOVERY
drha248a722015-09-07 19:52:55 +0000824 yypParser->yyerrcnt--;
drhdab943c2016-02-16 01:01:43 +0000825#endif
drha248a722015-09-07 19:52:55 +0000826 yymajor = YYNOCODE;
drh3bd48ab2015-09-07 18:23:37 +0000827 }else if( yyact <= YY_MAX_REDUCE ){
828 yy_reduce(yypParser,yyact-YY_MIN_REDUCE);
drhc4dd3fd2008-01-22 01:48:05 +0000829 }else{
830 assert( yyact == YY_ERROR_ACTION );
drh45f31be2016-02-16 21:19:49 +0000831 yyminorunion.yy0 = yyminor;
drhc4dd3fd2008-01-22 01:48:05 +0000832#ifdef YYERRORSYMBOL
drh3ddfdf72003-12-22 14:53:19 +0000833 int yymx;
drhc4dd3fd2008-01-22 01:48:05 +0000834#endif
drh75897232000-05-29 14:26:00 +0000835#ifndef NDEBUG
836 if( yyTraceFILE ){
837 fprintf(yyTraceFILE,"%sSyntax Error!\n",yyTracePrompt);
838 }
839#endif
840#ifdef YYERRORSYMBOL
841 /* A syntax error has occurred.
842 ** The response to an error depends upon whether or not the
843 ** grammar defines an error token "ERROR".
844 **
845 ** This is what we do if the grammar does define ERROR:
846 **
847 ** * Call the %syntax_error function.
848 **
849 ** * Begin popping the stack until we enter a state where
850 ** it is legal to shift the error symbol, then shift
851 ** the error symbol.
852 **
853 ** * Set the error count to three.
854 **
855 ** * Begin accepting and shifting new tokens. No new error
856 ** processing will occur until three tokens have been
857 ** shifted successfully.
858 **
859 */
drh1f245e42002-03-11 13:55:50 +0000860 if( yypParser->yyerrcnt<0 ){
drh45f31be2016-02-16 21:19:49 +0000861 yy_syntax_error(yypParser,yymajor,yyminor);
drh75897232000-05-29 14:26:00 +0000862 }
drh118ab652016-05-23 21:56:24 +0000863 yymx = yypParser->yytos->major;
drh3ddfdf72003-12-22 14:53:19 +0000864 if( yymx==YYERRORSYMBOL || yyerrorhit ){
drh75897232000-05-29 14:26:00 +0000865#ifndef NDEBUG
866 if( yyTraceFILE ){
867 fprintf(yyTraceFILE,"%sDiscard input token %s\n",
868 yyTracePrompt,yyTokenName[yymajor]);
869 }
870#endif
drh45f31be2016-02-16 21:19:49 +0000871 yy_destructor(yypParser, (YYCODETYPE)yymajor, &yyminorunion);
drh75897232000-05-29 14:26:00 +0000872 yymajor = YYNOCODE;
873 }else{
drh118ab652016-05-23 21:56:24 +0000874 while( yypParser->yytos >= &yypParser->yystack
875 && yymx != YYERRORSYMBOL
876 && (yyact = yy_find_reduce_action(
877 yypParser->yytos->stateno,
drh3bd48ab2015-09-07 18:23:37 +0000878 YYERRORSYMBOL)) >= YY_MIN_REDUCE
drh75897232000-05-29 14:26:00 +0000879 ){
880 yy_pop_parser_stack(yypParser);
881 }
drh118ab652016-05-23 21:56:24 +0000882 if( yypParser->yytos < yypParser->yystack || yymajor==0 ){
drhb27b7f52008-12-10 18:03:45 +0000883 yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
drh1f245e42002-03-11 13:55:50 +0000884 yy_parse_failed(yypParser);
drh240c7fa2016-07-05 12:47:28 +0000885#ifndef YYNOERRORRECOVERY
886 yypParser->yyerrcnt = -1;
887#endif
drh75897232000-05-29 14:26:00 +0000888 yymajor = YYNOCODE;
drh3ddfdf72003-12-22 14:53:19 +0000889 }else if( yymx!=YYERRORSYMBOL ){
drh45f31be2016-02-16 21:19:49 +0000890 yy_shift(yypParser,yyact,YYERRORSYMBOL,yyminor);
drh75897232000-05-29 14:26:00 +0000891 }
892 }
drh1f245e42002-03-11 13:55:50 +0000893 yypParser->yyerrcnt = 3;
drh75897232000-05-29 14:26:00 +0000894 yyerrorhit = 1;
drhd3ec02d2009-06-12 02:27:14 +0000895#elif defined(YYNOERRORRECOVERY)
896 /* If the YYNOERRORRECOVERY macro is defined, then do not attempt to
897 ** do any kind of error recovery. Instead, simply invoke the syntax
898 ** error routine and continue going as if nothing had happened.
899 **
900 ** Applications can set this macro (for example inside %include) if
901 ** they intend to abandon the parse upon the first syntax error seen.
902 */
drh45f31be2016-02-16 21:19:49 +0000903 yy_syntax_error(yypParser,yymajor, yyminor);
drhd3ec02d2009-06-12 02:27:14 +0000904 yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
905 yymajor = YYNOCODE;
906
drh75897232000-05-29 14:26:00 +0000907#else /* YYERRORSYMBOL is not defined */
908 /* This is what we do if the grammar does not define ERROR:
909 **
910 ** * Report an error message, and throw away the input token.
911 **
912 ** * If the input token is $, then fail the parse.
913 **
914 ** As before, subsequent error messages are suppressed until
915 ** three input tokens have been successfully shifted.
916 */
drh1f245e42002-03-11 13:55:50 +0000917 if( yypParser->yyerrcnt<=0 ){
drh45f31be2016-02-16 21:19:49 +0000918 yy_syntax_error(yypParser,yymajor, yyminor);
drh75897232000-05-29 14:26:00 +0000919 }
drh1f245e42002-03-11 13:55:50 +0000920 yypParser->yyerrcnt = 3;
drhb27b7f52008-12-10 18:03:45 +0000921 yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
drh75897232000-05-29 14:26:00 +0000922 if( yyendofinput ){
drh1f245e42002-03-11 13:55:50 +0000923 yy_parse_failed(yypParser);
drhd3d4b3c2016-07-08 19:54:38 +0000924#ifndef YYNOERRORRECOVERY
925 yypParser->yyerrcnt = -1;
926#endif
drh75897232000-05-29 14:26:00 +0000927 }
928 yymajor = YYNOCODE;
929#endif
drh75897232000-05-29 14:26:00 +0000930 }
drhabecc0b2016-05-24 00:40:54 +0000931 }while( yymajor!=YYNOCODE && yypParser->yytos>yypParser->yystack );
drh3bd48ab2015-09-07 18:23:37 +0000932#ifndef NDEBUG
933 if( yyTraceFILE ){
drh118ab652016-05-23 21:56:24 +0000934 yyStackEntry *i;
935 char cDiv = '[';
drh0c4105e2015-11-10 14:51:22 +0000936 fprintf(yyTraceFILE,"%sReturn. Stack=",yyTracePrompt);
drh118ab652016-05-23 21:56:24 +0000937 for(i=&yypParser->yystack[1]; i<=yypParser->yytos; i++){
938 fprintf(yyTraceFILE,"%c%s", cDiv, yyTokenName[i->major]);
939 cDiv = ' ';
940 }
drh0c4105e2015-11-10 14:51:22 +0000941 fprintf(yyTraceFILE,"]\n");
drh3bd48ab2015-09-07 18:23:37 +0000942 }
943#endif
drh75897232000-05-29 14:26:00 +0000944 return;
945}