blob: 9164eb0c1e94a4776be17c23f404aadb203f2e7a [file] [log] [blame]
drh82415f22015-11-09 19:33:42 +00001/*
2** 2000-05-29
drh75897232000-05-29 14:26:00 +00003**
drh82415f22015-11-09 19:33:42 +00004** The author disclaims copyright to this source code. In place of
5** a legal notice, here is a blessing:
6**
7** May you do good and not evil.
8** May you find forgiveness for yourself and forgive others.
9** May you share freely, never taking more than you give.
10**
11*************************************************************************
12** Driver template for the LEMON parser generator.
13**
14** The "lemon" program processes an LALR(1) input grammar file, then uses
15** this template to construct a parser. The "lemon" program inserts text
16** at each "%%" line. Also, any "P-a-r-s-e" identifer prefix (without the
17** interstitial "-" characters) contained in this template is changed into
18** the value of the %name directive from the grammar. Otherwise, the content
19** of this template is copied straight through into the generate parser
20** source file.
21**
22** The following is the concatenation of all %include directives from the
23** input grammar file:
drh75897232000-05-29 14:26:00 +000024*/
drh82415f22015-11-09 19:33:42 +000025#include <stdio.h>
26/************ Begin %include sections from the grammar ************************/
drh75897232000-05-29 14:26:00 +000027%%
drh82415f22015-11-09 19:33:42 +000028/**************** End of %include directives **********************************/
29/* These constants specify the various numeric values for terminal symbols
30** in a format understandable to "makeheaders". This section is blank unless
31** "lemon" is run with the "-m" command-line option.
32***************** Begin makeheaders token definitions *************************/
33%%
34/**************** End makeheaders token definitions ***************************/
drh822a62f2015-11-09 19:35:18 +000035
36/* The next sections is a series of control #defines.
drh75897232000-05-29 14:26:00 +000037** various aspects of the generated parser.
drh82415f22015-11-09 19:33:42 +000038** YYCODETYPE is the data type used to store the integer codes
39** that represent terminal and non-terminal symbols.
40** "unsigned char" is used if there are fewer than
41** 256 symbols. Larger types otherwise.
42** YYNOCODE is a number of type YYCODETYPE that is not used for
43** any terminal or nonterminal symbol.
drh0bd1f4e2002-06-06 18:54:39 +000044** YYFALLBACK If defined, this indicates that one or more tokens
drh82415f22015-11-09 19:33:42 +000045** (also known as: "terminal symbols") have fall-back
46** values which should be used if the original symbol
47** would not parse. This permits keywords to sometimes
48** be used as identifiers, for example.
49** YYACTIONTYPE is the data type used for "action codes" - numbers
50** that indicate what to do in response to the next
51** token.
52** ParseTOKENTYPE is the data type used for minor type for terminal
53** symbols. Background: A "minor type" is a semantic
54** value associated with a terminal or non-terminal
55** symbols. For example, for an "ID" terminal symbol,
56** the minor type might be the name of the identifier.
57** Each non-terminal can have a different minor type.
58** Terminal symbols all have the same minor type, though.
59** This macros defines the minor type for terminal
60** symbols.
61** YYMINORTYPE is the data type used for all minor types.
drh75897232000-05-29 14:26:00 +000062** This is typically a union of many types, one of
63** which is ParseTOKENTYPE. The entry in the union
drh82415f22015-11-09 19:33:42 +000064** for terminal symbols is called "yy0".
drhb19fd012007-03-29 01:44:45 +000065** YYSTACKDEPTH is the maximum depth of the parser's stack. If
66** zero the stack is dynamically sized using realloc()
drh1f245e42002-03-11 13:55:50 +000067** ParseARG_SDECL A static variable declaration for the %extra_argument
68** ParseARG_PDECL A parameter declaration for the %extra_argument
69** ParseARG_STORE Code to store %extra_argument into yypParser
70** ParseARG_FETCH Code to extract %extra_argument from yypParser
drh75897232000-05-29 14:26:00 +000071** YYERRORSYMBOL is the code number of the error symbol. If not
72** defined, then do no error processing.
drh3bd48ab2015-09-07 18:23:37 +000073** YYNSTATE the combined number of states.
74** YYNRULE the number of rules in the grammar
drh0d9de992017-12-26 18:04:23 +000075** YYNTOKEN Number of terminal symbols
drh3bd48ab2015-09-07 18:23:37 +000076** YY_MAX_SHIFT Maximum value for shift actions
77** YY_MIN_SHIFTREDUCE Minimum value for shift-reduce actions
78** YY_MAX_SHIFTREDUCE Maximum value for shift-reduce actions
drh3bd48ab2015-09-07 18:23:37 +000079** YY_ERROR_ACTION The yy_action[] code for syntax error
80** YY_ACCEPT_ACTION The yy_action[] code for accept
81** YY_NO_ACTION The yy_action[] code for no-op
drh5c8241b2017-12-24 23:38:10 +000082** YY_MIN_REDUCE Minimum value for reduce actions
83** YY_MAX_REDUCE Maximum value for reduce actions
drh75897232000-05-29 14:26:00 +000084*/
drh82415f22015-11-09 19:33:42 +000085#ifndef INTERFACE
86# define INTERFACE 1
87#endif
88/************* Begin control #defines *****************************************/
drh75897232000-05-29 14:26:00 +000089%%
drh82415f22015-11-09 19:33:42 +000090/************* End control #defines *******************************************/
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 */
drhb19fd012007-03-29 01:44:45 +0000214#if YYSTACKDEPTH<=0
215 int yystksz; /* Current side of the stack */
216 yyStackEntry *yystack; /* The parser's stack */
drh8dc82472016-05-27 04:10:47 +0000217 yyStackEntry yystk0; /* First stack entry */
drhb19fd012007-03-29 01:44:45 +0000218#else
drh1f245e42002-03-11 13:55:50 +0000219 yyStackEntry yystack[YYSTACKDEPTH]; /* The parser's stack */
drh8b471e72017-06-28 15:01:35 +0000220 yyStackEntry *yystackEnd; /* Last entry in the stack */
drhb19fd012007-03-29 01:44:45 +0000221#endif
drh75897232000-05-29 14:26:00 +0000222};
223typedef struct yyParser yyParser;
224
225#ifndef NDEBUG
226#include <stdio.h>
227static FILE *yyTraceFILE = 0;
228static char *yyTracePrompt = 0;
drh0bd1f4e2002-06-06 18:54:39 +0000229#endif /* NDEBUG */
drh75897232000-05-29 14:26:00 +0000230
drh0bd1f4e2002-06-06 18:54:39 +0000231#ifndef NDEBUG
drh75897232000-05-29 14:26:00 +0000232/*
233** Turn parser tracing on by giving a stream to which to write the trace
234** and a prompt to preface each trace message. Tracing is turned off
235** by making either argument NULL
236**
237** Inputs:
238** <ul>
239** <li> A FILE* to which trace output should be written.
240** If NULL, then tracing is turned off.
241** <li> A prefix string written at the beginning of every
242** line of trace output. If NULL, then tracing is
243** turned off.
244** </ul>
245**
246** Outputs:
247** None.
248*/
drh75897232000-05-29 14:26:00 +0000249void ParseTrace(FILE *TraceFILE, char *zTracePrompt){
250 yyTraceFILE = TraceFILE;
251 yyTracePrompt = zTracePrompt;
252 if( yyTraceFILE==0 ) yyTracePrompt = 0;
253 else if( yyTracePrompt==0 ) yyTraceFILE = 0;
254}
drh0bd1f4e2002-06-06 18:54:39 +0000255#endif /* NDEBUG */
drh75897232000-05-29 14:26:00 +0000256
drh0d9de992017-12-26 18:04:23 +0000257#if defined(YYCOVERAGE) || !defined(NDEBUG)
drh75897232000-05-29 14:26:00 +0000258/* For tracing shifts, the names of all terminals and nonterminals
259** are required. The following table supplies these names */
drh57196282004-10-06 15:41:16 +0000260static const char *const yyTokenName[] = {
drh75897232000-05-29 14:26:00 +0000261%%
262};
drh0d9de992017-12-26 18:04:23 +0000263#endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */
drh75897232000-05-29 14:26:00 +0000264
drh0bd1f4e2002-06-06 18:54:39 +0000265#ifndef NDEBUG
266/* For tracing reduce actions, the names of all rules are required.
267*/
drh57196282004-10-06 15:41:16 +0000268static const char *const yyRuleName[] = {
drh0bd1f4e2002-06-06 18:54:39 +0000269%%
270};
271#endif /* NDEBUG */
drha1b351a2001-09-14 16:42:12 +0000272
drh960e8c62001-04-03 16:53:21 +0000273
drhb19fd012007-03-29 01:44:45 +0000274#if YYSTACKDEPTH<=0
275/*
drh8dc82472016-05-27 04:10:47 +0000276** Try to increase the size of the parser stack. Return the number
277** of errors. Return 0 on success.
drhb19fd012007-03-29 01:44:45 +0000278*/
drh8dc82472016-05-27 04:10:47 +0000279static int yyGrowStack(yyParser *p){
drhb19fd012007-03-29 01:44:45 +0000280 int newSize;
drhabecc0b2016-05-24 00:40:54 +0000281 int idx;
drhb19fd012007-03-29 01:44:45 +0000282 yyStackEntry *pNew;
283
284 newSize = p->yystksz*2 + 100;
drhabecc0b2016-05-24 00:40:54 +0000285 idx = p->yytos ? (int)(p->yytos - p->yystack) : 0;
drh8dc82472016-05-27 04:10:47 +0000286 if( p->yystack==&p->yystk0 ){
287 pNew = malloc(newSize*sizeof(pNew[0]));
288 if( pNew ) pNew[0] = p->yystk0;
289 }else{
290 pNew = realloc(p->yystack, newSize*sizeof(pNew[0]));
291 }
drhb19fd012007-03-29 01:44:45 +0000292 if( pNew ){
293 p->yystack = pNew;
drhabecc0b2016-05-24 00:40:54 +0000294 p->yytos = &p->yystack[idx];
drhb19fd012007-03-29 01:44:45 +0000295#ifndef NDEBUG
296 if( yyTraceFILE ){
drh8dc82472016-05-27 04:10:47 +0000297 fprintf(yyTraceFILE,"%sStack grows from %d to %d entries.\n",
298 yyTracePrompt, p->yystksz, newSize);
drhb19fd012007-03-29 01:44:45 +0000299 }
300#endif
drh8dc82472016-05-27 04:10:47 +0000301 p->yystksz = newSize;
drhb19fd012007-03-29 01:44:45 +0000302 }
drh8dc82472016-05-27 04:10:47 +0000303 return pNew==0;
drhb19fd012007-03-29 01:44:45 +0000304}
305#endif
306
drh82415f22015-11-09 19:33:42 +0000307/* Datatype of the argument to the memory allocated passed as the
308** second argument to ParseAlloc() below. This can be changed by
309** putting an appropriate #define in the %include section of the input
310** grammar.
311*/
312#ifndef YYMALLOCARGTYPE
313# define YYMALLOCARGTYPE size_t
314#endif
315
drhd26cc542017-01-28 20:46:37 +0000316/* Initialize a new parser that has already been allocated.
317*/
318void ParseInit(void *yypParser){
319 yyParser *pParser = (yyParser*)yypParser;
320#ifdef YYTRACKMAXSTACKDEPTH
321 pParser->yyhwm = 0;
322#endif
323#if YYSTACKDEPTH<=0
324 pParser->yytos = NULL;
325 pParser->yystack = NULL;
326 pParser->yystksz = 0;
327 if( yyGrowStack(pParser) ){
328 pParser->yystack = &pParser->yystk0;
329 pParser->yystksz = 1;
330 }
331#endif
332#ifndef YYNOERRORRECOVERY
333 pParser->yyerrcnt = -1;
334#endif
335 pParser->yytos = pParser->yystack;
336 pParser->yystack[0].stateno = 0;
337 pParser->yystack[0].major = 0;
drh92395c52017-07-04 12:50:00 +0000338#if YYSTACKDEPTH>0
drh8b471e72017-06-28 15:01:35 +0000339 pParser->yystackEnd = &pParser->yystack[YYSTACKDEPTH-1];
drh92395c52017-07-04 12:50:00 +0000340#endif
drhd26cc542017-01-28 20:46:37 +0000341}
342
343#ifndef Parse_ENGINEALWAYSONSTACK
drh75897232000-05-29 14:26:00 +0000344/*
345** This function allocates a new parser.
346** The only argument is a pointer to a function which works like
347** malloc.
348**
349** Inputs:
350** A pointer to the function used to allocate memory.
351**
352** Outputs:
353** A pointer to a parser. This pointer is used in subsequent calls
354** to Parse and ParseFree.
355*/
drh82415f22015-11-09 19:33:42 +0000356void *ParseAlloc(void *(*mallocProc)(YYMALLOCARGTYPE)){
drh75897232000-05-29 14:26:00 +0000357 yyParser *pParser;
drh82415f22015-11-09 19:33:42 +0000358 pParser = (yyParser*)(*mallocProc)( (YYMALLOCARGTYPE)sizeof(yyParser) );
drhd26cc542017-01-28 20:46:37 +0000359 if( pParser ) ParseInit(pParser);
drh75897232000-05-29 14:26:00 +0000360 return pParser;
361}
drhd26cc542017-01-28 20:46:37 +0000362#endif /* Parse_ENGINEALWAYSONSTACK */
363
drh75897232000-05-29 14:26:00 +0000364
drh82415f22015-11-09 19:33:42 +0000365/* The following function deletes the "minor type" or semantic value
366** associated with a symbol. The symbol can be either a terminal
367** or nonterminal. "yymajor" is the symbol code, and "yypminor" is
368** a pointer to the value to be deleted. The code used to do the
369** deletions is derived from the %destructor and/or %token_destructor
370** directives of the input grammar.
drh75897232000-05-29 14:26:00 +0000371*/
drh633e6d52008-07-28 19:34:53 +0000372static void yy_destructor(
373 yyParser *yypParser, /* The parser */
374 YYCODETYPE yymajor, /* Type code for object to destroy */
375 YYMINORTYPE *yypminor /* The object to be destroyed */
376){
377 ParseARG_FETCH;
drh75897232000-05-29 14:26:00 +0000378 switch( yymajor ){
379 /* Here is inserted the actions which take place when a
380 ** terminal or non-terminal is destroyed. This can happen
381 ** when the symbol is popped from the stack during a
382 ** reduce or during error processing or when a parser is
383 ** being destroyed before it is finished parsing.
384 **
385 ** Note: during a reduce, the only symbols destroyed are those
drh82415f22015-11-09 19:33:42 +0000386 ** which appear on the RHS of the rule, but which are *not* used
drh75897232000-05-29 14:26:00 +0000387 ** inside the C code.
388 */
drh82415f22015-11-09 19:33:42 +0000389/********* Begin destructor definitions ***************************************/
drh75897232000-05-29 14:26:00 +0000390%%
drh82415f22015-11-09 19:33:42 +0000391/********* End destructor definitions *****************************************/
drh75897232000-05-29 14:26:00 +0000392 default: break; /* If no destructor action specified: do nothing */
393 }
394}
395
396/*
397** Pop the parser's stack once.
398**
399** If there is a destructor routine associated with the token which
400** is popped from the stack, then call it.
drh75897232000-05-29 14:26:00 +0000401*/
drh3781f012015-11-09 14:11:37 +0000402static void yy_pop_parser_stack(yyParser *pParser){
403 yyStackEntry *yytos;
drh118ab652016-05-23 21:56:24 +0000404 assert( pParser->yytos!=0 );
drh240c7fa2016-07-05 12:47:28 +0000405 assert( pParser->yytos > pParser->yystack );
drh118ab652016-05-23 21:56:24 +0000406 yytos = pParser->yytos--;
drh75897232000-05-29 14:26:00 +0000407#ifndef NDEBUG
drh3781f012015-11-09 14:11:37 +0000408 if( yyTraceFILE ){
drh75897232000-05-29 14:26:00 +0000409 fprintf(yyTraceFILE,"%sPopping %s\n",
410 yyTracePrompt,
drh3ddfdf72003-12-22 14:53:19 +0000411 yyTokenName[yytos->major]);
drh75897232000-05-29 14:26:00 +0000412 }
413#endif
drh3781f012015-11-09 14:11:37 +0000414 yy_destructor(pParser, yytos->major, &yytos->minor);
drh75897232000-05-29 14:26:00 +0000415}
416
drhd26cc542017-01-28 20:46:37 +0000417/*
418** Clear all secondary memory allocations from the parser
419*/
420void ParseFinalize(void *p){
421 yyParser *pParser = (yyParser*)p;
422 while( pParser->yytos>pParser->yystack ) yy_pop_parser_stack(pParser);
423#if YYSTACKDEPTH<=0
424 if( pParser->yystack!=&pParser->yystk0 ) free(pParser->yystack);
425#endif
426}
427
428#ifndef Parse_ENGINEALWAYSONSTACK
drh75897232000-05-29 14:26:00 +0000429/*
drh82415f22015-11-09 19:33:42 +0000430** Deallocate and destroy a parser. Destructors are called for
drh75897232000-05-29 14:26:00 +0000431** all stack elements before shutting the parser down.
432**
drh82415f22015-11-09 19:33:42 +0000433** If the YYPARSEFREENEVERNULL macro exists (for example because it
434** is defined in a %include section of the input grammar) then it is
435** assumed that the input pointer is never NULL.
drh75897232000-05-29 14:26:00 +0000436*/
drh75897232000-05-29 14:26:00 +0000437void ParseFree(
drh960e8c62001-04-03 16:53:21 +0000438 void *p, /* The parser to be deleted */
439 void (*freeProc)(void*) /* Function used to reclaim memory */
drh75897232000-05-29 14:26:00 +0000440){
drh82415f22015-11-09 19:33:42 +0000441#ifndef YYPARSEFREENEVERNULL
drhd26cc542017-01-28 20:46:37 +0000442 if( p==0 ) return;
drh82415f22015-11-09 19:33:42 +0000443#endif
drhd26cc542017-01-28 20:46:37 +0000444 ParseFinalize(p);
445 (*freeProc)(p);
drh75897232000-05-29 14:26:00 +0000446}
drhd26cc542017-01-28 20:46:37 +0000447#endif /* Parse_ENGINEALWAYSONSTACK */
drh75897232000-05-29 14:26:00 +0000448
449/*
drhec424a52008-07-25 15:39:03 +0000450** Return the peak depth of the stack for a parser.
451*/
452#ifdef YYTRACKMAXSTACKDEPTH
453int ParseStackPeak(void *p){
454 yyParser *pParser = (yyParser*)p;
drh118ab652016-05-23 21:56:24 +0000455 return pParser->yyhwm;
drhec424a52008-07-25 15:39:03 +0000456}
457#endif
458
drh0d9de992017-12-26 18:04:23 +0000459/* This array of booleans keeps track of the parser statement
460** coverage. The element yycoverage[X][Y] is set when the parser
461** is in state X and has a lookahead token Y. In a well-tested
462** systems, every element of this matrix should end up being set.
463*/
464#if defined(YYCOVERAGE)
465static unsigned char yycoverage[YYNSTATE][YYNTOKEN];
466#endif
467
468/*
469** Write into out a description of every state/lookahead combination that
drh7038a992017-12-27 17:14:50 +0000470**
471** (1) has not been used by the parser, and
472** (2) is not a syntax error.
473**
474** Return the number of missed state/lookahead combinations.
drh0d9de992017-12-26 18:04:23 +0000475*/
476#if defined(YYCOVERAGE)
477int ParseCoverage(FILE *out){
drh7038a992017-12-27 17:14:50 +0000478 int stateno, iLookAhead, i;
drh0d9de992017-12-26 18:04:23 +0000479 int nMissed = 0;
drh7038a992017-12-27 17:14:50 +0000480 for(stateno=0; stateno<YYNSTATE; stateno++){
481 i = yy_shift_ofst[stateno];
482 for(iLookAhead=0; iLookAhead<YYNTOKEN; iLookAhead++){
drhcf8e0e92017-12-27 17:36:58 +0000483 if( yy_lookahead[i+iLookAhead]!=iLookAhead ) continue;
drh7038a992017-12-27 17:14:50 +0000484 if( yycoverage[stateno][iLookAhead]==0 ) nMissed++;
drh22716cb2017-12-26 18:32:06 +0000485 if( out ){
drh7038a992017-12-27 17:14:50 +0000486 fprintf(out,"State %d lookahead %s %s\n", stateno,
487 yyTokenName[iLookAhead],
488 yycoverage[stateno][iLookAhead] ? "ok" : "missed");
drh22716cb2017-12-26 18:32:06 +0000489 }
drh0d9de992017-12-26 18:04:23 +0000490 }
491 }
492 return nMissed;
493}
494#endif
495
drhec424a52008-07-25 15:39:03 +0000496/*
drh8b582012003-10-21 13:16:03 +0000497** Find the appropriate action for a parser given the terminal
498** look-ahead token iLookAhead.
drh75897232000-05-29 14:26:00 +0000499*/
drh4ef07702016-03-16 19:45:54 +0000500static unsigned int yy_find_shift_action(
drh75897232000-05-29 14:26:00 +0000501 yyParser *pParser, /* The parser */
drhd9f291e2006-06-13 11:15:47 +0000502 YYCODETYPE iLookAhead /* The look-ahead token */
drh75897232000-05-29 14:26:00 +0000503){
drh8b582012003-10-21 13:16:03 +0000504 int i;
drh118ab652016-05-23 21:56:24 +0000505 int stateno = pParser->yytos->stateno;
drha4414042015-11-09 15:06:26 +0000506
drhef53a9f2017-12-25 00:10:05 +0000507 if( stateno>YY_MAX_SHIFT ) return stateno;
drhae2a4082015-09-07 20:02:39 +0000508 assert( stateno <= YY_SHIFT_COUNT );
drh0d9de992017-12-26 18:04:23 +0000509#if defined(YYCOVERAGE)
510 yycoverage[stateno][iLookAhead] = 1;
511#endif
drha4414042015-11-09 15:06:26 +0000512 do{
513 i = yy_shift_ofst[stateno];
drh7038a992017-12-27 17:14:50 +0000514 assert( i>=0 && i+YYNTOKEN<=sizeof(yy_lookahead)/sizeof(yy_lookahead[0]) );
drha4414042015-11-09 15:06:26 +0000515 assert( iLookAhead!=YYNOCODE );
drh7038a992017-12-27 17:14:50 +0000516 assert( iLookAhead < YYNTOKEN );
drha4414042015-11-09 15:06:26 +0000517 i += iLookAhead;
drh3a9d6c72017-12-25 04:15:38 +0000518 if( yy_lookahead[i]!=iLookAhead ){
drh4767d972006-06-14 15:03:49 +0000519#ifdef YYFALLBACK
drhc83db9e2016-08-10 01:43:30 +0000520 YYCODETYPE iFallback; /* Fallback token */
521 if( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0])
522 && (iFallback = yyFallback[iLookAhead])!=0 ){
drh4767d972006-06-14 15:03:49 +0000523#ifndef NDEBUG
drhc83db9e2016-08-10 01:43:30 +0000524 if( yyTraceFILE ){
525 fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n",
526 yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]);
drhe09daa92006-06-10 13:29:31 +0000527 }
drha4414042015-11-09 15:06:26 +0000528#endif
drhc83db9e2016-08-10 01:43:30 +0000529 assert( yyFallback[iFallback]==0 ); /* Fallback loop must terminate */
530 iLookAhead = iFallback;
531 continue;
532 }
533#endif
drha4414042015-11-09 15:06:26 +0000534#ifdef YYWILDCARD
drhc83db9e2016-08-10 01:43:30 +0000535 {
536 int j = i - iLookAhead + YYWILDCARD;
537 if(
drha4414042015-11-09 15:06:26 +0000538#if YY_SHIFT_MIN+YYWILDCARD<0
drhc83db9e2016-08-10 01:43:30 +0000539 j>=0 &&
drha4414042015-11-09 15:06:26 +0000540#endif
541#if YY_SHIFT_MAX+YYWILDCARD>=YY_ACTTAB_COUNT
drhc83db9e2016-08-10 01:43:30 +0000542 j<YY_ACTTAB_COUNT &&
drha4414042015-11-09 15:06:26 +0000543#endif
drhc83db9e2016-08-10 01:43:30 +0000544 yy_lookahead[j]==YYWILDCARD && iLookAhead>0
545 ){
drha4414042015-11-09 15:06:26 +0000546#ifndef NDEBUG
drhc83db9e2016-08-10 01:43:30 +0000547 if( yyTraceFILE ){
548 fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n",
549 yyTracePrompt, yyTokenName[iLookAhead],
550 yyTokenName[YYWILDCARD]);
drha4414042015-11-09 15:06:26 +0000551 }
drhc83db9e2016-08-10 01:43:30 +0000552#endif /* NDEBUG */
553 return yy_action[j];
drha4414042015-11-09 15:06:26 +0000554 }
drha4414042015-11-09 15:06:26 +0000555 }
drhc83db9e2016-08-10 01:43:30 +0000556#endif /* YYWILDCARD */
drha4414042015-11-09 15:06:26 +0000557 return yy_default[stateno];
558 }else{
559 return yy_action[i];
drh0bd1f4e2002-06-06 18:54:39 +0000560 }
drha4414042015-11-09 15:06:26 +0000561 }while(1);
drh8b582012003-10-21 13:16:03 +0000562}
563
564/*
565** Find the appropriate action for a parser given the non-terminal
566** look-ahead token iLookAhead.
drh8b582012003-10-21 13:16:03 +0000567*/
568static int yy_find_reduce_action(
drh161aba32005-02-01 04:09:36 +0000569 int stateno, /* Current state number */
drhd9f291e2006-06-13 11:15:47 +0000570 YYCODETYPE iLookAhead /* The look-ahead token */
drh8b582012003-10-21 13:16:03 +0000571){
572 int i;
drh7f7c2572008-04-27 18:45:10 +0000573#ifdef YYERRORSYMBOL
drhf16371d2009-11-03 19:18:31 +0000574 if( stateno>YY_REDUCE_COUNT ){
drh7f7c2572008-04-27 18:45:10 +0000575 return yy_default[stateno];
576 }
577#else
drhf16371d2009-11-03 19:18:31 +0000578 assert( stateno<=YY_REDUCE_COUNT );
drh7f7c2572008-04-27 18:45:10 +0000579#endif
drh01495b92008-01-23 12:52:40 +0000580 i = yy_reduce_ofst[stateno];
drh01495b92008-01-23 12:52:40 +0000581 assert( iLookAhead!=YYNOCODE );
drh8b582012003-10-21 13:16:03 +0000582 i += iLookAhead;
drh7f7c2572008-04-27 18:45:10 +0000583#ifdef YYERRORSYMBOL
drhf16371d2009-11-03 19:18:31 +0000584 if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){
drh7f7c2572008-04-27 18:45:10 +0000585 return yy_default[stateno];
586 }
587#else
drhf16371d2009-11-03 19:18:31 +0000588 assert( i>=0 && i<YY_ACTTAB_COUNT );
drh01495b92008-01-23 12:52:40 +0000589 assert( yy_lookahead[i]==iLookAhead );
drh7f7c2572008-04-27 18:45:10 +0000590#endif
drh01495b92008-01-23 12:52:40 +0000591 return yy_action[i];
drh75897232000-05-29 14:26:00 +0000592}
593
594/*
drhb19fd012007-03-29 01:44:45 +0000595** The following routine is called if the stack overflows.
596*/
drh45f31be2016-02-16 21:19:49 +0000597static void yyStackOverflow(yyParser *yypParser){
drhb19fd012007-03-29 01:44:45 +0000598 ParseARG_FETCH;
drhb19fd012007-03-29 01:44:45 +0000599#ifndef NDEBUG
600 if( yyTraceFILE ){
601 fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt);
602 }
603#endif
drhabecc0b2016-05-24 00:40:54 +0000604 while( yypParser->yytos>yypParser->yystack ) yy_pop_parser_stack(yypParser);
drhb19fd012007-03-29 01:44:45 +0000605 /* Here code is inserted which will execute if the parser
606 ** stack every overflows */
drh82415f22015-11-09 19:33:42 +0000607/******** Begin %stack_overflow code ******************************************/
drhb19fd012007-03-29 01:44:45 +0000608%%
drh82415f22015-11-09 19:33:42 +0000609/******** End %stack_overflow code ********************************************/
drhb19fd012007-03-29 01:44:45 +0000610 ParseARG_STORE; /* Suppress warning about unused %extra_argument var */
611}
612
613/*
drha248a722015-09-07 19:52:55 +0000614** Print tracing information for a SHIFT action
615*/
616#ifndef NDEBUG
drhe58f74f2017-12-24 17:06:41 +0000617static void yyTraceShift(yyParser *yypParser, int yyNewState, const char *zTag){
drha248a722015-09-07 19:52:55 +0000618 if( yyTraceFILE ){
drha248a722015-09-07 19:52:55 +0000619 if( yyNewState<YYNSTATE ){
drhe58f74f2017-12-24 17:06:41 +0000620 fprintf(yyTraceFILE,"%s%s '%s', go to state %d\n",
621 yyTracePrompt, zTag, yyTokenName[yypParser->yytos->major],
drh0c4105e2015-11-10 14:51:22 +0000622 yyNewState);
drha248a722015-09-07 19:52:55 +0000623 }else{
drhe58f74f2017-12-24 17:06:41 +0000624 fprintf(yyTraceFILE,"%s%s '%s', pending reduce %d\n",
625 yyTracePrompt, zTag, yyTokenName[yypParser->yytos->major],
626 yyNewState - YY_MIN_REDUCE);
drha248a722015-09-07 19:52:55 +0000627 }
628 }
629}
630#else
drhe58f74f2017-12-24 17:06:41 +0000631# define yyTraceShift(X,Y,Z)
drha248a722015-09-07 19:52:55 +0000632#endif
633
634/*
drh82415f22015-11-09 19:33:42 +0000635** Perform a shift action.
drh75897232000-05-29 14:26:00 +0000636*/
drha248a722015-09-07 19:52:55 +0000637static void yy_shift(
drh75897232000-05-29 14:26:00 +0000638 yyParser *yypParser, /* The parser to be shifted */
639 int yyNewState, /* The new state to shift in */
640 int yyMajor, /* The major token to shift in */
drh45f31be2016-02-16 21:19:49 +0000641 ParseTOKENTYPE yyMinor /* The minor token to shift in */
drh75897232000-05-29 14:26:00 +0000642){
drh3ddfdf72003-12-22 14:53:19 +0000643 yyStackEntry *yytos;
drh118ab652016-05-23 21:56:24 +0000644 yypParser->yytos++;
drhec424a52008-07-25 15:39:03 +0000645#ifdef YYTRACKMAXSTACKDEPTH
drh118ab652016-05-23 21:56:24 +0000646 if( (int)(yypParser->yytos - yypParser->yystack)>yypParser->yyhwm ){
647 yypParser->yyhwm++;
648 assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack) );
drhec424a52008-07-25 15:39:03 +0000649 }
650#endif
drhb19fd012007-03-29 01:44:45 +0000651#if YYSTACKDEPTH>0
drh8b471e72017-06-28 15:01:35 +0000652 if( yypParser->yytos>yypParser->yystackEnd ){
drh63413312016-12-06 17:59:05 +0000653 yypParser->yytos--;
drh45f31be2016-02-16 21:19:49 +0000654 yyStackOverflow(yypParser);
drha248a722015-09-07 19:52:55 +0000655 return;
drh75897232000-05-29 14:26:00 +0000656 }
drhb19fd012007-03-29 01:44:45 +0000657#else
drh118ab652016-05-23 21:56:24 +0000658 if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz] ){
drh8dc82472016-05-27 04:10:47 +0000659 if( yyGrowStack(yypParser) ){
drh63413312016-12-06 17:59:05 +0000660 yypParser->yytos--;
drh45f31be2016-02-16 21:19:49 +0000661 yyStackOverflow(yypParser);
drha248a722015-09-07 19:52:55 +0000662 return;
drhb19fd012007-03-29 01:44:45 +0000663 }
664 }
665#endif
drh0efd37f2016-06-06 18:17:36 +0000666 if( yyNewState > YY_MAX_SHIFT ){
667 yyNewState += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE;
668 }
drh118ab652016-05-23 21:56:24 +0000669 yytos = yypParser->yytos;
drhb27b7f52008-12-10 18:03:45 +0000670 yytos->stateno = (YYACTIONTYPE)yyNewState;
671 yytos->major = (YYCODETYPE)yyMajor;
drh45f31be2016-02-16 21:19:49 +0000672 yytos->minor.yy0 = yyMinor;
drhe58f74f2017-12-24 17:06:41 +0000673 yyTraceShift(yypParser, yyNewState, "Shift");
drh75897232000-05-29 14:26:00 +0000674}
675
676/* The following table contains information about every rule that
677** is used during the reduce.
678*/
drh57196282004-10-06 15:41:16 +0000679static const struct {
drh6be95362017-06-28 13:47:56 +0000680 YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */
681 signed char nrhs; /* Negative of the number of RHS symbols in the rule */
drh75897232000-05-29 14:26:00 +0000682} yyRuleInfo[] = {
683%%
684};
685
drh1f245e42002-03-11 13:55:50 +0000686static void yy_accept(yyParser*); /* Forward Declaration */
drh75897232000-05-29 14:26:00 +0000687
688/*
689** Perform a reduce action and the shift that must immediately
690** follow the reduce.
drh087316c2017-12-15 12:22:21 +0000691**
692** The yyLookahead and yyLookaheadToken parameters provide reduce actions
693** access to the lookahead token (if any). The yyLookahead will be YYNOCODE
694** if the lookahead token has already been consumed. As this procedure is
695** only called from one place, optimizing compilers will in-line it, which
696** means that the extra parameters have no performance impact.
drh75897232000-05-29 14:26:00 +0000697*/
698static void yy_reduce(
699 yyParser *yypParser, /* The parser */
drh087316c2017-12-15 12:22:21 +0000700 unsigned int yyruleno, /* Number of the rule by which to reduce */
701 int yyLookahead, /* Lookahead token, or YYNOCODE if none */
702 ParseTOKENTYPE yyLookaheadToken /* Value of the lookahead token */
drh75897232000-05-29 14:26:00 +0000703){
704 int yygoto; /* The next state */
705 int yyact; /* The next action */
drh1f245e42002-03-11 13:55:50 +0000706 yyStackEntry *yymsp; /* The top of the parser's stack */
drh75897232000-05-29 14:26:00 +0000707 int yysize; /* Amount to pop the stack */
drh1f245e42002-03-11 13:55:50 +0000708 ParseARG_FETCH;
drh118ab652016-05-23 21:56:24 +0000709 yymsp = yypParser->yytos;
drh0bd1f4e2002-06-06 18:54:39 +0000710#ifndef NDEBUG
drh4ef07702016-03-16 19:45:54 +0000711 if( yyTraceFILE && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){
drh3bd48ab2015-09-07 18:23:37 +0000712 yysize = yyRuleInfo[yyruleno].nrhs;
drhe58f74f2017-12-24 17:06:41 +0000713 if( yysize ){
714 fprintf(yyTraceFILE, "%sReduce %d [%s], go to state %d.\n",
715 yyTracePrompt,
716 yyruleno, yyRuleName[yyruleno], yymsp[yysize].stateno);
717 }else{
718 fprintf(yyTraceFILE, "%sReduce %d [%s].\n",
719 yyTracePrompt, yyruleno, yyRuleName[yyruleno]);
720 }
drh0bd1f4e2002-06-06 18:54:39 +0000721 }
722#endif /* NDEBUG */
drh45f31be2016-02-16 21:19:49 +0000723
724 /* Check that the stack is large enough to grow by a single entry
725 ** if the RHS of the rule is empty. This ensures that there is room
726 ** enough on the stack to push the LHS value */
727 if( yyRuleInfo[yyruleno].nrhs==0 ){
728#ifdef YYTRACKMAXSTACKDEPTH
drh118ab652016-05-23 21:56:24 +0000729 if( (int)(yypParser->yytos - yypParser->yystack)>yypParser->yyhwm ){
730 yypParser->yyhwm++;
731 assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack));
drh45f31be2016-02-16 21:19:49 +0000732 }
733#endif
734#if YYSTACKDEPTH>0
drh8b471e72017-06-28 15:01:35 +0000735 if( yypParser->yytos>=yypParser->yystackEnd ){
drh45f31be2016-02-16 21:19:49 +0000736 yyStackOverflow(yypParser);
737 return;
738 }
739#else
drh118ab652016-05-23 21:56:24 +0000740 if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz-1] ){
drh8dc82472016-05-27 04:10:47 +0000741 if( yyGrowStack(yypParser) ){
drh45f31be2016-02-16 21:19:49 +0000742 yyStackOverflow(yypParser);
743 return;
744 }
drh8dc82472016-05-27 04:10:47 +0000745 yymsp = yypParser->yytos;
drh45f31be2016-02-16 21:19:49 +0000746 }
747#endif
748 }
drhcb6c5652007-01-16 18:19:12 +0000749
drh75897232000-05-29 14:26:00 +0000750 switch( yyruleno ){
751 /* Beginning here are the reduction cases. A typical example
752 ** follows:
753 ** case 0:
drh75897232000-05-29 14:26:00 +0000754 ** #line <lineno> <grammarfile>
755 ** { ... } // User supplied code
756 ** #line <lineno> <thisfile>
757 ** break;
758 */
drh82415f22015-11-09 19:33:42 +0000759/********** Begin reduce actions **********************************************/
drh75897232000-05-29 14:26:00 +0000760%%
drh82415f22015-11-09 19:33:42 +0000761/********** End reduce actions ************************************************/
drh75897232000-05-29 14:26:00 +0000762 };
drh4ef07702016-03-16 19:45:54 +0000763 assert( yyruleno<sizeof(yyRuleInfo)/sizeof(yyRuleInfo[0]) );
drh75897232000-05-29 14:26:00 +0000764 yygoto = yyRuleInfo[yyruleno].lhs;
765 yysize = yyRuleInfo[yyruleno].nrhs;
drh6be95362017-06-28 13:47:56 +0000766 yyact = yy_find_reduce_action(yymsp[yysize].stateno,(YYCODETYPE)yygoto);
drhbd8fcc12017-06-28 11:56:18 +0000767
768 /* There are no SHIFTREDUCE actions on nonterminals because the table
769 ** generator has simplified them to pure REDUCE actions. */
770 assert( !(yyact>YY_MAX_SHIFT && yyact<=YY_MAX_SHIFTREDUCE) );
771
772 /* It is not possible for a REDUCE to be followed by an error */
773 assert( yyact!=YY_ERROR_ACTION );
774
drhef53a9f2017-12-25 00:10:05 +0000775 yymsp += yysize+1;
776 yypParser->yytos = yymsp;
777 yymsp->stateno = (YYACTIONTYPE)yyact;
778 yymsp->major = (YYCODETYPE)yygoto;
779 yyTraceShift(yypParser, yyact, "... then shift");
drh75897232000-05-29 14:26:00 +0000780}
781
782/*
783** The following code executes when the parse fails
784*/
drhd3ec02d2009-06-12 02:27:14 +0000785#ifndef YYNOERRORRECOVERY
drh75897232000-05-29 14:26:00 +0000786static void yy_parse_failed(
787 yyParser *yypParser /* The parser */
drh75897232000-05-29 14:26:00 +0000788){
drh1f245e42002-03-11 13:55:50 +0000789 ParseARG_FETCH;
drh75897232000-05-29 14:26:00 +0000790#ifndef NDEBUG
791 if( yyTraceFILE ){
792 fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt);
793 }
794#endif
drhabecc0b2016-05-24 00:40:54 +0000795 while( yypParser->yytos>yypParser->yystack ) yy_pop_parser_stack(yypParser);
drh75897232000-05-29 14:26:00 +0000796 /* Here code is inserted which will be executed whenever the
797 ** parser fails */
drh82415f22015-11-09 19:33:42 +0000798/************ Begin %parse_failure code ***************************************/
drh75897232000-05-29 14:26:00 +0000799%%
drh82415f22015-11-09 19:33:42 +0000800/************ End %parse_failure code *****************************************/
drh1f245e42002-03-11 13:55:50 +0000801 ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
drh75897232000-05-29 14:26:00 +0000802}
drhd3ec02d2009-06-12 02:27:14 +0000803#endif /* YYNOERRORRECOVERY */
drh75897232000-05-29 14:26:00 +0000804
805/*
806** The following code executes when a syntax error first occurs.
807*/
808static void yy_syntax_error(
809 yyParser *yypParser, /* The parser */
810 int yymajor, /* The major type of the error token */
drh45f31be2016-02-16 21:19:49 +0000811 ParseTOKENTYPE yyminor /* The minor type of the error token */
drh75897232000-05-29 14:26:00 +0000812){
drh1f245e42002-03-11 13:55:50 +0000813 ParseARG_FETCH;
drh45f31be2016-02-16 21:19:49 +0000814#define TOKEN yyminor
drh82415f22015-11-09 19:33:42 +0000815/************ Begin %syntax_error code ****************************************/
drh75897232000-05-29 14:26:00 +0000816%%
drh82415f22015-11-09 19:33:42 +0000817/************ End %syntax_error code ******************************************/
drh1f245e42002-03-11 13:55:50 +0000818 ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
drh75897232000-05-29 14:26:00 +0000819}
820
821/*
822** The following is executed when the parser accepts
823*/
824static void yy_accept(
825 yyParser *yypParser /* The parser */
drh75897232000-05-29 14:26:00 +0000826){
drh1f245e42002-03-11 13:55:50 +0000827 ParseARG_FETCH;
drh75897232000-05-29 14:26:00 +0000828#ifndef NDEBUG
829 if( yyTraceFILE ){
830 fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt);
831 }
832#endif
drhdd703e22016-07-12 19:54:49 +0000833#ifndef YYNOERRORRECOVERY
834 yypParser->yyerrcnt = -1;
835#endif
drh756b41e2016-05-24 18:55:08 +0000836 assert( yypParser->yytos==yypParser->yystack );
drh75897232000-05-29 14:26:00 +0000837 /* Here code is inserted which will be executed whenever the
838 ** parser accepts */
drh82415f22015-11-09 19:33:42 +0000839/*********** Begin %parse_accept code *****************************************/
drh75897232000-05-29 14:26:00 +0000840%%
drh82415f22015-11-09 19:33:42 +0000841/*********** End %parse_accept code *******************************************/
drh1f245e42002-03-11 13:55:50 +0000842 ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
drh75897232000-05-29 14:26:00 +0000843}
844
845/* The main parser program.
846** The first argument is a pointer to a structure obtained from
847** "ParseAlloc" which describes the current state of the parser.
848** The second argument is the major token number. The third is
849** the minor token. The fourth optional argument is whatever the
850** user wants (and specified in the grammar) and is available for
851** use by the action routines.
852**
853** Inputs:
854** <ul>
855** <li> A pointer to the parser (an opaque structure.)
856** <li> The major token number.
857** <li> The minor token number.
858** <li> An option argument of a grammar-specified type.
859** </ul>
860**
861** Outputs:
862** None.
863*/
drh75897232000-05-29 14:26:00 +0000864void Parse(
865 void *yyp, /* The parser */
866 int yymajor, /* The major token code number */
867 ParseTOKENTYPE yyminor /* The value for the token */
drh1f245e42002-03-11 13:55:50 +0000868 ParseARG_PDECL /* Optional %extra_argument parameter */
drh75897232000-05-29 14:26:00 +0000869){
870 YYMINORTYPE yyminorunion;
drh4ef07702016-03-16 19:45:54 +0000871 unsigned int yyact; /* The parser action. */
drha4414042015-11-09 15:06:26 +0000872#if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY)
drh75897232000-05-29 14:26:00 +0000873 int yyendofinput; /* True if we are at the end of input */
drha4414042015-11-09 15:06:26 +0000874#endif
drhc4dd3fd2008-01-22 01:48:05 +0000875#ifdef YYERRORSYMBOL
drh75897232000-05-29 14:26:00 +0000876 int yyerrorhit = 0; /* True if yymajor has invoked an error */
drhc4dd3fd2008-01-22 01:48:05 +0000877#endif
drh75897232000-05-29 14:26:00 +0000878 yyParser *yypParser; /* The parser */
879
drh75897232000-05-29 14:26:00 +0000880 yypParser = (yyParser*)yyp;
drhabecc0b2016-05-24 00:40:54 +0000881 assert( yypParser->yytos!=0 );
drha4414042015-11-09 15:06:26 +0000882#if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY)
drh75897232000-05-29 14:26:00 +0000883 yyendofinput = (yymajor==0);
drha4414042015-11-09 15:06:26 +0000884#endif
drh1f245e42002-03-11 13:55:50 +0000885 ParseARG_STORE;
drh75897232000-05-29 14:26:00 +0000886
887#ifndef NDEBUG
888 if( yyTraceFILE ){
drhe58f74f2017-12-24 17:06:41 +0000889 int stateno = yypParser->yytos->stateno;
890 if( stateno < YY_MIN_REDUCE ){
891 fprintf(yyTraceFILE,"%sInput '%s' in state %d\n",
892 yyTracePrompt,yyTokenName[yymajor],stateno);
893 }else{
894 fprintf(yyTraceFILE,"%sInput '%s' with pending reduce %d\n",
895 yyTracePrompt,yyTokenName[yymajor],stateno-YY_MIN_REDUCE);
896 }
drh75897232000-05-29 14:26:00 +0000897 }
898#endif
899
900 do{
drh3abbd392008-12-10 23:04:13 +0000901 yyact = yy_find_shift_action(yypParser,(YYCODETYPE)yymajor);
drh5c8241b2017-12-24 23:38:10 +0000902 if( yyact >= YY_MIN_REDUCE ){
903 yy_reduce(yypParser,yyact-YY_MIN_REDUCE,yymajor,yyminor);
904 }else if( yyact <= YY_MAX_SHIFTREDUCE ){
drh45f31be2016-02-16 21:19:49 +0000905 yy_shift(yypParser,yyact,yymajor,yyminor);
drhdab943c2016-02-16 01:01:43 +0000906#ifndef YYNOERRORRECOVERY
drha248a722015-09-07 19:52:55 +0000907 yypParser->yyerrcnt--;
drhdab943c2016-02-16 01:01:43 +0000908#endif
drha248a722015-09-07 19:52:55 +0000909 yymajor = YYNOCODE;
drhef53a9f2017-12-25 00:10:05 +0000910 }else if( yyact==YY_ACCEPT_ACTION ){
911 yypParser->yytos--;
912 yy_accept(yypParser);
913 return;
drhc4dd3fd2008-01-22 01:48:05 +0000914 }else{
915 assert( yyact == YY_ERROR_ACTION );
drh45f31be2016-02-16 21:19:49 +0000916 yyminorunion.yy0 = yyminor;
drhc4dd3fd2008-01-22 01:48:05 +0000917#ifdef YYERRORSYMBOL
drh3ddfdf72003-12-22 14:53:19 +0000918 int yymx;
drhc4dd3fd2008-01-22 01:48:05 +0000919#endif
drh75897232000-05-29 14:26:00 +0000920#ifndef NDEBUG
921 if( yyTraceFILE ){
922 fprintf(yyTraceFILE,"%sSyntax Error!\n",yyTracePrompt);
923 }
924#endif
925#ifdef YYERRORSYMBOL
926 /* A syntax error has occurred.
927 ** The response to an error depends upon whether or not the
928 ** grammar defines an error token "ERROR".
929 **
930 ** This is what we do if the grammar does define ERROR:
931 **
932 ** * Call the %syntax_error function.
933 **
934 ** * Begin popping the stack until we enter a state where
935 ** it is legal to shift the error symbol, then shift
936 ** the error symbol.
937 **
938 ** * Set the error count to three.
939 **
940 ** * Begin accepting and shifting new tokens. No new error
941 ** processing will occur until three tokens have been
942 ** shifted successfully.
943 **
944 */
drh1f245e42002-03-11 13:55:50 +0000945 if( yypParser->yyerrcnt<0 ){
drh45f31be2016-02-16 21:19:49 +0000946 yy_syntax_error(yypParser,yymajor,yyminor);
drh75897232000-05-29 14:26:00 +0000947 }
drh118ab652016-05-23 21:56:24 +0000948 yymx = yypParser->yytos->major;
drh3ddfdf72003-12-22 14:53:19 +0000949 if( yymx==YYERRORSYMBOL || yyerrorhit ){
drh75897232000-05-29 14:26:00 +0000950#ifndef NDEBUG
951 if( yyTraceFILE ){
952 fprintf(yyTraceFILE,"%sDiscard input token %s\n",
953 yyTracePrompt,yyTokenName[yymajor]);
954 }
955#endif
drh45f31be2016-02-16 21:19:49 +0000956 yy_destructor(yypParser, (YYCODETYPE)yymajor, &yyminorunion);
drh75897232000-05-29 14:26:00 +0000957 yymajor = YYNOCODE;
958 }else{
drh4eda15e2016-10-04 12:20:12 +0000959 while( yypParser->yytos >= yypParser->yystack
drh118ab652016-05-23 21:56:24 +0000960 && yymx != YYERRORSYMBOL
961 && (yyact = yy_find_reduce_action(
962 yypParser->yytos->stateno,
drh3bd48ab2015-09-07 18:23:37 +0000963 YYERRORSYMBOL)) >= YY_MIN_REDUCE
drh75897232000-05-29 14:26:00 +0000964 ){
965 yy_pop_parser_stack(yypParser);
966 }
drh118ab652016-05-23 21:56:24 +0000967 if( yypParser->yytos < yypParser->yystack || yymajor==0 ){
drhb27b7f52008-12-10 18:03:45 +0000968 yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
drh1f245e42002-03-11 13:55:50 +0000969 yy_parse_failed(yypParser);
drh240c7fa2016-07-05 12:47:28 +0000970#ifndef YYNOERRORRECOVERY
971 yypParser->yyerrcnt = -1;
972#endif
drh75897232000-05-29 14:26:00 +0000973 yymajor = YYNOCODE;
drh3ddfdf72003-12-22 14:53:19 +0000974 }else if( yymx!=YYERRORSYMBOL ){
drh45f31be2016-02-16 21:19:49 +0000975 yy_shift(yypParser,yyact,YYERRORSYMBOL,yyminor);
drh75897232000-05-29 14:26:00 +0000976 }
977 }
drh1f245e42002-03-11 13:55:50 +0000978 yypParser->yyerrcnt = 3;
drh75897232000-05-29 14:26:00 +0000979 yyerrorhit = 1;
drhd3ec02d2009-06-12 02:27:14 +0000980#elif defined(YYNOERRORRECOVERY)
981 /* If the YYNOERRORRECOVERY macro is defined, then do not attempt to
982 ** do any kind of error recovery. Instead, simply invoke the syntax
983 ** error routine and continue going as if nothing had happened.
984 **
985 ** Applications can set this macro (for example inside %include) if
986 ** they intend to abandon the parse upon the first syntax error seen.
987 */
drh45f31be2016-02-16 21:19:49 +0000988 yy_syntax_error(yypParser,yymajor, yyminor);
drhd3ec02d2009-06-12 02:27:14 +0000989 yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
990 yymajor = YYNOCODE;
991
drh75897232000-05-29 14:26:00 +0000992#else /* YYERRORSYMBOL is not defined */
993 /* This is what we do if the grammar does not define ERROR:
994 **
995 ** * Report an error message, and throw away the input token.
996 **
997 ** * If the input token is $, then fail the parse.
998 **
999 ** As before, subsequent error messages are suppressed until
1000 ** three input tokens have been successfully shifted.
1001 */
drh1f245e42002-03-11 13:55:50 +00001002 if( yypParser->yyerrcnt<=0 ){
drh45f31be2016-02-16 21:19:49 +00001003 yy_syntax_error(yypParser,yymajor, yyminor);
drh75897232000-05-29 14:26:00 +00001004 }
drh1f245e42002-03-11 13:55:50 +00001005 yypParser->yyerrcnt = 3;
drhb27b7f52008-12-10 18:03:45 +00001006 yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
drh75897232000-05-29 14:26:00 +00001007 if( yyendofinput ){
drh1f245e42002-03-11 13:55:50 +00001008 yy_parse_failed(yypParser);
drhd3d4b3c2016-07-08 19:54:38 +00001009#ifndef YYNOERRORRECOVERY
1010 yypParser->yyerrcnt = -1;
1011#endif
drh75897232000-05-29 14:26:00 +00001012 }
1013 yymajor = YYNOCODE;
1014#endif
drh75897232000-05-29 14:26:00 +00001015 }
drhabecc0b2016-05-24 00:40:54 +00001016 }while( yymajor!=YYNOCODE && yypParser->yytos>yypParser->yystack );
drh3bd48ab2015-09-07 18:23:37 +00001017#ifndef NDEBUG
1018 if( yyTraceFILE ){
drh118ab652016-05-23 21:56:24 +00001019 yyStackEntry *i;
1020 char cDiv = '[';
drh0c4105e2015-11-10 14:51:22 +00001021 fprintf(yyTraceFILE,"%sReturn. Stack=",yyTracePrompt);
drh118ab652016-05-23 21:56:24 +00001022 for(i=&yypParser->yystack[1]; i<=yypParser->yytos; i++){
1023 fprintf(yyTraceFILE,"%c%s", cDiv, yyTokenName[i->major]);
1024 cDiv = ' ';
1025 }
drh0c4105e2015-11-10 14:51:22 +00001026 fprintf(yyTraceFILE,"]\n");
drh3bd48ab2015-09-07 18:23:37 +00001027 }
1028#endif
drh75897232000-05-29 14:26:00 +00001029 return;
1030}