blob: 2ebc67ee5f63ce7d14822dbd2899eebf2ec07120 [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 *******************************************/
drh3773c252018-06-28 03:38:49 +000093#define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0])))
drh75897232000-05-29 14:26:00 +000094
drh8a415d32009-06-12 13:53:51 +000095/* Define the yytestcase() macro to be a no-op if is not already defined
96** otherwise.
97**
98** Applications can choose to define yytestcase() in the %include section
99** to a macro that can assist in verifying code coverage. For production
100** code the yytestcase() macro should be turned off. But it is useful
101** for testing.
102*/
103#ifndef yytestcase
104# define yytestcase(X)
105#endif
106
drh26c9b5e2008-04-11 14:56:53 +0000107
drh34ff57b2008-07-14 12:27:51 +0000108/* Next are the tables used to determine what action to take based on the
drh8b582012003-10-21 13:16:03 +0000109** current state and lookahead token. These tables are used to implement
110** functions that take a state number and lookahead value and return an
111** action integer.
drh75897232000-05-29 14:26:00 +0000112**
drh8548a052003-10-22 22:15:27 +0000113** Suppose the action integer is N. Then the action is determined as
114** follows
drh75897232000-05-29 14:26:00 +0000115**
drh3bd48ab2015-09-07 18:23:37 +0000116** 0 <= N <= YY_MAX_SHIFT Shift N. That is, push the lookahead
drh8548a052003-10-22 22:15:27 +0000117** token onto the stack and goto state N.
118**
drh3bd48ab2015-09-07 18:23:37 +0000119** N between YY_MIN_SHIFTREDUCE Shift to an arbitrary state then
120** and YY_MAX_SHIFTREDUCE reduce by rule N-YY_MIN_SHIFTREDUCE.
drh8548a052003-10-22 22:15:27 +0000121**
drh3bd48ab2015-09-07 18:23:37 +0000122** N == YY_ERROR_ACTION A syntax error has occurred.
drh8548a052003-10-22 22:15:27 +0000123**
drh3bd48ab2015-09-07 18:23:37 +0000124** N == YY_ACCEPT_ACTION The parser accepts its input.
drh8548a052003-10-22 22:15:27 +0000125**
drh3bd48ab2015-09-07 18:23:37 +0000126** N == YY_NO_ACTION No such action. Denotes unused
drh8548a052003-10-22 22:15:27 +0000127** slots in the yy_action[] table.
128**
drh5c8241b2017-12-24 23:38:10 +0000129** N between YY_MIN_REDUCE Reduce by rule N-YY_MIN_REDUCE
130** and YY_MAX_REDUCE
131**
drh8548a052003-10-22 22:15:27 +0000132** The action table is constructed as a single large table named yy_action[].
drh701b6882016-08-10 13:30:43 +0000133** Given state S and lookahead X, the action is computed as either:
drh75897232000-05-29 14:26:00 +0000134**
drh701b6882016-08-10 13:30:43 +0000135** (A) N = yy_action[ yy_shift_ofst[S] + X ]
136** (B) N = yy_default[S]
drh8b582012003-10-21 13:16:03 +0000137**
drh3a9d6c72017-12-25 04:15:38 +0000138** The (A) formula is preferred. The B formula is used instead if
139** yy_lookahead[yy_shift_ofst[S]+X] is not equal to X.
drh8b582012003-10-21 13:16:03 +0000140**
drh701b6882016-08-10 13:30:43 +0000141** The formulas above are for computing the action when the lookahead is
drh8b582012003-10-21 13:16:03 +0000142** a terminal symbol. If the lookahead is a non-terminal (as occurs after
143** a reduce action) then the yy_reduce_ofst[] array is used in place of
drh3a9d6c72017-12-25 04:15:38 +0000144** the yy_shift_ofst[] array.
drh8b582012003-10-21 13:16:03 +0000145**
146** The following are the tables generated in this section:
147**
148** yy_action[] A single table containing all actions.
149** yy_lookahead[] A table containing the lookahead for each entry in
150** yy_action. Used to detect hash collisions.
151** yy_shift_ofst[] For each state, the offset into yy_action for
152** shifting terminals.
153** yy_reduce_ofst[] For each state, the offset into yy_action for
154** shifting non-terminals after a reduce.
155** yy_default[] Default action for each state.
drh82415f22015-11-09 19:33:42 +0000156**
157*********** Begin parsing tables **********************************************/
drh75897232000-05-29 14:26:00 +0000158%%
drh82415f22015-11-09 19:33:42 +0000159/********** End of lemon-generated parsing tables *****************************/
drh75897232000-05-29 14:26:00 +0000160
drh82415f22015-11-09 19:33:42 +0000161/* The next table maps tokens (terminal symbols) into fallback tokens.
162** If a construct like the following:
drh0bd1f4e2002-06-06 18:54:39 +0000163**
164** %fallback ID X Y Z.
165**
drh34ff57b2008-07-14 12:27:51 +0000166** appears in the grammar, then ID becomes a fallback token for X, Y,
drh0bd1f4e2002-06-06 18:54:39 +0000167** and Z. Whenever one of the tokens X, Y, or Z is input to the parser
168** but it does not parse, the type of the token is changed to ID and
169** the parse is retried before an error is thrown.
drh82415f22015-11-09 19:33:42 +0000170**
171** This feature can be used, for example, to cause some keywords in a language
172** to revert to identifiers if they keyword does not apply in the context where
173** it appears.
drh0bd1f4e2002-06-06 18:54:39 +0000174*/
175#ifdef YYFALLBACK
176static const YYCODETYPE yyFallback[] = {
177%%
178};
179#endif /* YYFALLBACK */
180
drh75897232000-05-29 14:26:00 +0000181/* The following structure represents a single element of the
182** parser's stack. Information stored includes:
183**
184** + The state number for the parser at this level of the stack.
185**
186** + The value of the token stored at this level of the stack.
187** (In other words, the "major" token.)
188**
189** + The semantic value stored at this level of the stack. This is
190** the information used by the action routines in the grammar.
191** It is sometimes called the "minor" token.
drha248a722015-09-07 19:52:55 +0000192**
193** After the "shift" half of a SHIFTREDUCE action, the stateno field
194** actually contains the reduce action for the second half of the
195** SHIFTREDUCE.
drh75897232000-05-29 14:26:00 +0000196*/
197struct yyStackEntry {
drha248a722015-09-07 19:52:55 +0000198 YYACTIONTYPE stateno; /* The state-number, or reduce action in SHIFTREDUCE */
drh2abcd582008-07-24 23:34:07 +0000199 YYCODETYPE major; /* The major token value. This is the code
200 ** number for the token at this stack level */
201 YYMINORTYPE minor; /* The user-supplied minor token value. This
202 ** is the value of the token */
drh75897232000-05-29 14:26:00 +0000203};
drh1f245e42002-03-11 13:55:50 +0000204typedef struct yyStackEntry yyStackEntry;
drh75897232000-05-29 14:26:00 +0000205
206/* The state of the parser is completely contained in an instance of
207** the following structure */
208struct yyParser {
drh118ab652016-05-23 21:56:24 +0000209 yyStackEntry *yytos; /* Pointer to top element of the stack */
drhec424a52008-07-25 15:39:03 +0000210#ifdef YYTRACKMAXSTACKDEPTH
drh118ab652016-05-23 21:56:24 +0000211 int yyhwm; /* High-water mark of the stack */
drhec424a52008-07-25 15:39:03 +0000212#endif
drhdab943c2016-02-16 01:01:43 +0000213#ifndef YYNOERRORRECOVERY
drh1f245e42002-03-11 13:55:50 +0000214 int yyerrcnt; /* Shifts left before out of the error */
drhdab943c2016-02-16 01:01:43 +0000215#endif
drh1f245e42002-03-11 13:55:50 +0000216 ParseARG_SDECL /* A place to hold %extra_argument */
drhfb32c442018-04-21 13:51:42 +0000217 ParseCTX_SDECL /* A place to hold %extra_context */
drhb19fd012007-03-29 01:44:45 +0000218#if YYSTACKDEPTH<=0
219 int yystksz; /* Current side of the stack */
220 yyStackEntry *yystack; /* The parser's stack */
drh8dc82472016-05-27 04:10:47 +0000221 yyStackEntry yystk0; /* First stack entry */
drhb19fd012007-03-29 01:44:45 +0000222#else
drh1f245e42002-03-11 13:55:50 +0000223 yyStackEntry yystack[YYSTACKDEPTH]; /* The parser's stack */
drh8b471e72017-06-28 15:01:35 +0000224 yyStackEntry *yystackEnd; /* Last entry in the stack */
drhb19fd012007-03-29 01:44:45 +0000225#endif
drh75897232000-05-29 14:26:00 +0000226};
227typedef struct yyParser yyParser;
228
229#ifndef NDEBUG
230#include <stdio.h>
231static FILE *yyTraceFILE = 0;
232static char *yyTracePrompt = 0;
drh0bd1f4e2002-06-06 18:54:39 +0000233#endif /* NDEBUG */
drh75897232000-05-29 14:26:00 +0000234
drh0bd1f4e2002-06-06 18:54:39 +0000235#ifndef NDEBUG
drh75897232000-05-29 14:26:00 +0000236/*
237** Turn parser tracing on by giving a stream to which to write the trace
238** and a prompt to preface each trace message. Tracing is turned off
239** by making either argument NULL
240**
241** Inputs:
242** <ul>
243** <li> A FILE* to which trace output should be written.
244** If NULL, then tracing is turned off.
245** <li> A prefix string written at the beginning of every
246** line of trace output. If NULL, then tracing is
247** turned off.
248** </ul>
249**
250** Outputs:
251** None.
252*/
drh75897232000-05-29 14:26:00 +0000253void ParseTrace(FILE *TraceFILE, char *zTracePrompt){
254 yyTraceFILE = TraceFILE;
255 yyTracePrompt = zTracePrompt;
256 if( yyTraceFILE==0 ) yyTracePrompt = 0;
257 else if( yyTracePrompt==0 ) yyTraceFILE = 0;
258}
drh0bd1f4e2002-06-06 18:54:39 +0000259#endif /* NDEBUG */
drh75897232000-05-29 14:26:00 +0000260
drh0d9de992017-12-26 18:04:23 +0000261#if defined(YYCOVERAGE) || !defined(NDEBUG)
drh75897232000-05-29 14:26:00 +0000262/* For tracing shifts, the names of all terminals and nonterminals
263** are required. The following table supplies these names */
drh57196282004-10-06 15:41:16 +0000264static const char *const yyTokenName[] = {
drh75897232000-05-29 14:26:00 +0000265%%
266};
drh0d9de992017-12-26 18:04:23 +0000267#endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */
drh75897232000-05-29 14:26:00 +0000268
drh0bd1f4e2002-06-06 18:54:39 +0000269#ifndef NDEBUG
270/* For tracing reduce actions, the names of all rules are required.
271*/
drh57196282004-10-06 15:41:16 +0000272static const char *const yyRuleName[] = {
drh0bd1f4e2002-06-06 18:54:39 +0000273%%
274};
275#endif /* NDEBUG */
drha1b351a2001-09-14 16:42:12 +0000276
drh960e8c62001-04-03 16:53:21 +0000277
drhb19fd012007-03-29 01:44:45 +0000278#if YYSTACKDEPTH<=0
279/*
drh8dc82472016-05-27 04:10:47 +0000280** Try to increase the size of the parser stack. Return the number
281** of errors. Return 0 on success.
drhb19fd012007-03-29 01:44:45 +0000282*/
drh8dc82472016-05-27 04:10:47 +0000283static int yyGrowStack(yyParser *p){
drhb19fd012007-03-29 01:44:45 +0000284 int newSize;
drhabecc0b2016-05-24 00:40:54 +0000285 int idx;
drhb19fd012007-03-29 01:44:45 +0000286 yyStackEntry *pNew;
287
288 newSize = p->yystksz*2 + 100;
drhabecc0b2016-05-24 00:40:54 +0000289 idx = p->yytos ? (int)(p->yytos - p->yystack) : 0;
drh8dc82472016-05-27 04:10:47 +0000290 if( p->yystack==&p->yystk0 ){
291 pNew = malloc(newSize*sizeof(pNew[0]));
292 if( pNew ) pNew[0] = p->yystk0;
293 }else{
294 pNew = realloc(p->yystack, newSize*sizeof(pNew[0]));
295 }
drhb19fd012007-03-29 01:44:45 +0000296 if( pNew ){
297 p->yystack = pNew;
drhabecc0b2016-05-24 00:40:54 +0000298 p->yytos = &p->yystack[idx];
drhb19fd012007-03-29 01:44:45 +0000299#ifndef NDEBUG
300 if( yyTraceFILE ){
drh8dc82472016-05-27 04:10:47 +0000301 fprintf(yyTraceFILE,"%sStack grows from %d to %d entries.\n",
302 yyTracePrompt, p->yystksz, newSize);
drhb19fd012007-03-29 01:44:45 +0000303 }
304#endif
drh8dc82472016-05-27 04:10:47 +0000305 p->yystksz = newSize;
drhb19fd012007-03-29 01:44:45 +0000306 }
drh8dc82472016-05-27 04:10:47 +0000307 return pNew==0;
drhb19fd012007-03-29 01:44:45 +0000308}
309#endif
310
drh82415f22015-11-09 19:33:42 +0000311/* Datatype of the argument to the memory allocated passed as the
312** second argument to ParseAlloc() below. This can be changed by
313** putting an appropriate #define in the %include section of the input
314** grammar.
315*/
316#ifndef YYMALLOCARGTYPE
317# define YYMALLOCARGTYPE size_t
318#endif
319
drhd26cc542017-01-28 20:46:37 +0000320/* Initialize a new parser that has already been allocated.
321*/
drhfb32c442018-04-21 13:51:42 +0000322void ParseInit(void *yypRawParser ParseCTX_PDECL){
323 yyParser *yypParser = (yyParser*)yypRawParser;
324 ParseCTX_STORE
drhd26cc542017-01-28 20:46:37 +0000325#ifdef YYTRACKMAXSTACKDEPTH
drhfb32c442018-04-21 13:51:42 +0000326 yypParser->yyhwm = 0;
drhd26cc542017-01-28 20:46:37 +0000327#endif
328#if YYSTACKDEPTH<=0
drhfb32c442018-04-21 13:51:42 +0000329 yypParser->yytos = NULL;
330 yypParser->yystack = NULL;
331 yypParser->yystksz = 0;
332 if( yyGrowStack(yypParser) ){
333 yypParser->yystack = &yypParser->yystk0;
334 yypParser->yystksz = 1;
drhd26cc542017-01-28 20:46:37 +0000335 }
336#endif
337#ifndef YYNOERRORRECOVERY
drhfb32c442018-04-21 13:51:42 +0000338 yypParser->yyerrcnt = -1;
drhd26cc542017-01-28 20:46:37 +0000339#endif
drhfb32c442018-04-21 13:51:42 +0000340 yypParser->yytos = yypParser->yystack;
341 yypParser->yystack[0].stateno = 0;
342 yypParser->yystack[0].major = 0;
drh92395c52017-07-04 12:50:00 +0000343#if YYSTACKDEPTH>0
drhfb32c442018-04-21 13:51:42 +0000344 yypParser->yystackEnd = &yypParser->yystack[YYSTACKDEPTH-1];
drh92395c52017-07-04 12:50:00 +0000345#endif
drhd26cc542017-01-28 20:46:37 +0000346}
347
348#ifndef Parse_ENGINEALWAYSONSTACK
drh75897232000-05-29 14:26:00 +0000349/*
350** This function allocates a new parser.
351** The only argument is a pointer to a function which works like
352** malloc.
353**
354** Inputs:
355** A pointer to the function used to allocate memory.
356**
357** Outputs:
358** A pointer to a parser. This pointer is used in subsequent calls
359** to Parse and ParseFree.
360*/
drhfb32c442018-04-21 13:51:42 +0000361void *ParseAlloc(void *(*mallocProc)(YYMALLOCARGTYPE) ParseCTX_PDECL){
362 yyParser *yypParser;
363 yypParser = (yyParser*)(*mallocProc)( (YYMALLOCARGTYPE)sizeof(yyParser) );
364 if( yypParser ){
365 ParseCTX_STORE
366 ParseInit(yypParser ParseCTX_PARAM);
367 }
368 return (void*)yypParser;
drh75897232000-05-29 14:26:00 +0000369}
drhd26cc542017-01-28 20:46:37 +0000370#endif /* Parse_ENGINEALWAYSONSTACK */
371
drh75897232000-05-29 14:26:00 +0000372
drh82415f22015-11-09 19:33:42 +0000373/* The following function deletes the "minor type" or semantic value
374** associated with a symbol. The symbol can be either a terminal
375** or nonterminal. "yymajor" is the symbol code, and "yypminor" is
376** a pointer to the value to be deleted. The code used to do the
377** deletions is derived from the %destructor and/or %token_destructor
378** directives of the input grammar.
drh75897232000-05-29 14:26:00 +0000379*/
drh633e6d52008-07-28 19:34:53 +0000380static void yy_destructor(
381 yyParser *yypParser, /* The parser */
382 YYCODETYPE yymajor, /* Type code for object to destroy */
383 YYMINORTYPE *yypminor /* The object to be destroyed */
384){
drhfb32c442018-04-21 13:51:42 +0000385 ParseARG_FETCH
386 ParseCTX_FETCH
drh75897232000-05-29 14:26:00 +0000387 switch( yymajor ){
388 /* Here is inserted the actions which take place when a
389 ** terminal or non-terminal is destroyed. This can happen
390 ** when the symbol is popped from the stack during a
391 ** reduce or during error processing or when a parser is
392 ** being destroyed before it is finished parsing.
393 **
394 ** Note: during a reduce, the only symbols destroyed are those
drh82415f22015-11-09 19:33:42 +0000395 ** which appear on the RHS of the rule, but which are *not* used
drh75897232000-05-29 14:26:00 +0000396 ** inside the C code.
397 */
drh82415f22015-11-09 19:33:42 +0000398/********* Begin destructor definitions ***************************************/
drh75897232000-05-29 14:26:00 +0000399%%
drh82415f22015-11-09 19:33:42 +0000400/********* End destructor definitions *****************************************/
drh75897232000-05-29 14:26:00 +0000401 default: break; /* If no destructor action specified: do nothing */
402 }
403}
404
405/*
406** Pop the parser's stack once.
407**
408** If there is a destructor routine associated with the token which
409** is popped from the stack, then call it.
drh75897232000-05-29 14:26:00 +0000410*/
drh3781f012015-11-09 14:11:37 +0000411static void yy_pop_parser_stack(yyParser *pParser){
412 yyStackEntry *yytos;
drh118ab652016-05-23 21:56:24 +0000413 assert( pParser->yytos!=0 );
drh240c7fa2016-07-05 12:47:28 +0000414 assert( pParser->yytos > pParser->yystack );
drh118ab652016-05-23 21:56:24 +0000415 yytos = pParser->yytos--;
drh75897232000-05-29 14:26:00 +0000416#ifndef NDEBUG
drh3781f012015-11-09 14:11:37 +0000417 if( yyTraceFILE ){
drh75897232000-05-29 14:26:00 +0000418 fprintf(yyTraceFILE,"%sPopping %s\n",
419 yyTracePrompt,
drh3ddfdf72003-12-22 14:53:19 +0000420 yyTokenName[yytos->major]);
drh75897232000-05-29 14:26:00 +0000421 }
422#endif
drh3781f012015-11-09 14:11:37 +0000423 yy_destructor(pParser, yytos->major, &yytos->minor);
drh75897232000-05-29 14:26:00 +0000424}
425
drhd26cc542017-01-28 20:46:37 +0000426/*
427** Clear all secondary memory allocations from the parser
428*/
429void ParseFinalize(void *p){
430 yyParser *pParser = (yyParser*)p;
431 while( pParser->yytos>pParser->yystack ) yy_pop_parser_stack(pParser);
432#if YYSTACKDEPTH<=0
433 if( pParser->yystack!=&pParser->yystk0 ) free(pParser->yystack);
434#endif
435}
436
437#ifndef Parse_ENGINEALWAYSONSTACK
drh75897232000-05-29 14:26:00 +0000438/*
drh82415f22015-11-09 19:33:42 +0000439** Deallocate and destroy a parser. Destructors are called for
drh75897232000-05-29 14:26:00 +0000440** all stack elements before shutting the parser down.
441**
drh82415f22015-11-09 19:33:42 +0000442** If the YYPARSEFREENEVERNULL macro exists (for example because it
443** is defined in a %include section of the input grammar) then it is
444** assumed that the input pointer is never NULL.
drh75897232000-05-29 14:26:00 +0000445*/
drh75897232000-05-29 14:26:00 +0000446void ParseFree(
drh960e8c62001-04-03 16:53:21 +0000447 void *p, /* The parser to be deleted */
448 void (*freeProc)(void*) /* Function used to reclaim memory */
drh75897232000-05-29 14:26:00 +0000449){
drh82415f22015-11-09 19:33:42 +0000450#ifndef YYPARSEFREENEVERNULL
drhd26cc542017-01-28 20:46:37 +0000451 if( p==0 ) return;
drh82415f22015-11-09 19:33:42 +0000452#endif
drhd26cc542017-01-28 20:46:37 +0000453 ParseFinalize(p);
454 (*freeProc)(p);
drh75897232000-05-29 14:26:00 +0000455}
drhd26cc542017-01-28 20:46:37 +0000456#endif /* Parse_ENGINEALWAYSONSTACK */
drh75897232000-05-29 14:26:00 +0000457
458/*
drhec424a52008-07-25 15:39:03 +0000459** Return the peak depth of the stack for a parser.
460*/
461#ifdef YYTRACKMAXSTACKDEPTH
462int ParseStackPeak(void *p){
463 yyParser *pParser = (yyParser*)p;
drh118ab652016-05-23 21:56:24 +0000464 return pParser->yyhwm;
drhec424a52008-07-25 15:39:03 +0000465}
466#endif
467
drh0d9de992017-12-26 18:04:23 +0000468/* This array of booleans keeps track of the parser statement
469** coverage. The element yycoverage[X][Y] is set when the parser
470** is in state X and has a lookahead token Y. In a well-tested
471** systems, every element of this matrix should end up being set.
472*/
473#if defined(YYCOVERAGE)
474static unsigned char yycoverage[YYNSTATE][YYNTOKEN];
475#endif
476
477/*
478** Write into out a description of every state/lookahead combination that
drh7038a992017-12-27 17:14:50 +0000479**
480** (1) has not been used by the parser, and
481** (2) is not a syntax error.
482**
483** Return the number of missed state/lookahead combinations.
drh0d9de992017-12-26 18:04:23 +0000484*/
485#if defined(YYCOVERAGE)
486int ParseCoverage(FILE *out){
drh7038a992017-12-27 17:14:50 +0000487 int stateno, iLookAhead, i;
drh0d9de992017-12-26 18:04:23 +0000488 int nMissed = 0;
drh7038a992017-12-27 17:14:50 +0000489 for(stateno=0; stateno<YYNSTATE; stateno++){
490 i = yy_shift_ofst[stateno];
491 for(iLookAhead=0; iLookAhead<YYNTOKEN; iLookAhead++){
drhcf8e0e92017-12-27 17:36:58 +0000492 if( yy_lookahead[i+iLookAhead]!=iLookAhead ) continue;
drh7038a992017-12-27 17:14:50 +0000493 if( yycoverage[stateno][iLookAhead]==0 ) nMissed++;
drh22716cb2017-12-26 18:32:06 +0000494 if( out ){
drh7038a992017-12-27 17:14:50 +0000495 fprintf(out,"State %d lookahead %s %s\n", stateno,
496 yyTokenName[iLookAhead],
497 yycoverage[stateno][iLookAhead] ? "ok" : "missed");
drh22716cb2017-12-26 18:32:06 +0000498 }
drh0d9de992017-12-26 18:04:23 +0000499 }
500 }
501 return nMissed;
502}
503#endif
504
drhec424a52008-07-25 15:39:03 +0000505/*
drh8b582012003-10-21 13:16:03 +0000506** Find the appropriate action for a parser given the terminal
507** look-ahead token iLookAhead.
drh75897232000-05-29 14:26:00 +0000508*/
drhfd39c582018-04-21 22:40:08 +0000509static YYACTIONTYPE yy_find_shift_action(
510 YYCODETYPE iLookAhead, /* The look-ahead token */
511 YYACTIONTYPE stateno /* Current state number */
drh75897232000-05-29 14:26:00 +0000512){
drh8b582012003-10-21 13:16:03 +0000513 int i;
drhfd39c582018-04-21 22:40:08 +0000514
drhef53a9f2017-12-25 00:10:05 +0000515 if( stateno>YY_MAX_SHIFT ) return stateno;
drhae2a4082015-09-07 20:02:39 +0000516 assert( stateno <= YY_SHIFT_COUNT );
drh0d9de992017-12-26 18:04:23 +0000517#if defined(YYCOVERAGE)
518 yycoverage[stateno][iLookAhead] = 1;
519#endif
drha4414042015-11-09 15:06:26 +0000520 do{
521 i = yy_shift_ofst[stateno];
drh54cfb492018-02-09 15:04:51 +0000522 assert( i>=0 );
dan5001b332018-06-30 19:12:36 +0000523 /* assert( i+YYNTOKEN<=(int)YY_NLOOKAHEAD ); */
drha4414042015-11-09 15:06:26 +0000524 assert( iLookAhead!=YYNOCODE );
drh7038a992017-12-27 17:14:50 +0000525 assert( iLookAhead < YYNTOKEN );
drha4414042015-11-09 15:06:26 +0000526 i += iLookAhead;
dan5001b332018-06-30 19:12:36 +0000527 if( i>=YY_NLOOKAHEAD || yy_lookahead[i]!=iLookAhead ){
drh4767d972006-06-14 15:03:49 +0000528#ifdef YYFALLBACK
drhc83db9e2016-08-10 01:43:30 +0000529 YYCODETYPE iFallback; /* Fallback token */
530 if( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0])
531 && (iFallback = yyFallback[iLookAhead])!=0 ){
drh4767d972006-06-14 15:03:49 +0000532#ifndef NDEBUG
drhc83db9e2016-08-10 01:43:30 +0000533 if( yyTraceFILE ){
534 fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n",
535 yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]);
drhe09daa92006-06-10 13:29:31 +0000536 }
drha4414042015-11-09 15:06:26 +0000537#endif
drhc83db9e2016-08-10 01:43:30 +0000538 assert( yyFallback[iFallback]==0 ); /* Fallback loop must terminate */
539 iLookAhead = iFallback;
540 continue;
541 }
542#endif
drha4414042015-11-09 15:06:26 +0000543#ifdef YYWILDCARD
drhc83db9e2016-08-10 01:43:30 +0000544 {
545 int j = i - iLookAhead + YYWILDCARD;
546 if(
drha4414042015-11-09 15:06:26 +0000547#if YY_SHIFT_MIN+YYWILDCARD<0
drhc83db9e2016-08-10 01:43:30 +0000548 j>=0 &&
drha4414042015-11-09 15:06:26 +0000549#endif
550#if YY_SHIFT_MAX+YYWILDCARD>=YY_ACTTAB_COUNT
drhc83db9e2016-08-10 01:43:30 +0000551 j<YY_ACTTAB_COUNT &&
drha4414042015-11-09 15:06:26 +0000552#endif
drhc7bf5712018-07-09 22:49:01 +0000553 j<(int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0])) &&
drhc83db9e2016-08-10 01:43:30 +0000554 yy_lookahead[j]==YYWILDCARD && iLookAhead>0
555 ){
drha4414042015-11-09 15:06:26 +0000556#ifndef NDEBUG
drhc83db9e2016-08-10 01:43:30 +0000557 if( yyTraceFILE ){
558 fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n",
559 yyTracePrompt, yyTokenName[iLookAhead],
560 yyTokenName[YYWILDCARD]);
drha4414042015-11-09 15:06:26 +0000561 }
drhc83db9e2016-08-10 01:43:30 +0000562#endif /* NDEBUG */
563 return yy_action[j];
drha4414042015-11-09 15:06:26 +0000564 }
drha4414042015-11-09 15:06:26 +0000565 }
drhc83db9e2016-08-10 01:43:30 +0000566#endif /* YYWILDCARD */
drha4414042015-11-09 15:06:26 +0000567 return yy_default[stateno];
568 }else{
569 return yy_action[i];
drh0bd1f4e2002-06-06 18:54:39 +0000570 }
drha4414042015-11-09 15:06:26 +0000571 }while(1);
drh8b582012003-10-21 13:16:03 +0000572}
573
574/*
575** Find the appropriate action for a parser given the non-terminal
576** look-ahead token iLookAhead.
drh8b582012003-10-21 13:16:03 +0000577*/
mistachkin709c8222018-07-22 21:23:19 +0000578static YYACTIONTYPE yy_find_reduce_action(
drhfd39c582018-04-21 22:40:08 +0000579 YYACTIONTYPE stateno, /* Current state number */
drhd9f291e2006-06-13 11:15:47 +0000580 YYCODETYPE iLookAhead /* The look-ahead token */
drh8b582012003-10-21 13:16:03 +0000581){
582 int i;
drh7f7c2572008-04-27 18:45:10 +0000583#ifdef YYERRORSYMBOL
drhf16371d2009-11-03 19:18:31 +0000584 if( stateno>YY_REDUCE_COUNT ){
drh7f7c2572008-04-27 18:45:10 +0000585 return yy_default[stateno];
586 }
587#else
drhf16371d2009-11-03 19:18:31 +0000588 assert( stateno<=YY_REDUCE_COUNT );
drh7f7c2572008-04-27 18:45:10 +0000589#endif
drh01495b92008-01-23 12:52:40 +0000590 i = yy_reduce_ofst[stateno];
drh01495b92008-01-23 12:52:40 +0000591 assert( iLookAhead!=YYNOCODE );
drh8b582012003-10-21 13:16:03 +0000592 i += iLookAhead;
drh7f7c2572008-04-27 18:45:10 +0000593#ifdef YYERRORSYMBOL
drhf16371d2009-11-03 19:18:31 +0000594 if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){
drh7f7c2572008-04-27 18:45:10 +0000595 return yy_default[stateno];
596 }
597#else
drhf16371d2009-11-03 19:18:31 +0000598 assert( i>=0 && i<YY_ACTTAB_COUNT );
drh01495b92008-01-23 12:52:40 +0000599 assert( yy_lookahead[i]==iLookAhead );
drh7f7c2572008-04-27 18:45:10 +0000600#endif
drh01495b92008-01-23 12:52:40 +0000601 return yy_action[i];
drh75897232000-05-29 14:26:00 +0000602}
603
604/*
drhb19fd012007-03-29 01:44:45 +0000605** The following routine is called if the stack overflows.
606*/
drh45f31be2016-02-16 21:19:49 +0000607static void yyStackOverflow(yyParser *yypParser){
drhfb32c442018-04-21 13:51:42 +0000608 ParseARG_FETCH
609 ParseCTX_FETCH
drhb19fd012007-03-29 01:44:45 +0000610#ifndef NDEBUG
611 if( yyTraceFILE ){
612 fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt);
613 }
614#endif
drhabecc0b2016-05-24 00:40:54 +0000615 while( yypParser->yytos>yypParser->yystack ) yy_pop_parser_stack(yypParser);
drhb19fd012007-03-29 01:44:45 +0000616 /* Here code is inserted which will execute if the parser
617 ** stack every overflows */
drh82415f22015-11-09 19:33:42 +0000618/******** Begin %stack_overflow code ******************************************/
drhb19fd012007-03-29 01:44:45 +0000619%%
drh82415f22015-11-09 19:33:42 +0000620/******** End %stack_overflow code ********************************************/
drhfb32c442018-04-21 13:51:42 +0000621 ParseARG_STORE /* Suppress warning about unused %extra_argument var */
622 ParseCTX_STORE
drhb19fd012007-03-29 01:44:45 +0000623}
624
625/*
drha248a722015-09-07 19:52:55 +0000626** Print tracing information for a SHIFT action
627*/
628#ifndef NDEBUG
drhe58f74f2017-12-24 17:06:41 +0000629static void yyTraceShift(yyParser *yypParser, int yyNewState, const char *zTag){
drha248a722015-09-07 19:52:55 +0000630 if( yyTraceFILE ){
drha248a722015-09-07 19:52:55 +0000631 if( yyNewState<YYNSTATE ){
drhe58f74f2017-12-24 17:06:41 +0000632 fprintf(yyTraceFILE,"%s%s '%s', go to state %d\n",
633 yyTracePrompt, zTag, yyTokenName[yypParser->yytos->major],
drh0c4105e2015-11-10 14:51:22 +0000634 yyNewState);
drha248a722015-09-07 19:52:55 +0000635 }else{
drhe58f74f2017-12-24 17:06:41 +0000636 fprintf(yyTraceFILE,"%s%s '%s', pending reduce %d\n",
637 yyTracePrompt, zTag, yyTokenName[yypParser->yytos->major],
638 yyNewState - YY_MIN_REDUCE);
drha248a722015-09-07 19:52:55 +0000639 }
640 }
641}
642#else
drhe58f74f2017-12-24 17:06:41 +0000643# define yyTraceShift(X,Y,Z)
drha248a722015-09-07 19:52:55 +0000644#endif
645
646/*
drh82415f22015-11-09 19:33:42 +0000647** Perform a shift action.
drh75897232000-05-29 14:26:00 +0000648*/
drha248a722015-09-07 19:52:55 +0000649static void yy_shift(
drh75897232000-05-29 14:26:00 +0000650 yyParser *yypParser, /* The parser to be shifted */
drhfd39c582018-04-21 22:40:08 +0000651 YYACTIONTYPE yyNewState, /* The new state to shift in */
652 YYCODETYPE yyMajor, /* The major token to shift in */
drh45f31be2016-02-16 21:19:49 +0000653 ParseTOKENTYPE yyMinor /* The minor token to shift in */
drh75897232000-05-29 14:26:00 +0000654){
drh3ddfdf72003-12-22 14:53:19 +0000655 yyStackEntry *yytos;
drh118ab652016-05-23 21:56:24 +0000656 yypParser->yytos++;
drhec424a52008-07-25 15:39:03 +0000657#ifdef YYTRACKMAXSTACKDEPTH
drh118ab652016-05-23 21:56:24 +0000658 if( (int)(yypParser->yytos - yypParser->yystack)>yypParser->yyhwm ){
659 yypParser->yyhwm++;
660 assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack) );
drhec424a52008-07-25 15:39:03 +0000661 }
662#endif
drhb19fd012007-03-29 01:44:45 +0000663#if YYSTACKDEPTH>0
drh8b471e72017-06-28 15:01:35 +0000664 if( yypParser->yytos>yypParser->yystackEnd ){
drh63413312016-12-06 17:59:05 +0000665 yypParser->yytos--;
drh45f31be2016-02-16 21:19:49 +0000666 yyStackOverflow(yypParser);
drha248a722015-09-07 19:52:55 +0000667 return;
drh75897232000-05-29 14:26:00 +0000668 }
drhb19fd012007-03-29 01:44:45 +0000669#else
drh118ab652016-05-23 21:56:24 +0000670 if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz] ){
drh8dc82472016-05-27 04:10:47 +0000671 if( yyGrowStack(yypParser) ){
drh63413312016-12-06 17:59:05 +0000672 yypParser->yytos--;
drh45f31be2016-02-16 21:19:49 +0000673 yyStackOverflow(yypParser);
drha248a722015-09-07 19:52:55 +0000674 return;
drhb19fd012007-03-29 01:44:45 +0000675 }
676 }
677#endif
drh0efd37f2016-06-06 18:17:36 +0000678 if( yyNewState > YY_MAX_SHIFT ){
679 yyNewState += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE;
680 }
drh118ab652016-05-23 21:56:24 +0000681 yytos = yypParser->yytos;
drhfd39c582018-04-21 22:40:08 +0000682 yytos->stateno = yyNewState;
683 yytos->major = yyMajor;
drh45f31be2016-02-16 21:19:49 +0000684 yytos->minor.yy0 = yyMinor;
drhe58f74f2017-12-24 17:06:41 +0000685 yyTraceShift(yypParser, yyNewState, "Shift");
drh75897232000-05-29 14:26:00 +0000686}
687
688/* The following table contains information about every rule that
689** is used during the reduce.
690*/
drh57196282004-10-06 15:41:16 +0000691static const struct {
drh6be95362017-06-28 13:47:56 +0000692 YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */
693 signed char nrhs; /* Negative of the number of RHS symbols in the rule */
drh75897232000-05-29 14:26:00 +0000694} yyRuleInfo[] = {
695%%
696};
697
drh1f245e42002-03-11 13:55:50 +0000698static void yy_accept(yyParser*); /* Forward Declaration */
drh75897232000-05-29 14:26:00 +0000699
700/*
701** Perform a reduce action and the shift that must immediately
702** follow the reduce.
drh087316c2017-12-15 12:22:21 +0000703**
704** The yyLookahead and yyLookaheadToken parameters provide reduce actions
705** access to the lookahead token (if any). The yyLookahead will be YYNOCODE
706** if the lookahead token has already been consumed. As this procedure is
707** only called from one place, optimizing compilers will in-line it, which
708** means that the extra parameters have no performance impact.
drh75897232000-05-29 14:26:00 +0000709*/
drhfd39c582018-04-21 22:40:08 +0000710static YYACTIONTYPE yy_reduce(
drh75897232000-05-29 14:26:00 +0000711 yyParser *yypParser, /* The parser */
drh087316c2017-12-15 12:22:21 +0000712 unsigned int yyruleno, /* Number of the rule by which to reduce */
713 int yyLookahead, /* Lookahead token, or YYNOCODE if none */
714 ParseTOKENTYPE yyLookaheadToken /* Value of the lookahead token */
drhfb32c442018-04-21 13:51:42 +0000715 ParseCTX_PDECL /* %extra_context */
drh75897232000-05-29 14:26:00 +0000716){
717 int yygoto; /* The next state */
mistachkin709c8222018-07-22 21:23:19 +0000718 YYACTIONTYPE yyact; /* The next action */
drh1f245e42002-03-11 13:55:50 +0000719 yyStackEntry *yymsp; /* The top of the parser's stack */
drh75897232000-05-29 14:26:00 +0000720 int yysize; /* Amount to pop the stack */
drhfb32c442018-04-21 13:51:42 +0000721 ParseARG_FETCH
drhb9685182018-01-17 13:15:23 +0000722 (void)yyLookahead;
723 (void)yyLookaheadToken;
drh118ab652016-05-23 21:56:24 +0000724 yymsp = yypParser->yytos;
drh0bd1f4e2002-06-06 18:54:39 +0000725#ifndef NDEBUG
drh4ef07702016-03-16 19:45:54 +0000726 if( yyTraceFILE && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){
drh3bd48ab2015-09-07 18:23:37 +0000727 yysize = yyRuleInfo[yyruleno].nrhs;
drhe58f74f2017-12-24 17:06:41 +0000728 if( yysize ){
729 fprintf(yyTraceFILE, "%sReduce %d [%s], go to state %d.\n",
730 yyTracePrompt,
731 yyruleno, yyRuleName[yyruleno], yymsp[yysize].stateno);
732 }else{
733 fprintf(yyTraceFILE, "%sReduce %d [%s].\n",
734 yyTracePrompt, yyruleno, yyRuleName[yyruleno]);
735 }
drh0bd1f4e2002-06-06 18:54:39 +0000736 }
737#endif /* NDEBUG */
drh45f31be2016-02-16 21:19:49 +0000738
739 /* Check that the stack is large enough to grow by a single entry
740 ** if the RHS of the rule is empty. This ensures that there is room
741 ** enough on the stack to push the LHS value */
742 if( yyRuleInfo[yyruleno].nrhs==0 ){
743#ifdef YYTRACKMAXSTACKDEPTH
drh118ab652016-05-23 21:56:24 +0000744 if( (int)(yypParser->yytos - yypParser->yystack)>yypParser->yyhwm ){
745 yypParser->yyhwm++;
746 assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack));
drh45f31be2016-02-16 21:19:49 +0000747 }
748#endif
749#if YYSTACKDEPTH>0
drh8b471e72017-06-28 15:01:35 +0000750 if( yypParser->yytos>=yypParser->yystackEnd ){
drh45f31be2016-02-16 21:19:49 +0000751 yyStackOverflow(yypParser);
drh05ef50d2018-04-23 00:25:31 +0000752 /* The call to yyStackOverflow() above pops the stack until it is
753 ** empty, causing the main parser loop to exit. So the return value
754 ** is never used and does not matter. */
755 return 0;
drh45f31be2016-02-16 21:19:49 +0000756 }
757#else
drh118ab652016-05-23 21:56:24 +0000758 if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz-1] ){
drh8dc82472016-05-27 04:10:47 +0000759 if( yyGrowStack(yypParser) ){
drh45f31be2016-02-16 21:19:49 +0000760 yyStackOverflow(yypParser);
drh05ef50d2018-04-23 00:25:31 +0000761 /* The call to yyStackOverflow() above pops the stack until it is
762 ** empty, causing the main parser loop to exit. So the return value
763 ** is never used and does not matter. */
764 return 0;
drh45f31be2016-02-16 21:19:49 +0000765 }
drh8dc82472016-05-27 04:10:47 +0000766 yymsp = yypParser->yytos;
drh45f31be2016-02-16 21:19:49 +0000767 }
768#endif
769 }
drhcb6c5652007-01-16 18:19:12 +0000770
drh75897232000-05-29 14:26:00 +0000771 switch( yyruleno ){
772 /* Beginning here are the reduction cases. A typical example
773 ** follows:
774 ** case 0:
drh75897232000-05-29 14:26:00 +0000775 ** #line <lineno> <grammarfile>
776 ** { ... } // User supplied code
777 ** #line <lineno> <thisfile>
778 ** break;
779 */
drh82415f22015-11-09 19:33:42 +0000780/********** Begin reduce actions **********************************************/
drh75897232000-05-29 14:26:00 +0000781%%
drh82415f22015-11-09 19:33:42 +0000782/********** End reduce actions ************************************************/
drh75897232000-05-29 14:26:00 +0000783 };
drh4ef07702016-03-16 19:45:54 +0000784 assert( yyruleno<sizeof(yyRuleInfo)/sizeof(yyRuleInfo[0]) );
drh75897232000-05-29 14:26:00 +0000785 yygoto = yyRuleInfo[yyruleno].lhs;
786 yysize = yyRuleInfo[yyruleno].nrhs;
drh6be95362017-06-28 13:47:56 +0000787 yyact = yy_find_reduce_action(yymsp[yysize].stateno,(YYCODETYPE)yygoto);
drhbd8fcc12017-06-28 11:56:18 +0000788
789 /* There are no SHIFTREDUCE actions on nonterminals because the table
790 ** generator has simplified them to pure REDUCE actions. */
791 assert( !(yyact>YY_MAX_SHIFT && yyact<=YY_MAX_SHIFTREDUCE) );
792
793 /* It is not possible for a REDUCE to be followed by an error */
794 assert( yyact!=YY_ERROR_ACTION );
795
drhef53a9f2017-12-25 00:10:05 +0000796 yymsp += yysize+1;
797 yypParser->yytos = yymsp;
798 yymsp->stateno = (YYACTIONTYPE)yyact;
799 yymsp->major = (YYCODETYPE)yygoto;
800 yyTraceShift(yypParser, yyact, "... then shift");
drhfd39c582018-04-21 22:40:08 +0000801 return yyact;
drh75897232000-05-29 14:26:00 +0000802}
803
804/*
805** The following code executes when the parse fails
806*/
drhd3ec02d2009-06-12 02:27:14 +0000807#ifndef YYNOERRORRECOVERY
drh75897232000-05-29 14:26:00 +0000808static void yy_parse_failed(
809 yyParser *yypParser /* The parser */
drh75897232000-05-29 14:26:00 +0000810){
drhfb32c442018-04-21 13:51:42 +0000811 ParseARG_FETCH
812 ParseCTX_FETCH
drh75897232000-05-29 14:26:00 +0000813#ifndef NDEBUG
814 if( yyTraceFILE ){
815 fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt);
816 }
817#endif
drhabecc0b2016-05-24 00:40:54 +0000818 while( yypParser->yytos>yypParser->yystack ) yy_pop_parser_stack(yypParser);
drh75897232000-05-29 14:26:00 +0000819 /* Here code is inserted which will be executed whenever the
820 ** parser fails */
drh82415f22015-11-09 19:33:42 +0000821/************ Begin %parse_failure code ***************************************/
drh75897232000-05-29 14:26:00 +0000822%%
drh82415f22015-11-09 19:33:42 +0000823/************ End %parse_failure code *****************************************/
drhfb32c442018-04-21 13:51:42 +0000824 ParseARG_STORE /* Suppress warning about unused %extra_argument variable */
825 ParseCTX_STORE
drh75897232000-05-29 14:26:00 +0000826}
drhd3ec02d2009-06-12 02:27:14 +0000827#endif /* YYNOERRORRECOVERY */
drh75897232000-05-29 14:26:00 +0000828
829/*
830** The following code executes when a syntax error first occurs.
831*/
832static void yy_syntax_error(
833 yyParser *yypParser, /* The parser */
834 int yymajor, /* The major type of the error token */
drh45f31be2016-02-16 21:19:49 +0000835 ParseTOKENTYPE yyminor /* The minor type of the error token */
drh75897232000-05-29 14:26:00 +0000836){
drhfb32c442018-04-21 13:51:42 +0000837 ParseARG_FETCH
838 ParseCTX_FETCH
drh45f31be2016-02-16 21:19:49 +0000839#define TOKEN yyminor
drh82415f22015-11-09 19:33:42 +0000840/************ Begin %syntax_error code ****************************************/
drh75897232000-05-29 14:26:00 +0000841%%
drh82415f22015-11-09 19:33:42 +0000842/************ End %syntax_error code ******************************************/
drhfb32c442018-04-21 13:51:42 +0000843 ParseARG_STORE /* Suppress warning about unused %extra_argument variable */
844 ParseCTX_STORE
drh75897232000-05-29 14:26:00 +0000845}
846
847/*
848** The following is executed when the parser accepts
849*/
850static void yy_accept(
851 yyParser *yypParser /* The parser */
drh75897232000-05-29 14:26:00 +0000852){
drhfb32c442018-04-21 13:51:42 +0000853 ParseARG_FETCH
854 ParseCTX_FETCH
drh75897232000-05-29 14:26:00 +0000855#ifndef NDEBUG
856 if( yyTraceFILE ){
857 fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt);
858 }
859#endif
drhdd703e22016-07-12 19:54:49 +0000860#ifndef YYNOERRORRECOVERY
861 yypParser->yyerrcnt = -1;
862#endif
drh756b41e2016-05-24 18:55:08 +0000863 assert( yypParser->yytos==yypParser->yystack );
drh75897232000-05-29 14:26:00 +0000864 /* Here code is inserted which will be executed whenever the
865 ** parser accepts */
drh82415f22015-11-09 19:33:42 +0000866/*********** Begin %parse_accept code *****************************************/
drh75897232000-05-29 14:26:00 +0000867%%
drh82415f22015-11-09 19:33:42 +0000868/*********** End %parse_accept code *******************************************/
drhfb32c442018-04-21 13:51:42 +0000869 ParseARG_STORE /* Suppress warning about unused %extra_argument variable */
870 ParseCTX_STORE
drh75897232000-05-29 14:26:00 +0000871}
872
873/* The main parser program.
874** The first argument is a pointer to a structure obtained from
875** "ParseAlloc" which describes the current state of the parser.
876** The second argument is the major token number. The third is
877** the minor token. The fourth optional argument is whatever the
878** user wants (and specified in the grammar) and is available for
879** use by the action routines.
880**
881** Inputs:
882** <ul>
883** <li> A pointer to the parser (an opaque structure.)
884** <li> The major token number.
885** <li> The minor token number.
886** <li> An option argument of a grammar-specified type.
887** </ul>
888**
889** Outputs:
890** None.
891*/
drh75897232000-05-29 14:26:00 +0000892void Parse(
893 void *yyp, /* The parser */
894 int yymajor, /* The major token code number */
895 ParseTOKENTYPE yyminor /* The value for the token */
drh1f245e42002-03-11 13:55:50 +0000896 ParseARG_PDECL /* Optional %extra_argument parameter */
drh75897232000-05-29 14:26:00 +0000897){
898 YYMINORTYPE yyminorunion;
drhfd39c582018-04-21 22:40:08 +0000899 YYACTIONTYPE yyact; /* The parser action. */
drha4414042015-11-09 15:06:26 +0000900#if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY)
drh75897232000-05-29 14:26:00 +0000901 int yyendofinput; /* True if we are at the end of input */
drha4414042015-11-09 15:06:26 +0000902#endif
drhc4dd3fd2008-01-22 01:48:05 +0000903#ifdef YYERRORSYMBOL
drh75897232000-05-29 14:26:00 +0000904 int yyerrorhit = 0; /* True if yymajor has invoked an error */
drhc4dd3fd2008-01-22 01:48:05 +0000905#endif
drhfb32c442018-04-21 13:51:42 +0000906 yyParser *yypParser = (yyParser*)yyp; /* The parser */
907 ParseCTX_FETCH
908 ParseARG_STORE
drh75897232000-05-29 14:26:00 +0000909
drhabecc0b2016-05-24 00:40:54 +0000910 assert( yypParser->yytos!=0 );
drha4414042015-11-09 15:06:26 +0000911#if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY)
drh75897232000-05-29 14:26:00 +0000912 yyendofinput = (yymajor==0);
drha4414042015-11-09 15:06:26 +0000913#endif
drh75897232000-05-29 14:26:00 +0000914
drhfd39c582018-04-21 22:40:08 +0000915 yyact = yypParser->yytos->stateno;
drh75897232000-05-29 14:26:00 +0000916#ifndef NDEBUG
917 if( yyTraceFILE ){
drhfd39c582018-04-21 22:40:08 +0000918 if( yyact < YY_MIN_REDUCE ){
drhe58f74f2017-12-24 17:06:41 +0000919 fprintf(yyTraceFILE,"%sInput '%s' in state %d\n",
drhfd39c582018-04-21 22:40:08 +0000920 yyTracePrompt,yyTokenName[yymajor],yyact);
drhe58f74f2017-12-24 17:06:41 +0000921 }else{
922 fprintf(yyTraceFILE,"%sInput '%s' with pending reduce %d\n",
drhfd39c582018-04-21 22:40:08 +0000923 yyTracePrompt,yyTokenName[yymajor],yyact-YY_MIN_REDUCE);
drhe58f74f2017-12-24 17:06:41 +0000924 }
drh75897232000-05-29 14:26:00 +0000925 }
926#endif
927
928 do{
drhfd39c582018-04-21 22:40:08 +0000929 assert( yyact==yypParser->yytos->stateno );
mistachkin709c8222018-07-22 21:23:19 +0000930 yyact = yy_find_shift_action((YYCODETYPE)yymajor,yyact);
drh5c8241b2017-12-24 23:38:10 +0000931 if( yyact >= YY_MIN_REDUCE ){
drhfd39c582018-04-21 22:40:08 +0000932 yyact = yy_reduce(yypParser,yyact-YY_MIN_REDUCE,yymajor,
933 yyminor ParseCTX_PARAM);
drh5c8241b2017-12-24 23:38:10 +0000934 }else if( yyact <= YY_MAX_SHIFTREDUCE ){
mistachkin709c8222018-07-22 21:23:19 +0000935 yy_shift(yypParser,yyact,(YYCODETYPE)yymajor,yyminor);
drhdab943c2016-02-16 01:01:43 +0000936#ifndef YYNOERRORRECOVERY
drha248a722015-09-07 19:52:55 +0000937 yypParser->yyerrcnt--;
drhdab943c2016-02-16 01:01:43 +0000938#endif
drhfd39c582018-04-21 22:40:08 +0000939 break;
drhef53a9f2017-12-25 00:10:05 +0000940 }else if( yyact==YY_ACCEPT_ACTION ){
drh05ef50d2018-04-23 00:25:31 +0000941 yypParser->yytos--;
942 yy_accept(yypParser);
drhef53a9f2017-12-25 00:10:05 +0000943 return;
drhc4dd3fd2008-01-22 01:48:05 +0000944 }else{
945 assert( yyact == YY_ERROR_ACTION );
drh45f31be2016-02-16 21:19:49 +0000946 yyminorunion.yy0 = yyminor;
drhc4dd3fd2008-01-22 01:48:05 +0000947#ifdef YYERRORSYMBOL
drh3ddfdf72003-12-22 14:53:19 +0000948 int yymx;
drhc4dd3fd2008-01-22 01:48:05 +0000949#endif
drh75897232000-05-29 14:26:00 +0000950#ifndef NDEBUG
951 if( yyTraceFILE ){
952 fprintf(yyTraceFILE,"%sSyntax Error!\n",yyTracePrompt);
953 }
954#endif
955#ifdef YYERRORSYMBOL
956 /* A syntax error has occurred.
957 ** The response to an error depends upon whether or not the
958 ** grammar defines an error token "ERROR".
959 **
960 ** This is what we do if the grammar does define ERROR:
961 **
962 ** * Call the %syntax_error function.
963 **
964 ** * Begin popping the stack until we enter a state where
965 ** it is legal to shift the error symbol, then shift
966 ** the error symbol.
967 **
968 ** * Set the error count to three.
969 **
970 ** * Begin accepting and shifting new tokens. No new error
971 ** processing will occur until three tokens have been
972 ** shifted successfully.
973 **
974 */
drh1f245e42002-03-11 13:55:50 +0000975 if( yypParser->yyerrcnt<0 ){
drh45f31be2016-02-16 21:19:49 +0000976 yy_syntax_error(yypParser,yymajor,yyminor);
drh75897232000-05-29 14:26:00 +0000977 }
drh118ab652016-05-23 21:56:24 +0000978 yymx = yypParser->yytos->major;
drh3ddfdf72003-12-22 14:53:19 +0000979 if( yymx==YYERRORSYMBOL || yyerrorhit ){
drh75897232000-05-29 14:26:00 +0000980#ifndef NDEBUG
981 if( yyTraceFILE ){
982 fprintf(yyTraceFILE,"%sDiscard input token %s\n",
983 yyTracePrompt,yyTokenName[yymajor]);
984 }
985#endif
drh45f31be2016-02-16 21:19:49 +0000986 yy_destructor(yypParser, (YYCODETYPE)yymajor, &yyminorunion);
drh75897232000-05-29 14:26:00 +0000987 yymajor = YYNOCODE;
988 }else{
drh4eda15e2016-10-04 12:20:12 +0000989 while( yypParser->yytos >= yypParser->yystack
drh118ab652016-05-23 21:56:24 +0000990 && yymx != YYERRORSYMBOL
991 && (yyact = yy_find_reduce_action(
992 yypParser->yytos->stateno,
drh3bd48ab2015-09-07 18:23:37 +0000993 YYERRORSYMBOL)) >= YY_MIN_REDUCE
drh75897232000-05-29 14:26:00 +0000994 ){
995 yy_pop_parser_stack(yypParser);
996 }
drh118ab652016-05-23 21:56:24 +0000997 if( yypParser->yytos < yypParser->yystack || yymajor==0 ){
drhb27b7f52008-12-10 18:03:45 +0000998 yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
drh1f245e42002-03-11 13:55:50 +0000999 yy_parse_failed(yypParser);
drh240c7fa2016-07-05 12:47:28 +00001000#ifndef YYNOERRORRECOVERY
1001 yypParser->yyerrcnt = -1;
1002#endif
drh75897232000-05-29 14:26:00 +00001003 yymajor = YYNOCODE;
drh3ddfdf72003-12-22 14:53:19 +00001004 }else if( yymx!=YYERRORSYMBOL ){
drh45f31be2016-02-16 21:19:49 +00001005 yy_shift(yypParser,yyact,YYERRORSYMBOL,yyminor);
drh75897232000-05-29 14:26:00 +00001006 }
1007 }
drh1f245e42002-03-11 13:55:50 +00001008 yypParser->yyerrcnt = 3;
drh75897232000-05-29 14:26:00 +00001009 yyerrorhit = 1;
drhfd39c582018-04-21 22:40:08 +00001010 if( yymajor==YYNOCODE ) break;
1011 yyact = yypParser->yytos->stateno;
drhd3ec02d2009-06-12 02:27:14 +00001012#elif defined(YYNOERRORRECOVERY)
1013 /* If the YYNOERRORRECOVERY macro is defined, then do not attempt to
1014 ** do any kind of error recovery. Instead, simply invoke the syntax
1015 ** error routine and continue going as if nothing had happened.
1016 **
1017 ** Applications can set this macro (for example inside %include) if
1018 ** they intend to abandon the parse upon the first syntax error seen.
1019 */
drh45f31be2016-02-16 21:19:49 +00001020 yy_syntax_error(yypParser,yymajor, yyminor);
drhd3ec02d2009-06-12 02:27:14 +00001021 yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
drhfd39c582018-04-21 22:40:08 +00001022 break;
drh75897232000-05-29 14:26:00 +00001023#else /* YYERRORSYMBOL is not defined */
1024 /* This is what we do if the grammar does not define ERROR:
1025 **
1026 ** * Report an error message, and throw away the input token.
1027 **
1028 ** * If the input token is $, then fail the parse.
1029 **
1030 ** As before, subsequent error messages are suppressed until
1031 ** three input tokens have been successfully shifted.
1032 */
drh1f245e42002-03-11 13:55:50 +00001033 if( yypParser->yyerrcnt<=0 ){
drh45f31be2016-02-16 21:19:49 +00001034 yy_syntax_error(yypParser,yymajor, yyminor);
drh75897232000-05-29 14:26:00 +00001035 }
drh1f245e42002-03-11 13:55:50 +00001036 yypParser->yyerrcnt = 3;
drhb27b7f52008-12-10 18:03:45 +00001037 yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
drh75897232000-05-29 14:26:00 +00001038 if( yyendofinput ){
drh1f245e42002-03-11 13:55:50 +00001039 yy_parse_failed(yypParser);
drhd3d4b3c2016-07-08 19:54:38 +00001040#ifndef YYNOERRORRECOVERY
1041 yypParser->yyerrcnt = -1;
1042#endif
drh75897232000-05-29 14:26:00 +00001043 }
drhfd39c582018-04-21 22:40:08 +00001044 break;
drh75897232000-05-29 14:26:00 +00001045#endif
drh75897232000-05-29 14:26:00 +00001046 }
drhfd39c582018-04-21 22:40:08 +00001047 }while( yypParser->yytos>yypParser->yystack );
drh3bd48ab2015-09-07 18:23:37 +00001048#ifndef NDEBUG
1049 if( yyTraceFILE ){
drh118ab652016-05-23 21:56:24 +00001050 yyStackEntry *i;
1051 char cDiv = '[';
drh0c4105e2015-11-10 14:51:22 +00001052 fprintf(yyTraceFILE,"%sReturn. Stack=",yyTracePrompt);
drh118ab652016-05-23 21:56:24 +00001053 for(i=&yypParser->yystack[1]; i<=yypParser->yytos; i++){
1054 fprintf(yyTraceFILE,"%c%s", cDiv, yyTokenName[i->major]);
1055 cDiv = ' ';
1056 }
drh0c4105e2015-11-10 14:51:22 +00001057 fprintf(yyTraceFILE,"]\n");
drh3bd48ab2015-09-07 18:23:37 +00001058 }
1059#endif
drh75897232000-05-29 14:26:00 +00001060 return;
1061}
dan59ff4252018-06-29 17:44:52 +00001062
1063/*
1064** Return the fallback token corresponding to canonical token iToken, or
1065** 0 if iToken has no fallback.
1066*/
1067int ParseFallback(int iToken){
1068#ifdef YYFALLBACK
drhc7bf5712018-07-09 22:49:01 +00001069 if( iToken<(int)(sizeof(yyFallback)/sizeof(yyFallback[0])) ){
dan59ff4252018-06-29 17:44:52 +00001070 return yyFallback[iToken];
1071 }
drhc7bf5712018-07-09 22:49:01 +00001072#else
1073 (void)iToken;
dan59ff4252018-06-29 17:44:52 +00001074#endif
1075 return 0;
1076}