blob: 37a589219535f59df09a9301f977ba28ef8130e4 [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
drhde6422a2017-10-02 02:32:12 +000078** YY_MIN_REDUCE Minimum value for reduce actions
79** YY_MAX_REDUCE Maximum value for reduce actions
drh3bd48ab2015-09-07 18:23:37 +000080** YY_ERROR_ACTION The yy_action[] code for syntax error
81** YY_ACCEPT_ACTION The yy_action[] code for accept
82** YY_NO_ACTION The yy_action[] code for no-op
drh75897232000-05-29 14:26:00 +000083*/
drh82415f22015-11-09 19:33:42 +000084#ifndef INTERFACE
85# define INTERFACE 1
86#endif
87/************* Begin control #defines *****************************************/
drh75897232000-05-29 14:26:00 +000088%%
drh82415f22015-11-09 19:33:42 +000089/************* End control #defines *******************************************/
drh75897232000-05-29 14:26:00 +000090
drh8a415d32009-06-12 13:53:51 +000091/* Define the yytestcase() macro to be a no-op if is not already defined
92** otherwise.
93**
94** Applications can choose to define yytestcase() in the %include section
95** to a macro that can assist in verifying code coverage. For production
96** code the yytestcase() macro should be turned off. But it is useful
97** for testing.
98*/
99#ifndef yytestcase
100# define yytestcase(X)
101#endif
102
drh26c9b5e2008-04-11 14:56:53 +0000103
drh34ff57b2008-07-14 12:27:51 +0000104/* Next are the tables used to determine what action to take based on the
drh8b582012003-10-21 13:16:03 +0000105** current state and lookahead token. These tables are used to implement
106** functions that take a state number and lookahead value and return an
107** action integer.
drh75897232000-05-29 14:26:00 +0000108**
drh8548a052003-10-22 22:15:27 +0000109** Suppose the action integer is N. Then the action is determined as
110** follows
drh75897232000-05-29 14:26:00 +0000111**
drh3bd48ab2015-09-07 18:23:37 +0000112** 0 <= N <= YY_MAX_SHIFT Shift N. That is, push the lookahead
drh8548a052003-10-22 22:15:27 +0000113** token onto the stack and goto state N.
114**
drh3bd48ab2015-09-07 18:23:37 +0000115** N between YY_MIN_SHIFTREDUCE Shift to an arbitrary state then
116** and YY_MAX_SHIFTREDUCE reduce by rule N-YY_MIN_SHIFTREDUCE.
drh8548a052003-10-22 22:15:27 +0000117**
drh3bd48ab2015-09-07 18:23:37 +0000118** N between YY_MIN_REDUCE Reduce by rule N-YY_MIN_REDUCE
119** and YY_MAX_REDUCE
drh701b6882016-08-10 13:30:43 +0000120**
drh3bd48ab2015-09-07 18:23:37 +0000121** N == YY_ERROR_ACTION A syntax error has occurred.
drh8548a052003-10-22 22:15:27 +0000122**
drh3bd48ab2015-09-07 18:23:37 +0000123** N == YY_ACCEPT_ACTION The parser accepts its input.
drh8548a052003-10-22 22:15:27 +0000124**
drh3bd48ab2015-09-07 18:23:37 +0000125** N == YY_NO_ACTION No such action. Denotes unused
drh8548a052003-10-22 22:15:27 +0000126** slots in the yy_action[] table.
127**
128** The action table is constructed as a single large table named yy_action[].
drh701b6882016-08-10 13:30:43 +0000129** Given state S and lookahead X, the action is computed as either:
drh75897232000-05-29 14:26:00 +0000130**
drh701b6882016-08-10 13:30:43 +0000131** (A) N = yy_action[ yy_shift_ofst[S] + X ]
132** (B) N = yy_default[S]
drh8b582012003-10-21 13:16:03 +0000133**
drh701b6882016-08-10 13:30:43 +0000134** The (A) formula is preferred. The B formula is used instead if:
135** (1) The yy_shift_ofst[S]+X value is out of range, or
136** (2) yy_lookahead[yy_shift_ofst[S]+X] is not equal to X, or
137** (3) yy_shift_ofst[S] equal YY_SHIFT_USE_DFLT.
138** (Implementation note: YY_SHIFT_USE_DFLT is chosen so that
139** YY_SHIFT_USE_DFLT+X will be out of range for all possible lookaheads X.
140** Hence only tests (1) and (2) need to be evaluated.)
drh8b582012003-10-21 13:16:03 +0000141**
drh701b6882016-08-10 13:30:43 +0000142** The formulas above are for computing the action when the lookahead is
drh8b582012003-10-21 13:16:03 +0000143** a terminal symbol. If the lookahead is a non-terminal (as occurs after
144** a reduce action) then the yy_reduce_ofst[] array is used in place of
145** the yy_shift_ofst[] array and YY_REDUCE_USE_DFLT is used in place of
146** YY_SHIFT_USE_DFLT.
147**
148** The following are the tables generated in this section:
149**
150** yy_action[] A single table containing all actions.
151** yy_lookahead[] A table containing the lookahead for each entry in
152** yy_action. Used to detect hash collisions.
153** yy_shift_ofst[] For each state, the offset into yy_action for
154** shifting terminals.
155** yy_reduce_ofst[] For each state, the offset into yy_action for
156** shifting non-terminals after a reduce.
157** yy_default[] Default action for each state.
drh82415f22015-11-09 19:33:42 +0000158**
159*********** Begin parsing tables **********************************************/
drh75897232000-05-29 14:26:00 +0000160%%
drh82415f22015-11-09 19:33:42 +0000161/********** End of lemon-generated parsing tables *****************************/
drh75897232000-05-29 14:26:00 +0000162
drh82415f22015-11-09 19:33:42 +0000163/* The next table maps tokens (terminal symbols) into fallback tokens.
164** If a construct like the following:
drh0bd1f4e2002-06-06 18:54:39 +0000165**
166** %fallback ID X Y Z.
167**
drh34ff57b2008-07-14 12:27:51 +0000168** appears in the grammar, then ID becomes a fallback token for X, Y,
drh0bd1f4e2002-06-06 18:54:39 +0000169** and Z. Whenever one of the tokens X, Y, or Z is input to the parser
170** but it does not parse, the type of the token is changed to ID and
171** the parse is retried before an error is thrown.
drh82415f22015-11-09 19:33:42 +0000172**
173** This feature can be used, for example, to cause some keywords in a language
174** to revert to identifiers if they keyword does not apply in the context where
175** it appears.
drh0bd1f4e2002-06-06 18:54:39 +0000176*/
177#ifdef YYFALLBACK
178static const YYCODETYPE yyFallback[] = {
179%%
180};
181#endif /* YYFALLBACK */
182
drh75897232000-05-29 14:26:00 +0000183/* The following structure represents a single element of the
184** parser's stack. Information stored includes:
185**
186** + The state number for the parser at this level of the stack.
187**
188** + The value of the token stored at this level of the stack.
189** (In other words, the "major" token.)
190**
191** + The semantic value stored at this level of the stack. This is
192** the information used by the action routines in the grammar.
193** It is sometimes called the "minor" token.
drha248a722015-09-07 19:52:55 +0000194**
195** After the "shift" half of a SHIFTREDUCE action, the stateno field
196** actually contains the reduce action for the second half of the
197** SHIFTREDUCE.
drh75897232000-05-29 14:26:00 +0000198*/
199struct yyStackEntry {
drha248a722015-09-07 19:52:55 +0000200 YYACTIONTYPE stateno; /* The state-number, or reduce action in SHIFTREDUCE */
drh2abcd582008-07-24 23:34:07 +0000201 YYCODETYPE major; /* The major token value. This is the code
202 ** number for the token at this stack level */
203 YYMINORTYPE minor; /* The user-supplied minor token value. This
204 ** is the value of the token */
drh75897232000-05-29 14:26:00 +0000205};
drh1f245e42002-03-11 13:55:50 +0000206typedef struct yyStackEntry yyStackEntry;
drh75897232000-05-29 14:26:00 +0000207
208/* The state of the parser is completely contained in an instance of
209** the following structure */
210struct yyParser {
drh118ab652016-05-23 21:56:24 +0000211 yyStackEntry *yytos; /* Pointer to top element of the stack */
drhec424a52008-07-25 15:39:03 +0000212#ifdef YYTRACKMAXSTACKDEPTH
drh118ab652016-05-23 21:56:24 +0000213 int yyhwm; /* High-water mark of the stack */
drhec424a52008-07-25 15:39:03 +0000214#endif
drhdab943c2016-02-16 01:01:43 +0000215#ifndef YYNOERRORRECOVERY
drh1f245e42002-03-11 13:55:50 +0000216 int yyerrcnt; /* Shifts left before out of the error */
drhdab943c2016-02-16 01:01:43 +0000217#endif
drh1f245e42002-03-11 13:55:50 +0000218 ParseARG_SDECL /* A place to hold %extra_argument */
drhb19fd012007-03-29 01:44:45 +0000219#if YYSTACKDEPTH<=0
220 int yystksz; /* Current side of the stack */
221 yyStackEntry *yystack; /* The parser's stack */
drh8dc82472016-05-27 04:10:47 +0000222 yyStackEntry yystk0; /* First stack entry */
drhb19fd012007-03-29 01:44:45 +0000223#else
drh1f245e42002-03-11 13:55:50 +0000224 yyStackEntry yystack[YYSTACKDEPTH]; /* The parser's stack */
drh8b471e72017-06-28 15:01:35 +0000225 yyStackEntry *yystackEnd; /* Last entry in the stack */
drhb19fd012007-03-29 01:44:45 +0000226#endif
drh75897232000-05-29 14:26:00 +0000227};
228typedef struct yyParser yyParser;
229
230#ifndef NDEBUG
231#include <stdio.h>
232static FILE *yyTraceFILE = 0;
233static char *yyTracePrompt = 0;
drh0bd1f4e2002-06-06 18:54:39 +0000234#endif /* NDEBUG */
drh75897232000-05-29 14:26:00 +0000235
drh0bd1f4e2002-06-06 18:54:39 +0000236#ifndef NDEBUG
drh75897232000-05-29 14:26:00 +0000237/*
238** Turn parser tracing on by giving a stream to which to write the trace
239** and a prompt to preface each trace message. Tracing is turned off
240** by making either argument NULL
241**
242** Inputs:
243** <ul>
244** <li> A FILE* to which trace output should be written.
245** If NULL, then tracing is turned off.
246** <li> A prefix string written at the beginning of every
247** line of trace output. If NULL, then tracing is
248** turned off.
249** </ul>
250**
251** Outputs:
252** None.
253*/
drh75897232000-05-29 14:26:00 +0000254void ParseTrace(FILE *TraceFILE, char *zTracePrompt){
255 yyTraceFILE = TraceFILE;
256 yyTracePrompt = zTracePrompt;
257 if( yyTraceFILE==0 ) yyTracePrompt = 0;
258 else if( yyTracePrompt==0 ) yyTraceFILE = 0;
259}
drh0bd1f4e2002-06-06 18:54:39 +0000260#endif /* NDEBUG */
drh75897232000-05-29 14:26:00 +0000261
drh0bd1f4e2002-06-06 18:54:39 +0000262#ifndef NDEBUG
drh75897232000-05-29 14:26:00 +0000263/* For tracing shifts, the names of all terminals and nonterminals
264** are required. The following table supplies these names */
drh57196282004-10-06 15:41:16 +0000265static const char *const yyTokenName[] = {
drh75897232000-05-29 14:26:00 +0000266%%
267};
drh0bd1f4e2002-06-06 18:54:39 +0000268#endif /* NDEBUG */
drh75897232000-05-29 14:26:00 +0000269
drh0bd1f4e2002-06-06 18:54:39 +0000270#ifndef NDEBUG
271/* For tracing reduce actions, the names of all rules are required.
272*/
drh57196282004-10-06 15:41:16 +0000273static const char *const yyRuleName[] = {
drh0bd1f4e2002-06-06 18:54:39 +0000274%%
275};
276#endif /* NDEBUG */
drha1b351a2001-09-14 16:42:12 +0000277
drh960e8c62001-04-03 16:53:21 +0000278
drhb19fd012007-03-29 01:44:45 +0000279#if YYSTACKDEPTH<=0
280/*
drh8dc82472016-05-27 04:10:47 +0000281** Try to increase the size of the parser stack. Return the number
282** of errors. Return 0 on success.
drhb19fd012007-03-29 01:44:45 +0000283*/
drh8dc82472016-05-27 04:10:47 +0000284static int yyGrowStack(yyParser *p){
drhb19fd012007-03-29 01:44:45 +0000285 int newSize;
drhabecc0b2016-05-24 00:40:54 +0000286 int idx;
drhb19fd012007-03-29 01:44:45 +0000287 yyStackEntry *pNew;
288
289 newSize = p->yystksz*2 + 100;
drhabecc0b2016-05-24 00:40:54 +0000290 idx = p->yytos ? (int)(p->yytos - p->yystack) : 0;
drh8dc82472016-05-27 04:10:47 +0000291 if( p->yystack==&p->yystk0 ){
292 pNew = malloc(newSize*sizeof(pNew[0]));
293 if( pNew ) pNew[0] = p->yystk0;
294 }else{
295 pNew = realloc(p->yystack, newSize*sizeof(pNew[0]));
296 }
drhb19fd012007-03-29 01:44:45 +0000297 if( pNew ){
298 p->yystack = pNew;
drhabecc0b2016-05-24 00:40:54 +0000299 p->yytos = &p->yystack[idx];
drhb19fd012007-03-29 01:44:45 +0000300#ifndef NDEBUG
301 if( yyTraceFILE ){
drh8dc82472016-05-27 04:10:47 +0000302 fprintf(yyTraceFILE,"%sStack grows from %d to %d entries.\n",
303 yyTracePrompt, p->yystksz, newSize);
drhb19fd012007-03-29 01:44:45 +0000304 }
305#endif
drh8dc82472016-05-27 04:10:47 +0000306 p->yystksz = newSize;
drhb19fd012007-03-29 01:44:45 +0000307 }
drh8dc82472016-05-27 04:10:47 +0000308 return pNew==0;
drhb19fd012007-03-29 01:44:45 +0000309}
310#endif
311
drh82415f22015-11-09 19:33:42 +0000312/* Datatype of the argument to the memory allocated passed as the
313** second argument to ParseAlloc() below. This can be changed by
314** putting an appropriate #define in the %include section of the input
315** grammar.
316*/
317#ifndef YYMALLOCARGTYPE
318# define YYMALLOCARGTYPE size_t
319#endif
320
drhd26cc542017-01-28 20:46:37 +0000321/* Initialize a new parser that has already been allocated.
322*/
323void ParseInit(void *yypParser){
324 yyParser *pParser = (yyParser*)yypParser;
325#ifdef YYTRACKMAXSTACKDEPTH
326 pParser->yyhwm = 0;
327#endif
328#if YYSTACKDEPTH<=0
329 pParser->yytos = NULL;
330 pParser->yystack = NULL;
331 pParser->yystksz = 0;
332 if( yyGrowStack(pParser) ){
333 pParser->yystack = &pParser->yystk0;
334 pParser->yystksz = 1;
335 }
336#endif
337#ifndef YYNOERRORRECOVERY
338 pParser->yyerrcnt = -1;
339#endif
340 pParser->yytos = pParser->yystack;
341 pParser->yystack[0].stateno = 0;
342 pParser->yystack[0].major = 0;
drh92395c52017-07-04 12:50:00 +0000343#if YYSTACKDEPTH>0
drh8b471e72017-06-28 15:01:35 +0000344 pParser->yystackEnd = &pParser->yystack[YYSTACKDEPTH-1];
drh92395c52017-07-04 12:50:00 +0000345#endif
drhd26cc542017-01-28 20:46:37 +0000346}
347
348#ifndef Parse_ENGINEALWAYSONSTACK
drh75897232000-05-29 14:26:00 +0000349/*
350** This function allocates a new parser.
351** The only argument is a pointer to a function which works like
352** malloc.
353**
354** Inputs:
355** A pointer to the function used to allocate memory.
356**
357** Outputs:
358** A pointer to a parser. This pointer is used in subsequent calls
359** to Parse and ParseFree.
360*/
drh82415f22015-11-09 19:33:42 +0000361void *ParseAlloc(void *(*mallocProc)(YYMALLOCARGTYPE)){
drh75897232000-05-29 14:26:00 +0000362 yyParser *pParser;
drh82415f22015-11-09 19:33:42 +0000363 pParser = (yyParser*)(*mallocProc)( (YYMALLOCARGTYPE)sizeof(yyParser) );
drhd26cc542017-01-28 20:46:37 +0000364 if( pParser ) ParseInit(pParser);
drh75897232000-05-29 14:26:00 +0000365 return pParser;
366}
drhd26cc542017-01-28 20:46:37 +0000367#endif /* Parse_ENGINEALWAYSONSTACK */
368
drh75897232000-05-29 14:26:00 +0000369
drh82415f22015-11-09 19:33:42 +0000370/* The following function deletes the "minor type" or semantic value
371** associated with a symbol. The symbol can be either a terminal
372** or nonterminal. "yymajor" is the symbol code, and "yypminor" is
373** a pointer to the value to be deleted. The code used to do the
374** deletions is derived from the %destructor and/or %token_destructor
375** directives of the input grammar.
drh75897232000-05-29 14:26:00 +0000376*/
drh633e6d52008-07-28 19:34:53 +0000377static void yy_destructor(
378 yyParser *yypParser, /* The parser */
379 YYCODETYPE yymajor, /* Type code for object to destroy */
380 YYMINORTYPE *yypminor /* The object to be destroyed */
381){
382 ParseARG_FETCH;
drh75897232000-05-29 14:26:00 +0000383 switch( yymajor ){
384 /* Here is inserted the actions which take place when a
385 ** terminal or non-terminal is destroyed. This can happen
386 ** when the symbol is popped from the stack during a
387 ** reduce or during error processing or when a parser is
388 ** being destroyed before it is finished parsing.
389 **
390 ** Note: during a reduce, the only symbols destroyed are those
drh82415f22015-11-09 19:33:42 +0000391 ** which appear on the RHS of the rule, but which are *not* used
drh75897232000-05-29 14:26:00 +0000392 ** inside the C code.
393 */
drh82415f22015-11-09 19:33:42 +0000394/********* Begin destructor definitions ***************************************/
drh75897232000-05-29 14:26:00 +0000395%%
drh82415f22015-11-09 19:33:42 +0000396/********* End destructor definitions *****************************************/
drh75897232000-05-29 14:26:00 +0000397 default: break; /* If no destructor action specified: do nothing */
398 }
399}
400
401/*
402** Pop the parser's stack once.
403**
404** If there is a destructor routine associated with the token which
405** is popped from the stack, then call it.
drh75897232000-05-29 14:26:00 +0000406*/
drh3781f012015-11-09 14:11:37 +0000407static void yy_pop_parser_stack(yyParser *pParser){
408 yyStackEntry *yytos;
drh118ab652016-05-23 21:56:24 +0000409 assert( pParser->yytos!=0 );
drh240c7fa2016-07-05 12:47:28 +0000410 assert( pParser->yytos > pParser->yystack );
drh118ab652016-05-23 21:56:24 +0000411 yytos = pParser->yytos--;
drh75897232000-05-29 14:26:00 +0000412#ifndef NDEBUG
drh3781f012015-11-09 14:11:37 +0000413 if( yyTraceFILE ){
drh75897232000-05-29 14:26:00 +0000414 fprintf(yyTraceFILE,"%sPopping %s\n",
415 yyTracePrompt,
drh3ddfdf72003-12-22 14:53:19 +0000416 yyTokenName[yytos->major]);
drh75897232000-05-29 14:26:00 +0000417 }
418#endif
drh3781f012015-11-09 14:11:37 +0000419 yy_destructor(pParser, yytos->major, &yytos->minor);
drh75897232000-05-29 14:26:00 +0000420}
421
drhd26cc542017-01-28 20:46:37 +0000422/*
423** Clear all secondary memory allocations from the parser
424*/
425void ParseFinalize(void *p){
426 yyParser *pParser = (yyParser*)p;
427 while( pParser->yytos>pParser->yystack ) yy_pop_parser_stack(pParser);
428#if YYSTACKDEPTH<=0
429 if( pParser->yystack!=&pParser->yystk0 ) free(pParser->yystack);
430#endif
431}
432
433#ifndef Parse_ENGINEALWAYSONSTACK
drh75897232000-05-29 14:26:00 +0000434/*
drh82415f22015-11-09 19:33:42 +0000435** Deallocate and destroy a parser. Destructors are called for
drh75897232000-05-29 14:26:00 +0000436** all stack elements before shutting the parser down.
437**
drh82415f22015-11-09 19:33:42 +0000438** If the YYPARSEFREENEVERNULL macro exists (for example because it
439** is defined in a %include section of the input grammar) then it is
440** assumed that the input pointer is never NULL.
drh75897232000-05-29 14:26:00 +0000441*/
drh75897232000-05-29 14:26:00 +0000442void ParseFree(
drh960e8c62001-04-03 16:53:21 +0000443 void *p, /* The parser to be deleted */
444 void (*freeProc)(void*) /* Function used to reclaim memory */
drh75897232000-05-29 14:26:00 +0000445){
drh82415f22015-11-09 19:33:42 +0000446#ifndef YYPARSEFREENEVERNULL
drhd26cc542017-01-28 20:46:37 +0000447 if( p==0 ) return;
drh82415f22015-11-09 19:33:42 +0000448#endif
drhd26cc542017-01-28 20:46:37 +0000449 ParseFinalize(p);
450 (*freeProc)(p);
drh75897232000-05-29 14:26:00 +0000451}
drhd26cc542017-01-28 20:46:37 +0000452#endif /* Parse_ENGINEALWAYSONSTACK */
drh75897232000-05-29 14:26:00 +0000453
454/*
drhec424a52008-07-25 15:39:03 +0000455** Return the peak depth of the stack for a parser.
456*/
457#ifdef YYTRACKMAXSTACKDEPTH
458int ParseStackPeak(void *p){
459 yyParser *pParser = (yyParser*)p;
drh118ab652016-05-23 21:56:24 +0000460 return pParser->yyhwm;
drhec424a52008-07-25 15:39:03 +0000461}
462#endif
463
464/*
drh8b582012003-10-21 13:16:03 +0000465** Find the appropriate action for a parser given the terminal
466** look-ahead token iLookAhead.
drh75897232000-05-29 14:26:00 +0000467*/
drh4ef07702016-03-16 19:45:54 +0000468static unsigned int yy_find_shift_action(
drh75897232000-05-29 14:26:00 +0000469 yyParser *pParser, /* The parser */
drhd9f291e2006-06-13 11:15:47 +0000470 YYCODETYPE iLookAhead /* The look-ahead token */
drh75897232000-05-29 14:26:00 +0000471){
drh8b582012003-10-21 13:16:03 +0000472 int i;
drh118ab652016-05-23 21:56:24 +0000473 int stateno = pParser->yytos->stateno;
drha4414042015-11-09 15:06:26 +0000474
475 if( stateno>=YY_MIN_REDUCE ) return stateno;
drhae2a4082015-09-07 20:02:39 +0000476 assert( stateno <= YY_SHIFT_COUNT );
drha4414042015-11-09 15:06:26 +0000477 do{
478 i = yy_shift_ofst[stateno];
drha4414042015-11-09 15:06:26 +0000479 assert( iLookAhead!=YYNOCODE );
480 i += iLookAhead;
481 if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){
drh4767d972006-06-14 15:03:49 +0000482#ifdef YYFALLBACK
drhc83db9e2016-08-10 01:43:30 +0000483 YYCODETYPE iFallback; /* Fallback token */
484 if( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0])
485 && (iFallback = yyFallback[iLookAhead])!=0 ){
drh4767d972006-06-14 15:03:49 +0000486#ifndef NDEBUG
drhc83db9e2016-08-10 01:43:30 +0000487 if( yyTraceFILE ){
488 fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n",
489 yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]);
drhe09daa92006-06-10 13:29:31 +0000490 }
drha4414042015-11-09 15:06:26 +0000491#endif
drhc83db9e2016-08-10 01:43:30 +0000492 assert( yyFallback[iFallback]==0 ); /* Fallback loop must terminate */
493 iLookAhead = iFallback;
494 continue;
495 }
496#endif
drha4414042015-11-09 15:06:26 +0000497#ifdef YYWILDCARD
drhc83db9e2016-08-10 01:43:30 +0000498 {
499 int j = i - iLookAhead + YYWILDCARD;
500 if(
drha4414042015-11-09 15:06:26 +0000501#if YY_SHIFT_MIN+YYWILDCARD<0
drhc83db9e2016-08-10 01:43:30 +0000502 j>=0 &&
drha4414042015-11-09 15:06:26 +0000503#endif
504#if YY_SHIFT_MAX+YYWILDCARD>=YY_ACTTAB_COUNT
drhc83db9e2016-08-10 01:43:30 +0000505 j<YY_ACTTAB_COUNT &&
drha4414042015-11-09 15:06:26 +0000506#endif
drhc83db9e2016-08-10 01:43:30 +0000507 yy_lookahead[j]==YYWILDCARD && iLookAhead>0
508 ){
drha4414042015-11-09 15:06:26 +0000509#ifndef NDEBUG
drhc83db9e2016-08-10 01:43:30 +0000510 if( yyTraceFILE ){
511 fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n",
512 yyTracePrompt, yyTokenName[iLookAhead],
513 yyTokenName[YYWILDCARD]);
drha4414042015-11-09 15:06:26 +0000514 }
drhc83db9e2016-08-10 01:43:30 +0000515#endif /* NDEBUG */
516 return yy_action[j];
drha4414042015-11-09 15:06:26 +0000517 }
drha4414042015-11-09 15:06:26 +0000518 }
drhc83db9e2016-08-10 01:43:30 +0000519#endif /* YYWILDCARD */
drha4414042015-11-09 15:06:26 +0000520 return yy_default[stateno];
521 }else{
522 return yy_action[i];
drh0bd1f4e2002-06-06 18:54:39 +0000523 }
drha4414042015-11-09 15:06:26 +0000524 }while(1);
drh8b582012003-10-21 13:16:03 +0000525}
526
527/*
528** Find the appropriate action for a parser given the non-terminal
529** look-ahead token iLookAhead.
drh8b582012003-10-21 13:16:03 +0000530*/
531static int yy_find_reduce_action(
drh161aba32005-02-01 04:09:36 +0000532 int stateno, /* Current state number */
drhd9f291e2006-06-13 11:15:47 +0000533 YYCODETYPE iLookAhead /* The look-ahead token */
drh8b582012003-10-21 13:16:03 +0000534){
535 int i;
drh7f7c2572008-04-27 18:45:10 +0000536#ifdef YYERRORSYMBOL
drhf16371d2009-11-03 19:18:31 +0000537 if( stateno>YY_REDUCE_COUNT ){
drh7f7c2572008-04-27 18:45:10 +0000538 return yy_default[stateno];
539 }
540#else
drhf16371d2009-11-03 19:18:31 +0000541 assert( stateno<=YY_REDUCE_COUNT );
drh7f7c2572008-04-27 18:45:10 +0000542#endif
drh01495b92008-01-23 12:52:40 +0000543 i = yy_reduce_ofst[stateno];
544 assert( i!=YY_REDUCE_USE_DFLT );
545 assert( iLookAhead!=YYNOCODE );
drh8b582012003-10-21 13:16:03 +0000546 i += iLookAhead;
drh7f7c2572008-04-27 18:45:10 +0000547#ifdef YYERRORSYMBOL
drhf16371d2009-11-03 19:18:31 +0000548 if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){
drh7f7c2572008-04-27 18:45:10 +0000549 return yy_default[stateno];
550 }
551#else
drhf16371d2009-11-03 19:18:31 +0000552 assert( i>=0 && i<YY_ACTTAB_COUNT );
drh01495b92008-01-23 12:52:40 +0000553 assert( yy_lookahead[i]==iLookAhead );
drh7f7c2572008-04-27 18:45:10 +0000554#endif
drh01495b92008-01-23 12:52:40 +0000555 return yy_action[i];
drh75897232000-05-29 14:26:00 +0000556}
557
558/*
drhb19fd012007-03-29 01:44:45 +0000559** The following routine is called if the stack overflows.
560*/
drh45f31be2016-02-16 21:19:49 +0000561static void yyStackOverflow(yyParser *yypParser){
drhb19fd012007-03-29 01:44:45 +0000562 ParseARG_FETCH;
drhb19fd012007-03-29 01:44:45 +0000563#ifndef NDEBUG
564 if( yyTraceFILE ){
565 fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt);
566 }
567#endif
drhabecc0b2016-05-24 00:40:54 +0000568 while( yypParser->yytos>yypParser->yystack ) yy_pop_parser_stack(yypParser);
drhb19fd012007-03-29 01:44:45 +0000569 /* Here code is inserted which will execute if the parser
570 ** stack every overflows */
drh82415f22015-11-09 19:33:42 +0000571/******** Begin %stack_overflow code ******************************************/
drhb19fd012007-03-29 01:44:45 +0000572%%
drh82415f22015-11-09 19:33:42 +0000573/******** End %stack_overflow code ********************************************/
drhb19fd012007-03-29 01:44:45 +0000574 ParseARG_STORE; /* Suppress warning about unused %extra_argument var */
575}
576
577/*
drha248a722015-09-07 19:52:55 +0000578** Print tracing information for a SHIFT action
579*/
580#ifndef NDEBUG
581static void yyTraceShift(yyParser *yypParser, int yyNewState){
582 if( yyTraceFILE ){
drha248a722015-09-07 19:52:55 +0000583 if( yyNewState<YYNSTATE ){
drh0c4105e2015-11-10 14:51:22 +0000584 fprintf(yyTraceFILE,"%sShift '%s', go to state %d\n",
drh118ab652016-05-23 21:56:24 +0000585 yyTracePrompt,yyTokenName[yypParser->yytos->major],
drh0c4105e2015-11-10 14:51:22 +0000586 yyNewState);
drha248a722015-09-07 19:52:55 +0000587 }else{
drh0c4105e2015-11-10 14:51:22 +0000588 fprintf(yyTraceFILE,"%sShift '%s'\n",
drh118ab652016-05-23 21:56:24 +0000589 yyTracePrompt,yyTokenName[yypParser->yytos->major]);
drha248a722015-09-07 19:52:55 +0000590 }
591 }
592}
593#else
594# define yyTraceShift(X,Y)
595#endif
596
597/*
drh82415f22015-11-09 19:33:42 +0000598** Perform a shift action.
drh75897232000-05-29 14:26:00 +0000599*/
drha248a722015-09-07 19:52:55 +0000600static void yy_shift(
drh75897232000-05-29 14:26:00 +0000601 yyParser *yypParser, /* The parser to be shifted */
602 int yyNewState, /* The new state to shift in */
603 int yyMajor, /* The major token to shift in */
drh45f31be2016-02-16 21:19:49 +0000604 ParseTOKENTYPE yyMinor /* The minor token to shift in */
drh75897232000-05-29 14:26:00 +0000605){
drh3ddfdf72003-12-22 14:53:19 +0000606 yyStackEntry *yytos;
drh118ab652016-05-23 21:56:24 +0000607 yypParser->yytos++;
drhec424a52008-07-25 15:39:03 +0000608#ifdef YYTRACKMAXSTACKDEPTH
drh118ab652016-05-23 21:56:24 +0000609 if( (int)(yypParser->yytos - yypParser->yystack)>yypParser->yyhwm ){
610 yypParser->yyhwm++;
611 assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack) );
drhec424a52008-07-25 15:39:03 +0000612 }
613#endif
drhb19fd012007-03-29 01:44:45 +0000614#if YYSTACKDEPTH>0
drh8b471e72017-06-28 15:01:35 +0000615 if( yypParser->yytos>yypParser->yystackEnd ){
drh63413312016-12-06 17:59:05 +0000616 yypParser->yytos--;
drh45f31be2016-02-16 21:19:49 +0000617 yyStackOverflow(yypParser);
drha248a722015-09-07 19:52:55 +0000618 return;
drh75897232000-05-29 14:26:00 +0000619 }
drhb19fd012007-03-29 01:44:45 +0000620#else
drh118ab652016-05-23 21:56:24 +0000621 if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz] ){
drh8dc82472016-05-27 04:10:47 +0000622 if( yyGrowStack(yypParser) ){
drh63413312016-12-06 17:59:05 +0000623 yypParser->yytos--;
drh45f31be2016-02-16 21:19:49 +0000624 yyStackOverflow(yypParser);
drha248a722015-09-07 19:52:55 +0000625 return;
drhb19fd012007-03-29 01:44:45 +0000626 }
627 }
628#endif
drh0efd37f2016-06-06 18:17:36 +0000629 if( yyNewState > YY_MAX_SHIFT ){
630 yyNewState += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE;
631 }
drh118ab652016-05-23 21:56:24 +0000632 yytos = yypParser->yytos;
drhb27b7f52008-12-10 18:03:45 +0000633 yytos->stateno = (YYACTIONTYPE)yyNewState;
634 yytos->major = (YYCODETYPE)yyMajor;
drh45f31be2016-02-16 21:19:49 +0000635 yytos->minor.yy0 = yyMinor;
drha248a722015-09-07 19:52:55 +0000636 yyTraceShift(yypParser, yyNewState);
drh75897232000-05-29 14:26:00 +0000637}
638
639/* The following table contains information about every rule that
640** is used during the reduce.
641*/
drh57196282004-10-06 15:41:16 +0000642static const struct {
drh6be95362017-06-28 13:47:56 +0000643 YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */
644 signed char nrhs; /* Negative of the number of RHS symbols in the rule */
drh75897232000-05-29 14:26:00 +0000645} yyRuleInfo[] = {
646%%
647};
648
drh1f245e42002-03-11 13:55:50 +0000649static void yy_accept(yyParser*); /* Forward Declaration */
drh75897232000-05-29 14:26:00 +0000650
651/*
652** Perform a reduce action and the shift that must immediately
653** follow the reduce.
654*/
655static void yy_reduce(
656 yyParser *yypParser, /* The parser */
drh4ef07702016-03-16 19:45:54 +0000657 unsigned int yyruleno /* Number of the rule by which to reduce */
drh75897232000-05-29 14:26:00 +0000658){
659 int yygoto; /* The next state */
660 int yyact; /* The next action */
drh1f245e42002-03-11 13:55:50 +0000661 yyStackEntry *yymsp; /* The top of the parser's stack */
drh75897232000-05-29 14:26:00 +0000662 int yysize; /* Amount to pop the stack */
drh1f245e42002-03-11 13:55:50 +0000663 ParseARG_FETCH;
drh118ab652016-05-23 21:56:24 +0000664 yymsp = yypParser->yytos;
drh0bd1f4e2002-06-06 18:54:39 +0000665#ifndef NDEBUG
drh4ef07702016-03-16 19:45:54 +0000666 if( yyTraceFILE && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){
drh3bd48ab2015-09-07 18:23:37 +0000667 yysize = yyRuleInfo[yyruleno].nrhs;
drh0c4105e2015-11-10 14:51:22 +0000668 fprintf(yyTraceFILE, "%sReduce [%s], go to state %d.\n", yyTracePrompt,
drh6be95362017-06-28 13:47:56 +0000669 yyRuleName[yyruleno], yymsp[yysize].stateno);
drh0bd1f4e2002-06-06 18:54:39 +0000670 }
671#endif /* NDEBUG */
drh45f31be2016-02-16 21:19:49 +0000672
673 /* Check that the stack is large enough to grow by a single entry
674 ** if the RHS of the rule is empty. This ensures that there is room
675 ** enough on the stack to push the LHS value */
676 if( yyRuleInfo[yyruleno].nrhs==0 ){
677#ifdef YYTRACKMAXSTACKDEPTH
drh118ab652016-05-23 21:56:24 +0000678 if( (int)(yypParser->yytos - yypParser->yystack)>yypParser->yyhwm ){
679 yypParser->yyhwm++;
680 assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack));
drh45f31be2016-02-16 21:19:49 +0000681 }
682#endif
683#if YYSTACKDEPTH>0
drh8b471e72017-06-28 15:01:35 +0000684 if( yypParser->yytos>=yypParser->yystackEnd ){
drh45f31be2016-02-16 21:19:49 +0000685 yyStackOverflow(yypParser);
686 return;
687 }
688#else
drh118ab652016-05-23 21:56:24 +0000689 if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz-1] ){
drh8dc82472016-05-27 04:10:47 +0000690 if( yyGrowStack(yypParser) ){
drh45f31be2016-02-16 21:19:49 +0000691 yyStackOverflow(yypParser);
692 return;
693 }
drh8dc82472016-05-27 04:10:47 +0000694 yymsp = yypParser->yytos;
drh45f31be2016-02-16 21:19:49 +0000695 }
696#endif
697 }
drhcb6c5652007-01-16 18:19:12 +0000698
drh75897232000-05-29 14:26:00 +0000699 switch( yyruleno ){
700 /* Beginning here are the reduction cases. A typical example
701 ** follows:
702 ** case 0:
drh75897232000-05-29 14:26:00 +0000703 ** #line <lineno> <grammarfile>
704 ** { ... } // User supplied code
705 ** #line <lineno> <thisfile>
706 ** break;
707 */
drh82415f22015-11-09 19:33:42 +0000708/********** Begin reduce actions **********************************************/
drh75897232000-05-29 14:26:00 +0000709%%
drh82415f22015-11-09 19:33:42 +0000710/********** End reduce actions ************************************************/
drh75897232000-05-29 14:26:00 +0000711 };
drh4ef07702016-03-16 19:45:54 +0000712 assert( yyruleno<sizeof(yyRuleInfo)/sizeof(yyRuleInfo[0]) );
drh75897232000-05-29 14:26:00 +0000713 yygoto = yyRuleInfo[yyruleno].lhs;
714 yysize = yyRuleInfo[yyruleno].nrhs;
drh6be95362017-06-28 13:47:56 +0000715 yyact = yy_find_reduce_action(yymsp[yysize].stateno,(YYCODETYPE)yygoto);
drhbd8fcc12017-06-28 11:56:18 +0000716
717 /* There are no SHIFTREDUCE actions on nonterminals because the table
718 ** generator has simplified them to pure REDUCE actions. */
719 assert( !(yyact>YY_MAX_SHIFT && yyact<=YY_MAX_SHIFTREDUCE) );
720
721 /* It is not possible for a REDUCE to be followed by an error */
722 assert( yyact!=YY_ERROR_ACTION );
723
724 if( yyact==YY_ACCEPT_ACTION ){
drh6be95362017-06-28 13:47:56 +0000725 yypParser->yytos += yysize;
drhbd8fcc12017-06-28 11:56:18 +0000726 yy_accept(yypParser);
727 }else{
drh6be95362017-06-28 13:47:56 +0000728 yymsp += yysize+1;
drh118ab652016-05-23 21:56:24 +0000729 yypParser->yytos = yymsp;
drh45f31be2016-02-16 21:19:49 +0000730 yymsp->stateno = (YYACTIONTYPE)yyact;
731 yymsp->major = (YYCODETYPE)yygoto;
drh45f31be2016-02-16 21:19:49 +0000732 yyTraceShift(yypParser, yyact);
drh75897232000-05-29 14:26:00 +0000733 }
734}
735
736/*
737** The following code executes when the parse fails
738*/
drhd3ec02d2009-06-12 02:27:14 +0000739#ifndef YYNOERRORRECOVERY
drh75897232000-05-29 14:26:00 +0000740static void yy_parse_failed(
741 yyParser *yypParser /* The parser */
drh75897232000-05-29 14:26:00 +0000742){
drh1f245e42002-03-11 13:55:50 +0000743 ParseARG_FETCH;
drh75897232000-05-29 14:26:00 +0000744#ifndef NDEBUG
745 if( yyTraceFILE ){
746 fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt);
747 }
748#endif
drhabecc0b2016-05-24 00:40:54 +0000749 while( yypParser->yytos>yypParser->yystack ) yy_pop_parser_stack(yypParser);
drh75897232000-05-29 14:26:00 +0000750 /* Here code is inserted which will be executed whenever the
751 ** parser fails */
drh82415f22015-11-09 19:33:42 +0000752/************ Begin %parse_failure code ***************************************/
drh75897232000-05-29 14:26:00 +0000753%%
drh82415f22015-11-09 19:33:42 +0000754/************ End %parse_failure code *****************************************/
drh1f245e42002-03-11 13:55:50 +0000755 ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
drh75897232000-05-29 14:26:00 +0000756}
drhd3ec02d2009-06-12 02:27:14 +0000757#endif /* YYNOERRORRECOVERY */
drh75897232000-05-29 14:26:00 +0000758
759/*
760** The following code executes when a syntax error first occurs.
761*/
762static void yy_syntax_error(
763 yyParser *yypParser, /* The parser */
764 int yymajor, /* The major type of the error token */
drh45f31be2016-02-16 21:19:49 +0000765 ParseTOKENTYPE yyminor /* The minor type of the error token */
drh75897232000-05-29 14:26:00 +0000766){
drh1f245e42002-03-11 13:55:50 +0000767 ParseARG_FETCH;
drh45f31be2016-02-16 21:19:49 +0000768#define TOKEN yyminor
drh82415f22015-11-09 19:33:42 +0000769/************ Begin %syntax_error code ****************************************/
drh75897232000-05-29 14:26:00 +0000770%%
drh82415f22015-11-09 19:33:42 +0000771/************ End %syntax_error code ******************************************/
drh1f245e42002-03-11 13:55:50 +0000772 ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
drh75897232000-05-29 14:26:00 +0000773}
774
775/*
776** The following is executed when the parser accepts
777*/
778static void yy_accept(
779 yyParser *yypParser /* The parser */
drh75897232000-05-29 14:26:00 +0000780){
drh1f245e42002-03-11 13:55:50 +0000781 ParseARG_FETCH;
drh75897232000-05-29 14:26:00 +0000782#ifndef NDEBUG
783 if( yyTraceFILE ){
784 fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt);
785 }
786#endif
drhdd703e22016-07-12 19:54:49 +0000787#ifndef YYNOERRORRECOVERY
788 yypParser->yyerrcnt = -1;
789#endif
drh756b41e2016-05-24 18:55:08 +0000790 assert( yypParser->yytos==yypParser->yystack );
drh75897232000-05-29 14:26:00 +0000791 /* Here code is inserted which will be executed whenever the
792 ** parser accepts */
drh82415f22015-11-09 19:33:42 +0000793/*********** Begin %parse_accept code *****************************************/
drh75897232000-05-29 14:26:00 +0000794%%
drh82415f22015-11-09 19:33:42 +0000795/*********** End %parse_accept code *******************************************/
drh1f245e42002-03-11 13:55:50 +0000796 ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
drh75897232000-05-29 14:26:00 +0000797}
798
799/* The main parser program.
800** The first argument is a pointer to a structure obtained from
801** "ParseAlloc" which describes the current state of the parser.
802** The second argument is the major token number. The third is
803** the minor token. The fourth optional argument is whatever the
804** user wants (and specified in the grammar) and is available for
805** use by the action routines.
806**
807** Inputs:
808** <ul>
809** <li> A pointer to the parser (an opaque structure.)
810** <li> The major token number.
811** <li> The minor token number.
812** <li> An option argument of a grammar-specified type.
813** </ul>
814**
815** Outputs:
816** None.
817*/
drh75897232000-05-29 14:26:00 +0000818void Parse(
819 void *yyp, /* The parser */
820 int yymajor, /* The major token code number */
821 ParseTOKENTYPE yyminor /* The value for the token */
drh1f245e42002-03-11 13:55:50 +0000822 ParseARG_PDECL /* Optional %extra_argument parameter */
drh75897232000-05-29 14:26:00 +0000823){
824 YYMINORTYPE yyminorunion;
drh4ef07702016-03-16 19:45:54 +0000825 unsigned int yyact; /* The parser action. */
drha4414042015-11-09 15:06:26 +0000826#if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY)
drh75897232000-05-29 14:26:00 +0000827 int yyendofinput; /* True if we are at the end of input */
drha4414042015-11-09 15:06:26 +0000828#endif
drhc4dd3fd2008-01-22 01:48:05 +0000829#ifdef YYERRORSYMBOL
drh75897232000-05-29 14:26:00 +0000830 int yyerrorhit = 0; /* True if yymajor has invoked an error */
drhc4dd3fd2008-01-22 01:48:05 +0000831#endif
drh75897232000-05-29 14:26:00 +0000832 yyParser *yypParser; /* The parser */
833
drh75897232000-05-29 14:26:00 +0000834 yypParser = (yyParser*)yyp;
drhabecc0b2016-05-24 00:40:54 +0000835 assert( yypParser->yytos!=0 );
drha4414042015-11-09 15:06:26 +0000836#if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY)
drh75897232000-05-29 14:26:00 +0000837 yyendofinput = (yymajor==0);
drha4414042015-11-09 15:06:26 +0000838#endif
drh1f245e42002-03-11 13:55:50 +0000839 ParseARG_STORE;
drh75897232000-05-29 14:26:00 +0000840
841#ifndef NDEBUG
842 if( yyTraceFILE ){
drh0c4105e2015-11-10 14:51:22 +0000843 fprintf(yyTraceFILE,"%sInput '%s'\n",yyTracePrompt,yyTokenName[yymajor]);
drh75897232000-05-29 14:26:00 +0000844 }
845#endif
846
847 do{
drh3abbd392008-12-10 23:04:13 +0000848 yyact = yy_find_shift_action(yypParser,(YYCODETYPE)yymajor);
drh3bd48ab2015-09-07 18:23:37 +0000849 if( yyact <= YY_MAX_SHIFTREDUCE ){
drh45f31be2016-02-16 21:19:49 +0000850 yy_shift(yypParser,yyact,yymajor,yyminor);
drhdab943c2016-02-16 01:01:43 +0000851#ifndef YYNOERRORRECOVERY
drha248a722015-09-07 19:52:55 +0000852 yypParser->yyerrcnt--;
drhdab943c2016-02-16 01:01:43 +0000853#endif
drha248a722015-09-07 19:52:55 +0000854 yymajor = YYNOCODE;
drh3bd48ab2015-09-07 18:23:37 +0000855 }else if( yyact <= YY_MAX_REDUCE ){
856 yy_reduce(yypParser,yyact-YY_MIN_REDUCE);
drhc4dd3fd2008-01-22 01:48:05 +0000857 }else{
858 assert( yyact == YY_ERROR_ACTION );
drh45f31be2016-02-16 21:19:49 +0000859 yyminorunion.yy0 = yyminor;
drhc4dd3fd2008-01-22 01:48:05 +0000860#ifdef YYERRORSYMBOL
drh3ddfdf72003-12-22 14:53:19 +0000861 int yymx;
drhc4dd3fd2008-01-22 01:48:05 +0000862#endif
drh75897232000-05-29 14:26:00 +0000863#ifndef NDEBUG
864 if( yyTraceFILE ){
865 fprintf(yyTraceFILE,"%sSyntax Error!\n",yyTracePrompt);
866 }
867#endif
868#ifdef YYERRORSYMBOL
869 /* A syntax error has occurred.
870 ** The response to an error depends upon whether or not the
871 ** grammar defines an error token "ERROR".
872 **
873 ** This is what we do if the grammar does define ERROR:
874 **
875 ** * Call the %syntax_error function.
876 **
877 ** * Begin popping the stack until we enter a state where
878 ** it is legal to shift the error symbol, then shift
879 ** the error symbol.
880 **
881 ** * Set the error count to three.
882 **
883 ** * Begin accepting and shifting new tokens. No new error
884 ** processing will occur until three tokens have been
885 ** shifted successfully.
886 **
887 */
drh1f245e42002-03-11 13:55:50 +0000888 if( yypParser->yyerrcnt<0 ){
drh45f31be2016-02-16 21:19:49 +0000889 yy_syntax_error(yypParser,yymajor,yyminor);
drh75897232000-05-29 14:26:00 +0000890 }
drh118ab652016-05-23 21:56:24 +0000891 yymx = yypParser->yytos->major;
drh3ddfdf72003-12-22 14:53:19 +0000892 if( yymx==YYERRORSYMBOL || yyerrorhit ){
drh75897232000-05-29 14:26:00 +0000893#ifndef NDEBUG
894 if( yyTraceFILE ){
895 fprintf(yyTraceFILE,"%sDiscard input token %s\n",
896 yyTracePrompt,yyTokenName[yymajor]);
897 }
898#endif
drh45f31be2016-02-16 21:19:49 +0000899 yy_destructor(yypParser, (YYCODETYPE)yymajor, &yyminorunion);
drh75897232000-05-29 14:26:00 +0000900 yymajor = YYNOCODE;
901 }else{
drh4eda15e2016-10-04 12:20:12 +0000902 while( yypParser->yytos >= yypParser->yystack
drh118ab652016-05-23 21:56:24 +0000903 && yymx != YYERRORSYMBOL
904 && (yyact = yy_find_reduce_action(
905 yypParser->yytos->stateno,
drh3bd48ab2015-09-07 18:23:37 +0000906 YYERRORSYMBOL)) >= YY_MIN_REDUCE
drh75897232000-05-29 14:26:00 +0000907 ){
908 yy_pop_parser_stack(yypParser);
909 }
drh118ab652016-05-23 21:56:24 +0000910 if( yypParser->yytos < yypParser->yystack || yymajor==0 ){
drhb27b7f52008-12-10 18:03:45 +0000911 yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
drh1f245e42002-03-11 13:55:50 +0000912 yy_parse_failed(yypParser);
drh240c7fa2016-07-05 12:47:28 +0000913#ifndef YYNOERRORRECOVERY
914 yypParser->yyerrcnt = -1;
915#endif
drh75897232000-05-29 14:26:00 +0000916 yymajor = YYNOCODE;
drh3ddfdf72003-12-22 14:53:19 +0000917 }else if( yymx!=YYERRORSYMBOL ){
drh45f31be2016-02-16 21:19:49 +0000918 yy_shift(yypParser,yyact,YYERRORSYMBOL,yyminor);
drh75897232000-05-29 14:26:00 +0000919 }
920 }
drh1f245e42002-03-11 13:55:50 +0000921 yypParser->yyerrcnt = 3;
drh75897232000-05-29 14:26:00 +0000922 yyerrorhit = 1;
drhd3ec02d2009-06-12 02:27:14 +0000923#elif defined(YYNOERRORRECOVERY)
924 /* If the YYNOERRORRECOVERY macro is defined, then do not attempt to
925 ** do any kind of error recovery. Instead, simply invoke the syntax
926 ** error routine and continue going as if nothing had happened.
927 **
928 ** Applications can set this macro (for example inside %include) if
929 ** they intend to abandon the parse upon the first syntax error seen.
930 */
drh45f31be2016-02-16 21:19:49 +0000931 yy_syntax_error(yypParser,yymajor, yyminor);
drhd3ec02d2009-06-12 02:27:14 +0000932 yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
933 yymajor = YYNOCODE;
934
drh75897232000-05-29 14:26:00 +0000935#else /* YYERRORSYMBOL is not defined */
936 /* This is what we do if the grammar does not define ERROR:
937 **
938 ** * Report an error message, and throw away the input token.
939 **
940 ** * If the input token is $, then fail the parse.
941 **
942 ** As before, subsequent error messages are suppressed until
943 ** three input tokens have been successfully shifted.
944 */
drh1f245e42002-03-11 13:55:50 +0000945 if( yypParser->yyerrcnt<=0 ){
drh45f31be2016-02-16 21:19:49 +0000946 yy_syntax_error(yypParser,yymajor, yyminor);
drh75897232000-05-29 14:26:00 +0000947 }
drh1f245e42002-03-11 13:55:50 +0000948 yypParser->yyerrcnt = 3;
drhb27b7f52008-12-10 18:03:45 +0000949 yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
drh75897232000-05-29 14:26:00 +0000950 if( yyendofinput ){
drh1f245e42002-03-11 13:55:50 +0000951 yy_parse_failed(yypParser);
drhd3d4b3c2016-07-08 19:54:38 +0000952#ifndef YYNOERRORRECOVERY
953 yypParser->yyerrcnt = -1;
954#endif
drh75897232000-05-29 14:26:00 +0000955 }
956 yymajor = YYNOCODE;
957#endif
drh75897232000-05-29 14:26:00 +0000958 }
drhabecc0b2016-05-24 00:40:54 +0000959 }while( yymajor!=YYNOCODE && yypParser->yytos>yypParser->yystack );
drh3bd48ab2015-09-07 18:23:37 +0000960#ifndef NDEBUG
961 if( yyTraceFILE ){
drh118ab652016-05-23 21:56:24 +0000962 yyStackEntry *i;
963 char cDiv = '[';
drh0c4105e2015-11-10 14:51:22 +0000964 fprintf(yyTraceFILE,"%sReturn. Stack=",yyTracePrompt);
drh118ab652016-05-23 21:56:24 +0000965 for(i=&yypParser->yystack[1]; i<=yypParser->yytos; i++){
966 fprintf(yyTraceFILE,"%c%s", cDiv, yyTokenName[i->major]);
967 cDiv = ' ';
968 }
drh0c4105e2015-11-10 14:51:22 +0000969 fprintf(yyTraceFILE,"]\n");
drh3bd48ab2015-09-07 18:23:37 +0000970 }
971#endif
drh75897232000-05-29 14:26:00 +0000972 return;
973}