blob: 94c0a3162a3b02b87a548fa9f9bf7eeab1a8f10b [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>
drh60ce5d32018-11-27 14:34:33 +000026#include <assert.h>
drh82415f22015-11-09 19:33:42 +000027/************ Begin %include sections from the grammar ************************/
drh75897232000-05-29 14:26:00 +000028%%
drh82415f22015-11-09 19:33:42 +000029/**************** End of %include directives **********************************/
30/* These constants specify the various numeric values for terminal symbols
31** in a format understandable to "makeheaders". This section is blank unless
32** "lemon" is run with the "-m" command-line option.
33***************** Begin makeheaders token definitions *************************/
34%%
35/**************** End makeheaders token definitions ***************************/
drh822a62f2015-11-09 19:35:18 +000036
37/* The next sections is a series of control #defines.
drh75897232000-05-29 14:26:00 +000038** various aspects of the generated parser.
drh82415f22015-11-09 19:33:42 +000039** YYCODETYPE is the data type used to store the integer codes
40** that represent terminal and non-terminal symbols.
41** "unsigned char" is used if there are fewer than
42** 256 symbols. Larger types otherwise.
43** YYNOCODE is a number of type YYCODETYPE that is not used for
44** any terminal or nonterminal symbol.
drh0bd1f4e2002-06-06 18:54:39 +000045** YYFALLBACK If defined, this indicates that one or more tokens
drh82415f22015-11-09 19:33:42 +000046** (also known as: "terminal symbols") have fall-back
47** values which should be used if the original symbol
48** would not parse. This permits keywords to sometimes
49** be used as identifiers, for example.
50** YYACTIONTYPE is the data type used for "action codes" - numbers
51** that indicate what to do in response to the next
52** token.
53** ParseTOKENTYPE is the data type used for minor type for terminal
54** symbols. Background: A "minor type" is a semantic
55** value associated with a terminal or non-terminal
56** symbols. For example, for an "ID" terminal symbol,
57** the minor type might be the name of the identifier.
58** Each non-terminal can have a different minor type.
59** Terminal symbols all have the same minor type, though.
60** This macros defines the minor type for terminal
61** symbols.
62** YYMINORTYPE is the data type used for all minor types.
drh75897232000-05-29 14:26:00 +000063** This is typically a union of many types, one of
64** which is ParseTOKENTYPE. The entry in the union
drh82415f22015-11-09 19:33:42 +000065** for terminal symbols is called "yy0".
drhb19fd012007-03-29 01:44:45 +000066** YYSTACKDEPTH is the maximum depth of the parser's stack. If
67** zero the stack is dynamically sized using realloc()
drh1f245e42002-03-11 13:55:50 +000068** ParseARG_SDECL A static variable declaration for the %extra_argument
69** ParseARG_PDECL A parameter declaration for the %extra_argument
drhfb32c442018-04-21 13:51:42 +000070** ParseARG_PARAM Code to pass %extra_argument as a subroutine parameter
drh1f245e42002-03-11 13:55:50 +000071** ParseARG_STORE Code to store %extra_argument into yypParser
72** ParseARG_FETCH Code to extract %extra_argument from yypParser
drhfb32c442018-04-21 13:51:42 +000073** ParseCTX_* As ParseARG_ except for %extra_context
drh75897232000-05-29 14:26:00 +000074** YYERRORSYMBOL is the code number of the error symbol. If not
75** defined, then do no error processing.
drh3bd48ab2015-09-07 18:23:37 +000076** YYNSTATE the combined number of states.
77** YYNRULE the number of rules in the grammar
drh0d9de992017-12-26 18:04:23 +000078** YYNTOKEN Number of terminal symbols
drh3bd48ab2015-09-07 18:23:37 +000079** YY_MAX_SHIFT Maximum value for shift actions
80** YY_MIN_SHIFTREDUCE Minimum value for shift-reduce actions
81** YY_MAX_SHIFTREDUCE Maximum value for shift-reduce actions
drh3bd48ab2015-09-07 18:23:37 +000082** YY_ERROR_ACTION The yy_action[] code for syntax error
83** YY_ACCEPT_ACTION The yy_action[] code for accept
84** YY_NO_ACTION The yy_action[] code for no-op
drh5c8241b2017-12-24 23:38:10 +000085** YY_MIN_REDUCE Minimum value for reduce actions
86** YY_MAX_REDUCE Maximum value for reduce actions
drh75897232000-05-29 14:26:00 +000087*/
drh82415f22015-11-09 19:33:42 +000088#ifndef INTERFACE
89# define INTERFACE 1
90#endif
91/************* Begin control #defines *****************************************/
drh75897232000-05-29 14:26:00 +000092%%
drh82415f22015-11-09 19:33:42 +000093/************* End control #defines *******************************************/
drh3773c252018-06-28 03:38:49 +000094#define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0])))
drh75897232000-05-29 14:26:00 +000095
drh8a415d32009-06-12 13:53:51 +000096/* Define the yytestcase() macro to be a no-op if is not already defined
97** otherwise.
98**
99** Applications can choose to define yytestcase() in the %include section
100** to a macro that can assist in verifying code coverage. For production
101** code the yytestcase() macro should be turned off. But it is useful
102** for testing.
103*/
104#ifndef yytestcase
105# define yytestcase(X)
106#endif
107
drh26c9b5e2008-04-11 14:56:53 +0000108
drh34ff57b2008-07-14 12:27:51 +0000109/* Next are the tables used to determine what action to take based on the
drh8b582012003-10-21 13:16:03 +0000110** current state and lookahead token. These tables are used to implement
111** functions that take a state number and lookahead value and return an
112** action integer.
drh75897232000-05-29 14:26:00 +0000113**
drh8548a052003-10-22 22:15:27 +0000114** Suppose the action integer is N. Then the action is determined as
115** follows
drh75897232000-05-29 14:26:00 +0000116**
drh3bd48ab2015-09-07 18:23:37 +0000117** 0 <= N <= YY_MAX_SHIFT Shift N. That is, push the lookahead
drh8548a052003-10-22 22:15:27 +0000118** token onto the stack and goto state N.
119**
drh3bd48ab2015-09-07 18:23:37 +0000120** N between YY_MIN_SHIFTREDUCE Shift to an arbitrary state then
121** and YY_MAX_SHIFTREDUCE reduce by rule N-YY_MIN_SHIFTREDUCE.
drh8548a052003-10-22 22:15:27 +0000122**
drh3bd48ab2015-09-07 18:23:37 +0000123** N == YY_ERROR_ACTION A syntax error has occurred.
drh8548a052003-10-22 22:15:27 +0000124**
drh3bd48ab2015-09-07 18:23:37 +0000125** N == YY_ACCEPT_ACTION The parser accepts its input.
drh8548a052003-10-22 22:15:27 +0000126**
drh3bd48ab2015-09-07 18:23:37 +0000127** N == YY_NO_ACTION No such action. Denotes unused
drh8548a052003-10-22 22:15:27 +0000128** slots in the yy_action[] table.
129**
drh5c8241b2017-12-24 23:38:10 +0000130** N between YY_MIN_REDUCE Reduce by rule N-YY_MIN_REDUCE
131** and YY_MAX_REDUCE
132**
drh8548a052003-10-22 22:15:27 +0000133** The action table is constructed as a single large table named yy_action[].
drh701b6882016-08-10 13:30:43 +0000134** Given state S and lookahead X, the action is computed as either:
drh75897232000-05-29 14:26:00 +0000135**
drh701b6882016-08-10 13:30:43 +0000136** (A) N = yy_action[ yy_shift_ofst[S] + X ]
137** (B) N = yy_default[S]
drh8b582012003-10-21 13:16:03 +0000138**
drh3a9d6c72017-12-25 04:15:38 +0000139** The (A) formula is preferred. The B formula is used instead if
140** yy_lookahead[yy_shift_ofst[S]+X] is not equal to X.
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
drh3a9d6c72017-12-25 04:15:38 +0000145** the yy_shift_ofst[] array.
drh8b582012003-10-21 13:16:03 +0000146**
147** The following are the tables generated in this section:
148**
149** yy_action[] A single table containing all actions.
150** yy_lookahead[] A table containing the lookahead for each entry in
151** yy_action. Used to detect hash collisions.
152** yy_shift_ofst[] For each state, the offset into yy_action for
153** shifting terminals.
154** yy_reduce_ofst[] For each state, the offset into yy_action for
155** shifting non-terminals after a reduce.
156** yy_default[] Default action for each state.
drh82415f22015-11-09 19:33:42 +0000157**
158*********** Begin parsing tables **********************************************/
drh75897232000-05-29 14:26:00 +0000159%%
drh82415f22015-11-09 19:33:42 +0000160/********** End of lemon-generated parsing tables *****************************/
drh75897232000-05-29 14:26:00 +0000161
drh82415f22015-11-09 19:33:42 +0000162/* The next table maps tokens (terminal symbols) into fallback tokens.
163** If a construct like the following:
drh0bd1f4e2002-06-06 18:54:39 +0000164**
165** %fallback ID X Y Z.
166**
drh34ff57b2008-07-14 12:27:51 +0000167** appears in the grammar, then ID becomes a fallback token for X, Y,
drh0bd1f4e2002-06-06 18:54:39 +0000168** and Z. Whenever one of the tokens X, Y, or Z is input to the parser
169** but it does not parse, the type of the token is changed to ID and
170** the parse is retried before an error is thrown.
drh82415f22015-11-09 19:33:42 +0000171**
172** This feature can be used, for example, to cause some keywords in a language
173** to revert to identifiers if they keyword does not apply in the context where
174** it appears.
drh0bd1f4e2002-06-06 18:54:39 +0000175*/
176#ifdef YYFALLBACK
177static const YYCODETYPE yyFallback[] = {
178%%
179};
180#endif /* YYFALLBACK */
181
drh75897232000-05-29 14:26:00 +0000182/* The following structure represents a single element of the
183** parser's stack. Information stored includes:
184**
185** + The state number for the parser at this level of the stack.
186**
187** + The value of the token stored at this level of the stack.
188** (In other words, the "major" token.)
189**
190** + The semantic value stored at this level of the stack. This is
191** the information used by the action routines in the grammar.
192** It is sometimes called the "minor" token.
drha248a722015-09-07 19:52:55 +0000193**
194** After the "shift" half of a SHIFTREDUCE action, the stateno field
195** actually contains the reduce action for the second half of the
196** SHIFTREDUCE.
drh75897232000-05-29 14:26:00 +0000197*/
198struct yyStackEntry {
drha248a722015-09-07 19:52:55 +0000199 YYACTIONTYPE stateno; /* The state-number, or reduce action in SHIFTREDUCE */
drh2abcd582008-07-24 23:34:07 +0000200 YYCODETYPE major; /* The major token value. This is the code
201 ** number for the token at this stack level */
202 YYMINORTYPE minor; /* The user-supplied minor token value. This
203 ** is the value of the token */
drh75897232000-05-29 14:26:00 +0000204};
drh1f245e42002-03-11 13:55:50 +0000205typedef struct yyStackEntry yyStackEntry;
drh75897232000-05-29 14:26:00 +0000206
207/* The state of the parser is completely contained in an instance of
208** the following structure */
209struct yyParser {
drh118ab652016-05-23 21:56:24 +0000210 yyStackEntry *yytos; /* Pointer to top element of the stack */
drhec424a52008-07-25 15:39:03 +0000211#ifdef YYTRACKMAXSTACKDEPTH
drh118ab652016-05-23 21:56:24 +0000212 int yyhwm; /* High-water mark of the stack */
drhec424a52008-07-25 15:39:03 +0000213#endif
drhdab943c2016-02-16 01:01:43 +0000214#ifndef YYNOERRORRECOVERY
drh1f245e42002-03-11 13:55:50 +0000215 int yyerrcnt; /* Shifts left before out of the error */
drhdab943c2016-02-16 01:01:43 +0000216#endif
drh1f245e42002-03-11 13:55:50 +0000217 ParseARG_SDECL /* A place to hold %extra_argument */
drhfb32c442018-04-21 13:51:42 +0000218 ParseCTX_SDECL /* A place to hold %extra_context */
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
drh0d9de992017-12-26 18:04:23 +0000262#if defined(YYCOVERAGE) || !defined(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};
drh0d9de992017-12-26 18:04:23 +0000268#endif /* defined(YYCOVERAGE) || !defined(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*/
drhfb32c442018-04-21 13:51:42 +0000323void ParseInit(void *yypRawParser ParseCTX_PDECL){
324 yyParser *yypParser = (yyParser*)yypRawParser;
325 ParseCTX_STORE
drhd26cc542017-01-28 20:46:37 +0000326#ifdef YYTRACKMAXSTACKDEPTH
drhfb32c442018-04-21 13:51:42 +0000327 yypParser->yyhwm = 0;
drhd26cc542017-01-28 20:46:37 +0000328#endif
329#if YYSTACKDEPTH<=0
drhfb32c442018-04-21 13:51:42 +0000330 yypParser->yytos = NULL;
331 yypParser->yystack = NULL;
332 yypParser->yystksz = 0;
333 if( yyGrowStack(yypParser) ){
334 yypParser->yystack = &yypParser->yystk0;
335 yypParser->yystksz = 1;
drhd26cc542017-01-28 20:46:37 +0000336 }
337#endif
338#ifndef YYNOERRORRECOVERY
drhfb32c442018-04-21 13:51:42 +0000339 yypParser->yyerrcnt = -1;
drhd26cc542017-01-28 20:46:37 +0000340#endif
drhfb32c442018-04-21 13:51:42 +0000341 yypParser->yytos = yypParser->yystack;
342 yypParser->yystack[0].stateno = 0;
343 yypParser->yystack[0].major = 0;
drh92395c52017-07-04 12:50:00 +0000344#if YYSTACKDEPTH>0
drhfb32c442018-04-21 13:51:42 +0000345 yypParser->yystackEnd = &yypParser->yystack[YYSTACKDEPTH-1];
drh92395c52017-07-04 12:50:00 +0000346#endif
drhd26cc542017-01-28 20:46:37 +0000347}
348
349#ifndef Parse_ENGINEALWAYSONSTACK
drh75897232000-05-29 14:26:00 +0000350/*
351** This function allocates a new parser.
352** The only argument is a pointer to a function which works like
353** malloc.
354**
355** Inputs:
356** A pointer to the function used to allocate memory.
357**
358** Outputs:
359** A pointer to a parser. This pointer is used in subsequent calls
360** to Parse and ParseFree.
361*/
drhfb32c442018-04-21 13:51:42 +0000362void *ParseAlloc(void *(*mallocProc)(YYMALLOCARGTYPE) ParseCTX_PDECL){
363 yyParser *yypParser;
364 yypParser = (yyParser*)(*mallocProc)( (YYMALLOCARGTYPE)sizeof(yyParser) );
365 if( yypParser ){
366 ParseCTX_STORE
367 ParseInit(yypParser ParseCTX_PARAM);
368 }
369 return (void*)yypParser;
drh75897232000-05-29 14:26:00 +0000370}
drhd26cc542017-01-28 20:46:37 +0000371#endif /* Parse_ENGINEALWAYSONSTACK */
372
drh75897232000-05-29 14:26:00 +0000373
drh82415f22015-11-09 19:33:42 +0000374/* The following function deletes the "minor type" or semantic value
375** associated with a symbol. The symbol can be either a terminal
376** or nonterminal. "yymajor" is the symbol code, and "yypminor" is
377** a pointer to the value to be deleted. The code used to do the
378** deletions is derived from the %destructor and/or %token_destructor
379** directives of the input grammar.
drh75897232000-05-29 14:26:00 +0000380*/
drh633e6d52008-07-28 19:34:53 +0000381static void yy_destructor(
382 yyParser *yypParser, /* The parser */
383 YYCODETYPE yymajor, /* Type code for object to destroy */
384 YYMINORTYPE *yypminor /* The object to be destroyed */
385){
drhfb32c442018-04-21 13:51:42 +0000386 ParseARG_FETCH
387 ParseCTX_FETCH
drh75897232000-05-29 14:26:00 +0000388 switch( yymajor ){
389 /* Here is inserted the actions which take place when a
390 ** terminal or non-terminal is destroyed. This can happen
391 ** when the symbol is popped from the stack during a
392 ** reduce or during error processing or when a parser is
393 ** being destroyed before it is finished parsing.
394 **
395 ** Note: during a reduce, the only symbols destroyed are those
drh82415f22015-11-09 19:33:42 +0000396 ** which appear on the RHS of the rule, but which are *not* used
drh75897232000-05-29 14:26:00 +0000397 ** inside the C code.
398 */
drh82415f22015-11-09 19:33:42 +0000399/********* Begin destructor definitions ***************************************/
drh75897232000-05-29 14:26:00 +0000400%%
drh82415f22015-11-09 19:33:42 +0000401/********* End destructor definitions *****************************************/
drh75897232000-05-29 14:26:00 +0000402 default: break; /* If no destructor action specified: do nothing */
403 }
404}
405
406/*
407** Pop the parser's stack once.
408**
409** If there is a destructor routine associated with the token which
410** is popped from the stack, then call it.
drh75897232000-05-29 14:26:00 +0000411*/
drh3781f012015-11-09 14:11:37 +0000412static void yy_pop_parser_stack(yyParser *pParser){
413 yyStackEntry *yytos;
drh118ab652016-05-23 21:56:24 +0000414 assert( pParser->yytos!=0 );
drh240c7fa2016-07-05 12:47:28 +0000415 assert( pParser->yytos > pParser->yystack );
drh118ab652016-05-23 21:56:24 +0000416 yytos = pParser->yytos--;
drh75897232000-05-29 14:26:00 +0000417#ifndef NDEBUG
drh3781f012015-11-09 14:11:37 +0000418 if( yyTraceFILE ){
drh75897232000-05-29 14:26:00 +0000419 fprintf(yyTraceFILE,"%sPopping %s\n",
420 yyTracePrompt,
drh3ddfdf72003-12-22 14:53:19 +0000421 yyTokenName[yytos->major]);
drh75897232000-05-29 14:26:00 +0000422 }
423#endif
drh3781f012015-11-09 14:11:37 +0000424 yy_destructor(pParser, yytos->major, &yytos->minor);
drh75897232000-05-29 14:26:00 +0000425}
426
drhd26cc542017-01-28 20:46:37 +0000427/*
428** Clear all secondary memory allocations from the parser
429*/
430void ParseFinalize(void *p){
431 yyParser *pParser = (yyParser*)p;
432 while( pParser->yytos>pParser->yystack ) yy_pop_parser_stack(pParser);
433#if YYSTACKDEPTH<=0
434 if( pParser->yystack!=&pParser->yystk0 ) free(pParser->yystack);
435#endif
436}
437
438#ifndef Parse_ENGINEALWAYSONSTACK
drh75897232000-05-29 14:26:00 +0000439/*
drh82415f22015-11-09 19:33:42 +0000440** Deallocate and destroy a parser. Destructors are called for
drh75897232000-05-29 14:26:00 +0000441** all stack elements before shutting the parser down.
442**
drh82415f22015-11-09 19:33:42 +0000443** If the YYPARSEFREENEVERNULL macro exists (for example because it
444** is defined in a %include section of the input grammar) then it is
445** assumed that the input pointer is never NULL.
drh75897232000-05-29 14:26:00 +0000446*/
drh75897232000-05-29 14:26:00 +0000447void ParseFree(
drh960e8c62001-04-03 16:53:21 +0000448 void *p, /* The parser to be deleted */
449 void (*freeProc)(void*) /* Function used to reclaim memory */
drh75897232000-05-29 14:26:00 +0000450){
drh82415f22015-11-09 19:33:42 +0000451#ifndef YYPARSEFREENEVERNULL
drhd26cc542017-01-28 20:46:37 +0000452 if( p==0 ) return;
drh82415f22015-11-09 19:33:42 +0000453#endif
drhd26cc542017-01-28 20:46:37 +0000454 ParseFinalize(p);
455 (*freeProc)(p);
drh75897232000-05-29 14:26:00 +0000456}
drhd26cc542017-01-28 20:46:37 +0000457#endif /* Parse_ENGINEALWAYSONSTACK */
drh75897232000-05-29 14:26:00 +0000458
459/*
drhec424a52008-07-25 15:39:03 +0000460** Return the peak depth of the stack for a parser.
461*/
462#ifdef YYTRACKMAXSTACKDEPTH
463int ParseStackPeak(void *p){
464 yyParser *pParser = (yyParser*)p;
drh118ab652016-05-23 21:56:24 +0000465 return pParser->yyhwm;
drhec424a52008-07-25 15:39:03 +0000466}
467#endif
468
drh0d9de992017-12-26 18:04:23 +0000469/* This array of booleans keeps track of the parser statement
470** coverage. The element yycoverage[X][Y] is set when the parser
471** is in state X and has a lookahead token Y. In a well-tested
472** systems, every element of this matrix should end up being set.
473*/
474#if defined(YYCOVERAGE)
475static unsigned char yycoverage[YYNSTATE][YYNTOKEN];
476#endif
477
478/*
479** Write into out a description of every state/lookahead combination that
drh7038a992017-12-27 17:14:50 +0000480**
481** (1) has not been used by the parser, and
482** (2) is not a syntax error.
483**
484** Return the number of missed state/lookahead combinations.
drh0d9de992017-12-26 18:04:23 +0000485*/
486#if defined(YYCOVERAGE)
487int ParseCoverage(FILE *out){
drh7038a992017-12-27 17:14:50 +0000488 int stateno, iLookAhead, i;
drh0d9de992017-12-26 18:04:23 +0000489 int nMissed = 0;
drh7038a992017-12-27 17:14:50 +0000490 for(stateno=0; stateno<YYNSTATE; stateno++){
491 i = yy_shift_ofst[stateno];
492 for(iLookAhead=0; iLookAhead<YYNTOKEN; iLookAhead++){
drhcf8e0e92017-12-27 17:36:58 +0000493 if( yy_lookahead[i+iLookAhead]!=iLookAhead ) continue;
drh7038a992017-12-27 17:14:50 +0000494 if( yycoverage[stateno][iLookAhead]==0 ) nMissed++;
drh22716cb2017-12-26 18:32:06 +0000495 if( out ){
drh7038a992017-12-27 17:14:50 +0000496 fprintf(out,"State %d lookahead %s %s\n", stateno,
497 yyTokenName[iLookAhead],
498 yycoverage[stateno][iLookAhead] ? "ok" : "missed");
drh22716cb2017-12-26 18:32:06 +0000499 }
drh0d9de992017-12-26 18:04:23 +0000500 }
501 }
502 return nMissed;
503}
504#endif
505
drhec424a52008-07-25 15:39:03 +0000506/*
drh8b582012003-10-21 13:16:03 +0000507** Find the appropriate action for a parser given the terminal
508** look-ahead token iLookAhead.
drh75897232000-05-29 14:26:00 +0000509*/
drhfd39c582018-04-21 22:40:08 +0000510static YYACTIONTYPE yy_find_shift_action(
511 YYCODETYPE iLookAhead, /* The look-ahead token */
512 YYACTIONTYPE stateno /* Current state number */
drh75897232000-05-29 14:26:00 +0000513){
drh8b582012003-10-21 13:16:03 +0000514 int i;
drhfd39c582018-04-21 22:40:08 +0000515
drhef53a9f2017-12-25 00:10:05 +0000516 if( stateno>YY_MAX_SHIFT ) return stateno;
drhae2a4082015-09-07 20:02:39 +0000517 assert( stateno <= YY_SHIFT_COUNT );
drh0d9de992017-12-26 18:04:23 +0000518#if defined(YYCOVERAGE)
519 yycoverage[stateno][iLookAhead] = 1;
520#endif
drha4414042015-11-09 15:06:26 +0000521 do{
522 i = yy_shift_ofst[stateno];
drh54cfb492018-02-09 15:04:51 +0000523 assert( i>=0 );
dan5001b332018-06-30 19:12:36 +0000524 /* assert( i+YYNTOKEN<=(int)YY_NLOOKAHEAD ); */
drha4414042015-11-09 15:06:26 +0000525 assert( iLookAhead!=YYNOCODE );
drh7038a992017-12-27 17:14:50 +0000526 assert( iLookAhead < YYNTOKEN );
drha4414042015-11-09 15:06:26 +0000527 i += iLookAhead;
dan5001b332018-06-30 19:12:36 +0000528 if( i>=YY_NLOOKAHEAD || yy_lookahead[i]!=iLookAhead ){
drh4767d972006-06-14 15:03:49 +0000529#ifdef YYFALLBACK
drhc83db9e2016-08-10 01:43:30 +0000530 YYCODETYPE iFallback; /* Fallback token */
531 if( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0])
532 && (iFallback = yyFallback[iLookAhead])!=0 ){
drh4767d972006-06-14 15:03:49 +0000533#ifndef NDEBUG
drhc83db9e2016-08-10 01:43:30 +0000534 if( yyTraceFILE ){
535 fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n",
536 yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]);
drhe09daa92006-06-10 13:29:31 +0000537 }
drha4414042015-11-09 15:06:26 +0000538#endif
drhc83db9e2016-08-10 01:43:30 +0000539 assert( yyFallback[iFallback]==0 ); /* Fallback loop must terminate */
540 iLookAhead = iFallback;
541 continue;
542 }
543#endif
drha4414042015-11-09 15:06:26 +0000544#ifdef YYWILDCARD
drhc83db9e2016-08-10 01:43:30 +0000545 {
546 int j = i - iLookAhead + YYWILDCARD;
547 if(
drha4414042015-11-09 15:06:26 +0000548#if YY_SHIFT_MIN+YYWILDCARD<0
drhc83db9e2016-08-10 01:43:30 +0000549 j>=0 &&
drha4414042015-11-09 15:06:26 +0000550#endif
551#if YY_SHIFT_MAX+YYWILDCARD>=YY_ACTTAB_COUNT
drhc83db9e2016-08-10 01:43:30 +0000552 j<YY_ACTTAB_COUNT &&
drha4414042015-11-09 15:06:26 +0000553#endif
drhc7bf5712018-07-09 22:49:01 +0000554 j<(int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0])) &&
drhc83db9e2016-08-10 01:43:30 +0000555 yy_lookahead[j]==YYWILDCARD && iLookAhead>0
556 ){
drha4414042015-11-09 15:06:26 +0000557#ifndef NDEBUG
drhc83db9e2016-08-10 01:43:30 +0000558 if( yyTraceFILE ){
559 fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n",
560 yyTracePrompt, yyTokenName[iLookAhead],
561 yyTokenName[YYWILDCARD]);
drha4414042015-11-09 15:06:26 +0000562 }
drhc83db9e2016-08-10 01:43:30 +0000563#endif /* NDEBUG */
564 return yy_action[j];
drha4414042015-11-09 15:06:26 +0000565 }
drha4414042015-11-09 15:06:26 +0000566 }
drhc83db9e2016-08-10 01:43:30 +0000567#endif /* YYWILDCARD */
drha4414042015-11-09 15:06:26 +0000568 return yy_default[stateno];
569 }else{
570 return yy_action[i];
drh0bd1f4e2002-06-06 18:54:39 +0000571 }
drha4414042015-11-09 15:06:26 +0000572 }while(1);
drh8b582012003-10-21 13:16:03 +0000573}
574
575/*
576** Find the appropriate action for a parser given the non-terminal
577** look-ahead token iLookAhead.
drh8b582012003-10-21 13:16:03 +0000578*/
mistachkin709c8222018-07-22 21:23:19 +0000579static YYACTIONTYPE yy_find_reduce_action(
drhfd39c582018-04-21 22:40:08 +0000580 YYACTIONTYPE stateno, /* Current state number */
drhd9f291e2006-06-13 11:15:47 +0000581 YYCODETYPE iLookAhead /* The look-ahead token */
drh8b582012003-10-21 13:16:03 +0000582){
583 int i;
drh7f7c2572008-04-27 18:45:10 +0000584#ifdef YYERRORSYMBOL
drhf16371d2009-11-03 19:18:31 +0000585 if( stateno>YY_REDUCE_COUNT ){
drh7f7c2572008-04-27 18:45:10 +0000586 return yy_default[stateno];
587 }
588#else
drhf16371d2009-11-03 19:18:31 +0000589 assert( stateno<=YY_REDUCE_COUNT );
drh7f7c2572008-04-27 18:45:10 +0000590#endif
drh01495b92008-01-23 12:52:40 +0000591 i = yy_reduce_ofst[stateno];
drh01495b92008-01-23 12:52:40 +0000592 assert( iLookAhead!=YYNOCODE );
drh8b582012003-10-21 13:16:03 +0000593 i += iLookAhead;
drh7f7c2572008-04-27 18:45:10 +0000594#ifdef YYERRORSYMBOL
drhf16371d2009-11-03 19:18:31 +0000595 if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){
drh7f7c2572008-04-27 18:45:10 +0000596 return yy_default[stateno];
597 }
598#else
drhf16371d2009-11-03 19:18:31 +0000599 assert( i>=0 && i<YY_ACTTAB_COUNT );
drh01495b92008-01-23 12:52:40 +0000600 assert( yy_lookahead[i]==iLookAhead );
drh7f7c2572008-04-27 18:45:10 +0000601#endif
drh01495b92008-01-23 12:52:40 +0000602 return yy_action[i];
drh75897232000-05-29 14:26:00 +0000603}
604
605/*
drhb19fd012007-03-29 01:44:45 +0000606** The following routine is called if the stack overflows.
607*/
drh45f31be2016-02-16 21:19:49 +0000608static void yyStackOverflow(yyParser *yypParser){
drhfb32c442018-04-21 13:51:42 +0000609 ParseARG_FETCH
610 ParseCTX_FETCH
drhb19fd012007-03-29 01:44:45 +0000611#ifndef NDEBUG
612 if( yyTraceFILE ){
613 fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt);
614 }
615#endif
drhabecc0b2016-05-24 00:40:54 +0000616 while( yypParser->yytos>yypParser->yystack ) yy_pop_parser_stack(yypParser);
drhb19fd012007-03-29 01:44:45 +0000617 /* Here code is inserted which will execute if the parser
618 ** stack every overflows */
drh82415f22015-11-09 19:33:42 +0000619/******** Begin %stack_overflow code ******************************************/
drhb19fd012007-03-29 01:44:45 +0000620%%
drh82415f22015-11-09 19:33:42 +0000621/******** End %stack_overflow code ********************************************/
drhfb32c442018-04-21 13:51:42 +0000622 ParseARG_STORE /* Suppress warning about unused %extra_argument var */
623 ParseCTX_STORE
drhb19fd012007-03-29 01:44:45 +0000624}
625
626/*
drha248a722015-09-07 19:52:55 +0000627** Print tracing information for a SHIFT action
628*/
629#ifndef NDEBUG
drhe58f74f2017-12-24 17:06:41 +0000630static void yyTraceShift(yyParser *yypParser, int yyNewState, const char *zTag){
drha248a722015-09-07 19:52:55 +0000631 if( yyTraceFILE ){
drha248a722015-09-07 19:52:55 +0000632 if( yyNewState<YYNSTATE ){
drhe58f74f2017-12-24 17:06:41 +0000633 fprintf(yyTraceFILE,"%s%s '%s', go to state %d\n",
634 yyTracePrompt, zTag, yyTokenName[yypParser->yytos->major],
drh0c4105e2015-11-10 14:51:22 +0000635 yyNewState);
drha248a722015-09-07 19:52:55 +0000636 }else{
drhe58f74f2017-12-24 17:06:41 +0000637 fprintf(yyTraceFILE,"%s%s '%s', pending reduce %d\n",
638 yyTracePrompt, zTag, yyTokenName[yypParser->yytos->major],
639 yyNewState - YY_MIN_REDUCE);
drha248a722015-09-07 19:52:55 +0000640 }
641 }
642}
643#else
drhe58f74f2017-12-24 17:06:41 +0000644# define yyTraceShift(X,Y,Z)
drha248a722015-09-07 19:52:55 +0000645#endif
646
647/*
drh82415f22015-11-09 19:33:42 +0000648** Perform a shift action.
drh75897232000-05-29 14:26:00 +0000649*/
drha248a722015-09-07 19:52:55 +0000650static void yy_shift(
drh75897232000-05-29 14:26:00 +0000651 yyParser *yypParser, /* The parser to be shifted */
drhfd39c582018-04-21 22:40:08 +0000652 YYACTIONTYPE yyNewState, /* The new state to shift in */
653 YYCODETYPE yyMajor, /* The major token to shift in */
drh45f31be2016-02-16 21:19:49 +0000654 ParseTOKENTYPE yyMinor /* The minor token to shift in */
drh75897232000-05-29 14:26:00 +0000655){
drh3ddfdf72003-12-22 14:53:19 +0000656 yyStackEntry *yytos;
drh118ab652016-05-23 21:56:24 +0000657 yypParser->yytos++;
drhec424a52008-07-25 15:39:03 +0000658#ifdef YYTRACKMAXSTACKDEPTH
drh118ab652016-05-23 21:56:24 +0000659 if( (int)(yypParser->yytos - yypParser->yystack)>yypParser->yyhwm ){
660 yypParser->yyhwm++;
661 assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack) );
drhec424a52008-07-25 15:39:03 +0000662 }
663#endif
drhb19fd012007-03-29 01:44:45 +0000664#if YYSTACKDEPTH>0
drh8b471e72017-06-28 15:01:35 +0000665 if( yypParser->yytos>yypParser->yystackEnd ){
drh63413312016-12-06 17:59:05 +0000666 yypParser->yytos--;
drh45f31be2016-02-16 21:19:49 +0000667 yyStackOverflow(yypParser);
drha248a722015-09-07 19:52:55 +0000668 return;
drh75897232000-05-29 14:26:00 +0000669 }
drhb19fd012007-03-29 01:44:45 +0000670#else
drh118ab652016-05-23 21:56:24 +0000671 if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz] ){
drh8dc82472016-05-27 04:10:47 +0000672 if( yyGrowStack(yypParser) ){
drh63413312016-12-06 17:59:05 +0000673 yypParser->yytos--;
drh45f31be2016-02-16 21:19:49 +0000674 yyStackOverflow(yypParser);
drha248a722015-09-07 19:52:55 +0000675 return;
drhb19fd012007-03-29 01:44:45 +0000676 }
677 }
678#endif
drh0efd37f2016-06-06 18:17:36 +0000679 if( yyNewState > YY_MAX_SHIFT ){
680 yyNewState += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE;
681 }
drh118ab652016-05-23 21:56:24 +0000682 yytos = yypParser->yytos;
drhfd39c582018-04-21 22:40:08 +0000683 yytos->stateno = yyNewState;
684 yytos->major = yyMajor;
drh45f31be2016-02-16 21:19:49 +0000685 yytos->minor.yy0 = yyMinor;
drhe58f74f2017-12-24 17:06:41 +0000686 yyTraceShift(yypParser, yyNewState, "Shift");
drh75897232000-05-29 14:26:00 +0000687}
688
drhcfc45b12018-12-03 23:57:27 +0000689/* For rule J, yyRuleInfoLhs[J] contains the symbol on the left-hand side
690** of that rule */
691static const YYCODETYPE yyRuleInfoLhs[] = {
692%%
693};
694
695/* For rule J, yyRuleInfoNRhs[J] contains the negative of the number
696** of symbols on the right-hand side of that rule. */
697static const signed char yyRuleInfoNRhs[] = {
drh75897232000-05-29 14:26:00 +0000698%%
699};
700
drh1f245e42002-03-11 13:55:50 +0000701static void yy_accept(yyParser*); /* Forward Declaration */
drh75897232000-05-29 14:26:00 +0000702
703/*
704** Perform a reduce action and the shift that must immediately
705** follow the reduce.
drh087316c2017-12-15 12:22:21 +0000706**
707** The yyLookahead and yyLookaheadToken parameters provide reduce actions
708** access to the lookahead token (if any). The yyLookahead will be YYNOCODE
709** if the lookahead token has already been consumed. As this procedure is
710** only called from one place, optimizing compilers will in-line it, which
711** means that the extra parameters have no performance impact.
drh75897232000-05-29 14:26:00 +0000712*/
drhfd39c582018-04-21 22:40:08 +0000713static YYACTIONTYPE yy_reduce(
drh75897232000-05-29 14:26:00 +0000714 yyParser *yypParser, /* The parser */
drh087316c2017-12-15 12:22:21 +0000715 unsigned int yyruleno, /* Number of the rule by which to reduce */
716 int yyLookahead, /* Lookahead token, or YYNOCODE if none */
717 ParseTOKENTYPE yyLookaheadToken /* Value of the lookahead token */
drhfb32c442018-04-21 13:51:42 +0000718 ParseCTX_PDECL /* %extra_context */
drh75897232000-05-29 14:26:00 +0000719){
720 int yygoto; /* The next state */
mistachkin709c8222018-07-22 21:23:19 +0000721 YYACTIONTYPE yyact; /* The next action */
drh1f245e42002-03-11 13:55:50 +0000722 yyStackEntry *yymsp; /* The top of the parser's stack */
drh75897232000-05-29 14:26:00 +0000723 int yysize; /* Amount to pop the stack */
drhfb32c442018-04-21 13:51:42 +0000724 ParseARG_FETCH
drhb9685182018-01-17 13:15:23 +0000725 (void)yyLookahead;
726 (void)yyLookaheadToken;
drh118ab652016-05-23 21:56:24 +0000727 yymsp = yypParser->yytos;
drh0bd1f4e2002-06-06 18:54:39 +0000728#ifndef NDEBUG
drh4ef07702016-03-16 19:45:54 +0000729 if( yyTraceFILE && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){
drhcfc45b12018-12-03 23:57:27 +0000730 yysize = yyRuleInfoNRhs[yyruleno];
drhe58f74f2017-12-24 17:06:41 +0000731 if( yysize ){
732 fprintf(yyTraceFILE, "%sReduce %d [%s], go to state %d.\n",
733 yyTracePrompt,
734 yyruleno, yyRuleName[yyruleno], yymsp[yysize].stateno);
735 }else{
736 fprintf(yyTraceFILE, "%sReduce %d [%s].\n",
737 yyTracePrompt, yyruleno, yyRuleName[yyruleno]);
738 }
drh0bd1f4e2002-06-06 18:54:39 +0000739 }
740#endif /* NDEBUG */
drh45f31be2016-02-16 21:19:49 +0000741
742 /* Check that the stack is large enough to grow by a single entry
743 ** if the RHS of the rule is empty. This ensures that there is room
744 ** enough on the stack to push the LHS value */
drhcfc45b12018-12-03 23:57:27 +0000745 if( yyRuleInfoNRhs[yyruleno]==0 ){
drh45f31be2016-02-16 21:19:49 +0000746#ifdef YYTRACKMAXSTACKDEPTH
drh118ab652016-05-23 21:56:24 +0000747 if( (int)(yypParser->yytos - yypParser->yystack)>yypParser->yyhwm ){
748 yypParser->yyhwm++;
749 assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack));
drh45f31be2016-02-16 21:19:49 +0000750 }
751#endif
752#if YYSTACKDEPTH>0
drh8b471e72017-06-28 15:01:35 +0000753 if( yypParser->yytos>=yypParser->yystackEnd ){
drh45f31be2016-02-16 21:19:49 +0000754 yyStackOverflow(yypParser);
drh05ef50d2018-04-23 00:25:31 +0000755 /* The call to yyStackOverflow() above pops the stack until it is
756 ** empty, causing the main parser loop to exit. So the return value
757 ** is never used and does not matter. */
758 return 0;
drh45f31be2016-02-16 21:19:49 +0000759 }
760#else
drh118ab652016-05-23 21:56:24 +0000761 if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz-1] ){
drh8dc82472016-05-27 04:10:47 +0000762 if( yyGrowStack(yypParser) ){
drh45f31be2016-02-16 21:19:49 +0000763 yyStackOverflow(yypParser);
drh05ef50d2018-04-23 00:25:31 +0000764 /* The call to yyStackOverflow() above pops the stack until it is
765 ** empty, causing the main parser loop to exit. So the return value
766 ** is never used and does not matter. */
767 return 0;
drh45f31be2016-02-16 21:19:49 +0000768 }
drh8dc82472016-05-27 04:10:47 +0000769 yymsp = yypParser->yytos;
drh45f31be2016-02-16 21:19:49 +0000770 }
771#endif
772 }
drhcb6c5652007-01-16 18:19:12 +0000773
drh75897232000-05-29 14:26:00 +0000774 switch( yyruleno ){
775 /* Beginning here are the reduction cases. A typical example
776 ** follows:
777 ** case 0:
drh75897232000-05-29 14:26:00 +0000778 ** #line <lineno> <grammarfile>
779 ** { ... } // User supplied code
780 ** #line <lineno> <thisfile>
781 ** break;
782 */
drh82415f22015-11-09 19:33:42 +0000783/********** Begin reduce actions **********************************************/
drh75897232000-05-29 14:26:00 +0000784%%
drh82415f22015-11-09 19:33:42 +0000785/********** End reduce actions ************************************************/
drh75897232000-05-29 14:26:00 +0000786 };
drhcfc45b12018-12-03 23:57:27 +0000787 assert( yyruleno<sizeof(yyRuleInfoLhs)/sizeof(yyRuleInfoLhs[0]) );
788 yygoto = yyRuleInfoLhs[yyruleno];
789 yysize = yyRuleInfoNRhs[yyruleno];
drh6be95362017-06-28 13:47:56 +0000790 yyact = yy_find_reduce_action(yymsp[yysize].stateno,(YYCODETYPE)yygoto);
drhbd8fcc12017-06-28 11:56:18 +0000791
792 /* There are no SHIFTREDUCE actions on nonterminals because the table
793 ** generator has simplified them to pure REDUCE actions. */
794 assert( !(yyact>YY_MAX_SHIFT && yyact<=YY_MAX_SHIFTREDUCE) );
795
796 /* It is not possible for a REDUCE to be followed by an error */
797 assert( yyact!=YY_ERROR_ACTION );
798
drhef53a9f2017-12-25 00:10:05 +0000799 yymsp += yysize+1;
800 yypParser->yytos = yymsp;
801 yymsp->stateno = (YYACTIONTYPE)yyact;
802 yymsp->major = (YYCODETYPE)yygoto;
803 yyTraceShift(yypParser, yyact, "... then shift");
drhfd39c582018-04-21 22:40:08 +0000804 return yyact;
drh75897232000-05-29 14:26:00 +0000805}
806
807/*
808** The following code executes when the parse fails
809*/
drhd3ec02d2009-06-12 02:27:14 +0000810#ifndef YYNOERRORRECOVERY
drh75897232000-05-29 14:26:00 +0000811static void yy_parse_failed(
812 yyParser *yypParser /* The parser */
drh75897232000-05-29 14:26:00 +0000813){
drhfb32c442018-04-21 13:51:42 +0000814 ParseARG_FETCH
815 ParseCTX_FETCH
drh75897232000-05-29 14:26:00 +0000816#ifndef NDEBUG
817 if( yyTraceFILE ){
818 fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt);
819 }
820#endif
drhabecc0b2016-05-24 00:40:54 +0000821 while( yypParser->yytos>yypParser->yystack ) yy_pop_parser_stack(yypParser);
drh75897232000-05-29 14:26:00 +0000822 /* Here code is inserted which will be executed whenever the
823 ** parser fails */
drh82415f22015-11-09 19:33:42 +0000824/************ Begin %parse_failure code ***************************************/
drh75897232000-05-29 14:26:00 +0000825%%
drh82415f22015-11-09 19:33:42 +0000826/************ End %parse_failure code *****************************************/
drhfb32c442018-04-21 13:51:42 +0000827 ParseARG_STORE /* Suppress warning about unused %extra_argument variable */
828 ParseCTX_STORE
drh75897232000-05-29 14:26:00 +0000829}
drhd3ec02d2009-06-12 02:27:14 +0000830#endif /* YYNOERRORRECOVERY */
drh75897232000-05-29 14:26:00 +0000831
832/*
833** The following code executes when a syntax error first occurs.
834*/
835static void yy_syntax_error(
836 yyParser *yypParser, /* The parser */
837 int yymajor, /* The major type of the error token */
drh45f31be2016-02-16 21:19:49 +0000838 ParseTOKENTYPE yyminor /* The minor type of the error token */
drh75897232000-05-29 14:26:00 +0000839){
drhfb32c442018-04-21 13:51:42 +0000840 ParseARG_FETCH
841 ParseCTX_FETCH
drh45f31be2016-02-16 21:19:49 +0000842#define TOKEN yyminor
drh82415f22015-11-09 19:33:42 +0000843/************ Begin %syntax_error code ****************************************/
drh75897232000-05-29 14:26:00 +0000844%%
drh82415f22015-11-09 19:33:42 +0000845/************ End %syntax_error code ******************************************/
drhfb32c442018-04-21 13:51:42 +0000846 ParseARG_STORE /* Suppress warning about unused %extra_argument variable */
847 ParseCTX_STORE
drh75897232000-05-29 14:26:00 +0000848}
849
850/*
851** The following is executed when the parser accepts
852*/
853static void yy_accept(
854 yyParser *yypParser /* The parser */
drh75897232000-05-29 14:26:00 +0000855){
drhfb32c442018-04-21 13:51:42 +0000856 ParseARG_FETCH
857 ParseCTX_FETCH
drh75897232000-05-29 14:26:00 +0000858#ifndef NDEBUG
859 if( yyTraceFILE ){
860 fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt);
861 }
862#endif
drhdd703e22016-07-12 19:54:49 +0000863#ifndef YYNOERRORRECOVERY
864 yypParser->yyerrcnt = -1;
865#endif
drh756b41e2016-05-24 18:55:08 +0000866 assert( yypParser->yytos==yypParser->yystack );
drh75897232000-05-29 14:26:00 +0000867 /* Here code is inserted which will be executed whenever the
868 ** parser accepts */
drh82415f22015-11-09 19:33:42 +0000869/*********** Begin %parse_accept code *****************************************/
drh75897232000-05-29 14:26:00 +0000870%%
drh82415f22015-11-09 19:33:42 +0000871/*********** End %parse_accept code *******************************************/
drhfb32c442018-04-21 13:51:42 +0000872 ParseARG_STORE /* Suppress warning about unused %extra_argument variable */
873 ParseCTX_STORE
drh75897232000-05-29 14:26:00 +0000874}
875
876/* The main parser program.
877** The first argument is a pointer to a structure obtained from
878** "ParseAlloc" which describes the current state of the parser.
879** The second argument is the major token number. The third is
880** the minor token. The fourth optional argument is whatever the
881** user wants (and specified in the grammar) and is available for
882** use by the action routines.
883**
884** Inputs:
885** <ul>
886** <li> A pointer to the parser (an opaque structure.)
887** <li> The major token number.
888** <li> The minor token number.
889** <li> An option argument of a grammar-specified type.
890** </ul>
891**
892** Outputs:
893** None.
894*/
drh75897232000-05-29 14:26:00 +0000895void Parse(
896 void *yyp, /* The parser */
897 int yymajor, /* The major token code number */
898 ParseTOKENTYPE yyminor /* The value for the token */
drh1f245e42002-03-11 13:55:50 +0000899 ParseARG_PDECL /* Optional %extra_argument parameter */
drh75897232000-05-29 14:26:00 +0000900){
901 YYMINORTYPE yyminorunion;
drhfd39c582018-04-21 22:40:08 +0000902 YYACTIONTYPE yyact; /* The parser action. */
drha4414042015-11-09 15:06:26 +0000903#if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY)
drh75897232000-05-29 14:26:00 +0000904 int yyendofinput; /* True if we are at the end of input */
drha4414042015-11-09 15:06:26 +0000905#endif
drhc4dd3fd2008-01-22 01:48:05 +0000906#ifdef YYERRORSYMBOL
drh75897232000-05-29 14:26:00 +0000907 int yyerrorhit = 0; /* True if yymajor has invoked an error */
drhc4dd3fd2008-01-22 01:48:05 +0000908#endif
drhfb32c442018-04-21 13:51:42 +0000909 yyParser *yypParser = (yyParser*)yyp; /* The parser */
910 ParseCTX_FETCH
911 ParseARG_STORE
drh75897232000-05-29 14:26:00 +0000912
drhabecc0b2016-05-24 00:40:54 +0000913 assert( yypParser->yytos!=0 );
drha4414042015-11-09 15:06:26 +0000914#if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY)
drh75897232000-05-29 14:26:00 +0000915 yyendofinput = (yymajor==0);
drha4414042015-11-09 15:06:26 +0000916#endif
drh75897232000-05-29 14:26:00 +0000917
drhfd39c582018-04-21 22:40:08 +0000918 yyact = yypParser->yytos->stateno;
drh75897232000-05-29 14:26:00 +0000919#ifndef NDEBUG
920 if( yyTraceFILE ){
drhfd39c582018-04-21 22:40:08 +0000921 if( yyact < YY_MIN_REDUCE ){
drhe58f74f2017-12-24 17:06:41 +0000922 fprintf(yyTraceFILE,"%sInput '%s' in state %d\n",
drhfd39c582018-04-21 22:40:08 +0000923 yyTracePrompt,yyTokenName[yymajor],yyact);
drhe58f74f2017-12-24 17:06:41 +0000924 }else{
925 fprintf(yyTraceFILE,"%sInput '%s' with pending reduce %d\n",
drhfd39c582018-04-21 22:40:08 +0000926 yyTracePrompt,yyTokenName[yymajor],yyact-YY_MIN_REDUCE);
drhe58f74f2017-12-24 17:06:41 +0000927 }
drh75897232000-05-29 14:26:00 +0000928 }
929#endif
930
931 do{
drhfd39c582018-04-21 22:40:08 +0000932 assert( yyact==yypParser->yytos->stateno );
mistachkin709c8222018-07-22 21:23:19 +0000933 yyact = yy_find_shift_action((YYCODETYPE)yymajor,yyact);
drh5c8241b2017-12-24 23:38:10 +0000934 if( yyact >= YY_MIN_REDUCE ){
drhfd39c582018-04-21 22:40:08 +0000935 yyact = yy_reduce(yypParser,yyact-YY_MIN_REDUCE,yymajor,
936 yyminor ParseCTX_PARAM);
drh5c8241b2017-12-24 23:38:10 +0000937 }else if( yyact <= YY_MAX_SHIFTREDUCE ){
mistachkin709c8222018-07-22 21:23:19 +0000938 yy_shift(yypParser,yyact,(YYCODETYPE)yymajor,yyminor);
drhdab943c2016-02-16 01:01:43 +0000939#ifndef YYNOERRORRECOVERY
drha248a722015-09-07 19:52:55 +0000940 yypParser->yyerrcnt--;
drhdab943c2016-02-16 01:01:43 +0000941#endif
drhfd39c582018-04-21 22:40:08 +0000942 break;
drhef53a9f2017-12-25 00:10:05 +0000943 }else if( yyact==YY_ACCEPT_ACTION ){
drh05ef50d2018-04-23 00:25:31 +0000944 yypParser->yytos--;
945 yy_accept(yypParser);
drhef53a9f2017-12-25 00:10:05 +0000946 return;
drhc4dd3fd2008-01-22 01:48:05 +0000947 }else{
948 assert( yyact == YY_ERROR_ACTION );
drh45f31be2016-02-16 21:19:49 +0000949 yyminorunion.yy0 = yyminor;
drhc4dd3fd2008-01-22 01:48:05 +0000950#ifdef YYERRORSYMBOL
drh3ddfdf72003-12-22 14:53:19 +0000951 int yymx;
drhc4dd3fd2008-01-22 01:48:05 +0000952#endif
drh75897232000-05-29 14:26:00 +0000953#ifndef NDEBUG
954 if( yyTraceFILE ){
955 fprintf(yyTraceFILE,"%sSyntax Error!\n",yyTracePrompt);
956 }
957#endif
958#ifdef YYERRORSYMBOL
959 /* A syntax error has occurred.
960 ** The response to an error depends upon whether or not the
961 ** grammar defines an error token "ERROR".
962 **
963 ** This is what we do if the grammar does define ERROR:
964 **
965 ** * Call the %syntax_error function.
966 **
967 ** * Begin popping the stack until we enter a state where
968 ** it is legal to shift the error symbol, then shift
969 ** the error symbol.
970 **
971 ** * Set the error count to three.
972 **
973 ** * Begin accepting and shifting new tokens. No new error
974 ** processing will occur until three tokens have been
975 ** shifted successfully.
976 **
977 */
drh1f245e42002-03-11 13:55:50 +0000978 if( yypParser->yyerrcnt<0 ){
drh45f31be2016-02-16 21:19:49 +0000979 yy_syntax_error(yypParser,yymajor,yyminor);
drh75897232000-05-29 14:26:00 +0000980 }
drh118ab652016-05-23 21:56:24 +0000981 yymx = yypParser->yytos->major;
drh3ddfdf72003-12-22 14:53:19 +0000982 if( yymx==YYERRORSYMBOL || yyerrorhit ){
drh75897232000-05-29 14:26:00 +0000983#ifndef NDEBUG
984 if( yyTraceFILE ){
985 fprintf(yyTraceFILE,"%sDiscard input token %s\n",
986 yyTracePrompt,yyTokenName[yymajor]);
987 }
988#endif
drh45f31be2016-02-16 21:19:49 +0000989 yy_destructor(yypParser, (YYCODETYPE)yymajor, &yyminorunion);
drh75897232000-05-29 14:26:00 +0000990 yymajor = YYNOCODE;
991 }else{
drh4eda15e2016-10-04 12:20:12 +0000992 while( yypParser->yytos >= yypParser->yystack
drh118ab652016-05-23 21:56:24 +0000993 && (yyact = yy_find_reduce_action(
994 yypParser->yytos->stateno,
drhb8a76282018-11-27 14:03:11 +0000995 YYERRORSYMBOL)) > YY_MAX_SHIFTREDUCE
drh75897232000-05-29 14:26:00 +0000996 ){
997 yy_pop_parser_stack(yypParser);
998 }
drh118ab652016-05-23 21:56:24 +0000999 if( yypParser->yytos < yypParser->yystack || yymajor==0 ){
drhb27b7f52008-12-10 18:03:45 +00001000 yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
drh1f245e42002-03-11 13:55:50 +00001001 yy_parse_failed(yypParser);
drh240c7fa2016-07-05 12:47:28 +00001002#ifndef YYNOERRORRECOVERY
1003 yypParser->yyerrcnt = -1;
1004#endif
drh75897232000-05-29 14:26:00 +00001005 yymajor = YYNOCODE;
drh3ddfdf72003-12-22 14:53:19 +00001006 }else if( yymx!=YYERRORSYMBOL ){
drh45f31be2016-02-16 21:19:49 +00001007 yy_shift(yypParser,yyact,YYERRORSYMBOL,yyminor);
drh75897232000-05-29 14:26:00 +00001008 }
1009 }
drh1f245e42002-03-11 13:55:50 +00001010 yypParser->yyerrcnt = 3;
drh75897232000-05-29 14:26:00 +00001011 yyerrorhit = 1;
drhfd39c582018-04-21 22:40:08 +00001012 if( yymajor==YYNOCODE ) break;
1013 yyact = yypParser->yytos->stateno;
drhd3ec02d2009-06-12 02:27:14 +00001014#elif defined(YYNOERRORRECOVERY)
1015 /* If the YYNOERRORRECOVERY macro is defined, then do not attempt to
1016 ** do any kind of error recovery. Instead, simply invoke the syntax
1017 ** error routine and continue going as if nothing had happened.
1018 **
1019 ** Applications can set this macro (for example inside %include) if
1020 ** they intend to abandon the parse upon the first syntax error seen.
1021 */
drh45f31be2016-02-16 21:19:49 +00001022 yy_syntax_error(yypParser,yymajor, yyminor);
drhd3ec02d2009-06-12 02:27:14 +00001023 yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
drhfd39c582018-04-21 22:40:08 +00001024 break;
drh75897232000-05-29 14:26:00 +00001025#else /* YYERRORSYMBOL is not defined */
1026 /* This is what we do if the grammar does not define ERROR:
1027 **
1028 ** * Report an error message, and throw away the input token.
1029 **
1030 ** * If the input token is $, then fail the parse.
1031 **
1032 ** As before, subsequent error messages are suppressed until
1033 ** three input tokens have been successfully shifted.
1034 */
drh1f245e42002-03-11 13:55:50 +00001035 if( yypParser->yyerrcnt<=0 ){
drh45f31be2016-02-16 21:19:49 +00001036 yy_syntax_error(yypParser,yymajor, yyminor);
drh75897232000-05-29 14:26:00 +00001037 }
drh1f245e42002-03-11 13:55:50 +00001038 yypParser->yyerrcnt = 3;
drhb27b7f52008-12-10 18:03:45 +00001039 yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
drh75897232000-05-29 14:26:00 +00001040 if( yyendofinput ){
drh1f245e42002-03-11 13:55:50 +00001041 yy_parse_failed(yypParser);
drhd3d4b3c2016-07-08 19:54:38 +00001042#ifndef YYNOERRORRECOVERY
1043 yypParser->yyerrcnt = -1;
1044#endif
drh75897232000-05-29 14:26:00 +00001045 }
drhfd39c582018-04-21 22:40:08 +00001046 break;
drh75897232000-05-29 14:26:00 +00001047#endif
drh75897232000-05-29 14:26:00 +00001048 }
drhfd39c582018-04-21 22:40:08 +00001049 }while( yypParser->yytos>yypParser->yystack );
drh3bd48ab2015-09-07 18:23:37 +00001050#ifndef NDEBUG
1051 if( yyTraceFILE ){
drh118ab652016-05-23 21:56:24 +00001052 yyStackEntry *i;
1053 char cDiv = '[';
drh0c4105e2015-11-10 14:51:22 +00001054 fprintf(yyTraceFILE,"%sReturn. Stack=",yyTracePrompt);
drh118ab652016-05-23 21:56:24 +00001055 for(i=&yypParser->yystack[1]; i<=yypParser->yytos; i++){
1056 fprintf(yyTraceFILE,"%c%s", cDiv, yyTokenName[i->major]);
1057 cDiv = ' ';
1058 }
drh0c4105e2015-11-10 14:51:22 +00001059 fprintf(yyTraceFILE,"]\n");
drh3bd48ab2015-09-07 18:23:37 +00001060 }
1061#endif
drh75897232000-05-29 14:26:00 +00001062 return;
1063}
dan59ff4252018-06-29 17:44:52 +00001064
1065/*
1066** Return the fallback token corresponding to canonical token iToken, or
1067** 0 if iToken has no fallback.
1068*/
1069int ParseFallback(int iToken){
1070#ifdef YYFALLBACK
drhc7bf5712018-07-09 22:49:01 +00001071 if( iToken<(int)(sizeof(yyFallback)/sizeof(yyFallback[0])) ){
dan59ff4252018-06-29 17:44:52 +00001072 return yyFallback[iToken];
1073 }
drhc7bf5712018-07-09 22:49:01 +00001074#else
1075 (void)iToken;
dan59ff4252018-06-29 17:44:52 +00001076#endif
1077 return 0;
1078}