1 /*
2 ** 2000-05-29
3 **
4 ** 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:
24 */
25 #include <stdio.h>
26 /************ Begin %include sections from the grammar ************************/
27 
28 #include "token.h"
29 #include "expression.h"
30 #include "exprast.h"
31 #include "parser.h"
32 
33 /**************** End of %include directives **********************************/
34 /* These constants specify the various numeric values for terminal symbols
35 ** in a format understandable to "makeheaders".  This section is blank unless
36 ** "lemon" is run with the "-m" command-line option.
37 ***************** Begin makeheaders token definitions *************************/
38 /**************** End makeheaders token definitions ***************************/
39 
40 /* The next sections is a series of control #defines.
41 ** various aspects of the generated parser.
42 **    YYCODETYPE         is the data type used to store the integer codes
43 **                       that represent terminal and non-terminal symbols.
44 **                       "unsigned char" is used if there are fewer than
45 **                       256 symbols.  Larger types otherwise.
46 **    YYNOCODE           is a number of type YYCODETYPE that is not used for
47 **                       any terminal or nonterminal symbol.
48 **    YYFALLBACK         If defined, this indicates that one or more tokens
49 **                       (also known as: "terminal symbols") have fall-back
50 **                       values which should be used if the original symbol
51 **                       would not parse.  This permits keywords to sometimes
52 **                       be used as identifiers, for example.
53 **    YYACTIONTYPE       is the data type used for "action codes" - numbers
54 **                       that indicate what to do in response to the next
55 **                       token.
56 **    RSExprParser_ParseTOKENTYPE     is the data type used for minor type for terminal
57 **                       symbols.  Background: A "minor type" is a semantic
58 **                       value associated with a terminal or non-terminal
59 **                       symbols.  For example, for an "ID" terminal symbol,
60 **                       the minor type might be the name of the identifier.
61 **                       Each non-terminal can have a different minor type.
62 **                       Terminal symbols all have the same minor type, though.
63 **                       This macros defines the minor type for terminal
64 **                       symbols.
65 **    YYMINORTYPE        is the data type used for all minor types.
66 **                       This is typically a union of many types, one of
67 **                       which is RSExprParser_ParseTOKENTYPE.  The entry in the union
68 **                       for terminal symbols is called "yy0".
69 **    YYSTACKDEPTH       is the maximum depth of the parser's stack.  If
70 **                       zero the stack is dynamically sized using realloc()
71 **    RSExprParser_ParseARG_SDECL     A static variable declaration for the %extra_argument
72 **    RSExprParser_ParseARG_PDECL     A parameter declaration for the %extra_argument
73 **    RSExprParser_ParseARG_PARAM     Code to pass %extra_argument as a subroutine parameter
74 **    RSExprParser_ParseARG_STORE     Code to store %extra_argument into yypParser
75 **    RSExprParser_ParseARG_FETCH     Code to extract %extra_argument from yypParser
76 **    RSExprParser_ParseCTX_*         As RSExprParser_ParseARG_ except for %extra_context
77 **    YYERRORSYMBOL      is the code number of the error symbol.  If not
78 **                       defined, then do no error processing.
79 **    YYNSTATE           the combined number of states.
80 **    YYNRULE            the number of rules in the grammar
81 **    YYNTOKEN           Number of terminal symbols
82 **    YY_MAX_SHIFT       Maximum value for shift actions
83 **    YY_MIN_SHIFTREDUCE Minimum value for shift-reduce actions
84 **    YY_MAX_SHIFTREDUCE Maximum value for shift-reduce actions
85 **    YY_ERROR_ACTION    The yy_action[] code for syntax error
86 **    YY_ACCEPT_ACTION   The yy_action[] code for accept
87 **    YY_NO_ACTION       The yy_action[] code for no-op
88 **    YY_MIN_REDUCE      Minimum value for reduce actions
89 **    YY_MAX_REDUCE      Maximum value for reduce actions
90 */
91 #ifndef INTERFACE
92 # define INTERFACE 1
93 #endif
94 /************* Begin control #defines *****************************************/
95 #define YYCODETYPE unsigned char
96 #define YYNOCODE 28
97 #define YYACTIONTYPE unsigned char
98 #define RSExprParser_ParseTOKENTYPE  RSExprToken
99 typedef union {
100   int yyinit;
101   RSExprParser_ParseTOKENTYPE yy0;
102   RSExpr * yy19;
103   double yy32;
104   RSArgList * yy46;
105 } YYMINORTYPE;
106 #ifndef YYSTACKDEPTH
107 #define YYSTACKDEPTH 100
108 #endif
109 #define RSExprParser_ParseARG_SDECL  RSExprParseCtx *ctx ;
110 #define RSExprParser_ParseARG_PDECL , RSExprParseCtx *ctx
111 #define RSExprParser_ParseARG_PARAM ,ctx
112 #define RSExprParser_ParseARG_FETCH  RSExprParseCtx *ctx =yypParser->ctx ;
113 #define RSExprParser_ParseARG_STORE yypParser->ctx =ctx ;
114 #define RSExprParser_ParseCTX_SDECL
115 #define RSExprParser_ParseCTX_PDECL
116 #define RSExprParser_ParseCTX_PARAM
117 #define RSExprParser_ParseCTX_FETCH
118 #define RSExprParser_ParseCTX_STORE
119 #define YYNSTATE             37
120 #define YYNRULE              27
121 #define YYNTOKEN             24
122 #define YY_MAX_SHIFT         36
123 #define YY_MIN_SHIFTREDUCE   48
124 #define YY_MAX_SHIFTREDUCE   74
125 #define YY_ERROR_ACTION      75
126 #define YY_ACCEPT_ACTION     76
127 #define YY_NO_ACTION         77
128 #define YY_MIN_REDUCE        78
129 #define YY_MAX_REDUCE        104
130 /************* End control #defines *******************************************/
131 
132 /* Define the yytestcase() macro to be a no-op if is not already defined
133 ** otherwise.
134 **
135 ** Applications can choose to define yytestcase() in the %include section
136 ** to a macro that can assist in verifying code coverage.  For production
137 ** code the yytestcase() macro should be turned off.  But it is useful
138 ** for testing.
139 */
140 #ifndef yytestcase
141 # define yytestcase(X)
142 #endif
143 
144 
145 /* Next are the tables used to determine what action to take based on the
146 ** current state and lookahead token.  These tables are used to implement
147 ** functions that take a state number and lookahead value and return an
148 ** action integer.
149 **
150 ** Suppose the action integer is N.  Then the action is determined as
151 ** follows
152 **
153 **   0 <= N <= YY_MAX_SHIFT             Shift N.  That is, push the lookahead
154 **                                      token onto the stack and goto state N.
155 **
156 **   N between YY_MIN_SHIFTREDUCE       Shift to an arbitrary state then
157 **     and YY_MAX_SHIFTREDUCE           reduce by rule N-YY_MIN_SHIFTREDUCE.
158 **
159 **   N == YY_ERROR_ACTION               A syntax error has occurred.
160 **
161 **   N == YY_ACCEPT_ACTION              The parser accepts its input.
162 **
163 **   N == YY_NO_ACTION                  No such action.  Denotes unused
164 **                                      slots in the yy_action[] table.
165 **
166 **   N between YY_MIN_REDUCE            Reduce by rule N-YY_MIN_REDUCE
167 **     and YY_MAX_REDUCE
168 **
169 ** The action table is constructed as a single large table named yy_action[].
170 ** Given state S and lookahead X, the action is computed as either:
171 **
172 **    (A)   N = yy_action[ yy_shift_ofst[S] + X ]
173 **    (B)   N = yy_default[S]
174 **
175 ** The (A) formula is preferred.  The B formula is used instead if
176 ** yy_lookahead[yy_shift_ofst[S]+X] is not equal to X.
177 **
178 ** The formulas above are for computing the action when the lookahead is
179 ** a terminal symbol.  If the lookahead is a non-terminal (as occurs after
180 ** a reduce action) then the yy_reduce_ofst[] array is used in place of
181 ** the yy_shift_ofst[] array.
182 **
183 ** The following are the tables generated in this section:
184 **
185 **  yy_action[]        A single table containing all actions.
186 **  yy_lookahead[]     A table containing the lookahead for each entry in
187 **                     yy_action.  Used to detect hash collisions.
188 **  yy_shift_ofst[]    For each state, the offset into yy_action for
189 **                     shifting terminals.
190 **  yy_reduce_ofst[]   For each state, the offset into yy_action for
191 **                     shifting non-terminals after a reduce.
192 **  yy_default[]       Default action for each state.
193 **
194 *********** Begin parsing tables **********************************************/
195 #define YY_ACTTAB_COUNT (122)
196 static const YYACTIONTYPE yy_action[] = {
197  /*     0 */    96,    5,    4,   21,   11,   10,    9,    8,    7,    6,
198  /*    10 */    18,   14,   16,   15,   12,   13,   77,   49,   78,    5,
199  /*    20 */     4,    1,   11,   10,    9,    8,    7,    6,   18,   14,
200  /*    30 */    16,   15,   12,   13,    5,    4,   68,   11,   10,    9,
201  /*    40 */     8,    7,    6,   18,   14,   16,   15,   12,   13,   11,
202  /*    50 */    10,    9,    8,    7,    6,   18,   14,   16,   15,   12,
203  /*    60 */    13,    3,   18,   14,   16,   15,   12,   13,   96,   36,
204  /*    70 */    76,   20,   96,   34,   17,   22,   69,   35,   65,   67,
205  /*    80 */    16,   15,   12,   13,   96,   96,   96,   23,   24,   25,
206  /*    90 */    96,   96,   77,   26,   27,   96,   96,   96,   28,   29,
207  /*   100 */    30,   96,   96,   96,   31,   85,   84,   96,   96,   96,
208  /*   110 */    33,   82,   81,   96,   96,   70,   19,   32,   77,   77,
209  /*   120 */    77,    2,
210 };
211 static const YYCODETYPE yy_lookahead[] = {
212  /*     0 */    24,    1,    2,   27,    4,    5,    6,    7,    8,    9,
213  /*    10 */    10,   11,   12,   13,   14,   15,   28,   17,    0,    1,
214  /*    20 */     2,   16,    4,    5,    6,    7,    8,    9,   10,   11,
215  /*    30 */    12,   13,   14,   15,    1,    2,   21,    4,    5,    6,
216  /*    40 */     7,    8,    9,   10,   11,   12,   13,   14,   15,    4,
217  /*    50 */     5,    6,    7,    8,    9,   10,   11,   12,   13,   14,
218  /*    60 */    15,    3,   10,   11,   12,   13,   14,   15,   24,   11,
219  /*    70 */    26,   27,   24,   25,   16,   27,   18,   19,   20,   21,
220  /*    80 */    12,   13,   14,   15,   24,   24,   24,   27,   27,   27,
221  /*    90 */    24,   24,   28,   27,   27,   24,   24,   24,   27,   27,
222  /*   100 */    27,   24,   24,   24,   27,   27,   27,   24,   24,   24,
223  /*   110 */    27,   27,   27,   24,   24,   17,   27,   27,   28,   28,
224  /*   120 */    28,   23,   28,   28,   28,   28,   28,   28,   28,   28,
225  /*   130 */    28,   28,   28,   28,   28,   28,   28,   28,   28,   28,
226 };
227 #define YY_SHIFT_COUNT    (36)
228 #define YY_SHIFT_MIN      (0)
229 #define YY_SHIFT_MAX      (98)
230 static const unsigned char yy_shift_ofst[] = {
231  /*     0 */    58,   58,   58,   58,   58,   58,   58,   58,   58,   58,
232  /*    10 */    58,   58,   58,   58,   58,   58,   58,   58,   58,    0,
233  /*    20 */    18,   33,   33,   45,   45,   45,   52,   52,   52,   52,
234  /*    30 */    52,   52,   68,   68,   98,    5,   15,
235 };
236 #define YY_REDUCE_COUNT (18)
237 #define YY_REDUCE_MIN   (-24)
238 #define YY_REDUCE_MAX   (90)
239 static const signed char yy_reduce_ofst[] = {
240  /*     0 */    44,   48,  -24,   60,   61,   62,   66,   67,   71,   72,
241  /*    10 */    73,   77,   78,   79,   83,   84,   85,   89,   90,
242 };
243 static const YYACTIONTYPE yy_default[] = {
244  /*     0 */    75,  102,   75,   75,   75,   75,   75,   75,   75,   75,
245  /*    10 */    75,   75,   75,   75,   75,   75,   75,   75,   75,   75,
246  /*    20 */    75,  104,  103,   94,   93,   92,   91,   90,   89,   88,
247  /*    30 */    87,   86,   80,   83,   75,  101,   75,
248 };
249 /********** End of lemon-generated parsing tables *****************************/
250 
251 /* The next table maps tokens (terminal symbols) into fallback tokens.
252 ** If a construct like the following:
253 **
254 **      %fallback ID X Y Z.
255 **
256 ** appears in the grammar, then ID becomes a fallback token for X, Y,
257 ** and Z.  Whenever one of the tokens X, Y, or Z is input to the parser
258 ** but it does not parse, the type of the token is changed to ID and
259 ** the parse is retried before an error is thrown.
260 **
261 ** This feature can be used, for example, to cause some keywords in a language
262 ** to revert to identifiers if they keyword does not apply in the context where
263 ** it appears.
264 */
265 #ifdef YYFALLBACK
266 static const YYCODETYPE yyFallback[] = {
267 };
268 #endif /* YYFALLBACK */
269 
270 /* The following structure represents a single element of the
271 ** parser's stack.  Information stored includes:
272 **
273 **   +  The state number for the parser at this level of the stack.
274 **
275 **   +  The value of the token stored at this level of the stack.
276 **      (In other words, the "major" token.)
277 **
278 **   +  The semantic value stored at this level of the stack.  This is
279 **      the information used by the action routines in the grammar.
280 **      It is sometimes called the "minor" token.
281 **
282 ** After the "shift" half of a SHIFTREDUCE action, the stateno field
283 ** actually contains the reduce action for the second half of the
284 ** SHIFTREDUCE.
285 */
286 struct yyStackEntry {
287   YYACTIONTYPE stateno;  /* The state-number, or reduce action in SHIFTREDUCE */
288   YYCODETYPE major;      /* The major token value.  This is the code
289                          ** number for the token at this stack level */
290   YYMINORTYPE minor;     /* The user-supplied minor token value.  This
291                          ** is the value of the token  */
292 };
293 typedef struct yyStackEntry yyStackEntry;
294 
295 /* The state of the parser is completely contained in an instance of
296 ** the following structure */
297 struct yyParser {
298   yyStackEntry *yytos;          /* Pointer to top element of the stack */
299 #ifdef YYTRACKMAXSTACKDEPTH
300   int yyhwm;                    /* High-water mark of the stack */
301 #endif
302 #ifndef YYNOERRORRECOVERY
303   int yyerrcnt;                 /* Shifts left before out of the error */
304 #endif
305   RSExprParser_ParseARG_SDECL                /* A place to hold %extra_argument */
306   RSExprParser_ParseCTX_SDECL                /* A place to hold %extra_context */
307 #if YYSTACKDEPTH<=0
308   int yystksz;                  /* Current side of the stack */
309   yyStackEntry *yystack;        /* The parser's stack */
310   yyStackEntry yystk0;          /* First stack entry */
311 #else
312   yyStackEntry yystack[YYSTACKDEPTH];  /* The parser's stack */
313   yyStackEntry *yystackEnd;            /* Last entry in the stack */
314 #endif
315 };
316 typedef struct yyParser yyParser;
317 
318 #ifndef NDEBUG
319 #include <stdio.h>
320 static FILE *yyTraceFILE = 0;
321 static char *yyTracePrompt = 0;
322 #endif /* NDEBUG */
323 
324 #ifndef NDEBUG
325 /*
326 ** Turn parser tracing on by giving a stream to which to write the trace
327 ** and a prompt to preface each trace message.  Tracing is turned off
328 ** by making either argument NULL
329 **
330 ** Inputs:
331 ** <ul>
332 ** <li> A FILE* to which trace output should be written.
333 **      If NULL, then tracing is turned off.
334 ** <li> A prefix string written at the beginning of every
335 **      line of trace output.  If NULL, then tracing is
336 **      turned off.
337 ** </ul>
338 **
339 ** Outputs:
340 ** None.
341 */
RSExprParser_ParseTrace(FILE * TraceFILE,char * zTracePrompt)342 void RSExprParser_ParseTrace(FILE *TraceFILE, char *zTracePrompt){
343   yyTraceFILE = TraceFILE;
344   yyTracePrompt = zTracePrompt;
345   if( yyTraceFILE==0 ) yyTracePrompt = 0;
346   else if( yyTracePrompt==0 ) yyTraceFILE = 0;
347 }
348 #endif /* NDEBUG */
349 
350 #if defined(YYCOVERAGE) || !defined(NDEBUG)
351 /* For tracing shifts, the names of all terminals and nonterminals
352 ** are required.  The following table supplies these names */
353 static const char *const yyTokenName[] = {
354   /*    0 */ "$",
355   /*    1 */ "AND",
356   /*    2 */ "OR",
357   /*    3 */ "NOT",
358   /*    4 */ "EQ",
359   /*    5 */ "NE",
360   /*    6 */ "LT",
361   /*    7 */ "LE",
362   /*    8 */ "GT",
363   /*    9 */ "GE",
364   /*   10 */ "PLUS",
365   /*   11 */ "MINUS",
366   /*   12 */ "DIVIDE",
367   /*   13 */ "TIMES",
368   /*   14 */ "MOD",
369   /*   15 */ "POW",
370   /*   16 */ "LP",
371   /*   17 */ "RP",
372   /*   18 */ "PROPERTY",
373   /*   19 */ "SYMBOL",
374   /*   20 */ "STRING",
375   /*   21 */ "NUMBER",
376   /*   22 */ "ARGLIST",
377   /*   23 */ "COMMA",
378   /*   24 */ "number",
379   /*   25 */ "arglist",
380   /*   26 */ "program",
381   /*   27 */ "expr",
382 };
383 #endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */
384 
385 #ifndef NDEBUG
386 /* For tracing reduce actions, the names of all rules are required.
387 */
388 static const char *const yyRuleName[] = {
389  /*   0 */ "program ::= expr",
390  /*   1 */ "expr ::= LP expr RP",
391  /*   2 */ "expr ::= expr PLUS expr",
392  /*   3 */ "expr ::= expr DIVIDE expr",
393  /*   4 */ "expr ::= expr TIMES expr",
394  /*   5 */ "expr ::= expr MINUS expr",
395  /*   6 */ "expr ::= expr POW expr",
396  /*   7 */ "expr ::= expr MOD expr",
397  /*   8 */ "expr ::= expr EQ expr",
398  /*   9 */ "expr ::= expr NE expr",
399  /*  10 */ "expr ::= expr LT expr",
400  /*  11 */ "expr ::= expr LE expr",
401  /*  12 */ "expr ::= expr GT expr",
402  /*  13 */ "expr ::= expr GE expr",
403  /*  14 */ "expr ::= expr AND expr",
404  /*  15 */ "expr ::= expr OR expr",
405  /*  16 */ "expr ::= NOT expr",
406  /*  17 */ "expr ::= STRING",
407  /*  18 */ "expr ::= number",
408  /*  19 */ "number ::= NUMBER",
409  /*  20 */ "number ::= MINUS NUMBER",
410  /*  21 */ "expr ::= PROPERTY",
411  /*  22 */ "expr ::= SYMBOL LP arglist RP",
412  /*  23 */ "expr ::= SYMBOL",
413  /*  24 */ "arglist ::=",
414  /*  25 */ "arglist ::= expr",
415  /*  26 */ "arglist ::= arglist COMMA expr",
416 };
417 #endif /* NDEBUG */
418 
419 
420 #if YYSTACKDEPTH<=0
421 /*
422 ** Try to increase the size of the parser stack.  Return the number
423 ** of errors.  Return 0 on success.
424 */
yyGrowStack(yyParser * p)425 static int yyGrowStack(yyParser *p){
426   int newSize;
427   int idx;
428   yyStackEntry *pNew;
429 
430   newSize = p->yystksz*2 + 100;
431   idx = p->yytos ? (int)(p->yytos - p->yystack) : 0;
432   if( p->yystack==&p->yystk0 ){
433     pNew = malloc(newSize*sizeof(pNew[0]));
434     if( pNew ) pNew[0] = p->yystk0;
435   }else{
436     pNew = realloc(p->yystack, newSize*sizeof(pNew[0]));
437   }
438   if( pNew ){
439     p->yystack = pNew;
440     p->yytos = &p->yystack[idx];
441 #ifndef NDEBUG
442     if( yyTraceFILE ){
443       fprintf(yyTraceFILE,"%sStack grows from %d to %d entries.\n",
444               yyTracePrompt, p->yystksz, newSize);
445     }
446 #endif
447     p->yystksz = newSize;
448   }
449   return pNew==0;
450 }
451 #endif
452 
453 /* Datatype of the argument to the memory allocated passed as the
454 ** second argument to RSExprParser_ParseAlloc() below.  This can be changed by
455 ** putting an appropriate #define in the %include section of the input
456 ** grammar.
457 */
458 #ifndef YYMALLOCARGTYPE
459 # define YYMALLOCARGTYPE size_t
460 #endif
461 
462 /* Initialize a new parser that has already been allocated.
463 */
RSExprParser_ParseInit(void * yypRawParser RSExprParser_ParseCTX_PDECL)464 void RSExprParser_ParseInit(void *yypRawParser RSExprParser_ParseCTX_PDECL){
465   yyParser *yypParser = (yyParser*)yypRawParser;
466   RSExprParser_ParseCTX_STORE
467 #ifdef YYTRACKMAXSTACKDEPTH
468   yypParser->yyhwm = 0;
469 #endif
470 #if YYSTACKDEPTH<=0
471   yypParser->yytos = NULL;
472   yypParser->yystack = NULL;
473   yypParser->yystksz = 0;
474   if( yyGrowStack(yypParser) ){
475     yypParser->yystack = &yypParser->yystk0;
476     yypParser->yystksz = 1;
477   }
478 #endif
479 #ifndef YYNOERRORRECOVERY
480   yypParser->yyerrcnt = -1;
481 #endif
482   yypParser->yytos = yypParser->yystack;
483   yypParser->yystack[0].stateno = 0;
484   yypParser->yystack[0].major = 0;
485 #if YYSTACKDEPTH>0
486   yypParser->yystackEnd = &yypParser->yystack[YYSTACKDEPTH-1];
487 #endif
488 }
489 
490 #ifndef RSExprParser_Parse_ENGINEALWAYSONSTACK
491 /*
492 ** This function allocates a new parser.
493 ** The only argument is a pointer to a function which works like
494 ** malloc.
495 **
496 ** Inputs:
497 ** A pointer to the function used to allocate memory.
498 **
499 ** Outputs:
500 ** A pointer to a parser.  This pointer is used in subsequent calls
501 ** to RSExprParser_Parse and RSExprParser_ParseFree.
502 */
RSExprParser_ParseAlloc(void * (* mallocProc)(YYMALLOCARGTYPE)RSExprParser_ParseCTX_PDECL)503 void *RSExprParser_ParseAlloc(void *(*mallocProc)(YYMALLOCARGTYPE) RSExprParser_ParseCTX_PDECL){
504   yyParser *yypParser;
505   yypParser = (yyParser*)(*mallocProc)( (YYMALLOCARGTYPE)sizeof(yyParser) );
506   if( yypParser ){
507     RSExprParser_ParseCTX_STORE
508     RSExprParser_ParseInit(yypParser RSExprParser_ParseCTX_PARAM);
509   }
510   return (void*)yypParser;
511 }
512 #endif /* RSExprParser_Parse_ENGINEALWAYSONSTACK */
513 
514 
515 /* The following function deletes the "minor type" or semantic value
516 ** associated with a symbol.  The symbol can be either a terminal
517 ** or nonterminal. "yymajor" is the symbol code, and "yypminor" is
518 ** a pointer to the value to be deleted.  The code used to do the
519 ** deletions is derived from the %destructor and/or %token_destructor
520 ** directives of the input grammar.
521 */
yy_destructor(yyParser * yypParser,YYCODETYPE yymajor,YYMINORTYPE * yypminor)522 static void yy_destructor(
523   yyParser *yypParser,    /* The parser */
524   YYCODETYPE yymajor,     /* Type code for object to destroy */
525   YYMINORTYPE *yypminor   /* The object to be destroyed */
526 ){
527   RSExprParser_ParseARG_FETCH
528   RSExprParser_ParseCTX_FETCH
529   switch( yymajor ){
530     /* Here is inserted the actions which take place when a
531     ** terminal or non-terminal is destroyed.  This can happen
532     ** when the symbol is popped from the stack during a
533     ** reduce or during error processing or when a parser is
534     ** being destroyed before it is finished parsing.
535     **
536     ** Note: during a reduce, the only symbols destroyed are those
537     ** which appear on the RHS of the rule, but which are *not* used
538     ** inside the C code.
539     */
540 /********* Begin destructor definitions ***************************************/
541       /* Default NON-TERMINAL Destructor */
542     case 26: /* program */
543     case 27: /* expr */
544 {
545 RSExpr_Free((yypminor->yy19));
546 }
547       break;
548     case 24: /* number */
549 {
550 
551 }
552       break;
553     case 25: /* arglist */
554 {
555 RSArgList_Free((yypminor->yy46));
556 }
557       break;
558 /********* End destructor definitions *****************************************/
559     default:  break;   /* If no destructor action specified: do nothing */
560   }
561 }
562 
563 /*
564 ** Pop the parser's stack once.
565 **
566 ** If there is a destructor routine associated with the token which
567 ** is popped from the stack, then call it.
568 */
yy_pop_parser_stack(yyParser * pParser)569 static void yy_pop_parser_stack(yyParser *pParser){
570   yyStackEntry *yytos;
571   assert( pParser->yytos!=0 );
572   assert( pParser->yytos > pParser->yystack );
573   yytos = pParser->yytos--;
574 #ifndef NDEBUG
575   if( yyTraceFILE ){
576     fprintf(yyTraceFILE,"%sPopping %s\n",
577       yyTracePrompt,
578       yyTokenName[yytos->major]);
579   }
580 #endif
581   yy_destructor(pParser, yytos->major, &yytos->minor);
582 }
583 
584 /*
585 ** Clear all secondary memory allocations from the parser
586 */
RSExprParser_ParseFinalize(void * p)587 void RSExprParser_ParseFinalize(void *p){
588   yyParser *pParser = (yyParser*)p;
589   while( pParser->yytos>pParser->yystack ) yy_pop_parser_stack(pParser);
590 #if YYSTACKDEPTH<=0
591   if( pParser->yystack!=&pParser->yystk0 ) free(pParser->yystack);
592 #endif
593 }
594 
595 #ifndef RSExprParser_Parse_ENGINEALWAYSONSTACK
596 /*
597 ** Deallocate and destroy a parser.  Destructors are called for
598 ** all stack elements before shutting the parser down.
599 **
600 ** If the YYPARSEFREENEVERNULL macro exists (for example because it
601 ** is defined in a %include section of the input grammar) then it is
602 ** assumed that the input pointer is never NULL.
603 */
RSExprParser_ParseFree(void * p,void (* freeProc)(void *))604 void RSExprParser_ParseFree(
605   void *p,                    /* The parser to be deleted */
606   void (*freeProc)(void*)     /* Function used to reclaim memory */
607 ){
608 #ifndef YYPARSEFREENEVERNULL
609   if( p==0 ) return;
610 #endif
611   RSExprParser_ParseFinalize(p);
612   (*freeProc)(p);
613 }
614 #endif /* RSExprParser_Parse_ENGINEALWAYSONSTACK */
615 
616 /*
617 ** Return the peak depth of the stack for a parser.
618 */
619 #ifdef YYTRACKMAXSTACKDEPTH
RSExprParser_ParseStackPeak(void * p)620 int RSExprParser_ParseStackPeak(void *p){
621   yyParser *pParser = (yyParser*)p;
622   return pParser->yyhwm;
623 }
624 #endif
625 
626 /* This array of booleans keeps track of the parser statement
627 ** coverage.  The element yycoverage[X][Y] is set when the parser
628 ** is in state X and has a lookahead token Y.  In a well-tested
629 ** systems, every element of this matrix should end up being set.
630 */
631 #if defined(YYCOVERAGE)
632 static unsigned char yycoverage[YYNSTATE][YYNTOKEN];
633 #endif
634 
635 /*
636 ** Write into out a description of every state/lookahead combination that
637 **
638 **   (1)  has not been used by the parser, and
639 **   (2)  is not a syntax error.
640 **
641 ** Return the number of missed state/lookahead combinations.
642 */
643 #if defined(YYCOVERAGE)
RSExprParser_ParseCoverage(FILE * out)644 int RSExprParser_ParseCoverage(FILE *out){
645   int stateno, iLookAhead, i;
646   int nMissed = 0;
647   for(stateno=0; stateno<YYNSTATE; stateno++){
648     i = yy_shift_ofst[stateno];
649     for(iLookAhead=0; iLookAhead<YYNTOKEN; iLookAhead++){
650       if( yy_lookahead[i+iLookAhead]!=iLookAhead ) continue;
651       if( yycoverage[stateno][iLookAhead]==0 ) nMissed++;
652       if( out ){
653         fprintf(out,"State %d lookahead %s %s\n", stateno,
654                 yyTokenName[iLookAhead],
655                 yycoverage[stateno][iLookAhead] ? "ok" : "missed");
656       }
657     }
658   }
659   return nMissed;
660 }
661 #endif
662 
663 /*
664 ** Find the appropriate action for a parser given the terminal
665 ** look-ahead token iLookAhead.
666 */
yy_find_shift_action(YYCODETYPE iLookAhead,YYACTIONTYPE stateno)667 static YYACTIONTYPE yy_find_shift_action(
668   YYCODETYPE iLookAhead,    /* The look-ahead token */
669   YYACTIONTYPE stateno      /* Current state number */
670 ){
671   int i;
672 
673   if( stateno>YY_MAX_SHIFT ) return stateno;
674   assert( stateno <= YY_SHIFT_COUNT );
675 #if defined(YYCOVERAGE)
676   yycoverage[stateno][iLookAhead] = 1;
677 #endif
678   do{
679     i = yy_shift_ofst[stateno];
680     assert( i>=0 );
681     assert( i+YYNTOKEN<=(int)sizeof(yy_lookahead)/sizeof(yy_lookahead[0]) );
682     assert( iLookAhead!=YYNOCODE );
683     assert( iLookAhead < YYNTOKEN );
684     i += iLookAhead;
685     if( yy_lookahead[i]!=iLookAhead ){
686 #ifdef YYFALLBACK
687       YYCODETYPE iFallback;            /* Fallback token */
688       if( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0])
689              && (iFallback = yyFallback[iLookAhead])!=0 ){
690 #ifndef NDEBUG
691         if( yyTraceFILE ){
692           fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n",
693              yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]);
694         }
695 #endif
696         assert( yyFallback[iFallback]==0 ); /* Fallback loop must terminate */
697         iLookAhead = iFallback;
698         continue;
699       }
700 #endif
701 #ifdef YYWILDCARD
702       {
703         int j = i - iLookAhead + YYWILDCARD;
704         if(
705 #if YY_SHIFT_MIN+YYWILDCARD<0
706           j>=0 &&
707 #endif
708 #if YY_SHIFT_MAX+YYWILDCARD>=YY_ACTTAB_COUNT
709           j<YY_ACTTAB_COUNT &&
710 #endif
711           yy_lookahead[j]==YYWILDCARD && iLookAhead>0
712         ){
713 #ifndef NDEBUG
714           if( yyTraceFILE ){
715             fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n",
716                yyTracePrompt, yyTokenName[iLookAhead],
717                yyTokenName[YYWILDCARD]);
718           }
719 #endif /* NDEBUG */
720           return yy_action[j];
721         }
722       }
723 #endif /* YYWILDCARD */
724       return yy_default[stateno];
725     }else{
726       return yy_action[i];
727     }
728   }while(1);
729 }
730 
731 /*
732 ** Find the appropriate action for a parser given the non-terminal
733 ** look-ahead token iLookAhead.
734 */
yy_find_reduce_action(YYACTIONTYPE stateno,YYCODETYPE iLookAhead)735 static int yy_find_reduce_action(
736   YYACTIONTYPE stateno,     /* Current state number */
737   YYCODETYPE iLookAhead     /* The look-ahead token */
738 ){
739   int i;
740 #ifdef YYERRORSYMBOL
741   if( stateno>YY_REDUCE_COUNT ){
742     return yy_default[stateno];
743   }
744 #else
745   assert( stateno<=YY_REDUCE_COUNT );
746 #endif
747   i = yy_reduce_ofst[stateno];
748   assert( iLookAhead!=YYNOCODE );
749   i += iLookAhead;
750 #ifdef YYERRORSYMBOL
751   if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){
752     return yy_default[stateno];
753   }
754 #else
755   assert( i>=0 && i<YY_ACTTAB_COUNT );
756   assert( yy_lookahead[i]==iLookAhead );
757 #endif
758   return yy_action[i];
759 }
760 
761 /*
762 ** The following routine is called if the stack overflows.
763 */
yyStackOverflow(yyParser * yypParser)764 static void yyStackOverflow(yyParser *yypParser){
765    RSExprParser_ParseARG_FETCH
766    RSExprParser_ParseCTX_FETCH
767 #ifndef NDEBUG
768    if( yyTraceFILE ){
769      fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt);
770    }
771 #endif
772    while( yypParser->yytos>yypParser->yystack ) yy_pop_parser_stack(yypParser);
773    /* Here code is inserted which will execute if the parser
774    ** stack every overflows */
775 /******** Begin %stack_overflow code ******************************************/
776 /******** End %stack_overflow code ********************************************/
777    RSExprParser_ParseARG_STORE /* Suppress warning about unused %extra_argument var */
778    RSExprParser_ParseCTX_STORE
779 }
780 
781 /*
782 ** Print tracing information for a SHIFT action
783 */
784 #ifndef NDEBUG
yyTraceShift(yyParser * yypParser,int yyNewState,const char * zTag)785 static void yyTraceShift(yyParser *yypParser, int yyNewState, const char *zTag){
786   if( yyTraceFILE ){
787     if( yyNewState<YYNSTATE ){
788       fprintf(yyTraceFILE,"%s%s '%s', go to state %d\n",
789          yyTracePrompt, zTag, yyTokenName[yypParser->yytos->major],
790          yyNewState);
791     }else{
792       fprintf(yyTraceFILE,"%s%s '%s', pending reduce %d\n",
793          yyTracePrompt, zTag, yyTokenName[yypParser->yytos->major],
794          yyNewState - YY_MIN_REDUCE);
795     }
796   }
797 }
798 #else
799 # define yyTraceShift(X,Y,Z)
800 #endif
801 
802 /*
803 ** Perform a shift action.
804 */
yy_shift(yyParser * yypParser,YYACTIONTYPE yyNewState,YYCODETYPE yyMajor,RSExprParser_ParseTOKENTYPE yyMinor)805 static void yy_shift(
806   yyParser *yypParser,          /* The parser to be shifted */
807   YYACTIONTYPE yyNewState,      /* The new state to shift in */
808   YYCODETYPE yyMajor,           /* The major token to shift in */
809   RSExprParser_ParseTOKENTYPE yyMinor        /* The minor token to shift in */
810 ){
811   yyStackEntry *yytos;
812   yypParser->yytos++;
813 #ifdef YYTRACKMAXSTACKDEPTH
814   if( (int)(yypParser->yytos - yypParser->yystack)>yypParser->yyhwm ){
815     yypParser->yyhwm++;
816     assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack) );
817   }
818 #endif
819 #if YYSTACKDEPTH>0
820   if( yypParser->yytos>yypParser->yystackEnd ){
821     yypParser->yytos--;
822     yyStackOverflow(yypParser);
823     return;
824   }
825 #else
826   if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz] ){
827     if( yyGrowStack(yypParser) ){
828       yypParser->yytos--;
829       yyStackOverflow(yypParser);
830       return;
831     }
832   }
833 #endif
834   if( yyNewState > YY_MAX_SHIFT ){
835     yyNewState += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE;
836   }
837   yytos = yypParser->yytos;
838   yytos->stateno = yyNewState;
839   yytos->major = yyMajor;
840   yytos->minor.yy0 = yyMinor;
841   yyTraceShift(yypParser, yyNewState, "Shift");
842 }
843 
844 /* The following table contains information about every rule that
845 ** is used during the reduce.
846 */
847 static const struct {
848   YYCODETYPE lhs;       /* Symbol on the left-hand side of the rule */
849   signed char nrhs;     /* Negative of the number of RHS symbols in the rule */
850 } yyRuleInfo[] = {
851   {   26,   -1 }, /* (0) program ::= expr */
852   {   27,   -3 }, /* (1) expr ::= LP expr RP */
853   {   27,   -3 }, /* (2) expr ::= expr PLUS expr */
854   {   27,   -3 }, /* (3) expr ::= expr DIVIDE expr */
855   {   27,   -3 }, /* (4) expr ::= expr TIMES expr */
856   {   27,   -3 }, /* (5) expr ::= expr MINUS expr */
857   {   27,   -3 }, /* (6) expr ::= expr POW expr */
858   {   27,   -3 }, /* (7) expr ::= expr MOD expr */
859   {   27,   -3 }, /* (8) expr ::= expr EQ expr */
860   {   27,   -3 }, /* (9) expr ::= expr NE expr */
861   {   27,   -3 }, /* (10) expr ::= expr LT expr */
862   {   27,   -3 }, /* (11) expr ::= expr LE expr */
863   {   27,   -3 }, /* (12) expr ::= expr GT expr */
864   {   27,   -3 }, /* (13) expr ::= expr GE expr */
865   {   27,   -3 }, /* (14) expr ::= expr AND expr */
866   {   27,   -3 }, /* (15) expr ::= expr OR expr */
867   {   27,   -2 }, /* (16) expr ::= NOT expr */
868   {   27,   -1 }, /* (17) expr ::= STRING */
869   {   27,   -1 }, /* (18) expr ::= number */
870   {   24,   -1 }, /* (19) number ::= NUMBER */
871   {   24,   -2 }, /* (20) number ::= MINUS NUMBER */
872   {   27,   -1 }, /* (21) expr ::= PROPERTY */
873   {   27,   -4 }, /* (22) expr ::= SYMBOL LP arglist RP */
874   {   27,   -1 }, /* (23) expr ::= SYMBOL */
875   {   25,    0 }, /* (24) arglist ::= */
876   {   25,   -1 }, /* (25) arglist ::= expr */
877   {   25,   -3 }, /* (26) arglist ::= arglist COMMA expr */
878 };
879 
880 static void yy_accept(yyParser*);  /* Forward Declaration */
881 
882 /*
883 ** Perform a reduce action and the shift that must immediately
884 ** follow the reduce.
885 **
886 ** The yyLookahead and yyLookaheadToken parameters provide reduce actions
887 ** access to the lookahead token (if any).  The yyLookahead will be YYNOCODE
888 ** if the lookahead token has already been consumed.  As this procedure is
889 ** only called from one place, optimizing compilers will in-line it, which
890 ** means that the extra parameters have no performance impact.
891 */
yy_reduce(yyParser * yypParser,unsigned int yyruleno,int yyLookahead,RSExprParser_ParseTOKENTYPE yyLookaheadToken RSExprParser_ParseCTX_PDECL)892 static YYACTIONTYPE yy_reduce(
893   yyParser *yypParser,         /* The parser */
894   unsigned int yyruleno,       /* Number of the rule by which to reduce */
895   int yyLookahead,             /* Lookahead token, or YYNOCODE if none */
896   RSExprParser_ParseTOKENTYPE yyLookaheadToken  /* Value of the lookahead token */
897   RSExprParser_ParseCTX_PDECL                   /* %extra_context */
898 ){
899   int yygoto;                     /* The next state */
900   int yyact;                      /* The next action */
901   yyStackEntry *yymsp;            /* The top of the parser's stack */
902   int yysize;                     /* Amount to pop the stack */
903   RSExprParser_ParseARG_FETCH
904   (void)yyLookahead;
905   (void)yyLookaheadToken;
906   yymsp = yypParser->yytos;
907 #ifndef NDEBUG
908   if( yyTraceFILE && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){
909     yysize = yyRuleInfo[yyruleno].nrhs;
910     if( yysize ){
911       fprintf(yyTraceFILE, "%sReduce %d [%s], go to state %d.\n",
912         yyTracePrompt,
913         yyruleno, yyRuleName[yyruleno], yymsp[yysize].stateno);
914     }else{
915       fprintf(yyTraceFILE, "%sReduce %d [%s].\n",
916         yyTracePrompt, yyruleno, yyRuleName[yyruleno]);
917     }
918   }
919 #endif /* NDEBUG */
920 
921   /* Check that the stack is large enough to grow by a single entry
922   ** if the RHS of the rule is empty.  This ensures that there is room
923   ** enough on the stack to push the LHS value */
924   if( yyRuleInfo[yyruleno].nrhs==0 ){
925 #ifdef YYTRACKMAXSTACKDEPTH
926     if( (int)(yypParser->yytos - yypParser->yystack)>yypParser->yyhwm ){
927       yypParser->yyhwm++;
928       assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack));
929     }
930 #endif
931 #if YYSTACKDEPTH>0
932     if( yypParser->yytos>=yypParser->yystackEnd ){
933       yyStackOverflow(yypParser);
934       /* The call to yyStackOverflow() above pops the stack until it is
935       ** empty, causing the main parser loop to exit.  So the return value
936       ** is never used and does not matter. */
937       return 0;
938     }
939 #else
940     if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz-1] ){
941       if( yyGrowStack(yypParser) ){
942         yyStackOverflow(yypParser);
943         /* The call to yyStackOverflow() above pops the stack until it is
944         ** empty, causing the main parser loop to exit.  So the return value
945         ** is never used and does not matter. */
946         return 0;
947       }
948       yymsp = yypParser->yytos;
949     }
950 #endif
951   }
952 
953   switch( yyruleno ){
954   /* Beginning here are the reduction cases.  A typical example
955   ** follows:
956   **   case 0:
957   **  #line <lineno> <grammarfile>
958   **     { ... }           // User supplied code
959   **  #line <lineno> <thisfile>
960   **     break;
961   */
962 /********** Begin reduce actions **********************************************/
963         YYMINORTYPE yylhsminor;
964       case 0: /* program ::= expr */
965 { ctx->root = yymsp[0].minor.yy19; }
966         break;
967       case 1: /* expr ::= LP expr RP */
968 { yymsp[-2].minor.yy19 = yymsp[-1].minor.yy19; }
969         break;
970       case 2: /* expr ::= expr PLUS expr */
971 { yylhsminor.yy19 = RS_NewOp('+', yymsp[-2].minor.yy19, yymsp[0].minor.yy19); }
972   yymsp[-2].minor.yy19 = yylhsminor.yy19;
973         break;
974       case 3: /* expr ::= expr DIVIDE expr */
975 {  yylhsminor.yy19 = RS_NewOp('/', yymsp[-2].minor.yy19, yymsp[0].minor.yy19); }
976   yymsp[-2].minor.yy19 = yylhsminor.yy19;
977         break;
978       case 4: /* expr ::= expr TIMES expr */
979 {  yylhsminor.yy19 = RS_NewOp('*', yymsp[-2].minor.yy19, yymsp[0].minor.yy19);}
980   yymsp[-2].minor.yy19 = yylhsminor.yy19;
981         break;
982       case 5: /* expr ::= expr MINUS expr */
983 {  yylhsminor.yy19 = RS_NewOp('-', yymsp[-2].minor.yy19, yymsp[0].minor.yy19); }
984   yymsp[-2].minor.yy19 = yylhsminor.yy19;
985         break;
986       case 6: /* expr ::= expr POW expr */
987 {  yylhsminor.yy19 = RS_NewOp('^', yymsp[-2].minor.yy19, yymsp[0].minor.yy19); }
988   yymsp[-2].minor.yy19 = yylhsminor.yy19;
989         break;
990       case 7: /* expr ::= expr MOD expr */
991 { yylhsminor.yy19 = RS_NewOp('%', yymsp[-2].minor.yy19, yymsp[0].minor.yy19); }
992   yymsp[-2].minor.yy19 = yylhsminor.yy19;
993         break;
994       case 8: /* expr ::= expr EQ expr */
995 { yylhsminor.yy19 = RS_NewPredicate(RSCondition_Eq, yymsp[-2].minor.yy19, yymsp[0].minor.yy19); }
996   yymsp[-2].minor.yy19 = yylhsminor.yy19;
997         break;
998       case 9: /* expr ::= expr NE expr */
999 { yylhsminor.yy19 = RS_NewPredicate(RSCondition_Ne, yymsp[-2].minor.yy19, yymsp[0].minor.yy19); }
1000   yymsp[-2].minor.yy19 = yylhsminor.yy19;
1001         break;
1002       case 10: /* expr ::= expr LT expr */
1003 { yylhsminor.yy19 = RS_NewPredicate(RSCondition_Lt, yymsp[-2].minor.yy19, yymsp[0].minor.yy19); }
1004   yymsp[-2].minor.yy19 = yylhsminor.yy19;
1005         break;
1006       case 11: /* expr ::= expr LE expr */
1007 { yylhsminor.yy19 = RS_NewPredicate(RSCondition_Le, yymsp[-2].minor.yy19, yymsp[0].minor.yy19); }
1008   yymsp[-2].minor.yy19 = yylhsminor.yy19;
1009         break;
1010       case 12: /* expr ::= expr GT expr */
1011 { yylhsminor.yy19 = RS_NewPredicate(RSCondition_Gt, yymsp[-2].minor.yy19, yymsp[0].minor.yy19); }
1012   yymsp[-2].minor.yy19 = yylhsminor.yy19;
1013         break;
1014       case 13: /* expr ::= expr GE expr */
1015 { yylhsminor.yy19 = RS_NewPredicate(RSCondition_Ge, yymsp[-2].minor.yy19, yymsp[0].minor.yy19); }
1016   yymsp[-2].minor.yy19 = yylhsminor.yy19;
1017         break;
1018       case 14: /* expr ::= expr AND expr */
1019 { yylhsminor.yy19 = RS_NewPredicate(RSCondition_And, yymsp[-2].minor.yy19, yymsp[0].minor.yy19); }
1020   yymsp[-2].minor.yy19 = yylhsminor.yy19;
1021         break;
1022       case 15: /* expr ::= expr OR expr */
1023 { yylhsminor.yy19 = RS_NewPredicate(RSCondition_Or, yymsp[-2].minor.yy19, yymsp[0].minor.yy19); }
1024   yymsp[-2].minor.yy19 = yylhsminor.yy19;
1025         break;
1026       case 16: /* expr ::= NOT expr */
1027 { yymsp[-1].minor.yy19 = RS_NewInverted(yymsp[0].minor.yy19); }
1028         break;
1029       case 17: /* expr ::= STRING */
1030 { yylhsminor.yy19 =  RS_NewStringLiteral((char*)yymsp[0].minor.yy0.s, yymsp[0].minor.yy0.len); }
1031   yymsp[0].minor.yy19 = yylhsminor.yy19;
1032         break;
1033       case 18: /* expr ::= number */
1034 { yylhsminor.yy19 = RS_NewNumberLiteral(yymsp[0].minor.yy32); }
1035   yymsp[0].minor.yy19 = yylhsminor.yy19;
1036         break;
1037       case 19: /* number ::= NUMBER */
1038 { yylhsminor.yy32 = yymsp[0].minor.yy0.numval; }
1039   yymsp[0].minor.yy32 = yylhsminor.yy32;
1040         break;
1041       case 20: /* number ::= MINUS NUMBER */
1042 { yymsp[-1].minor.yy32 = -yymsp[0].minor.yy0.numval; }
1043         break;
1044       case 21: /* expr ::= PROPERTY */
1045 { yylhsminor.yy19 = RS_NewProp(yymsp[0].minor.yy0.s, yymsp[0].minor.yy0.len); }
1046   yymsp[0].minor.yy19 = yylhsminor.yy19;
1047         break;
1048       case 22: /* expr ::= SYMBOL LP arglist RP */
1049 {
1050     RSFunction cb = RSFunctionRegistry_Get(yymsp[-3].minor.yy0.s, yymsp[-3].minor.yy0.len);
1051     if (!cb) {
1052         rm_asprintf(&ctx->errorMsg, "Unknown function name '%.*s'", yymsp[-3].minor.yy0.len, yymsp[-3].minor.yy0.s);
1053         ctx->ok = 0;
1054         yylhsminor.yy19 = NULL;
1055     } else {
1056          yylhsminor.yy19 = RS_NewFunc(yymsp[-3].minor.yy0.s, yymsp[-3].minor.yy0.len, yymsp[-1].minor.yy46, cb);
1057     }
1058 }
1059   yymsp[-3].minor.yy19 = yylhsminor.yy19;
1060         break;
1061       case 23: /* expr ::= SYMBOL */
1062 {
1063     if (yymsp[0].minor.yy0.len == 4 && !strncmp(yymsp[0].minor.yy0.s, "NULL", 4)) {
1064         yylhsminor.yy19 = RS_NewNullLiteral();
1065     } else {
1066         rm_asprintf(&ctx->errorMsg, "Unknown symbol '%.*s'", yymsp[0].minor.yy0.len, yymsp[0].minor.yy0.s);
1067         ctx->ok = 0;
1068         yylhsminor.yy19 = NULL;
1069     }
1070 }
1071   yymsp[0].minor.yy19 = yylhsminor.yy19;
1072         break;
1073       case 24: /* arglist ::= */
1074 { yymsp[1].minor.yy46 = RS_NewArgList(NULL); }
1075         break;
1076       case 25: /* arglist ::= expr */
1077 { yylhsminor.yy46 = RS_NewArgList(yymsp[0].minor.yy19); }
1078   yymsp[0].minor.yy46 = yylhsminor.yy46;
1079         break;
1080       case 26: /* arglist ::= arglist COMMA expr */
1081 {
1082     yylhsminor.yy46 = RSArgList_Append(yymsp[-2].minor.yy46, yymsp[0].minor.yy19);
1083 }
1084   yymsp[-2].minor.yy46 = yylhsminor.yy46;
1085         break;
1086       default:
1087         break;
1088 /********** End reduce actions ************************************************/
1089   };
1090   assert( yyruleno<sizeof(yyRuleInfo)/sizeof(yyRuleInfo[0]) );
1091   yygoto = yyRuleInfo[yyruleno].lhs;
1092   yysize = yyRuleInfo[yyruleno].nrhs;
1093   yyact = yy_find_reduce_action(yymsp[yysize].stateno,(YYCODETYPE)yygoto);
1094 
1095   /* There are no SHIFTREDUCE actions on nonterminals because the table
1096   ** generator has simplified them to pure REDUCE actions. */
1097   assert( !(yyact>YY_MAX_SHIFT && yyact<=YY_MAX_SHIFTREDUCE) );
1098 
1099   /* It is not possible for a REDUCE to be followed by an error */
1100   assert( yyact!=YY_ERROR_ACTION );
1101 
1102   yymsp += yysize+1;
1103   yypParser->yytos = yymsp;
1104   yymsp->stateno = (YYACTIONTYPE)yyact;
1105   yymsp->major = (YYCODETYPE)yygoto;
1106   yyTraceShift(yypParser, yyact, "... then shift");
1107   return yyact;
1108 }
1109 
1110 /*
1111 ** The following code executes when the parse fails
1112 */
1113 #ifndef YYNOERRORRECOVERY
yy_parse_failed(yyParser * yypParser)1114 static void yy_parse_failed(
1115   yyParser *yypParser           /* The parser */
1116 ){
1117   RSExprParser_ParseARG_FETCH
1118   RSExprParser_ParseCTX_FETCH
1119 #ifndef NDEBUG
1120   if( yyTraceFILE ){
1121     fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt);
1122   }
1123 #endif
1124   while( yypParser->yytos>yypParser->yystack ) yy_pop_parser_stack(yypParser);
1125   /* Here code is inserted which will be executed whenever the
1126   ** parser fails */
1127 /************ Begin %parse_failure code ***************************************/
1128 /************ End %parse_failure code *****************************************/
1129   RSExprParser_ParseARG_STORE /* Suppress warning about unused %extra_argument variable */
1130   RSExprParser_ParseCTX_STORE
1131 }
1132 #endif /* YYNOERRORRECOVERY */
1133 
1134 /*
1135 ** The following code executes when a syntax error first occurs.
1136 */
yy_syntax_error(yyParser * yypParser,int yymajor,RSExprParser_ParseTOKENTYPE yyminor)1137 static void yy_syntax_error(
1138   yyParser *yypParser,           /* The parser */
1139   int yymajor,                   /* The major type of the error token */
1140   RSExprParser_ParseTOKENTYPE yyminor         /* The minor type of the error token */
1141 ){
1142   RSExprParser_ParseARG_FETCH
1143   RSExprParser_ParseCTX_FETCH
1144 #define TOKEN yyminor
1145 /************ Begin %syntax_error code ****************************************/
1146 
1147 
1148     rm_asprintf(&ctx->errorMsg, "Syntax error at offset %d near '%.*s'", TOKEN.pos, TOKEN.len, TOKEN.s);
1149     ctx->ok = 0;
1150 /************ End %syntax_error code ******************************************/
1151   RSExprParser_ParseARG_STORE /* Suppress warning about unused %extra_argument variable */
1152   RSExprParser_ParseCTX_STORE
1153 }
1154 
1155 /*
1156 ** The following is executed when the parser accepts
1157 */
yy_accept(yyParser * yypParser)1158 static void yy_accept(
1159   yyParser *yypParser           /* The parser */
1160 ){
1161   RSExprParser_ParseARG_FETCH
1162   RSExprParser_ParseCTX_FETCH
1163 #ifndef NDEBUG
1164   if( yyTraceFILE ){
1165     fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt);
1166   }
1167 #endif
1168 #ifndef YYNOERRORRECOVERY
1169   yypParser->yyerrcnt = -1;
1170 #endif
1171   assert( yypParser->yytos==yypParser->yystack );
1172   /* Here code is inserted which will be executed whenever the
1173   ** parser accepts */
1174 /*********** Begin %parse_accept code *****************************************/
1175 /*********** End %parse_accept code *******************************************/
1176   RSExprParser_ParseARG_STORE /* Suppress warning about unused %extra_argument variable */
1177   RSExprParser_ParseCTX_STORE
1178 }
1179 
1180 /* The main parser program.
1181 ** The first argument is a pointer to a structure obtained from
1182 ** "RSExprParser_ParseAlloc" which describes the current state of the parser.
1183 ** The second argument is the major token number.  The third is
1184 ** the minor token.  The fourth optional argument is whatever the
1185 ** user wants (and specified in the grammar) and is available for
1186 ** use by the action routines.
1187 **
1188 ** Inputs:
1189 ** <ul>
1190 ** <li> A pointer to the parser (an opaque structure.)
1191 ** <li> The major token number.
1192 ** <li> The minor token number.
1193 ** <li> An option argument of a grammar-specified type.
1194 ** </ul>
1195 **
1196 ** Outputs:
1197 ** None.
1198 */
RSExprParser_Parse(void * yyp,int yymajor,RSExprParser_ParseTOKENTYPE yyminor RSExprParser_ParseARG_PDECL)1199 void RSExprParser_Parse(
1200   void *yyp,                   /* The parser */
1201   int yymajor,                 /* The major token code number */
1202   RSExprParser_ParseTOKENTYPE yyminor       /* The value for the token */
1203   RSExprParser_ParseARG_PDECL               /* Optional %extra_argument parameter */
1204 ){
1205   YYMINORTYPE yyminorunion;
1206   YYACTIONTYPE yyact;   /* The parser action. */
1207 #if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY)
1208   int yyendofinput;     /* True if we are at the end of input */
1209 #endif
1210 #ifdef YYERRORSYMBOL
1211   int yyerrorhit = 0;   /* True if yymajor has invoked an error */
1212 #endif
1213   yyParser *yypParser = (yyParser*)yyp;  /* The parser */
1214   RSExprParser_ParseCTX_FETCH
1215   RSExprParser_ParseARG_STORE
1216 
1217   assert( yypParser->yytos!=0 );
1218 #if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY)
1219   yyendofinput = (yymajor==0);
1220 #endif
1221 
1222   yyact = yypParser->yytos->stateno;
1223 #ifndef NDEBUG
1224   if( yyTraceFILE ){
1225     if( yyact < YY_MIN_REDUCE ){
1226       fprintf(yyTraceFILE,"%sInput '%s' in state %d\n",
1227               yyTracePrompt,yyTokenName[yymajor],yyact);
1228     }else{
1229       fprintf(yyTraceFILE,"%sInput '%s' with pending reduce %d\n",
1230               yyTracePrompt,yyTokenName[yymajor],yyact-YY_MIN_REDUCE);
1231     }
1232   }
1233 #endif
1234 
1235   do{
1236     assert( yyact==yypParser->yytos->stateno );
1237     yyact = yy_find_shift_action(yymajor,yyact);
1238     if( yyact >= YY_MIN_REDUCE ){
1239       yyact = yy_reduce(yypParser,yyact-YY_MIN_REDUCE,yymajor,
1240                         yyminor RSExprParser_ParseCTX_PARAM);
1241     }else if( yyact <= YY_MAX_SHIFTREDUCE ){
1242       yy_shift(yypParser,yyact,yymajor,yyminor);
1243 #ifndef YYNOERRORRECOVERY
1244       yypParser->yyerrcnt--;
1245 #endif
1246       break;
1247     }else if( yyact==YY_ACCEPT_ACTION ){
1248       yypParser->yytos--;
1249       yy_accept(yypParser);
1250       return;
1251     }else{
1252       assert( yyact == YY_ERROR_ACTION );
1253       yyminorunion.yy0 = yyminor;
1254 #ifdef YYERRORSYMBOL
1255       int yymx;
1256 #endif
1257 #ifndef NDEBUG
1258       if( yyTraceFILE ){
1259         fprintf(yyTraceFILE,"%sSyntax Error!\n",yyTracePrompt);
1260       }
1261 #endif
1262 #ifdef YYERRORSYMBOL
1263       /* A syntax error has occurred.
1264       ** The response to an error depends upon whether or not the
1265       ** grammar defines an error token "ERROR".
1266       **
1267       ** This is what we do if the grammar does define ERROR:
1268       **
1269       **  * Call the %syntax_error function.
1270       **
1271       **  * Begin popping the stack until we enter a state where
1272       **    it is legal to shift the error symbol, then shift
1273       **    the error symbol.
1274       **
1275       **  * Set the error count to three.
1276       **
1277       **  * Begin accepting and shifting new tokens.  No new error
1278       **    processing will occur until three tokens have been
1279       **    shifted successfully.
1280       **
1281       */
1282       if( yypParser->yyerrcnt<0 ){
1283         yy_syntax_error(yypParser,yymajor,yyminor);
1284       }
1285       yymx = yypParser->yytos->major;
1286       if( yymx==YYERRORSYMBOL || yyerrorhit ){
1287 #ifndef NDEBUG
1288         if( yyTraceFILE ){
1289           fprintf(yyTraceFILE,"%sDiscard input token %s\n",
1290              yyTracePrompt,yyTokenName[yymajor]);
1291         }
1292 #endif
1293         yy_destructor(yypParser, (YYCODETYPE)yymajor, &yyminorunion);
1294         yymajor = YYNOCODE;
1295       }else{
1296         while( yypParser->yytos >= yypParser->yystack
1297             && yymx != YYERRORSYMBOL
1298             && (yyact = yy_find_reduce_action(
1299                         yypParser->yytos->stateno,
1300                         YYERRORSYMBOL)) >= YY_MIN_REDUCE
1301         ){
1302           yy_pop_parser_stack(yypParser);
1303         }
1304         if( yypParser->yytos < yypParser->yystack || yymajor==0 ){
1305           yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
1306           yy_parse_failed(yypParser);
1307 #ifndef YYNOERRORRECOVERY
1308           yypParser->yyerrcnt = -1;
1309 #endif
1310           yymajor = YYNOCODE;
1311         }else if( yymx!=YYERRORSYMBOL ){
1312           yy_shift(yypParser,yyact,YYERRORSYMBOL,yyminor);
1313         }
1314       }
1315       yypParser->yyerrcnt = 3;
1316       yyerrorhit = 1;
1317       if( yymajor==YYNOCODE ) break;
1318       yyact = yypParser->yytos->stateno;
1319 #elif defined(YYNOERRORRECOVERY)
1320       /* If the YYNOERRORRECOVERY macro is defined, then do not attempt to
1321       ** do any kind of error recovery.  Instead, simply invoke the syntax
1322       ** error routine and continue going as if nothing had happened.
1323       **
1324       ** Applications can set this macro (for example inside %include) if
1325       ** they intend to abandon the parse upon the first syntax error seen.
1326       */
1327       yy_syntax_error(yypParser,yymajor, yyminor);
1328       yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
1329       break;
1330 #else  /* YYERRORSYMBOL is not defined */
1331       /* This is what we do if the grammar does not define ERROR:
1332       **
1333       **  * Report an error message, and throw away the input token.
1334       **
1335       **  * If the input token is $, then fail the parse.
1336       **
1337       ** As before, subsequent error messages are suppressed until
1338       ** three input tokens have been successfully shifted.
1339       */
1340       if( yypParser->yyerrcnt<=0 ){
1341         yy_syntax_error(yypParser,yymajor, yyminor);
1342       }
1343       yypParser->yyerrcnt = 3;
1344       yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
1345       if( yyendofinput ){
1346         yy_parse_failed(yypParser);
1347 #ifndef YYNOERRORRECOVERY
1348         yypParser->yyerrcnt = -1;
1349 #endif
1350       }
1351       break;
1352 #endif
1353     }
1354   }while( yypParser->yytos>yypParser->yystack );
1355 #ifndef NDEBUG
1356   if( yyTraceFILE ){
1357     yyStackEntry *i;
1358     char cDiv = '[';
1359     fprintf(yyTraceFILE,"%sReturn. Stack=",yyTracePrompt);
1360     for(i=&yypParser->yystack[1]; i<=yypParser->yytos; i++){
1361       fprintf(yyTraceFILE,"%c%s", cDiv, yyTokenName[i->major]);
1362       cDiv = ' ';
1363     }
1364     fprintf(yyTraceFILE,"]\n");
1365   }
1366 #endif
1367   return;
1368 }
1369