blob: 8cc57897db13a3b4d83c669aa58f720547c11def [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/************ Begin %include sections from the grammar ************************/
drh75897232000-05-29 14:26:00 +000026%%
drh82415f22015-11-09 19:33:42 +000027/**************** End of %include directives **********************************/
drh60c71b02020-09-01 11:20:03 +000028/* These constants specify the various numeric values for terminal symbols.
29***************** Begin token definitions *************************************/
drh82415f22015-11-09 19:33:42 +000030%%
drh60c71b02020-09-01 11:20:03 +000031/**************** End token definitions ***************************************/
drh822a62f2015-11-09 19:35:18 +000032
33/* The next sections is a series of control #defines.
drh75897232000-05-29 14:26:00 +000034** various aspects of the generated parser.
drh82415f22015-11-09 19:33:42 +000035** YYCODETYPE is the data type used to store the integer codes
36** that represent terminal and non-terminal symbols.
37** "unsigned char" is used if there are fewer than
38** 256 symbols. Larger types otherwise.
39** YYNOCODE is a number of type YYCODETYPE that is not used for
40** any terminal or nonterminal symbol.
drh0bd1f4e2002-06-06 18:54:39 +000041** YYFALLBACK If defined, this indicates that one or more tokens
drh82415f22015-11-09 19:33:42 +000042** (also known as: "terminal symbols") have fall-back
43** values which should be used if the original symbol
44** would not parse. This permits keywords to sometimes
45** be used as identifiers, for example.
46** YYACTIONTYPE is the data type used for "action codes" - numbers
47** that indicate what to do in response to the next
48** token.
49** ParseTOKENTYPE is the data type used for minor type for terminal
50** symbols. Background: A "minor type" is a semantic
51** value associated with a terminal or non-terminal
52** symbols. For example, for an "ID" terminal symbol,
53** the minor type might be the name of the identifier.
54** Each non-terminal can have a different minor type.
55** Terminal symbols all have the same minor type, though.
56** This macros defines the minor type for terminal
57** symbols.
58** YYMINORTYPE is the data type used for all minor types.
drh75897232000-05-29 14:26:00 +000059** This is typically a union of many types, one of
60** which is ParseTOKENTYPE. The entry in the union
drh82415f22015-11-09 19:33:42 +000061** for terminal symbols is called "yy0".
drhb19fd012007-03-29 01:44:45 +000062** YYSTACKDEPTH is the maximum depth of the parser's stack. If
63** zero the stack is dynamically sized using realloc()
drh1f245e42002-03-11 13:55:50 +000064** ParseARG_SDECL A static variable declaration for the %extra_argument
65** ParseARG_PDECL A parameter declaration for the %extra_argument
drhfb32c442018-04-21 13:51:42 +000066** ParseARG_PARAM Code to pass %extra_argument as a subroutine parameter
drh1f245e42002-03-11 13:55:50 +000067** ParseARG_STORE Code to store %extra_argument into yypParser
68** ParseARG_FETCH Code to extract %extra_argument from yypParser
drhfb32c442018-04-21 13:51:42 +000069** ParseCTX_* As ParseARG_ except for %extra_context
drh75897232000-05-29 14:26:00 +000070** YYERRORSYMBOL is the code number of the error symbol. If not
71** defined, then do no error processing.
drh3bd48ab2015-09-07 18:23:37 +000072** YYNSTATE the combined number of states.
73** YYNRULE the number of rules in the grammar
drh0d9de992017-12-26 18:04:23 +000074** YYNTOKEN Number of terminal symbols
drh3bd48ab2015-09-07 18:23:37 +000075** 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
drh3bd48ab2015-09-07 18:23:37 +000078** YY_ERROR_ACTION The yy_action[] code for syntax error
79** YY_ACCEPT_ACTION The yy_action[] code for accept
80** YY_NO_ACTION The yy_action[] code for no-op
drh5c8241b2017-12-24 23:38:10 +000081** YY_MIN_REDUCE Minimum value for reduce actions
82** YY_MAX_REDUCE Maximum value for reduce actions
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 *******************************************/
drh3773c252018-06-28 03:38:49 +000090#define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0])))
drh75897232000-05-29 14:26:00 +000091
drh8a415d32009-06-12 13:53:51 +000092/* Define the yytestcase() macro to be a no-op if is not already defined
93** otherwise.
94**
95** Applications can choose to define yytestcase() in the %include section
96** to a macro that can assist in verifying code coverage. For production
97** code the yytestcase() macro should be turned off. But it is useful
98** for testing.
99*/
100#ifndef yytestcase
101# define yytestcase(X)
102#endif
103
drh26c9b5e2008-04-11 14:56:53 +0000104
drh34ff57b2008-07-14 12:27:51 +0000105/* Next are the tables used to determine what action to take based on the
drh8b582012003-10-21 13:16:03 +0000106** current state and lookahead token. These tables are used to implement
107** functions that take a state number and lookahead value and return an
108** action integer.
drh75897232000-05-29 14:26:00 +0000109**
drh8548a052003-10-22 22:15:27 +0000110** Suppose the action integer is N. Then the action is determined as
111** follows
drh75897232000-05-29 14:26:00 +0000112**
drh3bd48ab2015-09-07 18:23:37 +0000113** 0 <= N <= YY_MAX_SHIFT Shift N. That is, push the lookahead
drh8548a052003-10-22 22:15:27 +0000114** token onto the stack and goto state N.
115**
drh3bd48ab2015-09-07 18:23:37 +0000116** N between YY_MIN_SHIFTREDUCE Shift to an arbitrary state then
117** and YY_MAX_SHIFTREDUCE reduce by rule N-YY_MIN_SHIFTREDUCE.
drh8548a052003-10-22 22:15:27 +0000118**
drh3bd48ab2015-09-07 18:23:37 +0000119** N == YY_ERROR_ACTION A syntax error has occurred.
drh8548a052003-10-22 22:15:27 +0000120**
drh3bd48ab2015-09-07 18:23:37 +0000121** N == YY_ACCEPT_ACTION The parser accepts its input.
drh8548a052003-10-22 22:15:27 +0000122**
drh3bd48ab2015-09-07 18:23:37 +0000123** N == YY_NO_ACTION No such action. Denotes unused
drh8548a052003-10-22 22:15:27 +0000124** slots in the yy_action[] table.
125**
drh5c8241b2017-12-24 23:38:10 +0000126** N between YY_MIN_REDUCE Reduce by rule N-YY_MIN_REDUCE
127** and YY_MAX_REDUCE
128**
drh8548a052003-10-22 22:15:27 +0000129** The action table is constructed as a single large table named yy_action[].
drh701b6882016-08-10 13:30:43 +0000130** Given state S and lookahead X, the action is computed as either:
drh75897232000-05-29 14:26:00 +0000131**
drh701b6882016-08-10 13:30:43 +0000132** (A) N = yy_action[ yy_shift_ofst[S] + X ]
133** (B) N = yy_default[S]
drh8b582012003-10-21 13:16:03 +0000134**
drh3a9d6c72017-12-25 04:15:38 +0000135** The (A) formula is preferred. The B formula is used instead if
136** yy_lookahead[yy_shift_ofst[S]+X] is not equal to X.
drh8b582012003-10-21 13:16:03 +0000137**
drh701b6882016-08-10 13:30:43 +0000138** The formulas above are for computing the action when the lookahead is
drh8b582012003-10-21 13:16:03 +0000139** a terminal symbol. If the lookahead is a non-terminal (as occurs after
140** a reduce action) then the yy_reduce_ofst[] array is used in place of
drh3a9d6c72017-12-25 04:15:38 +0000141** the yy_shift_ofst[] array.
drh8b582012003-10-21 13:16:03 +0000142**
143** The following are the tables generated in this section:
144**
145** yy_action[] A single table containing all actions.
146** yy_lookahead[] A table containing the lookahead for each entry in
147** yy_action. Used to detect hash collisions.
148** yy_shift_ofst[] For each state, the offset into yy_action for
149** shifting terminals.
150** yy_reduce_ofst[] For each state, the offset into yy_action for
151** shifting non-terminals after a reduce.
152** yy_default[] Default action for each state.
drh82415f22015-11-09 19:33:42 +0000153**
154*********** Begin parsing tables **********************************************/
drh75897232000-05-29 14:26:00 +0000155%%
drh82415f22015-11-09 19:33:42 +0000156/********** End of lemon-generated parsing tables *****************************/
drh75897232000-05-29 14:26:00 +0000157
drh82415f22015-11-09 19:33:42 +0000158/* The next table maps tokens (terminal symbols) into fallback tokens.
159** If a construct like the following:
drh0bd1f4e2002-06-06 18:54:39 +0000160**
161** %fallback ID X Y Z.
162**
drh34ff57b2008-07-14 12:27:51 +0000163** appears in the grammar, then ID becomes a fallback token for X, Y,
drh0bd1f4e2002-06-06 18:54:39 +0000164** and Z. Whenever one of the tokens X, Y, or Z is input to the parser
165** but it does not parse, the type of the token is changed to ID and
166** the parse is retried before an error is thrown.
drh82415f22015-11-09 19:33:42 +0000167**
168** This feature can be used, for example, to cause some keywords in a language
169** to revert to identifiers if they keyword does not apply in the context where
170** it appears.
drh0bd1f4e2002-06-06 18:54:39 +0000171*/
172#ifdef YYFALLBACK
173static const YYCODETYPE yyFallback[] = {
174%%
175};
176#endif /* YYFALLBACK */
177
drh75897232000-05-29 14:26:00 +0000178/* The following structure represents a single element of the
179** parser's stack. Information stored includes:
180**
181** + The state number for the parser at this level of the stack.
182**
183** + The value of the token stored at this level of the stack.
184** (In other words, the "major" token.)
185**
186** + The semantic value stored at this level of the stack. This is
187** the information used by the action routines in the grammar.
188** It is sometimes called the "minor" token.
drha248a722015-09-07 19:52:55 +0000189**
190** After the "shift" half of a SHIFTREDUCE action, the stateno field
191** actually contains the reduce action for the second half of the
192** SHIFTREDUCE.
drh75897232000-05-29 14:26:00 +0000193*/
194struct yyStackEntry {
drha248a722015-09-07 19:52:55 +0000195 YYACTIONTYPE stateno; /* The state-number, or reduce action in SHIFTREDUCE */
drh2abcd582008-07-24 23:34:07 +0000196 YYCODETYPE major; /* The major token value. This is the code
197 ** number for the token at this stack level */
198 YYMINORTYPE minor; /* The user-supplied minor token value. This
199 ** is the value of the token */
drh75897232000-05-29 14:26:00 +0000200};
drh1f245e42002-03-11 13:55:50 +0000201typedef struct yyStackEntry yyStackEntry;
drh75897232000-05-29 14:26:00 +0000202
203/* The state of the parser is completely contained in an instance of
204** the following structure */
205struct yyParser {
drh118ab652016-05-23 21:56:24 +0000206 yyStackEntry *yytos; /* Pointer to top element of the stack */
drhec424a52008-07-25 15:39:03 +0000207#ifdef YYTRACKMAXSTACKDEPTH
drh118ab652016-05-23 21:56:24 +0000208 int yyhwm; /* High-water mark of the stack */
drhec424a52008-07-25 15:39:03 +0000209#endif
drhdab943c2016-02-16 01:01:43 +0000210#ifndef YYNOERRORRECOVERY
drh1f245e42002-03-11 13:55:50 +0000211 int yyerrcnt; /* Shifts left before out of the error */
drhdab943c2016-02-16 01:01:43 +0000212#endif
drh1f245e42002-03-11 13:55:50 +0000213 ParseARG_SDECL /* A place to hold %extra_argument */
drhfb32c442018-04-21 13:51:42 +0000214 ParseCTX_SDECL /* A place to hold %extra_context */
drhb19fd012007-03-29 01:44:45 +0000215#if YYSTACKDEPTH<=0
216 int yystksz; /* Current side of the stack */
217 yyStackEntry *yystack; /* The parser's stack */
drh8dc82472016-05-27 04:10:47 +0000218 yyStackEntry yystk0; /* First stack entry */
drhb19fd012007-03-29 01:44:45 +0000219#else
drh1f245e42002-03-11 13:55:50 +0000220 yyStackEntry yystack[YYSTACKDEPTH]; /* The parser's stack */
drh8b471e72017-06-28 15:01:35 +0000221 yyStackEntry *yystackEnd; /* Last entry in the stack */
drhb19fd012007-03-29 01:44:45 +0000222#endif
drh75897232000-05-29 14:26:00 +0000223};
224typedef struct yyParser yyParser;
225
drh4e86aa82021-11-09 01:48:15 +0000226#include <assert.h>
drh75897232000-05-29 14:26:00 +0000227#ifndef NDEBUG
228#include <stdio.h>
229static FILE *yyTraceFILE = 0;
230static char *yyTracePrompt = 0;
drh0bd1f4e2002-06-06 18:54:39 +0000231#endif /* NDEBUG */
drh75897232000-05-29 14:26:00 +0000232
drh0bd1f4e2002-06-06 18:54:39 +0000233#ifndef NDEBUG
drh75897232000-05-29 14:26:00 +0000234/*
235** Turn parser tracing on by giving a stream to which to write the trace
236** and a prompt to preface each trace message. Tracing is turned off
237** by making either argument NULL
238**
239** Inputs:
240** <ul>
241** <li> A FILE* to which trace output should be written.
242** If NULL, then tracing is turned off.
243** <li> A prefix string written at the beginning of every
244** line of trace output. If NULL, then tracing is
245** turned off.
246** </ul>
247**
248** Outputs:
249** None.
250*/
drh75897232000-05-29 14:26:00 +0000251void ParseTrace(FILE *TraceFILE, char *zTracePrompt){
252 yyTraceFILE = TraceFILE;
253 yyTracePrompt = zTracePrompt;
254 if( yyTraceFILE==0 ) yyTracePrompt = 0;
255 else if( yyTracePrompt==0 ) yyTraceFILE = 0;
256}
drh0bd1f4e2002-06-06 18:54:39 +0000257#endif /* NDEBUG */
drh75897232000-05-29 14:26:00 +0000258
drh0d9de992017-12-26 18:04:23 +0000259#if defined(YYCOVERAGE) || !defined(NDEBUG)
drh75897232000-05-29 14:26:00 +0000260/* For tracing shifts, the names of all terminals and nonterminals
261** are required. The following table supplies these names */
drh57196282004-10-06 15:41:16 +0000262static const char *const yyTokenName[] = {
drh75897232000-05-29 14:26:00 +0000263%%
264};
drh0d9de992017-12-26 18:04:23 +0000265#endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */
drh75897232000-05-29 14:26:00 +0000266
drh0bd1f4e2002-06-06 18:54:39 +0000267#ifndef NDEBUG
268/* For tracing reduce actions, the names of all rules are required.
269*/
drh57196282004-10-06 15:41:16 +0000270static const char *const yyRuleName[] = {
drh0bd1f4e2002-06-06 18:54:39 +0000271%%
272};
273#endif /* NDEBUG */
drha1b351a2001-09-14 16:42:12 +0000274
drh960e8c62001-04-03 16:53:21 +0000275
drhb19fd012007-03-29 01:44:45 +0000276#if YYSTACKDEPTH<=0
277/*
drh8dc82472016-05-27 04:10:47 +0000278** Try to increase the size of the parser stack. Return the number
279** of errors. Return 0 on success.
drhb19fd012007-03-29 01:44:45 +0000280*/
drh8dc82472016-05-27 04:10:47 +0000281static int yyGrowStack(yyParser *p){
drhb19fd012007-03-29 01:44:45 +0000282 int newSize;
drhabecc0b2016-05-24 00:40:54 +0000283 int idx;
drhb19fd012007-03-29 01:44:45 +0000284 yyStackEntry *pNew;
285
286 newSize = p->yystksz*2 + 100;
drhabecc0b2016-05-24 00:40:54 +0000287 idx = p->yytos ? (int)(p->yytos - p->yystack) : 0;
drh8dc82472016-05-27 04:10:47 +0000288 if( p->yystack==&p->yystk0 ){
289 pNew = malloc(newSize*sizeof(pNew[0]));
290 if( pNew ) pNew[0] = p->yystk0;
291 }else{
292 pNew = realloc(p->yystack, newSize*sizeof(pNew[0]));
293 }
drhb19fd012007-03-29 01:44:45 +0000294 if( pNew ){
295 p->yystack = pNew;
drhabecc0b2016-05-24 00:40:54 +0000296 p->yytos = &p->yystack[idx];
drhb19fd012007-03-29 01:44:45 +0000297#ifndef NDEBUG
298 if( yyTraceFILE ){
drh8dc82472016-05-27 04:10:47 +0000299 fprintf(yyTraceFILE,"%sStack grows from %d to %d entries.\n",
300 yyTracePrompt, p->yystksz, newSize);
drhb19fd012007-03-29 01:44:45 +0000301 }
302#endif
drh8dc82472016-05-27 04:10:47 +0000303 p->yystksz = newSize;
drhb19fd012007-03-29 01:44:45 +0000304 }
drh8dc82472016-05-27 04:10:47 +0000305 return pNew==0;
drhb19fd012007-03-29 01:44:45 +0000306}
307#endif
308
drh82415f22015-11-09 19:33:42 +0000309/* Datatype of the argument to the memory allocated passed as the
310** second argument to ParseAlloc() below. This can be changed by
311** putting an appropriate #define in the %include section of the input
312** grammar.
313*/
314#ifndef YYMALLOCARGTYPE
315# define YYMALLOCARGTYPE size_t
316#endif
317
drhd26cc542017-01-28 20:46:37 +0000318/* Initialize a new parser that has already been allocated.
319*/
drhfb32c442018-04-21 13:51:42 +0000320void ParseInit(void *yypRawParser ParseCTX_PDECL){
321 yyParser *yypParser = (yyParser*)yypRawParser;
322 ParseCTX_STORE
drhd26cc542017-01-28 20:46:37 +0000323#ifdef YYTRACKMAXSTACKDEPTH
drhfb32c442018-04-21 13:51:42 +0000324 yypParser->yyhwm = 0;
drhd26cc542017-01-28 20:46:37 +0000325#endif
326#if YYSTACKDEPTH<=0
drhfb32c442018-04-21 13:51:42 +0000327 yypParser->yytos = NULL;
328 yypParser->yystack = NULL;
329 yypParser->yystksz = 0;
330 if( yyGrowStack(yypParser) ){
331 yypParser->yystack = &yypParser->yystk0;
332 yypParser->yystksz = 1;
drhd26cc542017-01-28 20:46:37 +0000333 }
334#endif
335#ifndef YYNOERRORRECOVERY
drhfb32c442018-04-21 13:51:42 +0000336 yypParser->yyerrcnt = -1;
drhd26cc542017-01-28 20:46:37 +0000337#endif
drhfb32c442018-04-21 13:51:42 +0000338 yypParser->yytos = yypParser->yystack;
339 yypParser->yystack[0].stateno = 0;
340 yypParser->yystack[0].major = 0;
drh92395c52017-07-04 12:50:00 +0000341#if YYSTACKDEPTH>0
drhfb32c442018-04-21 13:51:42 +0000342 yypParser->yystackEnd = &yypParser->yystack[YYSTACKDEPTH-1];
drh92395c52017-07-04 12:50:00 +0000343#endif
drhd26cc542017-01-28 20:46:37 +0000344}
345
346#ifndef Parse_ENGINEALWAYSONSTACK
drh75897232000-05-29 14:26:00 +0000347/*
348** This function allocates a new parser.
349** The only argument is a pointer to a function which works like
350** malloc.
351**
352** Inputs:
353** A pointer to the function used to allocate memory.
354**
355** Outputs:
356** A pointer to a parser. This pointer is used in subsequent calls
357** to Parse and ParseFree.
358*/
drhfb32c442018-04-21 13:51:42 +0000359void *ParseAlloc(void *(*mallocProc)(YYMALLOCARGTYPE) ParseCTX_PDECL){
360 yyParser *yypParser;
361 yypParser = (yyParser*)(*mallocProc)( (YYMALLOCARGTYPE)sizeof(yyParser) );
362 if( yypParser ){
363 ParseCTX_STORE
364 ParseInit(yypParser ParseCTX_PARAM);
365 }
366 return (void*)yypParser;
drh75897232000-05-29 14:26:00 +0000367}
drhd26cc542017-01-28 20:46:37 +0000368#endif /* Parse_ENGINEALWAYSONSTACK */
369
drh75897232000-05-29 14:26:00 +0000370
drh82415f22015-11-09 19:33:42 +0000371/* The following function deletes the "minor type" or semantic value
372** associated with a symbol. The symbol can be either a terminal
373** or nonterminal. "yymajor" is the symbol code, and "yypminor" is
374** a pointer to the value to be deleted. The code used to do the
375** deletions is derived from the %destructor and/or %token_destructor
376** directives of the input grammar.
drh75897232000-05-29 14:26:00 +0000377*/
drh633e6d52008-07-28 19:34:53 +0000378static void yy_destructor(
379 yyParser *yypParser, /* The parser */
380 YYCODETYPE yymajor, /* Type code for object to destroy */
381 YYMINORTYPE *yypminor /* The object to be destroyed */
382){
drhfb32c442018-04-21 13:51:42 +0000383 ParseARG_FETCH
384 ParseCTX_FETCH
drh75897232000-05-29 14:26:00 +0000385 switch( yymajor ){
386 /* Here is inserted the actions which take place when a
387 ** terminal or non-terminal is destroyed. This can happen
388 ** when the symbol is popped from the stack during a
389 ** reduce or during error processing or when a parser is
390 ** being destroyed before it is finished parsing.
391 **
392 ** Note: during a reduce, the only symbols destroyed are those
drh82415f22015-11-09 19:33:42 +0000393 ** which appear on the RHS of the rule, but which are *not* used
drh75897232000-05-29 14:26:00 +0000394 ** inside the C code.
395 */
drh82415f22015-11-09 19:33:42 +0000396/********* Begin destructor definitions ***************************************/
drh75897232000-05-29 14:26:00 +0000397%%
drh82415f22015-11-09 19:33:42 +0000398/********* End destructor definitions *****************************************/
drh75897232000-05-29 14:26:00 +0000399 default: break; /* If no destructor action specified: do nothing */
400 }
401}
402
403/*
404** Pop the parser's stack once.
405**
406** If there is a destructor routine associated with the token which
407** is popped from the stack, then call it.
drh75897232000-05-29 14:26:00 +0000408*/
drh3781f012015-11-09 14:11:37 +0000409static void yy_pop_parser_stack(yyParser *pParser){
410 yyStackEntry *yytos;
drh118ab652016-05-23 21:56:24 +0000411 assert( pParser->yytos!=0 );
drh240c7fa2016-07-05 12:47:28 +0000412 assert( pParser->yytos > pParser->yystack );
drh118ab652016-05-23 21:56:24 +0000413 yytos = pParser->yytos--;
drh75897232000-05-29 14:26:00 +0000414#ifndef NDEBUG
drh3781f012015-11-09 14:11:37 +0000415 if( yyTraceFILE ){
drh75897232000-05-29 14:26:00 +0000416 fprintf(yyTraceFILE,"%sPopping %s\n",
417 yyTracePrompt,
drh3ddfdf72003-12-22 14:53:19 +0000418 yyTokenName[yytos->major]);
drh75897232000-05-29 14:26:00 +0000419 }
420#endif
drh3781f012015-11-09 14:11:37 +0000421 yy_destructor(pParser, yytos->major, &yytos->minor);
drh75897232000-05-29 14:26:00 +0000422}
423
drhd26cc542017-01-28 20:46:37 +0000424/*
425** Clear all secondary memory allocations from the parser
426*/
427void ParseFinalize(void *p){
428 yyParser *pParser = (yyParser*)p;
429 while( pParser->yytos>pParser->yystack ) yy_pop_parser_stack(pParser);
430#if YYSTACKDEPTH<=0
431 if( pParser->yystack!=&pParser->yystk0 ) free(pParser->yystack);
432#endif
433}
434
435#ifndef Parse_ENGINEALWAYSONSTACK
drh75897232000-05-29 14:26:00 +0000436/*
drh82415f22015-11-09 19:33:42 +0000437** Deallocate and destroy a parser. Destructors are called for
drh75897232000-05-29 14:26:00 +0000438** all stack elements before shutting the parser down.
439**
drh82415f22015-11-09 19:33:42 +0000440** If the YYPARSEFREENEVERNULL macro exists (for example because it
441** is defined in a %include section of the input grammar) then it is
442** assumed that the input pointer is never NULL.
drh75897232000-05-29 14:26:00 +0000443*/
drh75897232000-05-29 14:26:00 +0000444void ParseFree(
drh960e8c62001-04-03 16:53:21 +0000445 void *p, /* The parser to be deleted */
446 void (*freeProc)(void*) /* Function used to reclaim memory */
drh75897232000-05-29 14:26:00 +0000447){
drh82415f22015-11-09 19:33:42 +0000448#ifndef YYPARSEFREENEVERNULL
drhd26cc542017-01-28 20:46:37 +0000449 if( p==0 ) return;
drh82415f22015-11-09 19:33:42 +0000450#endif
drhd26cc542017-01-28 20:46:37 +0000451 ParseFinalize(p);
452 (*freeProc)(p);
drh75897232000-05-29 14:26:00 +0000453}
drhd26cc542017-01-28 20:46:37 +0000454#endif /* Parse_ENGINEALWAYSONSTACK */
drh75897232000-05-29 14:26:00 +0000455
456/*
drhec424a52008-07-25 15:39:03 +0000457** Return the peak depth of the stack for a parser.
458*/
459#ifdef YYTRACKMAXSTACKDEPTH
460int ParseStackPeak(void *p){
461 yyParser *pParser = (yyParser*)p;
drh118ab652016-05-23 21:56:24 +0000462 return pParser->yyhwm;
drhec424a52008-07-25 15:39:03 +0000463}
464#endif
465
drh0d9de992017-12-26 18:04:23 +0000466/* This array of booleans keeps track of the parser statement
467** coverage. The element yycoverage[X][Y] is set when the parser
468** is in state X and has a lookahead token Y. In a well-tested
469** systems, every element of this matrix should end up being set.
470*/
471#if defined(YYCOVERAGE)
472static unsigned char yycoverage[YYNSTATE][YYNTOKEN];
473#endif
474
475/*
476** Write into out a description of every state/lookahead combination that
drh7038a992017-12-27 17:14:50 +0000477**
478** (1) has not been used by the parser, and
479** (2) is not a syntax error.
480**
481** Return the number of missed state/lookahead combinations.
drh0d9de992017-12-26 18:04:23 +0000482*/
483#if defined(YYCOVERAGE)
484int ParseCoverage(FILE *out){
drh7038a992017-12-27 17:14:50 +0000485 int stateno, iLookAhead, i;
drh0d9de992017-12-26 18:04:23 +0000486 int nMissed = 0;
drh7038a992017-12-27 17:14:50 +0000487 for(stateno=0; stateno<YYNSTATE; stateno++){
488 i = yy_shift_ofst[stateno];
489 for(iLookAhead=0; iLookAhead<YYNTOKEN; iLookAhead++){
drhcf8e0e92017-12-27 17:36:58 +0000490 if( yy_lookahead[i+iLookAhead]!=iLookAhead ) continue;
drh7038a992017-12-27 17:14:50 +0000491 if( yycoverage[stateno][iLookAhead]==0 ) nMissed++;
drh22716cb2017-12-26 18:32:06 +0000492 if( out ){
drh7038a992017-12-27 17:14:50 +0000493 fprintf(out,"State %d lookahead %s %s\n", stateno,
494 yyTokenName[iLookAhead],
495 yycoverage[stateno][iLookAhead] ? "ok" : "missed");
drh22716cb2017-12-26 18:32:06 +0000496 }
drh0d9de992017-12-26 18:04:23 +0000497 }
498 }
499 return nMissed;
500}
501#endif
502
drhec424a52008-07-25 15:39:03 +0000503/*
drh8b582012003-10-21 13:16:03 +0000504** Find the appropriate action for a parser given the terminal
505** look-ahead token iLookAhead.
drh75897232000-05-29 14:26:00 +0000506*/
drhfd39c582018-04-21 22:40:08 +0000507static YYACTIONTYPE yy_find_shift_action(
508 YYCODETYPE iLookAhead, /* The look-ahead token */
509 YYACTIONTYPE stateno /* Current state number */
drh75897232000-05-29 14:26:00 +0000510){
drh8b582012003-10-21 13:16:03 +0000511 int i;
drhfd39c582018-04-21 22:40:08 +0000512
drhef53a9f2017-12-25 00:10:05 +0000513 if( stateno>YY_MAX_SHIFT ) return stateno;
drhae2a4082015-09-07 20:02:39 +0000514 assert( stateno <= YY_SHIFT_COUNT );
drh0d9de992017-12-26 18:04:23 +0000515#if defined(YYCOVERAGE)
516 yycoverage[stateno][iLookAhead] = 1;
517#endif
drha4414042015-11-09 15:06:26 +0000518 do{
519 i = yy_shift_ofst[stateno];
drh54cfb492018-02-09 15:04:51 +0000520 assert( i>=0 );
drh2e517162019-08-28 02:09:47 +0000521 assert( i<=YY_ACTTAB_COUNT );
522 assert( i+YYNTOKEN<=(int)YY_NLOOKAHEAD );
drha4414042015-11-09 15:06:26 +0000523 assert( iLookAhead!=YYNOCODE );
drh7038a992017-12-27 17:14:50 +0000524 assert( iLookAhead < YYNTOKEN );
drha4414042015-11-09 15:06:26 +0000525 i += iLookAhead;
drh2e517162019-08-28 02:09:47 +0000526 assert( i<(int)YY_NLOOKAHEAD );
527 if( yy_lookahead[i]!=iLookAhead ){
drh4767d972006-06-14 15:03:49 +0000528#ifdef YYFALLBACK
drhc83db9e2016-08-10 01:43:30 +0000529 YYCODETYPE iFallback; /* Fallback token */
drh010bdb42019-08-28 11:31:11 +0000530 assert( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0]) );
531 iFallback = yyFallback[iLookAhead];
532 if( iFallback!=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;
drh010bdb42019-08-28 11:31:11 +0000547 assert( j<(int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0])) );
548 if( yy_lookahead[j]==YYWILDCARD && iLookAhead>0 ){
drha4414042015-11-09 15:06:26 +0000549#ifndef NDEBUG
drhc83db9e2016-08-10 01:43:30 +0000550 if( yyTraceFILE ){
551 fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n",
552 yyTracePrompt, yyTokenName[iLookAhead],
553 yyTokenName[YYWILDCARD]);
drha4414042015-11-09 15:06:26 +0000554 }
drhc83db9e2016-08-10 01:43:30 +0000555#endif /* NDEBUG */
556 return yy_action[j];
drha4414042015-11-09 15:06:26 +0000557 }
drha4414042015-11-09 15:06:26 +0000558 }
drhc83db9e2016-08-10 01:43:30 +0000559#endif /* YYWILDCARD */
drha4414042015-11-09 15:06:26 +0000560 return yy_default[stateno];
561 }else{
drh18ef40e2020-09-16 16:55:56 +0000562 assert( i>=0 && i<(int)(sizeof(yy_action)/sizeof(yy_action[0])) );
drha4414042015-11-09 15:06:26 +0000563 return yy_action[i];
drh0bd1f4e2002-06-06 18:54:39 +0000564 }
drha4414042015-11-09 15:06:26 +0000565 }while(1);
drh8b582012003-10-21 13:16:03 +0000566}
567
568/*
569** Find the appropriate action for a parser given the non-terminal
570** look-ahead token iLookAhead.
drh8b582012003-10-21 13:16:03 +0000571*/
mistachkin709c8222018-07-22 21:23:19 +0000572static YYACTIONTYPE yy_find_reduce_action(
drhfd39c582018-04-21 22:40:08 +0000573 YYACTIONTYPE stateno, /* Current state number */
drhd9f291e2006-06-13 11:15:47 +0000574 YYCODETYPE iLookAhead /* The look-ahead token */
drh8b582012003-10-21 13:16:03 +0000575){
576 int i;
drh7f7c2572008-04-27 18:45:10 +0000577#ifdef YYERRORSYMBOL
drhf16371d2009-11-03 19:18:31 +0000578 if( stateno>YY_REDUCE_COUNT ){
drh7f7c2572008-04-27 18:45:10 +0000579 return yy_default[stateno];
580 }
581#else
drhf16371d2009-11-03 19:18:31 +0000582 assert( stateno<=YY_REDUCE_COUNT );
drh7f7c2572008-04-27 18:45:10 +0000583#endif
drh01495b92008-01-23 12:52:40 +0000584 i = yy_reduce_ofst[stateno];
drh01495b92008-01-23 12:52:40 +0000585 assert( iLookAhead!=YYNOCODE );
drh8b582012003-10-21 13:16:03 +0000586 i += iLookAhead;
drh7f7c2572008-04-27 18:45:10 +0000587#ifdef YYERRORSYMBOL
drhf16371d2009-11-03 19:18:31 +0000588 if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){
drh7f7c2572008-04-27 18:45:10 +0000589 return yy_default[stateno];
590 }
591#else
drhf16371d2009-11-03 19:18:31 +0000592 assert( i>=0 && i<YY_ACTTAB_COUNT );
drh01495b92008-01-23 12:52:40 +0000593 assert( yy_lookahead[i]==iLookAhead );
drh7f7c2572008-04-27 18:45:10 +0000594#endif
drh01495b92008-01-23 12:52:40 +0000595 return yy_action[i];
drh75897232000-05-29 14:26:00 +0000596}
597
598/*
drhb19fd012007-03-29 01:44:45 +0000599** The following routine is called if the stack overflows.
600*/
drh45f31be2016-02-16 21:19:49 +0000601static void yyStackOverflow(yyParser *yypParser){
drhfb32c442018-04-21 13:51:42 +0000602 ParseARG_FETCH
603 ParseCTX_FETCH
drhb19fd012007-03-29 01:44:45 +0000604#ifndef NDEBUG
605 if( yyTraceFILE ){
606 fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt);
607 }
608#endif
drhabecc0b2016-05-24 00:40:54 +0000609 while( yypParser->yytos>yypParser->yystack ) yy_pop_parser_stack(yypParser);
drhb19fd012007-03-29 01:44:45 +0000610 /* Here code is inserted which will execute if the parser
611 ** stack every overflows */
drh82415f22015-11-09 19:33:42 +0000612/******** Begin %stack_overflow code ******************************************/
drhb19fd012007-03-29 01:44:45 +0000613%%
drh82415f22015-11-09 19:33:42 +0000614/******** End %stack_overflow code ********************************************/
drhfb32c442018-04-21 13:51:42 +0000615 ParseARG_STORE /* Suppress warning about unused %extra_argument var */
616 ParseCTX_STORE
drhb19fd012007-03-29 01:44:45 +0000617}
618
619/*
drha248a722015-09-07 19:52:55 +0000620** Print tracing information for a SHIFT action
621*/
622#ifndef NDEBUG
drhe58f74f2017-12-24 17:06:41 +0000623static void yyTraceShift(yyParser *yypParser, int yyNewState, const char *zTag){
drha248a722015-09-07 19:52:55 +0000624 if( yyTraceFILE ){
drha248a722015-09-07 19:52:55 +0000625 if( yyNewState<YYNSTATE ){
drhe58f74f2017-12-24 17:06:41 +0000626 fprintf(yyTraceFILE,"%s%s '%s', go to state %d\n",
627 yyTracePrompt, zTag, yyTokenName[yypParser->yytos->major],
drh0c4105e2015-11-10 14:51:22 +0000628 yyNewState);
drha248a722015-09-07 19:52:55 +0000629 }else{
drhe58f74f2017-12-24 17:06:41 +0000630 fprintf(yyTraceFILE,"%s%s '%s', pending reduce %d\n",
631 yyTracePrompt, zTag, yyTokenName[yypParser->yytos->major],
632 yyNewState - YY_MIN_REDUCE);
drha248a722015-09-07 19:52:55 +0000633 }
634 }
635}
636#else
drhe58f74f2017-12-24 17:06:41 +0000637# define yyTraceShift(X,Y,Z)
drha248a722015-09-07 19:52:55 +0000638#endif
639
640/*
drh82415f22015-11-09 19:33:42 +0000641** Perform a shift action.
drh75897232000-05-29 14:26:00 +0000642*/
drha248a722015-09-07 19:52:55 +0000643static void yy_shift(
drh75897232000-05-29 14:26:00 +0000644 yyParser *yypParser, /* The parser to be shifted */
drhfd39c582018-04-21 22:40:08 +0000645 YYACTIONTYPE yyNewState, /* The new state to shift in */
646 YYCODETYPE yyMajor, /* The major token to shift in */
drh45f31be2016-02-16 21:19:49 +0000647 ParseTOKENTYPE yyMinor /* The minor token to shift in */
drh75897232000-05-29 14:26:00 +0000648){
drh3ddfdf72003-12-22 14:53:19 +0000649 yyStackEntry *yytos;
drh118ab652016-05-23 21:56:24 +0000650 yypParser->yytos++;
drhec424a52008-07-25 15:39:03 +0000651#ifdef YYTRACKMAXSTACKDEPTH
drh118ab652016-05-23 21:56:24 +0000652 if( (int)(yypParser->yytos - yypParser->yystack)>yypParser->yyhwm ){
653 yypParser->yyhwm++;
654 assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack) );
drhec424a52008-07-25 15:39:03 +0000655 }
656#endif
drhb19fd012007-03-29 01:44:45 +0000657#if YYSTACKDEPTH>0
drh8b471e72017-06-28 15:01:35 +0000658 if( yypParser->yytos>yypParser->yystackEnd ){
drh63413312016-12-06 17:59:05 +0000659 yypParser->yytos--;
drh45f31be2016-02-16 21:19:49 +0000660 yyStackOverflow(yypParser);
drha248a722015-09-07 19:52:55 +0000661 return;
drh75897232000-05-29 14:26:00 +0000662 }
drhb19fd012007-03-29 01:44:45 +0000663#else
drh118ab652016-05-23 21:56:24 +0000664 if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz] ){
drh8dc82472016-05-27 04:10:47 +0000665 if( yyGrowStack(yypParser) ){
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;
drhb19fd012007-03-29 01:44:45 +0000669 }
670 }
671#endif
drh0efd37f2016-06-06 18:17:36 +0000672 if( yyNewState > YY_MAX_SHIFT ){
673 yyNewState += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE;
674 }
drh118ab652016-05-23 21:56:24 +0000675 yytos = yypParser->yytos;
drhfd39c582018-04-21 22:40:08 +0000676 yytos->stateno = yyNewState;
677 yytos->major = yyMajor;
drh45f31be2016-02-16 21:19:49 +0000678 yytos->minor.yy0 = yyMinor;
drhe58f74f2017-12-24 17:06:41 +0000679 yyTraceShift(yypParser, yyNewState, "Shift");
drh75897232000-05-29 14:26:00 +0000680}
681
drhcfc45b12018-12-03 23:57:27 +0000682/* For rule J, yyRuleInfoLhs[J] contains the symbol on the left-hand side
683** of that rule */
684static const YYCODETYPE yyRuleInfoLhs[] = {
685%%
686};
687
688/* For rule J, yyRuleInfoNRhs[J] contains the negative of the number
689** of symbols on the right-hand side of that rule. */
690static const signed char yyRuleInfoNRhs[] = {
drh75897232000-05-29 14:26:00 +0000691%%
692};
693
drh1f245e42002-03-11 13:55:50 +0000694static void yy_accept(yyParser*); /* Forward Declaration */
drh75897232000-05-29 14:26:00 +0000695
696/*
697** Perform a reduce action and the shift that must immediately
698** follow the reduce.
drh087316c2017-12-15 12:22:21 +0000699**
700** The yyLookahead and yyLookaheadToken parameters provide reduce actions
701** access to the lookahead token (if any). The yyLookahead will be YYNOCODE
702** if the lookahead token has already been consumed. As this procedure is
703** only called from one place, optimizing compilers will in-line it, which
704** means that the extra parameters have no performance impact.
drh75897232000-05-29 14:26:00 +0000705*/
drhfd39c582018-04-21 22:40:08 +0000706static YYACTIONTYPE yy_reduce(
drh75897232000-05-29 14:26:00 +0000707 yyParser *yypParser, /* The parser */
drh087316c2017-12-15 12:22:21 +0000708 unsigned int yyruleno, /* Number of the rule by which to reduce */
709 int yyLookahead, /* Lookahead token, or YYNOCODE if none */
710 ParseTOKENTYPE yyLookaheadToken /* Value of the lookahead token */
drhfb32c442018-04-21 13:51:42 +0000711 ParseCTX_PDECL /* %extra_context */
drh75897232000-05-29 14:26:00 +0000712){
713 int yygoto; /* The next state */
mistachkin709c8222018-07-22 21:23:19 +0000714 YYACTIONTYPE yyact; /* The next action */
drh1f245e42002-03-11 13:55:50 +0000715 yyStackEntry *yymsp; /* The top of the parser's stack */
drh75897232000-05-29 14:26:00 +0000716 int yysize; /* Amount to pop the stack */
drhfb32c442018-04-21 13:51:42 +0000717 ParseARG_FETCH
drhb9685182018-01-17 13:15:23 +0000718 (void)yyLookahead;
719 (void)yyLookaheadToken;
drh118ab652016-05-23 21:56:24 +0000720 yymsp = yypParser->yytos;
drhcb6c5652007-01-16 18:19:12 +0000721
drh75897232000-05-29 14:26:00 +0000722 switch( yyruleno ){
723 /* Beginning here are the reduction cases. A typical example
724 ** follows:
725 ** case 0:
drh75897232000-05-29 14:26:00 +0000726 ** #line <lineno> <grammarfile>
727 ** { ... } // User supplied code
728 ** #line <lineno> <thisfile>
729 ** break;
730 */
drh82415f22015-11-09 19:33:42 +0000731/********** Begin reduce actions **********************************************/
drh75897232000-05-29 14:26:00 +0000732%%
drh82415f22015-11-09 19:33:42 +0000733/********** End reduce actions ************************************************/
drh75897232000-05-29 14:26:00 +0000734 };
drhcfc45b12018-12-03 23:57:27 +0000735 assert( yyruleno<sizeof(yyRuleInfoLhs)/sizeof(yyRuleInfoLhs[0]) );
736 yygoto = yyRuleInfoLhs[yyruleno];
737 yysize = yyRuleInfoNRhs[yyruleno];
drh6be95362017-06-28 13:47:56 +0000738 yyact = yy_find_reduce_action(yymsp[yysize].stateno,(YYCODETYPE)yygoto);
drhbd8fcc12017-06-28 11:56:18 +0000739
740 /* There are no SHIFTREDUCE actions on nonterminals because the table
741 ** generator has simplified them to pure REDUCE actions. */
742 assert( !(yyact>YY_MAX_SHIFT && yyact<=YY_MAX_SHIFTREDUCE) );
743
744 /* It is not possible for a REDUCE to be followed by an error */
745 assert( yyact!=YY_ERROR_ACTION );
746
drhef53a9f2017-12-25 00:10:05 +0000747 yymsp += yysize+1;
748 yypParser->yytos = yymsp;
749 yymsp->stateno = (YYACTIONTYPE)yyact;
750 yymsp->major = (YYCODETYPE)yygoto;
751 yyTraceShift(yypParser, yyact, "... then shift");
drhfd39c582018-04-21 22:40:08 +0000752 return yyact;
drh75897232000-05-29 14:26:00 +0000753}
754
755/*
756** The following code executes when the parse fails
757*/
drhd3ec02d2009-06-12 02:27:14 +0000758#ifndef YYNOERRORRECOVERY
drh75897232000-05-29 14:26:00 +0000759static void yy_parse_failed(
760 yyParser *yypParser /* The parser */
drh75897232000-05-29 14:26:00 +0000761){
drhfb32c442018-04-21 13:51:42 +0000762 ParseARG_FETCH
763 ParseCTX_FETCH
drh75897232000-05-29 14:26:00 +0000764#ifndef NDEBUG
765 if( yyTraceFILE ){
766 fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt);
767 }
768#endif
drhabecc0b2016-05-24 00:40:54 +0000769 while( yypParser->yytos>yypParser->yystack ) yy_pop_parser_stack(yypParser);
drh75897232000-05-29 14:26:00 +0000770 /* Here code is inserted which will be executed whenever the
771 ** parser fails */
drh82415f22015-11-09 19:33:42 +0000772/************ Begin %parse_failure code ***************************************/
drh75897232000-05-29 14:26:00 +0000773%%
drh82415f22015-11-09 19:33:42 +0000774/************ End %parse_failure code *****************************************/
drhfb32c442018-04-21 13:51:42 +0000775 ParseARG_STORE /* Suppress warning about unused %extra_argument variable */
776 ParseCTX_STORE
drh75897232000-05-29 14:26:00 +0000777}
drhd3ec02d2009-06-12 02:27:14 +0000778#endif /* YYNOERRORRECOVERY */
drh75897232000-05-29 14:26:00 +0000779
780/*
781** The following code executes when a syntax error first occurs.
782*/
783static void yy_syntax_error(
784 yyParser *yypParser, /* The parser */
785 int yymajor, /* The major type of the error token */
drh45f31be2016-02-16 21:19:49 +0000786 ParseTOKENTYPE yyminor /* The minor type of the error token */
drh75897232000-05-29 14:26:00 +0000787){
drhfb32c442018-04-21 13:51:42 +0000788 ParseARG_FETCH
789 ParseCTX_FETCH
drh45f31be2016-02-16 21:19:49 +0000790#define TOKEN yyminor
drh82415f22015-11-09 19:33:42 +0000791/************ Begin %syntax_error code ****************************************/
drh75897232000-05-29 14:26:00 +0000792%%
drh82415f22015-11-09 19:33:42 +0000793/************ End %syntax_error code ******************************************/
drhfb32c442018-04-21 13:51:42 +0000794 ParseARG_STORE /* Suppress warning about unused %extra_argument variable */
795 ParseCTX_STORE
drh75897232000-05-29 14:26:00 +0000796}
797
798/*
799** The following is executed when the parser accepts
800*/
801static void yy_accept(
802 yyParser *yypParser /* The parser */
drh75897232000-05-29 14:26:00 +0000803){
drhfb32c442018-04-21 13:51:42 +0000804 ParseARG_FETCH
805 ParseCTX_FETCH
drh75897232000-05-29 14:26:00 +0000806#ifndef NDEBUG
807 if( yyTraceFILE ){
808 fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt);
809 }
810#endif
drhdd703e22016-07-12 19:54:49 +0000811#ifndef YYNOERRORRECOVERY
812 yypParser->yyerrcnt = -1;
813#endif
drh756b41e2016-05-24 18:55:08 +0000814 assert( yypParser->yytos==yypParser->yystack );
drh75897232000-05-29 14:26:00 +0000815 /* Here code is inserted which will be executed whenever the
816 ** parser accepts */
drh82415f22015-11-09 19:33:42 +0000817/*********** Begin %parse_accept code *****************************************/
drh75897232000-05-29 14:26:00 +0000818%%
drh82415f22015-11-09 19:33:42 +0000819/*********** End %parse_accept code *******************************************/
drhfb32c442018-04-21 13:51:42 +0000820 ParseARG_STORE /* Suppress warning about unused %extra_argument variable */
821 ParseCTX_STORE
drh75897232000-05-29 14:26:00 +0000822}
823
824/* The main parser program.
825** The first argument is a pointer to a structure obtained from
826** "ParseAlloc" which describes the current state of the parser.
827** The second argument is the major token number. The third is
828** the minor token. The fourth optional argument is whatever the
829** user wants (and specified in the grammar) and is available for
830** use by the action routines.
831**
832** Inputs:
833** <ul>
834** <li> A pointer to the parser (an opaque structure.)
835** <li> The major token number.
836** <li> The minor token number.
837** <li> An option argument of a grammar-specified type.
838** </ul>
839**
840** Outputs:
841** None.
842*/
drh75897232000-05-29 14:26:00 +0000843void Parse(
844 void *yyp, /* The parser */
845 int yymajor, /* The major token code number */
846 ParseTOKENTYPE yyminor /* The value for the token */
drh1f245e42002-03-11 13:55:50 +0000847 ParseARG_PDECL /* Optional %extra_argument parameter */
drh75897232000-05-29 14:26:00 +0000848){
849 YYMINORTYPE yyminorunion;
drhfd39c582018-04-21 22:40:08 +0000850 YYACTIONTYPE yyact; /* The parser action. */
drha4414042015-11-09 15:06:26 +0000851#if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY)
drh75897232000-05-29 14:26:00 +0000852 int yyendofinput; /* True if we are at the end of input */
drha4414042015-11-09 15:06:26 +0000853#endif
drhc4dd3fd2008-01-22 01:48:05 +0000854#ifdef YYERRORSYMBOL
drh75897232000-05-29 14:26:00 +0000855 int yyerrorhit = 0; /* True if yymajor has invoked an error */
drhc4dd3fd2008-01-22 01:48:05 +0000856#endif
drhfb32c442018-04-21 13:51:42 +0000857 yyParser *yypParser = (yyParser*)yyp; /* The parser */
858 ParseCTX_FETCH
859 ParseARG_STORE
drh75897232000-05-29 14:26:00 +0000860
drhabecc0b2016-05-24 00:40:54 +0000861 assert( yypParser->yytos!=0 );
drha4414042015-11-09 15:06:26 +0000862#if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY)
drh75897232000-05-29 14:26:00 +0000863 yyendofinput = (yymajor==0);
drha4414042015-11-09 15:06:26 +0000864#endif
drh75897232000-05-29 14:26:00 +0000865
drhfd39c582018-04-21 22:40:08 +0000866 yyact = yypParser->yytos->stateno;
drh75897232000-05-29 14:26:00 +0000867#ifndef NDEBUG
868 if( yyTraceFILE ){
drhfd39c582018-04-21 22:40:08 +0000869 if( yyact < YY_MIN_REDUCE ){
drhe58f74f2017-12-24 17:06:41 +0000870 fprintf(yyTraceFILE,"%sInput '%s' in state %d\n",
drhfd39c582018-04-21 22:40:08 +0000871 yyTracePrompt,yyTokenName[yymajor],yyact);
drhe58f74f2017-12-24 17:06:41 +0000872 }else{
873 fprintf(yyTraceFILE,"%sInput '%s' with pending reduce %d\n",
drhfd39c582018-04-21 22:40:08 +0000874 yyTracePrompt,yyTokenName[yymajor],yyact-YY_MIN_REDUCE);
drhe58f74f2017-12-24 17:06:41 +0000875 }
drh75897232000-05-29 14:26:00 +0000876 }
877#endif
878
drhe81f8792021-01-02 23:56:37 +0000879 while(1){ /* Exit by "break" */
880 assert( yypParser->yytos>=yypParser->yystack );
drhfd39c582018-04-21 22:40:08 +0000881 assert( yyact==yypParser->yytos->stateno );
mistachkin709c8222018-07-22 21:23:19 +0000882 yyact = yy_find_shift_action((YYCODETYPE)yymajor,yyact);
drh5c8241b2017-12-24 23:38:10 +0000883 if( yyact >= YY_MIN_REDUCE ){
drhe81f8792021-01-02 23:56:37 +0000884 unsigned int yyruleno = yyact - YY_MIN_REDUCE; /* Reduce by this rule */
drhe81f8792021-01-02 23:56:37 +0000885#ifndef NDEBUG
drh4e86aa82021-11-09 01:48:15 +0000886 assert( yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) );
drhe81f8792021-01-02 23:56:37 +0000887 if( yyTraceFILE ){
888 int yysize = yyRuleInfoNRhs[yyruleno];
889 if( yysize ){
890 fprintf(yyTraceFILE, "%sReduce %d [%s]%s, pop back to state %d.\n",
891 yyTracePrompt,
892 yyruleno, yyRuleName[yyruleno],
893 yyruleno<YYNRULE_WITH_ACTION ? "" : " without external action",
894 yypParser->yytos[yysize].stateno);
895 }else{
896 fprintf(yyTraceFILE, "%sReduce %d [%s]%s.\n",
897 yyTracePrompt, yyruleno, yyRuleName[yyruleno],
898 yyruleno<YYNRULE_WITH_ACTION ? "" : " without external action");
899 }
900 }
901#endif /* NDEBUG */
902
903 /* Check that the stack is large enough to grow by a single entry
904 ** if the RHS of the rule is empty. This ensures that there is room
905 ** enough on the stack to push the LHS value */
906 if( yyRuleInfoNRhs[yyruleno]==0 ){
907#ifdef YYTRACKMAXSTACKDEPTH
908 if( (int)(yypParser->yytos - yypParser->yystack)>yypParser->yyhwm ){
909 yypParser->yyhwm++;
910 assert( yypParser->yyhwm ==
911 (int)(yypParser->yytos - yypParser->yystack));
912 }
913#endif
914#if YYSTACKDEPTH>0
915 if( yypParser->yytos>=yypParser->yystackEnd ){
916 yyStackOverflow(yypParser);
917 break;
918 }
919#else
920 if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz-1] ){
921 if( yyGrowStack(yypParser) ){
922 yyStackOverflow(yypParser);
923 break;
924 }
925 }
926#endif
927 }
928 yyact = yy_reduce(yypParser,yyruleno,yymajor,yyminor ParseCTX_PARAM);
drh5c8241b2017-12-24 23:38:10 +0000929 }else if( yyact <= YY_MAX_SHIFTREDUCE ){
mistachkin709c8222018-07-22 21:23:19 +0000930 yy_shift(yypParser,yyact,(YYCODETYPE)yymajor,yyminor);
drhdab943c2016-02-16 01:01:43 +0000931#ifndef YYNOERRORRECOVERY
drha248a722015-09-07 19:52:55 +0000932 yypParser->yyerrcnt--;
drhdab943c2016-02-16 01:01:43 +0000933#endif
drhfd39c582018-04-21 22:40:08 +0000934 break;
drhef53a9f2017-12-25 00:10:05 +0000935 }else if( yyact==YY_ACCEPT_ACTION ){
drh05ef50d2018-04-23 00:25:31 +0000936 yypParser->yytos--;
937 yy_accept(yypParser);
drhef53a9f2017-12-25 00:10:05 +0000938 return;
drhc4dd3fd2008-01-22 01:48:05 +0000939 }else{
940 assert( yyact == YY_ERROR_ACTION );
drh45f31be2016-02-16 21:19:49 +0000941 yyminorunion.yy0 = yyminor;
drhc4dd3fd2008-01-22 01:48:05 +0000942#ifdef YYERRORSYMBOL
drh3ddfdf72003-12-22 14:53:19 +0000943 int yymx;
drhc4dd3fd2008-01-22 01:48:05 +0000944#endif
drh75897232000-05-29 14:26:00 +0000945#ifndef NDEBUG
946 if( yyTraceFILE ){
947 fprintf(yyTraceFILE,"%sSyntax Error!\n",yyTracePrompt);
948 }
949#endif
950#ifdef YYERRORSYMBOL
951 /* A syntax error has occurred.
952 ** The response to an error depends upon whether or not the
953 ** grammar defines an error token "ERROR".
954 **
955 ** This is what we do if the grammar does define ERROR:
956 **
957 ** * Call the %syntax_error function.
958 **
959 ** * Begin popping the stack until we enter a state where
960 ** it is legal to shift the error symbol, then shift
961 ** the error symbol.
962 **
963 ** * Set the error count to three.
964 **
965 ** * Begin accepting and shifting new tokens. No new error
966 ** processing will occur until three tokens have been
967 ** shifted successfully.
968 **
969 */
drh1f245e42002-03-11 13:55:50 +0000970 if( yypParser->yyerrcnt<0 ){
drh45f31be2016-02-16 21:19:49 +0000971 yy_syntax_error(yypParser,yymajor,yyminor);
drh75897232000-05-29 14:26:00 +0000972 }
drh118ab652016-05-23 21:56:24 +0000973 yymx = yypParser->yytos->major;
drh3ddfdf72003-12-22 14:53:19 +0000974 if( yymx==YYERRORSYMBOL || yyerrorhit ){
drh75897232000-05-29 14:26:00 +0000975#ifndef NDEBUG
976 if( yyTraceFILE ){
977 fprintf(yyTraceFILE,"%sDiscard input token %s\n",
978 yyTracePrompt,yyTokenName[yymajor]);
979 }
980#endif
drh45f31be2016-02-16 21:19:49 +0000981 yy_destructor(yypParser, (YYCODETYPE)yymajor, &yyminorunion);
drh75897232000-05-29 14:26:00 +0000982 yymajor = YYNOCODE;
983 }else{
drh8eaf6c62021-08-20 19:51:22 +0000984 while( yypParser->yytos > yypParser->yystack ){
985 yyact = yy_find_reduce_action(yypParser->yytos->stateno,
986 YYERRORSYMBOL);
987 if( yyact<=YY_MAX_SHIFTREDUCE ) break;
drh75897232000-05-29 14:26:00 +0000988 yy_pop_parser_stack(yypParser);
989 }
drhd519bbd2021-08-17 19:59:09 +0000990 if( yypParser->yytos <= yypParser->yystack || yymajor==0 ){
drhb27b7f52008-12-10 18:03:45 +0000991 yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
drh1f245e42002-03-11 13:55:50 +0000992 yy_parse_failed(yypParser);
drh240c7fa2016-07-05 12:47:28 +0000993#ifndef YYNOERRORRECOVERY
994 yypParser->yyerrcnt = -1;
995#endif
drh75897232000-05-29 14:26:00 +0000996 yymajor = YYNOCODE;
drh3ddfdf72003-12-22 14:53:19 +0000997 }else if( yymx!=YYERRORSYMBOL ){
drh45f31be2016-02-16 21:19:49 +0000998 yy_shift(yypParser,yyact,YYERRORSYMBOL,yyminor);
drh75897232000-05-29 14:26:00 +0000999 }
1000 }
drh1f245e42002-03-11 13:55:50 +00001001 yypParser->yyerrcnt = 3;
drh75897232000-05-29 14:26:00 +00001002 yyerrorhit = 1;
drhfd39c582018-04-21 22:40:08 +00001003 if( yymajor==YYNOCODE ) break;
1004 yyact = yypParser->yytos->stateno;
drhd3ec02d2009-06-12 02:27:14 +00001005#elif defined(YYNOERRORRECOVERY)
1006 /* If the YYNOERRORRECOVERY macro is defined, then do not attempt to
1007 ** do any kind of error recovery. Instead, simply invoke the syntax
1008 ** error routine and continue going as if nothing had happened.
1009 **
1010 ** Applications can set this macro (for example inside %include) if
1011 ** they intend to abandon the parse upon the first syntax error seen.
1012 */
drh45f31be2016-02-16 21:19:49 +00001013 yy_syntax_error(yypParser,yymajor, yyminor);
drhd3ec02d2009-06-12 02:27:14 +00001014 yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
drhfd39c582018-04-21 22:40:08 +00001015 break;
drh75897232000-05-29 14:26:00 +00001016#else /* YYERRORSYMBOL is not defined */
1017 /* This is what we do if the grammar does not define ERROR:
1018 **
1019 ** * Report an error message, and throw away the input token.
1020 **
1021 ** * If the input token is $, then fail the parse.
1022 **
1023 ** As before, subsequent error messages are suppressed until
1024 ** three input tokens have been successfully shifted.
1025 */
drh1f245e42002-03-11 13:55:50 +00001026 if( yypParser->yyerrcnt<=0 ){
drh45f31be2016-02-16 21:19:49 +00001027 yy_syntax_error(yypParser,yymajor, yyminor);
drh75897232000-05-29 14:26:00 +00001028 }
drh1f245e42002-03-11 13:55:50 +00001029 yypParser->yyerrcnt = 3;
drhb27b7f52008-12-10 18:03:45 +00001030 yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
drh75897232000-05-29 14:26:00 +00001031 if( yyendofinput ){
drh1f245e42002-03-11 13:55:50 +00001032 yy_parse_failed(yypParser);
drhd3d4b3c2016-07-08 19:54:38 +00001033#ifndef YYNOERRORRECOVERY
1034 yypParser->yyerrcnt = -1;
1035#endif
drh75897232000-05-29 14:26:00 +00001036 }
drhfd39c582018-04-21 22:40:08 +00001037 break;
drh75897232000-05-29 14:26:00 +00001038#endif
drh75897232000-05-29 14:26:00 +00001039 }
drhe81f8792021-01-02 23:56:37 +00001040 }
drh3bd48ab2015-09-07 18:23:37 +00001041#ifndef NDEBUG
1042 if( yyTraceFILE ){
drh118ab652016-05-23 21:56:24 +00001043 yyStackEntry *i;
1044 char cDiv = '[';
drh0c4105e2015-11-10 14:51:22 +00001045 fprintf(yyTraceFILE,"%sReturn. Stack=",yyTracePrompt);
drh118ab652016-05-23 21:56:24 +00001046 for(i=&yypParser->yystack[1]; i<=yypParser->yytos; i++){
1047 fprintf(yyTraceFILE,"%c%s", cDiv, yyTokenName[i->major]);
1048 cDiv = ' ';
1049 }
drh0c4105e2015-11-10 14:51:22 +00001050 fprintf(yyTraceFILE,"]\n");
drh3bd48ab2015-09-07 18:23:37 +00001051 }
1052#endif
drh75897232000-05-29 14:26:00 +00001053 return;
1054}
dan59ff4252018-06-29 17:44:52 +00001055
1056/*
1057** Return the fallback token corresponding to canonical token iToken, or
1058** 0 if iToken has no fallback.
1059*/
1060int ParseFallback(int iToken){
1061#ifdef YYFALLBACK
drh6ee3fa82019-08-28 11:49:45 +00001062 assert( iToken<(int)(sizeof(yyFallback)/sizeof(yyFallback[0])) );
1063 return yyFallback[iToken];
drhc7bf5712018-07-09 22:49:01 +00001064#else
1065 (void)iToken;
dan59ff4252018-06-29 17:44:52 +00001066 return 0;
drh276d7f72019-10-21 16:15:57 +00001067#endif
dan59ff4252018-06-29 17:44:52 +00001068}