blob: 885cefe1435f221956b729fdca6172834d4d7d09 [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
drhfb32c442018-04-21 13:51:42 +000069** ParseARG_PARAM Code to pass %extra_argument as a subroutine parameter
drh1f245e42002-03-11 13:55:50 +000070** ParseARG_STORE Code to store %extra_argument into yypParser
71** ParseARG_FETCH Code to extract %extra_argument from yypParser
drhfb32c442018-04-21 13:51:42 +000072** ParseCTX_* As ParseARG_ except for %extra_context
drh75897232000-05-29 14:26:00 +000073** YYERRORSYMBOL is the code number of the error symbol. If not
74** defined, then do no error processing.
drh3bd48ab2015-09-07 18:23:37 +000075** YYNSTATE the combined number of states.
76** YYNRULE the number of rules in the grammar
drh0d9de992017-12-26 18:04:23 +000077** YYNTOKEN Number of terminal symbols
drh3bd48ab2015-09-07 18:23:37 +000078** YY_MAX_SHIFT Maximum value for shift actions
79** YY_MIN_SHIFTREDUCE Minimum value for shift-reduce actions
80** YY_MAX_SHIFTREDUCE Maximum value for shift-reduce actions
drh3bd48ab2015-09-07 18:23:37 +000081** YY_ERROR_ACTION The yy_action[] code for syntax error
82** YY_ACCEPT_ACTION The yy_action[] code for accept
83** YY_NO_ACTION The yy_action[] code for no-op
drh5c8241b2017-12-24 23:38:10 +000084** YY_MIN_REDUCE Minimum value for reduce actions
85** YY_MAX_REDUCE Maximum value for reduce actions
drh75897232000-05-29 14:26:00 +000086*/
drh82415f22015-11-09 19:33:42 +000087#ifndef INTERFACE
88# define INTERFACE 1
89#endif
90/************* Begin control #defines *****************************************/
drh75897232000-05-29 14:26:00 +000091%%
drh82415f22015-11-09 19:33:42 +000092/************* End control #defines *******************************************/
drh75897232000-05-29 14:26:00 +000093
drh8a415d32009-06-12 13:53:51 +000094/* Define the yytestcase() macro to be a no-op if is not already defined
95** otherwise.
96**
97** Applications can choose to define yytestcase() in the %include section
98** to a macro that can assist in verifying code coverage. For production
99** code the yytestcase() macro should be turned off. But it is useful
100** for testing.
101*/
102#ifndef yytestcase
103# define yytestcase(X)
104#endif
105
drh26c9b5e2008-04-11 14:56:53 +0000106
drh34ff57b2008-07-14 12:27:51 +0000107/* Next are the tables used to determine what action to take based on the
drh8b582012003-10-21 13:16:03 +0000108** current state and lookahead token. These tables are used to implement
109** functions that take a state number and lookahead value and return an
110** action integer.
drh75897232000-05-29 14:26:00 +0000111**
drh8548a052003-10-22 22:15:27 +0000112** Suppose the action integer is N. Then the action is determined as
113** follows
drh75897232000-05-29 14:26:00 +0000114**
drh3bd48ab2015-09-07 18:23:37 +0000115** 0 <= N <= YY_MAX_SHIFT Shift N. That is, push the lookahead
drh8548a052003-10-22 22:15:27 +0000116** token onto the stack and goto state N.
117**
drh3bd48ab2015-09-07 18:23:37 +0000118** N between YY_MIN_SHIFTREDUCE Shift to an arbitrary state then
119** and YY_MAX_SHIFTREDUCE reduce by rule N-YY_MIN_SHIFTREDUCE.
drh8548a052003-10-22 22:15:27 +0000120**
drh3bd48ab2015-09-07 18:23:37 +0000121** N == YY_ERROR_ACTION A syntax error has occurred.
drh8548a052003-10-22 22:15:27 +0000122**
drh3bd48ab2015-09-07 18:23:37 +0000123** N == YY_ACCEPT_ACTION The parser accepts its input.
drh8548a052003-10-22 22:15:27 +0000124**
drh3bd48ab2015-09-07 18:23:37 +0000125** N == YY_NO_ACTION No such action. Denotes unused
drh8548a052003-10-22 22:15:27 +0000126** slots in the yy_action[] table.
127**
drh5c8241b2017-12-24 23:38:10 +0000128** N between YY_MIN_REDUCE Reduce by rule N-YY_MIN_REDUCE
129** and YY_MAX_REDUCE
130**
drh8548a052003-10-22 22:15:27 +0000131** The action table is constructed as a single large table named yy_action[].
drh701b6882016-08-10 13:30:43 +0000132** Given state S and lookahead X, the action is computed as either:
drh75897232000-05-29 14:26:00 +0000133**
drh701b6882016-08-10 13:30:43 +0000134** (A) N = yy_action[ yy_shift_ofst[S] + X ]
135** (B) N = yy_default[S]
drh8b582012003-10-21 13:16:03 +0000136**
drh3a9d6c72017-12-25 04:15:38 +0000137** The (A) formula is preferred. The B formula is used instead if
138** yy_lookahead[yy_shift_ofst[S]+X] is not equal to X.
drh8b582012003-10-21 13:16:03 +0000139**
drh701b6882016-08-10 13:30:43 +0000140** The formulas above are for computing the action when the lookahead is
drh8b582012003-10-21 13:16:03 +0000141** a terminal symbol. If the lookahead is a non-terminal (as occurs after
142** a reduce action) then the yy_reduce_ofst[] array is used in place of
drh3a9d6c72017-12-25 04:15:38 +0000143** the yy_shift_ofst[] array.
drh8b582012003-10-21 13:16:03 +0000144**
145** The following are the tables generated in this section:
146**
147** yy_action[] A single table containing all actions.
148** yy_lookahead[] A table containing the lookahead for each entry in
149** yy_action. Used to detect hash collisions.
150** yy_shift_ofst[] For each state, the offset into yy_action for
151** shifting terminals.
152** yy_reduce_ofst[] For each state, the offset into yy_action for
153** shifting non-terminals after a reduce.
154** yy_default[] Default action for each state.
drh82415f22015-11-09 19:33:42 +0000155**
156*********** Begin parsing tables **********************************************/
drh75897232000-05-29 14:26:00 +0000157%%
drh82415f22015-11-09 19:33:42 +0000158/********** End of lemon-generated parsing tables *****************************/
drh75897232000-05-29 14:26:00 +0000159
drh82415f22015-11-09 19:33:42 +0000160/* The next table maps tokens (terminal symbols) into fallback tokens.
161** If a construct like the following:
drh0bd1f4e2002-06-06 18:54:39 +0000162**
163** %fallback ID X Y Z.
164**
drh34ff57b2008-07-14 12:27:51 +0000165** appears in the grammar, then ID becomes a fallback token for X, Y,
drh0bd1f4e2002-06-06 18:54:39 +0000166** and Z. Whenever one of the tokens X, Y, or Z is input to the parser
167** but it does not parse, the type of the token is changed to ID and
168** the parse is retried before an error is thrown.
drh82415f22015-11-09 19:33:42 +0000169**
170** This feature can be used, for example, to cause some keywords in a language
171** to revert to identifiers if they keyword does not apply in the context where
172** it appears.
drh0bd1f4e2002-06-06 18:54:39 +0000173*/
174#ifdef YYFALLBACK
175static const YYCODETYPE yyFallback[] = {
176%%
177};
178#endif /* YYFALLBACK */
179
drh75897232000-05-29 14:26:00 +0000180/* The following structure represents a single element of the
181** parser's stack. Information stored includes:
182**
183** + The state number for the parser at this level of the stack.
184**
185** + The value of the token stored at this level of the stack.
186** (In other words, the "major" token.)
187**
188** + The semantic value stored at this level of the stack. This is
189** the information used by the action routines in the grammar.
190** It is sometimes called the "minor" token.
drha248a722015-09-07 19:52:55 +0000191**
192** After the "shift" half of a SHIFTREDUCE action, the stateno field
193** actually contains the reduce action for the second half of the
194** SHIFTREDUCE.
drh75897232000-05-29 14:26:00 +0000195*/
196struct yyStackEntry {
drha248a722015-09-07 19:52:55 +0000197 YYACTIONTYPE stateno; /* The state-number, or reduce action in SHIFTREDUCE */
drh2abcd582008-07-24 23:34:07 +0000198 YYCODETYPE major; /* The major token value. This is the code
199 ** number for the token at this stack level */
200 YYMINORTYPE minor; /* The user-supplied minor token value. This
201 ** is the value of the token */
drh75897232000-05-29 14:26:00 +0000202};
drh1f245e42002-03-11 13:55:50 +0000203typedef struct yyStackEntry yyStackEntry;
drh75897232000-05-29 14:26:00 +0000204
205/* The state of the parser is completely contained in an instance of
206** the following structure */
207struct yyParser {
drh118ab652016-05-23 21:56:24 +0000208 yyStackEntry *yytos; /* Pointer to top element of the stack */
drhec424a52008-07-25 15:39:03 +0000209#ifdef YYTRACKMAXSTACKDEPTH
drh118ab652016-05-23 21:56:24 +0000210 int yyhwm; /* High-water mark of the stack */
drhec424a52008-07-25 15:39:03 +0000211#endif
drhdab943c2016-02-16 01:01:43 +0000212#ifndef YYNOERRORRECOVERY
drh1f245e42002-03-11 13:55:50 +0000213 int yyerrcnt; /* Shifts left before out of the error */
drhdab943c2016-02-16 01:01:43 +0000214#endif
drh1f245e42002-03-11 13:55:50 +0000215 ParseARG_SDECL /* A place to hold %extra_argument */
drhfb32c442018-04-21 13:51:42 +0000216 ParseCTX_SDECL /* A place to hold %extra_context */
drhb19fd012007-03-29 01:44:45 +0000217#if YYSTACKDEPTH<=0
218 int yystksz; /* Current side of the stack */
219 yyStackEntry *yystack; /* The parser's stack */
drh8dc82472016-05-27 04:10:47 +0000220 yyStackEntry yystk0; /* First stack entry */
drhb19fd012007-03-29 01:44:45 +0000221#else
drh1f245e42002-03-11 13:55:50 +0000222 yyStackEntry yystack[YYSTACKDEPTH]; /* The parser's stack */
drh8b471e72017-06-28 15:01:35 +0000223 yyStackEntry *yystackEnd; /* Last entry in the stack */
drhb19fd012007-03-29 01:44:45 +0000224#endif
drh75897232000-05-29 14:26:00 +0000225};
226typedef struct yyParser yyParser;
227
228#ifndef NDEBUG
229#include <stdio.h>
230static FILE *yyTraceFILE = 0;
231static char *yyTracePrompt = 0;
drh0bd1f4e2002-06-06 18:54:39 +0000232#endif /* NDEBUG */
drh75897232000-05-29 14:26:00 +0000233
drh0bd1f4e2002-06-06 18:54:39 +0000234#ifndef NDEBUG
drh75897232000-05-29 14:26:00 +0000235/*
236** Turn parser tracing on by giving a stream to which to write the trace
237** and a prompt to preface each trace message. Tracing is turned off
238** by making either argument NULL
239**
240** Inputs:
241** <ul>
242** <li> A FILE* to which trace output should be written.
243** If NULL, then tracing is turned off.
244** <li> A prefix string written at the beginning of every
245** line of trace output. If NULL, then tracing is
246** turned off.
247** </ul>
248**
249** Outputs:
250** None.
251*/
drh75897232000-05-29 14:26:00 +0000252void ParseTrace(FILE *TraceFILE, char *zTracePrompt){
253 yyTraceFILE = TraceFILE;
254 yyTracePrompt = zTracePrompt;
255 if( yyTraceFILE==0 ) yyTracePrompt = 0;
256 else if( yyTracePrompt==0 ) yyTraceFILE = 0;
257}
drh0bd1f4e2002-06-06 18:54:39 +0000258#endif /* NDEBUG */
drh75897232000-05-29 14:26:00 +0000259
drh0d9de992017-12-26 18:04:23 +0000260#if defined(YYCOVERAGE) || !defined(NDEBUG)
drh75897232000-05-29 14:26:00 +0000261/* For tracing shifts, the names of all terminals and nonterminals
262** are required. The following table supplies these names */
drh57196282004-10-06 15:41:16 +0000263static const char *const yyTokenName[] = {
drh75897232000-05-29 14:26:00 +0000264%%
265};
drh0d9de992017-12-26 18:04:23 +0000266#endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */
drh75897232000-05-29 14:26:00 +0000267
drh0bd1f4e2002-06-06 18:54:39 +0000268#ifndef NDEBUG
269/* For tracing reduce actions, the names of all rules are required.
270*/
drh57196282004-10-06 15:41:16 +0000271static const char *const yyRuleName[] = {
drh0bd1f4e2002-06-06 18:54:39 +0000272%%
273};
274#endif /* NDEBUG */
drha1b351a2001-09-14 16:42:12 +0000275
drh960e8c62001-04-03 16:53:21 +0000276
drhb19fd012007-03-29 01:44:45 +0000277#if YYSTACKDEPTH<=0
278/*
drh8dc82472016-05-27 04:10:47 +0000279** Try to increase the size of the parser stack. Return the number
280** of errors. Return 0 on success.
drhb19fd012007-03-29 01:44:45 +0000281*/
drh8dc82472016-05-27 04:10:47 +0000282static int yyGrowStack(yyParser *p){
drhb19fd012007-03-29 01:44:45 +0000283 int newSize;
drhabecc0b2016-05-24 00:40:54 +0000284 int idx;
drhb19fd012007-03-29 01:44:45 +0000285 yyStackEntry *pNew;
286
287 newSize = p->yystksz*2 + 100;
drhabecc0b2016-05-24 00:40:54 +0000288 idx = p->yytos ? (int)(p->yytos - p->yystack) : 0;
drh8dc82472016-05-27 04:10:47 +0000289 if( p->yystack==&p->yystk0 ){
290 pNew = malloc(newSize*sizeof(pNew[0]));
291 if( pNew ) pNew[0] = p->yystk0;
292 }else{
293 pNew = realloc(p->yystack, newSize*sizeof(pNew[0]));
294 }
drhb19fd012007-03-29 01:44:45 +0000295 if( pNew ){
296 p->yystack = pNew;
drhabecc0b2016-05-24 00:40:54 +0000297 p->yytos = &p->yystack[idx];
drhb19fd012007-03-29 01:44:45 +0000298#ifndef NDEBUG
299 if( yyTraceFILE ){
drh8dc82472016-05-27 04:10:47 +0000300 fprintf(yyTraceFILE,"%sStack grows from %d to %d entries.\n",
301 yyTracePrompt, p->yystksz, newSize);
drhb19fd012007-03-29 01:44:45 +0000302 }
303#endif
drh8dc82472016-05-27 04:10:47 +0000304 p->yystksz = newSize;
drhb19fd012007-03-29 01:44:45 +0000305 }
drh8dc82472016-05-27 04:10:47 +0000306 return pNew==0;
drhb19fd012007-03-29 01:44:45 +0000307}
308#endif
309
drh82415f22015-11-09 19:33:42 +0000310/* Datatype of the argument to the memory allocated passed as the
311** second argument to ParseAlloc() below. This can be changed by
312** putting an appropriate #define in the %include section of the input
313** grammar.
314*/
315#ifndef YYMALLOCARGTYPE
316# define YYMALLOCARGTYPE size_t
317#endif
318
drhd26cc542017-01-28 20:46:37 +0000319/* Initialize a new parser that has already been allocated.
320*/
drhfb32c442018-04-21 13:51:42 +0000321void ParseInit(void *yypRawParser ParseCTX_PDECL){
322 yyParser *yypParser = (yyParser*)yypRawParser;
323 ParseCTX_STORE
drhd26cc542017-01-28 20:46:37 +0000324#ifdef YYTRACKMAXSTACKDEPTH
drhfb32c442018-04-21 13:51:42 +0000325 yypParser->yyhwm = 0;
drhd26cc542017-01-28 20:46:37 +0000326#endif
327#if YYSTACKDEPTH<=0
drhfb32c442018-04-21 13:51:42 +0000328 yypParser->yytos = NULL;
329 yypParser->yystack = NULL;
330 yypParser->yystksz = 0;
331 if( yyGrowStack(yypParser) ){
332 yypParser->yystack = &yypParser->yystk0;
333 yypParser->yystksz = 1;
drhd26cc542017-01-28 20:46:37 +0000334 }
335#endif
336#ifndef YYNOERRORRECOVERY
drhfb32c442018-04-21 13:51:42 +0000337 yypParser->yyerrcnt = -1;
drhd26cc542017-01-28 20:46:37 +0000338#endif
drhfb32c442018-04-21 13:51:42 +0000339 yypParser->yytos = yypParser->yystack;
340 yypParser->yystack[0].stateno = 0;
341 yypParser->yystack[0].major = 0;
drh92395c52017-07-04 12:50:00 +0000342#if YYSTACKDEPTH>0
drhfb32c442018-04-21 13:51:42 +0000343 yypParser->yystackEnd = &yypParser->yystack[YYSTACKDEPTH-1];
drh92395c52017-07-04 12:50:00 +0000344#endif
drhd26cc542017-01-28 20:46:37 +0000345}
346
347#ifndef Parse_ENGINEALWAYSONSTACK
drh75897232000-05-29 14:26:00 +0000348/*
349** This function allocates a new parser.
350** The only argument is a pointer to a function which works like
351** malloc.
352**
353** Inputs:
354** A pointer to the function used to allocate memory.
355**
356** Outputs:
357** A pointer to a parser. This pointer is used in subsequent calls
358** to Parse and ParseFree.
359*/
drhfb32c442018-04-21 13:51:42 +0000360void *ParseAlloc(void *(*mallocProc)(YYMALLOCARGTYPE) ParseCTX_PDECL){
361 yyParser *yypParser;
362 yypParser = (yyParser*)(*mallocProc)( (YYMALLOCARGTYPE)sizeof(yyParser) );
363 if( yypParser ){
364 ParseCTX_STORE
365 ParseInit(yypParser ParseCTX_PARAM);
366 }
367 return (void*)yypParser;
drh75897232000-05-29 14:26:00 +0000368}
drhd26cc542017-01-28 20:46:37 +0000369#endif /* Parse_ENGINEALWAYSONSTACK */
370
drh75897232000-05-29 14:26:00 +0000371
drh82415f22015-11-09 19:33:42 +0000372/* The following function deletes the "minor type" or semantic value
373** associated with a symbol. The symbol can be either a terminal
374** or nonterminal. "yymajor" is the symbol code, and "yypminor" is
375** a pointer to the value to be deleted. The code used to do the
376** deletions is derived from the %destructor and/or %token_destructor
377** directives of the input grammar.
drh75897232000-05-29 14:26:00 +0000378*/
drh633e6d52008-07-28 19:34:53 +0000379static void yy_destructor(
380 yyParser *yypParser, /* The parser */
381 YYCODETYPE yymajor, /* Type code for object to destroy */
382 YYMINORTYPE *yypminor /* The object to be destroyed */
383){
drhfb32c442018-04-21 13:51:42 +0000384 ParseARG_FETCH
385 ParseCTX_FETCH
drh75897232000-05-29 14:26:00 +0000386 switch( yymajor ){
387 /* Here is inserted the actions which take place when a
388 ** terminal or non-terminal is destroyed. This can happen
389 ** when the symbol is popped from the stack during a
390 ** reduce or during error processing or when a parser is
391 ** being destroyed before it is finished parsing.
392 **
393 ** Note: during a reduce, the only symbols destroyed are those
drh82415f22015-11-09 19:33:42 +0000394 ** which appear on the RHS of the rule, but which are *not* used
drh75897232000-05-29 14:26:00 +0000395 ** inside the C code.
396 */
drh82415f22015-11-09 19:33:42 +0000397/********* Begin destructor definitions ***************************************/
drh75897232000-05-29 14:26:00 +0000398%%
drh82415f22015-11-09 19:33:42 +0000399/********* End destructor definitions *****************************************/
drh75897232000-05-29 14:26:00 +0000400 default: break; /* If no destructor action specified: do nothing */
401 }
402}
403
404/*
405** Pop the parser's stack once.
406**
407** If there is a destructor routine associated with the token which
408** is popped from the stack, then call it.
drh75897232000-05-29 14:26:00 +0000409*/
drh3781f012015-11-09 14:11:37 +0000410static void yy_pop_parser_stack(yyParser *pParser){
411 yyStackEntry *yytos;
drh118ab652016-05-23 21:56:24 +0000412 assert( pParser->yytos!=0 );
drh240c7fa2016-07-05 12:47:28 +0000413 assert( pParser->yytos > pParser->yystack );
drh118ab652016-05-23 21:56:24 +0000414 yytos = pParser->yytos--;
drh75897232000-05-29 14:26:00 +0000415#ifndef NDEBUG
drh3781f012015-11-09 14:11:37 +0000416 if( yyTraceFILE ){
drh75897232000-05-29 14:26:00 +0000417 fprintf(yyTraceFILE,"%sPopping %s\n",
418 yyTracePrompt,
drh3ddfdf72003-12-22 14:53:19 +0000419 yyTokenName[yytos->major]);
drh75897232000-05-29 14:26:00 +0000420 }
421#endif
drh3781f012015-11-09 14:11:37 +0000422 yy_destructor(pParser, yytos->major, &yytos->minor);
drh75897232000-05-29 14:26:00 +0000423}
424
drhd26cc542017-01-28 20:46:37 +0000425/*
426** Clear all secondary memory allocations from the parser
427*/
428void ParseFinalize(void *p){
429 yyParser *pParser = (yyParser*)p;
430 while( pParser->yytos>pParser->yystack ) yy_pop_parser_stack(pParser);
431#if YYSTACKDEPTH<=0
432 if( pParser->yystack!=&pParser->yystk0 ) free(pParser->yystack);
433#endif
434}
435
436#ifndef Parse_ENGINEALWAYSONSTACK
drh75897232000-05-29 14:26:00 +0000437/*
drh82415f22015-11-09 19:33:42 +0000438** Deallocate and destroy a parser. Destructors are called for
drh75897232000-05-29 14:26:00 +0000439** all stack elements before shutting the parser down.
440**
drh82415f22015-11-09 19:33:42 +0000441** If the YYPARSEFREENEVERNULL macro exists (for example because it
442** is defined in a %include section of the input grammar) then it is
443** assumed that the input pointer is never NULL.
drh75897232000-05-29 14:26:00 +0000444*/
drh75897232000-05-29 14:26:00 +0000445void ParseFree(
drh960e8c62001-04-03 16:53:21 +0000446 void *p, /* The parser to be deleted */
447 void (*freeProc)(void*) /* Function used to reclaim memory */
drh75897232000-05-29 14:26:00 +0000448){
drh82415f22015-11-09 19:33:42 +0000449#ifndef YYPARSEFREENEVERNULL
drhd26cc542017-01-28 20:46:37 +0000450 if( p==0 ) return;
drh82415f22015-11-09 19:33:42 +0000451#endif
drhd26cc542017-01-28 20:46:37 +0000452 ParseFinalize(p);
453 (*freeProc)(p);
drh75897232000-05-29 14:26:00 +0000454}
drhd26cc542017-01-28 20:46:37 +0000455#endif /* Parse_ENGINEALWAYSONSTACK */
drh75897232000-05-29 14:26:00 +0000456
457/*
drhec424a52008-07-25 15:39:03 +0000458** Return the peak depth of the stack for a parser.
459*/
460#ifdef YYTRACKMAXSTACKDEPTH
461int ParseStackPeak(void *p){
462 yyParser *pParser = (yyParser*)p;
drh118ab652016-05-23 21:56:24 +0000463 return pParser->yyhwm;
drhec424a52008-07-25 15:39:03 +0000464}
465#endif
466
drh0d9de992017-12-26 18:04:23 +0000467/* This array of booleans keeps track of the parser statement
468** coverage. The element yycoverage[X][Y] is set when the parser
469** is in state X and has a lookahead token Y. In a well-tested
470** systems, every element of this matrix should end up being set.
471*/
472#if defined(YYCOVERAGE)
473static unsigned char yycoverage[YYNSTATE][YYNTOKEN];
474#endif
475
476/*
477** Write into out a description of every state/lookahead combination that
drh7038a992017-12-27 17:14:50 +0000478**
479** (1) has not been used by the parser, and
480** (2) is not a syntax error.
481**
482** Return the number of missed state/lookahead combinations.
drh0d9de992017-12-26 18:04:23 +0000483*/
484#if defined(YYCOVERAGE)
485int ParseCoverage(FILE *out){
drh7038a992017-12-27 17:14:50 +0000486 int stateno, iLookAhead, i;
drh0d9de992017-12-26 18:04:23 +0000487 int nMissed = 0;
drh7038a992017-12-27 17:14:50 +0000488 for(stateno=0; stateno<YYNSTATE; stateno++){
489 i = yy_shift_ofst[stateno];
490 for(iLookAhead=0; iLookAhead<YYNTOKEN; iLookAhead++){
drhcf8e0e92017-12-27 17:36:58 +0000491 if( yy_lookahead[i+iLookAhead]!=iLookAhead ) continue;
drh7038a992017-12-27 17:14:50 +0000492 if( yycoverage[stateno][iLookAhead]==0 ) nMissed++;
drh22716cb2017-12-26 18:32:06 +0000493 if( out ){
drh7038a992017-12-27 17:14:50 +0000494 fprintf(out,"State %d lookahead %s %s\n", stateno,
495 yyTokenName[iLookAhead],
496 yycoverage[stateno][iLookAhead] ? "ok" : "missed");
drh22716cb2017-12-26 18:32:06 +0000497 }
drh0d9de992017-12-26 18:04:23 +0000498 }
499 }
500 return nMissed;
501}
502#endif
503
drhec424a52008-07-25 15:39:03 +0000504/*
drh8b582012003-10-21 13:16:03 +0000505** Find the appropriate action for a parser given the terminal
506** look-ahead token iLookAhead.
drh75897232000-05-29 14:26:00 +0000507*/
drhfd39c582018-04-21 22:40:08 +0000508static YYACTIONTYPE yy_find_shift_action(
509 YYCODETYPE iLookAhead, /* The look-ahead token */
510 YYACTIONTYPE stateno /* Current state number */
drh75897232000-05-29 14:26:00 +0000511){
drh8b582012003-10-21 13:16:03 +0000512 int i;
drhfd39c582018-04-21 22:40:08 +0000513
drhef53a9f2017-12-25 00:10:05 +0000514 if( stateno>YY_MAX_SHIFT ) return stateno;
drhae2a4082015-09-07 20:02:39 +0000515 assert( stateno <= YY_SHIFT_COUNT );
drh0d9de992017-12-26 18:04:23 +0000516#if defined(YYCOVERAGE)
517 yycoverage[stateno][iLookAhead] = 1;
518#endif
drha4414042015-11-09 15:06:26 +0000519 do{
520 i = yy_shift_ofst[stateno];
drh54cfb492018-02-09 15:04:51 +0000521 assert( i>=0 );
522 assert( i+YYNTOKEN<=(int)sizeof(yy_lookahead)/sizeof(yy_lookahead[0]) );
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;
drh3a9d6c72017-12-25 04:15:38 +0000526 if( yy_lookahead[i]!=iLookAhead ){
drh4767d972006-06-14 15:03:49 +0000527#ifdef YYFALLBACK
drhc83db9e2016-08-10 01:43:30 +0000528 YYCODETYPE iFallback; /* Fallback token */
529 if( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0])
530 && (iFallback = yyFallback[iLookAhead])!=0 ){
drh4767d972006-06-14 15:03:49 +0000531#ifndef NDEBUG
drhc83db9e2016-08-10 01:43:30 +0000532 if( yyTraceFILE ){
533 fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n",
534 yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]);
drhe09daa92006-06-10 13:29:31 +0000535 }
drha4414042015-11-09 15:06:26 +0000536#endif
drhc83db9e2016-08-10 01:43:30 +0000537 assert( yyFallback[iFallback]==0 ); /* Fallback loop must terminate */
538 iLookAhead = iFallback;
539 continue;
540 }
541#endif
drha4414042015-11-09 15:06:26 +0000542#ifdef YYWILDCARD
drhc83db9e2016-08-10 01:43:30 +0000543 {
544 int j = i - iLookAhead + YYWILDCARD;
545 if(
drha4414042015-11-09 15:06:26 +0000546#if YY_SHIFT_MIN+YYWILDCARD<0
drhc83db9e2016-08-10 01:43:30 +0000547 j>=0 &&
drha4414042015-11-09 15:06:26 +0000548#endif
549#if YY_SHIFT_MAX+YYWILDCARD>=YY_ACTTAB_COUNT
drhc83db9e2016-08-10 01:43:30 +0000550 j<YY_ACTTAB_COUNT &&
drha4414042015-11-09 15:06:26 +0000551#endif
drhc83db9e2016-08-10 01:43:30 +0000552 yy_lookahead[j]==YYWILDCARD && iLookAhead>0
553 ){
drha4414042015-11-09 15:06:26 +0000554#ifndef NDEBUG
drhc83db9e2016-08-10 01:43:30 +0000555 if( yyTraceFILE ){
556 fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n",
557 yyTracePrompt, yyTokenName[iLookAhead],
558 yyTokenName[YYWILDCARD]);
drha4414042015-11-09 15:06:26 +0000559 }
drhc83db9e2016-08-10 01:43:30 +0000560#endif /* NDEBUG */
561 return yy_action[j];
drha4414042015-11-09 15:06:26 +0000562 }
drha4414042015-11-09 15:06:26 +0000563 }
drhc83db9e2016-08-10 01:43:30 +0000564#endif /* YYWILDCARD */
drha4414042015-11-09 15:06:26 +0000565 return yy_default[stateno];
566 }else{
567 return yy_action[i];
drh0bd1f4e2002-06-06 18:54:39 +0000568 }
drha4414042015-11-09 15:06:26 +0000569 }while(1);
drh8b582012003-10-21 13:16:03 +0000570}
571
572/*
573** Find the appropriate action for a parser given the non-terminal
574** look-ahead token iLookAhead.
drh8b582012003-10-21 13:16:03 +0000575*/
576static int yy_find_reduce_action(
drhfd39c582018-04-21 22:40:08 +0000577 YYACTIONTYPE stateno, /* Current state number */
drhd9f291e2006-06-13 11:15:47 +0000578 YYCODETYPE iLookAhead /* The look-ahead token */
drh8b582012003-10-21 13:16:03 +0000579){
580 int i;
drh7f7c2572008-04-27 18:45:10 +0000581#ifdef YYERRORSYMBOL
drhf16371d2009-11-03 19:18:31 +0000582 if( stateno>YY_REDUCE_COUNT ){
drh7f7c2572008-04-27 18:45:10 +0000583 return yy_default[stateno];
584 }
585#else
drhf16371d2009-11-03 19:18:31 +0000586 assert( stateno<=YY_REDUCE_COUNT );
drh7f7c2572008-04-27 18:45:10 +0000587#endif
drh01495b92008-01-23 12:52:40 +0000588 i = yy_reduce_ofst[stateno];
drh01495b92008-01-23 12:52:40 +0000589 assert( iLookAhead!=YYNOCODE );
drh8b582012003-10-21 13:16:03 +0000590 i += iLookAhead;
drh7f7c2572008-04-27 18:45:10 +0000591#ifdef YYERRORSYMBOL
drhf16371d2009-11-03 19:18:31 +0000592 if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){
drh7f7c2572008-04-27 18:45:10 +0000593 return yy_default[stateno];
594 }
595#else
drhf16371d2009-11-03 19:18:31 +0000596 assert( i>=0 && i<YY_ACTTAB_COUNT );
drh01495b92008-01-23 12:52:40 +0000597 assert( yy_lookahead[i]==iLookAhead );
drh7f7c2572008-04-27 18:45:10 +0000598#endif
drh01495b92008-01-23 12:52:40 +0000599 return yy_action[i];
drh75897232000-05-29 14:26:00 +0000600}
601
602/*
drhb19fd012007-03-29 01:44:45 +0000603** The following routine is called if the stack overflows.
604*/
drh45f31be2016-02-16 21:19:49 +0000605static void yyStackOverflow(yyParser *yypParser){
drhfb32c442018-04-21 13:51:42 +0000606 ParseARG_FETCH
607 ParseCTX_FETCH
drhb19fd012007-03-29 01:44:45 +0000608#ifndef NDEBUG
609 if( yyTraceFILE ){
610 fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt);
611 }
612#endif
drhabecc0b2016-05-24 00:40:54 +0000613 while( yypParser->yytos>yypParser->yystack ) yy_pop_parser_stack(yypParser);
drhb19fd012007-03-29 01:44:45 +0000614 /* Here code is inserted which will execute if the parser
615 ** stack every overflows */
drh82415f22015-11-09 19:33:42 +0000616/******** Begin %stack_overflow code ******************************************/
drhb19fd012007-03-29 01:44:45 +0000617%%
drh82415f22015-11-09 19:33:42 +0000618/******** End %stack_overflow code ********************************************/
drhfb32c442018-04-21 13:51:42 +0000619 ParseARG_STORE /* Suppress warning about unused %extra_argument var */
620 ParseCTX_STORE
drhb19fd012007-03-29 01:44:45 +0000621}
622
623/*
drha248a722015-09-07 19:52:55 +0000624** Print tracing information for a SHIFT action
625*/
626#ifndef NDEBUG
drhe58f74f2017-12-24 17:06:41 +0000627static void yyTraceShift(yyParser *yypParser, int yyNewState, const char *zTag){
drha248a722015-09-07 19:52:55 +0000628 if( yyTraceFILE ){
drha248a722015-09-07 19:52:55 +0000629 if( yyNewState<YYNSTATE ){
drhe58f74f2017-12-24 17:06:41 +0000630 fprintf(yyTraceFILE,"%s%s '%s', go to state %d\n",
631 yyTracePrompt, zTag, yyTokenName[yypParser->yytos->major],
drh0c4105e2015-11-10 14:51:22 +0000632 yyNewState);
drha248a722015-09-07 19:52:55 +0000633 }else{
drhe58f74f2017-12-24 17:06:41 +0000634 fprintf(yyTraceFILE,"%s%s '%s', pending reduce %d\n",
635 yyTracePrompt, zTag, yyTokenName[yypParser->yytos->major],
636 yyNewState - YY_MIN_REDUCE);
drha248a722015-09-07 19:52:55 +0000637 }
638 }
639}
640#else
drhe58f74f2017-12-24 17:06:41 +0000641# define yyTraceShift(X,Y,Z)
drha248a722015-09-07 19:52:55 +0000642#endif
643
644/*
drh82415f22015-11-09 19:33:42 +0000645** Perform a shift action.
drh75897232000-05-29 14:26:00 +0000646*/
drha248a722015-09-07 19:52:55 +0000647static void yy_shift(
drh75897232000-05-29 14:26:00 +0000648 yyParser *yypParser, /* The parser to be shifted */
drhfd39c582018-04-21 22:40:08 +0000649 YYACTIONTYPE yyNewState, /* The new state to shift in */
650 YYCODETYPE yyMajor, /* The major token to shift in */
drh45f31be2016-02-16 21:19:49 +0000651 ParseTOKENTYPE yyMinor /* The minor token to shift in */
drh75897232000-05-29 14:26:00 +0000652){
drh3ddfdf72003-12-22 14:53:19 +0000653 yyStackEntry *yytos;
drh118ab652016-05-23 21:56:24 +0000654 yypParser->yytos++;
drhec424a52008-07-25 15:39:03 +0000655#ifdef YYTRACKMAXSTACKDEPTH
drh118ab652016-05-23 21:56:24 +0000656 if( (int)(yypParser->yytos - yypParser->yystack)>yypParser->yyhwm ){
657 yypParser->yyhwm++;
658 assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack) );
drhec424a52008-07-25 15:39:03 +0000659 }
660#endif
drhb19fd012007-03-29 01:44:45 +0000661#if YYSTACKDEPTH>0
drh8b471e72017-06-28 15:01:35 +0000662 if( yypParser->yytos>yypParser->yystackEnd ){
drh63413312016-12-06 17:59:05 +0000663 yypParser->yytos--;
drh45f31be2016-02-16 21:19:49 +0000664 yyStackOverflow(yypParser);
drha248a722015-09-07 19:52:55 +0000665 return;
drh75897232000-05-29 14:26:00 +0000666 }
drhb19fd012007-03-29 01:44:45 +0000667#else
drh118ab652016-05-23 21:56:24 +0000668 if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz] ){
drh8dc82472016-05-27 04:10:47 +0000669 if( yyGrowStack(yypParser) ){
drh63413312016-12-06 17:59:05 +0000670 yypParser->yytos--;
drh45f31be2016-02-16 21:19:49 +0000671 yyStackOverflow(yypParser);
drha248a722015-09-07 19:52:55 +0000672 return;
drhb19fd012007-03-29 01:44:45 +0000673 }
674 }
675#endif
drh0efd37f2016-06-06 18:17:36 +0000676 if( yyNewState > YY_MAX_SHIFT ){
677 yyNewState += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE;
678 }
drh118ab652016-05-23 21:56:24 +0000679 yytos = yypParser->yytos;
drhfd39c582018-04-21 22:40:08 +0000680 yytos->stateno = yyNewState;
681 yytos->major = yyMajor;
drh45f31be2016-02-16 21:19:49 +0000682 yytos->minor.yy0 = yyMinor;
drhe58f74f2017-12-24 17:06:41 +0000683 yyTraceShift(yypParser, yyNewState, "Shift");
drh75897232000-05-29 14:26:00 +0000684}
685
686/* The following table contains information about every rule that
687** is used during the reduce.
688*/
drh57196282004-10-06 15:41:16 +0000689static const struct {
drh6be95362017-06-28 13:47:56 +0000690 YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */
691 signed char nrhs; /* Negative of the number of RHS symbols in the rule */
drh75897232000-05-29 14:26:00 +0000692} yyRuleInfo[] = {
693%%
694};
695
drh1f245e42002-03-11 13:55:50 +0000696static void yy_accept(yyParser*); /* Forward Declaration */
drh75897232000-05-29 14:26:00 +0000697
698/*
699** Perform a reduce action and the shift that must immediately
700** follow the reduce.
drh087316c2017-12-15 12:22:21 +0000701**
702** The yyLookahead and yyLookaheadToken parameters provide reduce actions
703** access to the lookahead token (if any). The yyLookahead will be YYNOCODE
704** if the lookahead token has already been consumed. As this procedure is
705** only called from one place, optimizing compilers will in-line it, which
706** means that the extra parameters have no performance impact.
drh75897232000-05-29 14:26:00 +0000707*/
drhfd39c582018-04-21 22:40:08 +0000708static YYACTIONTYPE yy_reduce(
drh75897232000-05-29 14:26:00 +0000709 yyParser *yypParser, /* The parser */
drh087316c2017-12-15 12:22:21 +0000710 unsigned int yyruleno, /* Number of the rule by which to reduce */
711 int yyLookahead, /* Lookahead token, or YYNOCODE if none */
712 ParseTOKENTYPE yyLookaheadToken /* Value of the lookahead token */
drhfb32c442018-04-21 13:51:42 +0000713 ParseCTX_PDECL /* %extra_context */
drh75897232000-05-29 14:26:00 +0000714){
715 int yygoto; /* The next state */
716 int yyact; /* The next action */
drh1f245e42002-03-11 13:55:50 +0000717 yyStackEntry *yymsp; /* The top of the parser's stack */
drh75897232000-05-29 14:26:00 +0000718 int yysize; /* Amount to pop the stack */
drhfb32c442018-04-21 13:51:42 +0000719 ParseARG_FETCH
drhb9685182018-01-17 13:15:23 +0000720 (void)yyLookahead;
721 (void)yyLookaheadToken;
drh118ab652016-05-23 21:56:24 +0000722 yymsp = yypParser->yytos;
drh0bd1f4e2002-06-06 18:54:39 +0000723#ifndef NDEBUG
drh4ef07702016-03-16 19:45:54 +0000724 if( yyTraceFILE && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){
drh3bd48ab2015-09-07 18:23:37 +0000725 yysize = yyRuleInfo[yyruleno].nrhs;
drhe58f74f2017-12-24 17:06:41 +0000726 if( yysize ){
727 fprintf(yyTraceFILE, "%sReduce %d [%s], go to state %d.\n",
728 yyTracePrompt,
729 yyruleno, yyRuleName[yyruleno], yymsp[yysize].stateno);
730 }else{
731 fprintf(yyTraceFILE, "%sReduce %d [%s].\n",
732 yyTracePrompt, yyruleno, yyRuleName[yyruleno]);
733 }
drh0bd1f4e2002-06-06 18:54:39 +0000734 }
735#endif /* NDEBUG */
drh45f31be2016-02-16 21:19:49 +0000736
737 /* Check that the stack is large enough to grow by a single entry
738 ** if the RHS of the rule is empty. This ensures that there is room
739 ** enough on the stack to push the LHS value */
740 if( yyRuleInfo[yyruleno].nrhs==0 ){
741#ifdef YYTRACKMAXSTACKDEPTH
drh118ab652016-05-23 21:56:24 +0000742 if( (int)(yypParser->yytos - yypParser->yystack)>yypParser->yyhwm ){
743 yypParser->yyhwm++;
744 assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack));
drh45f31be2016-02-16 21:19:49 +0000745 }
746#endif
747#if YYSTACKDEPTH>0
drh8b471e72017-06-28 15:01:35 +0000748 if( yypParser->yytos>=yypParser->yystackEnd ){
drh45f31be2016-02-16 21:19:49 +0000749 yyStackOverflow(yypParser);
drh05ef50d2018-04-23 00:25:31 +0000750 /* The call to yyStackOverflow() above pops the stack until it is
751 ** empty, causing the main parser loop to exit. So the return value
752 ** is never used and does not matter. */
753 return 0;
drh45f31be2016-02-16 21:19:49 +0000754 }
755#else
drh118ab652016-05-23 21:56:24 +0000756 if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz-1] ){
drh8dc82472016-05-27 04:10:47 +0000757 if( yyGrowStack(yypParser) ){
drh45f31be2016-02-16 21:19:49 +0000758 yyStackOverflow(yypParser);
drh05ef50d2018-04-23 00:25:31 +0000759 /* The call to yyStackOverflow() above pops the stack until it is
760 ** empty, causing the main parser loop to exit. So the return value
761 ** is never used and does not matter. */
762 return 0;
drh45f31be2016-02-16 21:19:49 +0000763 }
drh8dc82472016-05-27 04:10:47 +0000764 yymsp = yypParser->yytos;
drh45f31be2016-02-16 21:19:49 +0000765 }
766#endif
767 }
drhcb6c5652007-01-16 18:19:12 +0000768
drh75897232000-05-29 14:26:00 +0000769 switch( yyruleno ){
770 /* Beginning here are the reduction cases. A typical example
771 ** follows:
772 ** case 0:
drh75897232000-05-29 14:26:00 +0000773 ** #line <lineno> <grammarfile>
774 ** { ... } // User supplied code
775 ** #line <lineno> <thisfile>
776 ** break;
777 */
drh82415f22015-11-09 19:33:42 +0000778/********** Begin reduce actions **********************************************/
drh75897232000-05-29 14:26:00 +0000779%%
drh82415f22015-11-09 19:33:42 +0000780/********** End reduce actions ************************************************/
drh75897232000-05-29 14:26:00 +0000781 };
drh4ef07702016-03-16 19:45:54 +0000782 assert( yyruleno<sizeof(yyRuleInfo)/sizeof(yyRuleInfo[0]) );
drh75897232000-05-29 14:26:00 +0000783 yygoto = yyRuleInfo[yyruleno].lhs;
784 yysize = yyRuleInfo[yyruleno].nrhs;
drh6be95362017-06-28 13:47:56 +0000785 yyact = yy_find_reduce_action(yymsp[yysize].stateno,(YYCODETYPE)yygoto);
drhbd8fcc12017-06-28 11:56:18 +0000786
787 /* There are no SHIFTREDUCE actions on nonterminals because the table
788 ** generator has simplified them to pure REDUCE actions. */
789 assert( !(yyact>YY_MAX_SHIFT && yyact<=YY_MAX_SHIFTREDUCE) );
790
791 /* It is not possible for a REDUCE to be followed by an error */
792 assert( yyact!=YY_ERROR_ACTION );
793
drhef53a9f2017-12-25 00:10:05 +0000794 yymsp += yysize+1;
795 yypParser->yytos = yymsp;
796 yymsp->stateno = (YYACTIONTYPE)yyact;
797 yymsp->major = (YYCODETYPE)yygoto;
798 yyTraceShift(yypParser, yyact, "... then shift");
drhfd39c582018-04-21 22:40:08 +0000799 return yyact;
drh75897232000-05-29 14:26:00 +0000800}
801
802/*
803** The following code executes when the parse fails
804*/
drhd3ec02d2009-06-12 02:27:14 +0000805#ifndef YYNOERRORRECOVERY
drh75897232000-05-29 14:26:00 +0000806static void yy_parse_failed(
807 yyParser *yypParser /* The parser */
drh75897232000-05-29 14:26:00 +0000808){
drhfb32c442018-04-21 13:51:42 +0000809 ParseARG_FETCH
810 ParseCTX_FETCH
drh75897232000-05-29 14:26:00 +0000811#ifndef NDEBUG
812 if( yyTraceFILE ){
813 fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt);
814 }
815#endif
drhabecc0b2016-05-24 00:40:54 +0000816 while( yypParser->yytos>yypParser->yystack ) yy_pop_parser_stack(yypParser);
drh75897232000-05-29 14:26:00 +0000817 /* Here code is inserted which will be executed whenever the
818 ** parser fails */
drh82415f22015-11-09 19:33:42 +0000819/************ Begin %parse_failure code ***************************************/
drh75897232000-05-29 14:26:00 +0000820%%
drh82415f22015-11-09 19:33:42 +0000821/************ End %parse_failure code *****************************************/
drhfb32c442018-04-21 13:51:42 +0000822 ParseARG_STORE /* Suppress warning about unused %extra_argument variable */
823 ParseCTX_STORE
drh75897232000-05-29 14:26:00 +0000824}
drhd3ec02d2009-06-12 02:27:14 +0000825#endif /* YYNOERRORRECOVERY */
drh75897232000-05-29 14:26:00 +0000826
827/*
828** The following code executes when a syntax error first occurs.
829*/
830static void yy_syntax_error(
831 yyParser *yypParser, /* The parser */
832 int yymajor, /* The major type of the error token */
drh45f31be2016-02-16 21:19:49 +0000833 ParseTOKENTYPE yyminor /* The minor type of the error token */
drh75897232000-05-29 14:26:00 +0000834){
drhfb32c442018-04-21 13:51:42 +0000835 ParseARG_FETCH
836 ParseCTX_FETCH
drh45f31be2016-02-16 21:19:49 +0000837#define TOKEN yyminor
drh82415f22015-11-09 19:33:42 +0000838/************ Begin %syntax_error code ****************************************/
drh75897232000-05-29 14:26:00 +0000839%%
drh82415f22015-11-09 19:33:42 +0000840/************ End %syntax_error code ******************************************/
drhfb32c442018-04-21 13:51:42 +0000841 ParseARG_STORE /* Suppress warning about unused %extra_argument variable */
842 ParseCTX_STORE
drh75897232000-05-29 14:26:00 +0000843}
844
845/*
846** The following is executed when the parser accepts
847*/
848static void yy_accept(
849 yyParser *yypParser /* The parser */
drh75897232000-05-29 14:26:00 +0000850){
drhfb32c442018-04-21 13:51:42 +0000851 ParseARG_FETCH
852 ParseCTX_FETCH
drh75897232000-05-29 14:26:00 +0000853#ifndef NDEBUG
854 if( yyTraceFILE ){
855 fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt);
856 }
857#endif
drhdd703e22016-07-12 19:54:49 +0000858#ifndef YYNOERRORRECOVERY
859 yypParser->yyerrcnt = -1;
860#endif
drh756b41e2016-05-24 18:55:08 +0000861 assert( yypParser->yytos==yypParser->yystack );
drh75897232000-05-29 14:26:00 +0000862 /* Here code is inserted which will be executed whenever the
863 ** parser accepts */
drh82415f22015-11-09 19:33:42 +0000864/*********** Begin %parse_accept code *****************************************/
drh75897232000-05-29 14:26:00 +0000865%%
drh82415f22015-11-09 19:33:42 +0000866/*********** End %parse_accept code *******************************************/
drhfb32c442018-04-21 13:51:42 +0000867 ParseARG_STORE /* Suppress warning about unused %extra_argument variable */
868 ParseCTX_STORE
drh75897232000-05-29 14:26:00 +0000869}
870
871/* The main parser program.
872** The first argument is a pointer to a structure obtained from
873** "ParseAlloc" which describes the current state of the parser.
874** The second argument is the major token number. The third is
875** the minor token. The fourth optional argument is whatever the
876** user wants (and specified in the grammar) and is available for
877** use by the action routines.
878**
879** Inputs:
880** <ul>
881** <li> A pointer to the parser (an opaque structure.)
882** <li> The major token number.
883** <li> The minor token number.
884** <li> An option argument of a grammar-specified type.
885** </ul>
886**
887** Outputs:
888** None.
889*/
drh75897232000-05-29 14:26:00 +0000890void Parse(
891 void *yyp, /* The parser */
892 int yymajor, /* The major token code number */
893 ParseTOKENTYPE yyminor /* The value for the token */
drh1f245e42002-03-11 13:55:50 +0000894 ParseARG_PDECL /* Optional %extra_argument parameter */
drh75897232000-05-29 14:26:00 +0000895){
896 YYMINORTYPE yyminorunion;
drhfd39c582018-04-21 22:40:08 +0000897 YYACTIONTYPE yyact; /* The parser action. */
drha4414042015-11-09 15:06:26 +0000898#if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY)
drh75897232000-05-29 14:26:00 +0000899 int yyendofinput; /* True if we are at the end of input */
drha4414042015-11-09 15:06:26 +0000900#endif
drhc4dd3fd2008-01-22 01:48:05 +0000901#ifdef YYERRORSYMBOL
drh75897232000-05-29 14:26:00 +0000902 int yyerrorhit = 0; /* True if yymajor has invoked an error */
drhc4dd3fd2008-01-22 01:48:05 +0000903#endif
drhfb32c442018-04-21 13:51:42 +0000904 yyParser *yypParser = (yyParser*)yyp; /* The parser */
905 ParseCTX_FETCH
906 ParseARG_STORE
drh75897232000-05-29 14:26:00 +0000907
drhabecc0b2016-05-24 00:40:54 +0000908 assert( yypParser->yytos!=0 );
drha4414042015-11-09 15:06:26 +0000909#if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY)
drh75897232000-05-29 14:26:00 +0000910 yyendofinput = (yymajor==0);
drha4414042015-11-09 15:06:26 +0000911#endif
drh75897232000-05-29 14:26:00 +0000912
drhfd39c582018-04-21 22:40:08 +0000913 yyact = yypParser->yytos->stateno;
drh75897232000-05-29 14:26:00 +0000914#ifndef NDEBUG
915 if( yyTraceFILE ){
drhfd39c582018-04-21 22:40:08 +0000916 if( yyact < YY_MIN_REDUCE ){
drhe58f74f2017-12-24 17:06:41 +0000917 fprintf(yyTraceFILE,"%sInput '%s' in state %d\n",
drhfd39c582018-04-21 22:40:08 +0000918 yyTracePrompt,yyTokenName[yymajor],yyact);
drhe58f74f2017-12-24 17:06:41 +0000919 }else{
920 fprintf(yyTraceFILE,"%sInput '%s' with pending reduce %d\n",
drhfd39c582018-04-21 22:40:08 +0000921 yyTracePrompt,yyTokenName[yymajor],yyact-YY_MIN_REDUCE);
drhe58f74f2017-12-24 17:06:41 +0000922 }
drh75897232000-05-29 14:26:00 +0000923 }
924#endif
925
926 do{
drhfd39c582018-04-21 22:40:08 +0000927 assert( yyact==yypParser->yytos->stateno );
928 yyact = yy_find_shift_action(yymajor,yyact);
drh5c8241b2017-12-24 23:38:10 +0000929 if( yyact >= YY_MIN_REDUCE ){
drhfd39c582018-04-21 22:40:08 +0000930 yyact = yy_reduce(yypParser,yyact-YY_MIN_REDUCE,yymajor,
931 yyminor ParseCTX_PARAM);
drh5c8241b2017-12-24 23:38:10 +0000932 }else if( yyact <= YY_MAX_SHIFTREDUCE ){
drh45f31be2016-02-16 21:19:49 +0000933 yy_shift(yypParser,yyact,yymajor,yyminor);
drhdab943c2016-02-16 01:01:43 +0000934#ifndef YYNOERRORRECOVERY
drha248a722015-09-07 19:52:55 +0000935 yypParser->yyerrcnt--;
drhdab943c2016-02-16 01:01:43 +0000936#endif
drhfd39c582018-04-21 22:40:08 +0000937 break;
drhef53a9f2017-12-25 00:10:05 +0000938 }else if( yyact==YY_ACCEPT_ACTION ){
drh05ef50d2018-04-23 00:25:31 +0000939 yypParser->yytos--;
940 yy_accept(yypParser);
drhef53a9f2017-12-25 00:10:05 +0000941 return;
drhc4dd3fd2008-01-22 01:48:05 +0000942 }else{
943 assert( yyact == YY_ERROR_ACTION );
drh45f31be2016-02-16 21:19:49 +0000944 yyminorunion.yy0 = yyminor;
drhc4dd3fd2008-01-22 01:48:05 +0000945#ifdef YYERRORSYMBOL
drh3ddfdf72003-12-22 14:53:19 +0000946 int yymx;
drhc4dd3fd2008-01-22 01:48:05 +0000947#endif
drh75897232000-05-29 14:26:00 +0000948#ifndef NDEBUG
949 if( yyTraceFILE ){
950 fprintf(yyTraceFILE,"%sSyntax Error!\n",yyTracePrompt);
951 }
952#endif
953#ifdef YYERRORSYMBOL
954 /* A syntax error has occurred.
955 ** The response to an error depends upon whether or not the
956 ** grammar defines an error token "ERROR".
957 **
958 ** This is what we do if the grammar does define ERROR:
959 **
960 ** * Call the %syntax_error function.
961 **
962 ** * Begin popping the stack until we enter a state where
963 ** it is legal to shift the error symbol, then shift
964 ** the error symbol.
965 **
966 ** * Set the error count to three.
967 **
968 ** * Begin accepting and shifting new tokens. No new error
969 ** processing will occur until three tokens have been
970 ** shifted successfully.
971 **
972 */
drh1f245e42002-03-11 13:55:50 +0000973 if( yypParser->yyerrcnt<0 ){
drh45f31be2016-02-16 21:19:49 +0000974 yy_syntax_error(yypParser,yymajor,yyminor);
drh75897232000-05-29 14:26:00 +0000975 }
drh118ab652016-05-23 21:56:24 +0000976 yymx = yypParser->yytos->major;
drh3ddfdf72003-12-22 14:53:19 +0000977 if( yymx==YYERRORSYMBOL || yyerrorhit ){
drh75897232000-05-29 14:26:00 +0000978#ifndef NDEBUG
979 if( yyTraceFILE ){
980 fprintf(yyTraceFILE,"%sDiscard input token %s\n",
981 yyTracePrompt,yyTokenName[yymajor]);
982 }
983#endif
drh45f31be2016-02-16 21:19:49 +0000984 yy_destructor(yypParser, (YYCODETYPE)yymajor, &yyminorunion);
drh75897232000-05-29 14:26:00 +0000985 yymajor = YYNOCODE;
986 }else{
drh4eda15e2016-10-04 12:20:12 +0000987 while( yypParser->yytos >= yypParser->yystack
drh118ab652016-05-23 21:56:24 +0000988 && yymx != YYERRORSYMBOL
989 && (yyact = yy_find_reduce_action(
990 yypParser->yytos->stateno,
drh3bd48ab2015-09-07 18:23:37 +0000991 YYERRORSYMBOL)) >= YY_MIN_REDUCE
drh75897232000-05-29 14:26:00 +0000992 ){
993 yy_pop_parser_stack(yypParser);
994 }
drh118ab652016-05-23 21:56:24 +0000995 if( yypParser->yytos < yypParser->yystack || yymajor==0 ){
drhb27b7f52008-12-10 18:03:45 +0000996 yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
drh1f245e42002-03-11 13:55:50 +0000997 yy_parse_failed(yypParser);
drh240c7fa2016-07-05 12:47:28 +0000998#ifndef YYNOERRORRECOVERY
999 yypParser->yyerrcnt = -1;
1000#endif
drh75897232000-05-29 14:26:00 +00001001 yymajor = YYNOCODE;
drh3ddfdf72003-12-22 14:53:19 +00001002 }else if( yymx!=YYERRORSYMBOL ){
drh45f31be2016-02-16 21:19:49 +00001003 yy_shift(yypParser,yyact,YYERRORSYMBOL,yyminor);
drh75897232000-05-29 14:26:00 +00001004 }
1005 }
drh1f245e42002-03-11 13:55:50 +00001006 yypParser->yyerrcnt = 3;
drh75897232000-05-29 14:26:00 +00001007 yyerrorhit = 1;
drhfd39c582018-04-21 22:40:08 +00001008 if( yymajor==YYNOCODE ) break;
1009 yyact = yypParser->yytos->stateno;
drhd3ec02d2009-06-12 02:27:14 +00001010#elif defined(YYNOERRORRECOVERY)
1011 /* If the YYNOERRORRECOVERY macro is defined, then do not attempt to
1012 ** do any kind of error recovery. Instead, simply invoke the syntax
1013 ** error routine and continue going as if nothing had happened.
1014 **
1015 ** Applications can set this macro (for example inside %include) if
1016 ** they intend to abandon the parse upon the first syntax error seen.
1017 */
drh45f31be2016-02-16 21:19:49 +00001018 yy_syntax_error(yypParser,yymajor, yyminor);
drhd3ec02d2009-06-12 02:27:14 +00001019 yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
drhfd39c582018-04-21 22:40:08 +00001020 break;
drh75897232000-05-29 14:26:00 +00001021#else /* YYERRORSYMBOL is not defined */
1022 /* This is what we do if the grammar does not define ERROR:
1023 **
1024 ** * Report an error message, and throw away the input token.
1025 **
1026 ** * If the input token is $, then fail the parse.
1027 **
1028 ** As before, subsequent error messages are suppressed until
1029 ** three input tokens have been successfully shifted.
1030 */
drh1f245e42002-03-11 13:55:50 +00001031 if( yypParser->yyerrcnt<=0 ){
drh45f31be2016-02-16 21:19:49 +00001032 yy_syntax_error(yypParser,yymajor, yyminor);
drh75897232000-05-29 14:26:00 +00001033 }
drh1f245e42002-03-11 13:55:50 +00001034 yypParser->yyerrcnt = 3;
drhb27b7f52008-12-10 18:03:45 +00001035 yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
drh75897232000-05-29 14:26:00 +00001036 if( yyendofinput ){
drh1f245e42002-03-11 13:55:50 +00001037 yy_parse_failed(yypParser);
drhd3d4b3c2016-07-08 19:54:38 +00001038#ifndef YYNOERRORRECOVERY
1039 yypParser->yyerrcnt = -1;
1040#endif
drh75897232000-05-29 14:26:00 +00001041 }
drhfd39c582018-04-21 22:40:08 +00001042 break;
drh75897232000-05-29 14:26:00 +00001043#endif
drh75897232000-05-29 14:26:00 +00001044 }
drhfd39c582018-04-21 22:40:08 +00001045 }while( yypParser->yytos>yypParser->yystack );
drh3bd48ab2015-09-07 18:23:37 +00001046#ifndef NDEBUG
1047 if( yyTraceFILE ){
drh118ab652016-05-23 21:56:24 +00001048 yyStackEntry *i;
1049 char cDiv = '[';
drh0c4105e2015-11-10 14:51:22 +00001050 fprintf(yyTraceFILE,"%sReturn. Stack=",yyTracePrompt);
drh118ab652016-05-23 21:56:24 +00001051 for(i=&yypParser->yystack[1]; i<=yypParser->yytos; i++){
1052 fprintf(yyTraceFILE,"%c%s", cDiv, yyTokenName[i->major]);
1053 cDiv = ' ';
1054 }
drh0c4105e2015-11-10 14:51:22 +00001055 fprintf(yyTraceFILE,"]\n");
drh3bd48ab2015-09-07 18:23:37 +00001056 }
1057#endif
drh75897232000-05-29 14:26:00 +00001058 return;
1059}