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