1 /* original parser id follows */ 2 /* yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93" */ 3 /* (use YYMAJOR/YYMINOR for ifdefs dependent on parser version) */ 4 5 #define YYBYACC 1 6 #define YYMAJOR 1 7 #define YYMINOR 9 8 #define YYCHECK "yyyymmdd" 9 10 #define YYEMPTY (-1) 11 #define yyclearin (yychar = YYEMPTY) 12 #define yyerrok (yyerrflag = 0) 13 #define YYRECOVERING() (yyerrflag != 0) 14 #define YYENOMEM (-2) 15 #define YYEOF 0 16 #undef YYBTYACC 17 #define YYBTYACC 1 18 #define YYDEBUGSTR (yytrial ? YYPREFIX "debug(trial)" : YYPREFIX "debug") 19 20 #ifndef yyparse 21 #define yyparse calc1_parse 22 #endif /* yyparse */ 23 24 #ifndef yylex 25 #define yylex calc1_lex 26 #endif /* yylex */ 27 28 #ifndef yyerror 29 #define yyerror calc1_error 30 #endif /* yyerror */ 31 32 #ifndef yychar 33 #define yychar calc1_char 34 #endif /* yychar */ 35 36 #ifndef yyval 37 #define yyval calc1_val 38 #endif /* yyval */ 39 40 #ifndef yylval 41 #define yylval calc1_lval 42 #endif /* yylval */ 43 44 #ifndef yydebug 45 #define yydebug calc1_debug 46 #endif /* yydebug */ 47 48 #ifndef yynerrs 49 #define yynerrs calc1_nerrs 50 #endif /* yynerrs */ 51 52 #ifndef yyerrflag 53 #define yyerrflag calc1_errflag 54 #endif /* yyerrflag */ 55 56 #ifndef yylhs 57 #define yylhs calc1_lhs 58 #endif /* yylhs */ 59 60 #ifndef yylen 61 #define yylen calc1_len 62 #endif /* yylen */ 63 64 #ifndef yydefred 65 #define yydefred calc1_defred 66 #endif /* yydefred */ 67 68 #ifndef yystos 69 #define yystos calc1_stos 70 #endif /* yystos */ 71 72 #ifndef yydgoto 73 #define yydgoto calc1_dgoto 74 #endif /* yydgoto */ 75 76 #ifndef yysindex 77 #define yysindex calc1_sindex 78 #endif /* yysindex */ 79 80 #ifndef yyrindex 81 #define yyrindex calc1_rindex 82 #endif /* yyrindex */ 83 84 #ifndef yygindex 85 #define yygindex calc1_gindex 86 #endif /* yygindex */ 87 88 #ifndef yytable 89 #define yytable calc1_table 90 #endif /* yytable */ 91 92 #ifndef yycheck 93 #define yycheck calc1_check 94 #endif /* yycheck */ 95 96 #ifndef yyname 97 #define yyname calc1_name 98 #endif /* yyname */ 99 100 #ifndef yyrule 101 #define yyrule calc1_rule 102 #endif /* yyrule */ 103 104 #if YYBTYACC 105 106 #ifndef yycindex 107 #define yycindex calc1_cindex 108 #endif /* yycindex */ 109 110 #ifndef yyctable 111 #define yyctable calc1_ctable 112 #endif /* yyctable */ 113 114 #endif /* YYBTYACC */ 115 116 #define YYPREFIX "calc1_" 117 118 #define YYPURE 1 119 120 #line 3 "btyacc_calc1.y" 121 122 /* http://dinosaur.compilertools.net/yacc/index.html */ 123 124 #include <stdlib.h> 125 #include <stdio.h> 126 #include <ctype.h> 127 #include <math.h> 128 129 typedef struct interval 130 { 131 double lo, hi; 132 } 133 INTERVAL; 134 135 INTERVAL vmul(double, double, INTERVAL); 136 INTERVAL vdiv(double, double, INTERVAL); 137 138 int dcheck(INTERVAL); 139 140 double dreg[26]; 141 INTERVAL vreg[26]; 142 143 #line 29 "btyacc_calc1.y" 144 #ifdef YYSTYPE 145 #undef YYSTYPE_IS_DECLARED 146 #define YYSTYPE_IS_DECLARED 1 147 #endif 148 #ifndef YYSTYPE_IS_DECLARED 149 #define YYSTYPE_IS_DECLARED 1 150 typedef union 151 { 152 int ival; 153 double dval; 154 INTERVAL vval; 155 } YYSTYPE; 156 #endif /* !YYSTYPE_IS_DECLARED */ 157 #line 158 "btyacc_calc1.tab.c" 158 159 /* compatibility with bison */ 160 #ifdef YYPARSE_PARAM 161 /* compatibility with FreeBSD */ 162 # ifdef YYPARSE_PARAM_TYPE 163 # define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM) 164 # else 165 # define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM) 166 # endif 167 #else 168 # define YYPARSE_DECL() yyparse(void) 169 #endif 170 171 /* Parameters sent to lex. */ 172 #ifdef YYLEX_PARAM 173 # ifdef YYLEX_PARAM_TYPE 174 # define YYLEX_DECL() yylex(YYSTYPE *yylval, YYLEX_PARAM_TYPE YYLEX_PARAM) 175 # else 176 # define YYLEX_DECL() yylex(YYSTYPE *yylval, void * YYLEX_PARAM) 177 # endif 178 # define YYLEX yylex(&yylval, YYLEX_PARAM) 179 #else 180 # define YYLEX_DECL() yylex(YYSTYPE *yylval) 181 # define YYLEX yylex(&yylval) 182 #endif 183 184 /* Parameters sent to yyerror. */ 185 #ifndef YYERROR_DECL 186 #define YYERROR_DECL() yyerror(const char *s) 187 #endif 188 #ifndef YYERROR_CALL 189 #define YYERROR_CALL(msg) yyerror(msg) 190 #endif 191 192 extern int YYPARSE_DECL(); 193 194 #define DREG 257 195 #define VREG 258 196 #define CONST 259 197 #define UMINUS 260 198 #define YYERRCODE 256 199 typedef short YYINT; 200 static const YYINT calc1_lhs[] = { -1, 201 0, 0, 0, 3, 3, 3, 3, 1, 1, 1, 202 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 203 2, 2, 2, 2, 2, 2, 2, 2, 204 }; 205 static const YYINT calc1_len[] = { 2, 206 0, 3, 3, 1, 1, 3, 3, 1, 1, 3, 207 3, 3, 3, 2, 3, 1, 5, 1, 3, 3, 208 3, 3, 3, 3, 3, 3, 2, 3, 209 }; 210 static const YYINT calc1_defred[] = { 1, 211 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 212 3, 0, 0, 9, 18, 0, 27, 0, 0, 0, 213 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 214 0, 0, 0, 15, 0, 28, 0, 0, 0, 0, 215 0, 24, 0, 26, 0, 0, 23, 25, 14, 0, 216 0, 0, 0, 0, 0, 0, 0, 12, 13, 17, 217 }; 218 static const YYINT calc1_stos[] = { 0, 219 262, 256, 257, 258, 259, 45, 40, 263, 264, 265, 220 10, 61, 61, 257, 258, 263, 264, 263, 264, 43, 221 45, 42, 47, 43, 45, 42, 47, 10, 45, 40, 222 263, 263, 264, 41, 44, 41, 263, 264, 263, 264, 223 263, 264, 263, 264, 264, 264, 264, 264, 263, 263, 224 43, 45, 42, 47, 263, 263, 263, 263, 263, 41, 225 }; 226 static const YYINT calc1_dgoto[] = { 1, 227 32, 9, 10, 228 }; 229 static const YYINT calc1_sindex[] = { 0, 230 -40, -9, -59, -54, 0, -37, -37, 0, 82, 4, 231 0, -34, -37, 0, 0, 0, 0, -31, -25, -37, 232 -37, -37, -37, -37, -37, -37, -37, 0, -34, -34, 233 132, 0, 82, 0, -34, 0, 0, -12, 0, -12, 234 0, 0, 0, 0, -12, -12, 0, 0, 0, 112, 235 -34, -34, -34, -34, 119, -11, -11, 0, 0, 0, 236 }; 237 static const YYINT calc1_rindex[] = { 0, 238 0, 0, 51, 58, 0, 0, 0, 0, 11, 0, 239 0, 0, 0, 0, 0, -16, 0, 0, 0, 0, 240 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 241 19, 9, 27, 0, 0, 0, -5, 41, -4, 77, 242 -2, 0, 8, 0, 78, 85, 0, 0, 0, 0, 243 0, 0, 0, 0, 0, 92, 99, 0, 0, 0, 244 }; 245 #if YYBTYACC 246 static const YYINT calc1_cindex[] = { 0, 247 0, 0, 0, 0, 0, 0, 0, 65, 0, 0, 248 0, 0, 0, 0, 0, 2, 0, 126, 0, 0, 249 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 250 0, 138, 0, 0, 0, 0, 17, 0, 24, 0, 251 31, 0, 38, 0, 0, 0, 0, 0, 0, 0, 252 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 253 }; 254 #endif 255 static const YYINT calc1_gindex[] = { 0, 256 3, 125, 0, 257 }; 258 #define YYTABLESIZE 225 259 static const YYINT calc1_table[] = { 7, 260 11, 12, 7, 8, 6, 30, 13, 6, 16, 18, 261 29, 14, 35, 28, 31, 36, 26, 24, 16, 25, 262 5, 27, 37, 39, 41, 43, 20, 14, 6, 26, 263 53, 49, 50, 23, 27, 54, 7, 55, 10, 11, 264 26, 12, 14, 14, 14, 0, 14, 29, 14, 16, 265 20, 13, 0, 56, 57, 58, 59, 20, 6, 20, 266 9, 20, 0, 9, 23, 6, 23, 18, 23, 0, 267 9, 26, 26, 26, 11, 26, 0, 26, 29, 29, 268 29, 20, 29, 20, 29, 20, 22, 19, 0, 0, 269 0, 0, 9, 9, 21, 9, 0, 9, 0, 18, 270 18, 10, 18, 0, 18, 0, 6, 0, 11, 3, 271 0, 9, 0, 0, 0, 0, 0, 22, 19, 22, 272 19, 22, 19, 26, 24, 21, 25, 21, 27, 21, 273 17, 19, 10, 0, 10, 0, 10, 33, 0, 11, 274 0, 11, 0, 11, 38, 40, 42, 44, 45, 46, 275 47, 48, 34, 53, 51, 0, 52, 0, 54, 60, 276 53, 51, 0, 52, 0, 54, 18, 6, 0, 0, 277 3, 0, 9, 53, 51, 0, 52, 0, 54, 6, 278 0, 0, 3, 0, 9, 0, 0, 0, 0, 0, 279 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 280 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 281 0, 0, 0, 0, 0, 2, 3, 4, 5, 14, 282 15, 5, 14, 0, 5, 283 }; 284 static const YYINT calc1_check[] = { 40, 285 10, 61, 40, 1, 45, 40, 61, 45, 6, 7, 286 45, 10, 44, 10, 12, 41, 42, 43, 10, 45, 287 10, 47, 20, 21, 22, 23, 10, 44, 10, 42, 288 42, 29, 30, 10, 47, 47, 10, 35, 44, 44, 289 10, 44, 41, 42, 43, -1, 45, 10, 47, 41, 290 10, 44, -1, 51, 52, 53, 54, 41, 42, 43, 291 10, 45, -1, 47, 41, 42, 43, 10, 45, -1, 292 47, 41, 42, 43, 10, 45, -1, 47, 41, 42, 293 43, 41, 45, 43, 47, 45, 10, 10, -1, -1, 294 -1, -1, 42, 43, 10, 45, -1, 47, -1, 42, 295 43, 10, 45, -1, 47, -1, 42, 43, 10, 45, 296 -1, 47, -1, -1, -1, -1, -1, 41, 41, 43, 297 43, 45, 45, 42, 43, 41, 45, 43, 47, 45, 298 6, 7, 41, -1, 43, -1, 45, 13, -1, 41, 299 -1, 43, -1, 45, 20, 21, 22, 23, 24, 25, 300 26, 27, 41, 42, 43, -1, 45, -1, 47, 41, 301 42, 43, -1, 45, -1, 47, 41, 42, 43, -1, 302 45, -1, 47, 42, 43, -1, 45, -1, 47, 42, 303 43, -1, 45, -1, 47, -1, -1, -1, -1, -1, 304 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 305 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 306 -1, -1, -1, -1, -1, 256, 257, 258, 259, 257, 307 258, 259, 257, -1, 259, 308 }; 309 #if YYBTYACC 310 static const YYINT calc1_ctable[] = { 20, 311 16, -1, 21, 16, -1, 22, 16, -1, 23, 16, 312 -1, 4, 16, -1, 14, 16, -1, 34, 16, -1, 313 10, 16, -1, 11, 16, -1, 12, 16, -1, 13, 314 16, -1, 315 }; 316 #endif 317 #define YYFINAL 1 318 #ifndef YYDEBUG 319 #define YYDEBUG 0 320 #endif 321 #define YYMAXTOKEN 260 322 #define YYUNDFTOKEN 266 323 #define YYTRANSLATE(a) ((a) > YYMAXTOKEN ? YYUNDFTOKEN : (a)) 324 #if YYDEBUG 325 static const char *const calc1_name[] = { 326 327 "$end",0,0,0,0,0,0,0,0,0,"'\\n'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 328 0,0,0,0,0,0,"'('","')'","'*'","'+'","','","'-'",0,"'/'",0,0,0,0,0,0,0,0,0,0,0,0, 329 0,"'='",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 330 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 331 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 332 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 333 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 334 "error","DREG","VREG","CONST","UMINUS","$accept","lines","dexp","vexp","line", 335 "illegal-symbol", 336 }; 337 static const char *const calc1_rule[] = { 338 "$accept : lines", 339 "lines :", 340 "lines : lines line '\\n'", 341 "lines : lines error '\\n'", 342 "line : dexp", 343 "line : vexp", 344 "line : DREG '=' dexp", 345 "line : VREG '=' vexp", 346 "dexp : CONST", 347 "dexp : DREG", 348 "dexp : dexp '+' dexp", 349 "dexp : dexp '-' dexp", 350 "dexp : dexp '*' dexp", 351 "dexp : dexp '/' dexp", 352 "dexp : '-' dexp", 353 "dexp : '(' dexp ')'", 354 "vexp : dexp", 355 "vexp : '(' dexp ',' dexp ')'", 356 "vexp : VREG", 357 "vexp : vexp '+' vexp", 358 "vexp : dexp '+' vexp", 359 "vexp : vexp '-' vexp", 360 "vexp : dexp '-' vexp", 361 "vexp : vexp '*' vexp", 362 "vexp : dexp '*' vexp", 363 "vexp : vexp '/' vexp", 364 "vexp : dexp '/' vexp", 365 "vexp : '-' vexp", 366 "vexp : '(' vexp ')'", 367 368 }; 369 #endif 370 371 int yydebug; 372 int yynerrs; 373 374 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 375 #ifndef YYLLOC_DEFAULT 376 #define YYLLOC_DEFAULT(loc, rhs, n) \ 377 do \ 378 { \ 379 if (n == 0) \ 380 { \ 381 (loc).first_line = ((rhs)[-1]).last_line; \ 382 (loc).first_column = ((rhs)[-1]).last_column; \ 383 (loc).last_line = ((rhs)[-1]).last_line; \ 384 (loc).last_column = ((rhs)[-1]).last_column; \ 385 } \ 386 else \ 387 { \ 388 (loc).first_line = ((rhs)[ 0 ]).first_line; \ 389 (loc).first_column = ((rhs)[ 0 ]).first_column; \ 390 (loc).last_line = ((rhs)[n-1]).last_line; \ 391 (loc).last_column = ((rhs)[n-1]).last_column; \ 392 } \ 393 } while (0) 394 #endif /* YYLLOC_DEFAULT */ 395 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */ 396 #if YYBTYACC 397 398 #ifndef YYLVQUEUEGROWTH 399 #define YYLVQUEUEGROWTH 32 400 #endif 401 #endif /* YYBTYACC */ 402 403 /* define the initial stack-sizes */ 404 #ifdef YYSTACKSIZE 405 #undef YYMAXDEPTH 406 #define YYMAXDEPTH YYSTACKSIZE 407 #else 408 #ifdef YYMAXDEPTH 409 #define YYSTACKSIZE YYMAXDEPTH 410 #else 411 #define YYSTACKSIZE 10000 412 #define YYMAXDEPTH 10000 413 #endif 414 #endif 415 416 #ifndef YYINITSTACKSIZE 417 #define YYINITSTACKSIZE 200 418 #endif 419 420 typedef struct { 421 unsigned stacksize; 422 short *s_base; 423 short *s_mark; 424 short *s_last; 425 YYSTYPE *l_base; 426 YYSTYPE *l_mark; 427 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 428 YYLTYPE *p_base; 429 YYLTYPE *p_mark; 430 #endif 431 } YYSTACKDATA; 432 #if YYBTYACC 433 434 struct YYParseState_s 435 { 436 struct YYParseState_s *save; /* Previously saved parser state */ 437 YYSTACKDATA yystack; /* saved parser stack */ 438 int state; /* saved parser state */ 439 int errflag; /* saved error recovery status */ 440 int lexeme; /* saved index of the conflict lexeme in the lexical queue */ 441 YYINT ctry; /* saved index in yyctable[] for this conflict */ 442 }; 443 typedef struct YYParseState_s YYParseState; 444 #endif /* YYBTYACC */ 445 #line 174 "btyacc_calc1.y" 446 /* beginning of subroutines section */ 447 448 int 449 main (void) 450 { 451 while(!feof(stdin)) { 452 yyparse(); 453 } 454 return 0; 455 } 456 457 #define BSZ 50 /* buffer size for floating point numbers */ 458 459 static void 460 YYERROR_DECL() 461 { 462 fprintf(stderr, "%s\n", s); 463 } 464 465 /* lexical analysis */ 466 467 static int 468 YYLEX_DECL() 469 { 470 int c; 471 472 while ((c = getchar()) == ' ') 473 { /* skip over blanks */ 474 } 475 476 if (isupper(c)) 477 { 478 #if YYPURE 479 (*yylval).ival = c - 'A'; 480 #else 481 yylval.ival = c - 'A'; 482 #endif 483 return (VREG); 484 } 485 if (islower(c)) 486 { 487 #if YYPURE 488 (*yylval).ival = c - 'a'; 489 #else 490 yylval.ival = c - 'a'; 491 #endif 492 return (DREG); 493 } 494 495 if (isdigit(c) || c == '.') 496 { 497 /* gobble up digits, points, exponents */ 498 char buf[BSZ + 1], *cp = buf; 499 int dot = 0, expr = 0; 500 501 for (; (cp - buf) < BSZ; ++cp, c = getchar()) 502 { 503 504 *cp = (char) c; 505 if (isdigit(c)) 506 continue; 507 if (c == '.') 508 { 509 if (dot++ || expr) 510 return ('.'); /* will cause syntax error */ 511 continue; 512 } 513 514 if (c == 'e') 515 { 516 if (expr++) 517 return ('e'); /* will cause syntax error */ 518 continue; 519 } 520 521 /* end of number */ 522 break; 523 } 524 *cp = '\0'; 525 526 if ((cp - buf) >= BSZ) 527 printf("constant too long: truncated\n"); 528 else 529 ungetc(c, stdin); /* push back last char read */ 530 #if YYPURE 531 (*yylval).dval = atof(buf); 532 #else 533 yylval.dval = atof(buf); 534 #endif 535 return (CONST); 536 } 537 return (c); 538 } 539 540 static INTERVAL 541 hilo(double a, double b, double c, double d) 542 { 543 /* returns the smallest interval containing a, b, c, and d */ 544 /* used by *, / routines */ 545 INTERVAL v; 546 547 if (a > b) 548 { 549 v.hi = a; 550 v.lo = b; 551 } 552 else 553 { 554 v.hi = b; 555 v.lo = a; 556 } 557 558 if (c > d) 559 { 560 if (c > v.hi) 561 v.hi = c; 562 if (d < v.lo) 563 v.lo = d; 564 } 565 else 566 { 567 if (d > v.hi) 568 v.hi = d; 569 if (c < v.lo) 570 v.lo = c; 571 } 572 return (v); 573 } 574 575 INTERVAL 576 vmul(double a, double b, INTERVAL v) 577 { 578 return (hilo(a * v.hi, a * v.lo, b * v.hi, b * v.lo)); 579 } 580 581 int 582 dcheck(INTERVAL v) 583 { 584 if (v.hi >= 0. && v.lo <= 0.) 585 { 586 printf("divisor interval contains 0.\n"); 587 return (1); 588 } 589 return (0); 590 } 591 592 INTERVAL 593 vdiv(double a, double b, INTERVAL v) 594 { 595 return (hilo(a / v.hi, a / v.lo, b / v.hi, b / v.lo)); 596 } 597 #line 598 "btyacc_calc1.tab.c" 598 599 /* For use in generated program */ 600 #define yydepth (int)(yystack.s_mark - yystack.s_base) 601 #if YYBTYACC 602 #define yytrial (yyps->save) 603 #endif /* YYBTYACC */ 604 605 #if YYDEBUG 606 #include <stdio.h> /* needed for printf */ 607 #endif 608 609 #include <stdlib.h> /* needed for malloc, etc */ 610 #include <string.h> /* needed for memset */ 611 612 /* allocate initial stack or double stack size, up to YYMAXDEPTH */ 613 static int yygrowstack(YYSTACKDATA *data) 614 { 615 int i; 616 unsigned newsize; 617 short *newss; 618 YYSTYPE *newvs; 619 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 620 YYLTYPE *newps; 621 #endif 622 623 if ((newsize = data->stacksize) == 0) 624 newsize = YYINITSTACKSIZE; 625 else if (newsize >= YYMAXDEPTH) 626 return YYENOMEM; 627 else if ((newsize *= 2) > YYMAXDEPTH) 628 newsize = YYMAXDEPTH; 629 630 i = (int) (data->s_mark - data->s_base); 631 newss = (short *)realloc(data->s_base, newsize * sizeof(*newss)); 632 if (newss == 0) 633 return YYENOMEM; 634 635 data->s_base = newss; 636 data->s_mark = newss + i; 637 638 newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs)); 639 if (newvs == 0) 640 return YYENOMEM; 641 642 data->l_base = newvs; 643 data->l_mark = newvs + i; 644 645 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 646 newps = (YYLTYPE *)realloc(data->p_base, newsize * sizeof(*newps)); 647 if (newps == 0) 648 return YYENOMEM; 649 650 data->p_base = newps; 651 data->p_mark = newps + i; 652 #endif 653 654 data->stacksize = newsize; 655 data->s_last = data->s_base + newsize - 1; 656 657 #if YYDEBUG 658 if (yydebug) 659 fprintf(stderr, "%sdebug: stack size increased to %d\n", YYPREFIX, newsize); 660 #endif 661 return 0; 662 } 663 664 #if YYPURE || defined(YY_NO_LEAKS) 665 static void yyfreestack(YYSTACKDATA *data) 666 { 667 free(data->s_base); 668 free(data->l_base); 669 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 670 free(data->p_base); 671 #endif 672 memset(data, 0, sizeof(*data)); 673 } 674 #else 675 #define yyfreestack(data) /* nothing */ 676 #endif /* YYPURE || defined(YY_NO_LEAKS) */ 677 #if YYBTYACC 678 679 static YYParseState * 680 yyNewState(unsigned size) 681 { 682 YYParseState *p = (YYParseState *) malloc(sizeof(YYParseState)); 683 if (p == NULL) return NULL; 684 685 p->yystack.stacksize = size; 686 if (size == 0) 687 { 688 p->yystack.s_base = NULL; 689 p->yystack.l_base = NULL; 690 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 691 p->yystack.p_base = NULL; 692 #endif 693 return p; 694 } 695 p->yystack.s_base = (short *) malloc(size * sizeof(short)); 696 if (p->yystack.s_base == NULL) return NULL; 697 p->yystack.l_base = (YYSTYPE *) malloc(size * sizeof(YYSTYPE)); 698 if (p->yystack.l_base == NULL) return NULL; 699 memset(p->yystack.l_base, 0, size * sizeof(YYSTYPE)); 700 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 701 p->yystack.p_base = (YYLTYPE *) malloc(size * sizeof(YYLTYPE)); 702 if (p->yystack.p_base == NULL) return NULL; 703 memset(p->yystack.p_base, 0, size * sizeof(YYLTYPE)); 704 #endif 705 706 return p; 707 } 708 709 static void 710 yyFreeState(YYParseState *p) 711 { 712 yyfreestack(&p->yystack); 713 free(p); 714 } 715 #endif /* YYBTYACC */ 716 717 #define YYABORT goto yyabort 718 #define YYREJECT goto yyabort 719 #define YYACCEPT goto yyaccept 720 #define YYERROR goto yyerrlab 721 #if YYBTYACC 722 #define YYVALID do { if (yyps->save) goto yyvalid; } while(0) 723 #define YYVALID_NESTED do { if (yyps->save && \ 724 yyps->save->save == 0) goto yyvalid; } while(0) 725 #endif /* YYBTYACC */ 726 727 int 728 YYPARSE_DECL() 729 { 730 int yyerrflag; 731 int yychar; 732 YYSTYPE yyval; 733 YYSTYPE yylval; 734 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 735 YYLTYPE yyloc; /* position returned by actions */ 736 YYLTYPE yylloc; /* position from the lexer */ 737 #endif 738 739 /* variables for the parser stack */ 740 YYSTACKDATA yystack; 741 #if YYBTYACC 742 743 /* Current parser state */ 744 static YYParseState *yyps = 0; 745 746 /* yypath != NULL: do the full parse, starting at *yypath parser state. */ 747 static YYParseState *yypath = 0; 748 749 /* Base of the lexical value queue */ 750 static YYSTYPE *yylvals = 0; 751 752 /* Current position at lexical value queue */ 753 static YYSTYPE *yylvp = 0; 754 755 /* End position of lexical value queue */ 756 static YYSTYPE *yylve = 0; 757 758 /* The last allocated position at the lexical value queue */ 759 static YYSTYPE *yylvlim = 0; 760 761 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 762 /* Base of the lexical position queue */ 763 static YYLTYPE *yylpsns = 0; 764 765 /* Current position at lexical position queue */ 766 static YYLTYPE *yylpp = 0; 767 768 /* End position of lexical position queue */ 769 static YYLTYPE *yylpe = 0; 770 771 /* The last allocated position at the lexical position queue */ 772 static YYLTYPE *yylplim = 0; 773 #endif 774 775 /* Current position at lexical token queue */ 776 static short *yylexp = 0; 777 778 static short *yylexemes = 0; 779 #endif /* YYBTYACC */ 780 int yym, yyn, yystate, yyresult; 781 #if YYBTYACC 782 int yynewerrflag; 783 YYParseState *yyerrctx = NULL; 784 #endif /* YYBTYACC */ 785 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 786 YYLTYPE yyerror_loc_range[2]; /* position of error start & end */ 787 #endif 788 #if YYDEBUG 789 const char *yys; 790 791 if ((yys = getenv("YYDEBUG")) != 0) 792 { 793 yyn = *yys; 794 if (yyn >= '0' && yyn <= '9') 795 yydebug = yyn - '0'; 796 } 797 if (yydebug) 798 fprintf(stderr, "%sdebug[<# of symbols on state stack>]\n", YYPREFIX); 799 #endif 800 801 #if YYBTYACC 802 yyps = yyNewState(0); if (yyps == 0) goto yyenomem; 803 yyps->save = 0; 804 #endif /* YYBTYACC */ 805 yynerrs = 0; 806 yyerrflag = 0; 807 yychar = YYEMPTY; 808 yystate = 0; 809 810 #if YYPURE 811 memset(&yystack, 0, sizeof(yystack)); 812 #endif 813 814 if (yystack.s_base == NULL && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow; 815 yystack.s_mark = yystack.s_base; 816 yystack.l_mark = yystack.l_base; 817 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 818 yystack.p_mark = yystack.p_base; 819 #endif 820 yystate = 0; 821 *yystack.s_mark = 0; 822 823 yyloop: 824 if ((yyn = yydefred[yystate]) != 0) goto yyreduce; 825 if (yychar < 0) 826 { 827 #if YYBTYACC 828 do { 829 if (yylvp < yylve) 830 { 831 /* we're currently re-reading tokens */ 832 yylval = *yylvp++; 833 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 834 yylloc = *yylpp++; 835 #endif 836 yychar = *yylexp++; 837 break; 838 } 839 if (yyps->save) 840 { 841 /* in trial mode; save scanner results for future parse attempts */ 842 if (yylvp == yylvlim) 843 { /* Enlarge lexical value queue */ 844 int p = yylvp - yylvals; 845 int s = yylvlim - yylvals; 846 847 s += YYLVQUEUEGROWTH; 848 if ((yylexemes = (short *) realloc(yylexemes, s * sizeof(short))) == NULL) goto yyenomem; 849 if ((yylvals = (YYSTYPE *) realloc(yylvals, s * sizeof(YYSTYPE))) == NULL) goto yyenomem; 850 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 851 if ((yylpsns = (YYLTYPE *) realloc(yylpsns, s * sizeof(YYLTYPE))) == NULL) goto yyenomem; 852 #endif 853 yylvp = yylve = yylvals + p; 854 yylvlim = yylvals + s; 855 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 856 yylpp = yylpe = yylpsns + p; 857 yylplim = yylpsns + s; 858 #endif 859 yylexp = yylexemes + p; 860 } 861 *yylexp = (short) YYLEX; 862 *yylvp++ = yylval; 863 yylve++; 864 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 865 *yylpp++ = yylloc; 866 yylpe++; 867 #endif 868 yychar = *yylexp++; 869 break; 870 } 871 /* normal operation, no conflict encountered */ 872 #endif /* YYBTYACC */ 873 yychar = YYLEX; 874 #if YYBTYACC 875 } while (0); 876 #endif /* YYBTYACC */ 877 if (yychar < 0) yychar = YYEOF; 878 /* if ((yychar = YYLEX) < 0) yychar = YYEOF; */ 879 #if YYDEBUG 880 if (yydebug) 881 { 882 yys = yyname[YYTRANSLATE(yychar)]; 883 fprintf(stderr, "%s[%d]: state %d, reading token %d (%s)", 884 YYDEBUGSTR, yydepth, yystate, yychar, yys); 885 #ifdef YYSTYPE_TOSTRING 886 #if YYBTYACC 887 if (!yytrial) 888 #endif /* YYBTYACC */ 889 fprintf(stderr, " <%s>", YYSTYPE_TOSTRING(yychar, yylval)); 890 #endif 891 fputc('\n', stderr); 892 } 893 #endif 894 } 895 #if YYBTYACC 896 897 /* Do we have a conflict? */ 898 if (((yyn = yycindex[yystate]) != 0) && (yyn += yychar) >= 0 && 899 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar) 900 { 901 YYINT ctry; 902 903 if (yypath) 904 { 905 YYParseState *save; 906 #if YYDEBUG 907 if (yydebug) 908 fprintf(stderr, "%s[%d]: CONFLICT in state %d: following successful trial parse\n", 909 YYDEBUGSTR, yydepth, yystate); 910 #endif 911 /* Switch to the next conflict context */ 912 save = yypath; 913 yypath = save->save; 914 save->save = NULL; 915 ctry = save->ctry; 916 if (save->state != yystate) YYABORT; 917 yyFreeState(save); 918 919 } 920 else 921 { 922 923 /* Unresolved conflict - start/continue trial parse */ 924 YYParseState *save; 925 #if YYDEBUG 926 if (yydebug) 927 { 928 fprintf(stderr, "%s[%d]: CONFLICT in state %d. ", YYDEBUGSTR, yydepth, yystate); 929 if (yyps->save) 930 fputs("ALREADY in conflict, continuing trial parse.\n", stderr); 931 else 932 fputs("Starting trial parse.\n", stderr); 933 } 934 #endif 935 save = yyNewState((unsigned)(yystack.s_mark - yystack.s_base + 1)); 936 if (save == NULL) goto yyenomem; 937 save->save = yyps->save; 938 save->state = yystate; 939 save->errflag = yyerrflag; 940 save->yystack.s_mark = save->yystack.s_base + (yystack.s_mark - yystack.s_base); 941 memcpy (save->yystack.s_base, yystack.s_base, (yystack.s_mark - yystack.s_base + 1) * sizeof(short)); 942 save->yystack.l_mark = save->yystack.l_base + (yystack.l_mark - yystack.l_base); 943 memcpy (save->yystack.l_base, yystack.l_base, (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE)); 944 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 945 save->yystack.p_mark = save->yystack.p_base + (yystack.p_mark - yystack.p_base); 946 memcpy (save->yystack.p_base, yystack.p_base, (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE)); 947 #endif 948 ctry = yytable[yyn]; 949 if (yyctable[ctry] == -1) 950 { 951 #if YYDEBUG 952 if (yydebug && yychar >= YYEOF) 953 fprintf(stderr, "%s[%d]: backtracking 1 token\n", YYDEBUGSTR, yydepth); 954 #endif 955 ctry++; 956 } 957 save->ctry = ctry; 958 if (yyps->save == NULL) 959 { 960 /* If this is a first conflict in the stack, start saving lexemes */ 961 if (!yylexemes) 962 { 963 yylexemes = (short *) malloc((YYLVQUEUEGROWTH) * sizeof(short)); 964 if (yylexemes == NULL) goto yyenomem; 965 yylvals = (YYSTYPE *) malloc((YYLVQUEUEGROWTH) * sizeof(YYSTYPE)); 966 if (yylvals == NULL) goto yyenomem; 967 yylvlim = yylvals + YYLVQUEUEGROWTH; 968 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 969 yylpsns = (YYLTYPE *) malloc((YYLVQUEUEGROWTH) * sizeof(YYLTYPE)); 970 if (yylpsns == NULL) goto yyenomem; 971 yylplim = yylpsns + YYLVQUEUEGROWTH; 972 #endif 973 } 974 if (yylvp == yylve) 975 { 976 yylvp = yylve = yylvals; 977 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 978 yylpp = yylpe = yylpsns; 979 #endif 980 yylexp = yylexemes; 981 if (yychar >= YYEOF) 982 { 983 *yylve++ = yylval; 984 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 985 *yylpe++ = yylloc; 986 #endif 987 *yylexp = (short) yychar; 988 yychar = YYEMPTY; 989 } 990 } 991 } 992 if (yychar >= YYEOF) 993 { 994 yylvp--; 995 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 996 yylpp--; 997 #endif 998 yylexp--; 999 yychar = YYEMPTY; 1000 } 1001 save->lexeme = yylvp - yylvals; 1002 yyps->save = save; 1003 } 1004 if (yytable[yyn] == ctry) 1005 { 1006 #if YYDEBUG 1007 if (yydebug) 1008 fprintf(stderr, "%s[%d]: state %d, shifting to state %d\n", 1009 YYDEBUGSTR, yydepth, yystate, yyctable[ctry]); 1010 #endif 1011 if (yychar < 0) 1012 { 1013 yylvp++; 1014 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1015 yylpp++; 1016 #endif 1017 yylexp++; 1018 } 1019 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) 1020 goto yyoverflow; 1021 yystate = yyctable[ctry]; 1022 *++yystack.s_mark = (short) yystate; 1023 *++yystack.l_mark = yylval; 1024 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1025 *++yystack.p_mark = yylloc; 1026 #endif 1027 yychar = YYEMPTY; 1028 if (yyerrflag > 0) --yyerrflag; 1029 goto yyloop; 1030 } 1031 else 1032 { 1033 yyn = yyctable[ctry]; 1034 goto yyreduce; 1035 } 1036 } /* End of code dealing with conflicts */ 1037 #endif /* YYBTYACC */ 1038 if (((yyn = yysindex[yystate]) != 0) && (yyn += yychar) >= 0 && 1039 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar) 1040 { 1041 #if YYDEBUG 1042 if (yydebug) 1043 fprintf(stderr, "%s[%d]: state %d, shifting to state %d\n", 1044 YYDEBUGSTR, yydepth, yystate, yytable[yyn]); 1045 #endif 1046 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow; 1047 yystate = yytable[yyn]; 1048 *++yystack.s_mark = yytable[yyn]; 1049 *++yystack.l_mark = yylval; 1050 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1051 *++yystack.p_mark = yylloc; 1052 #endif 1053 yychar = YYEMPTY; 1054 if (yyerrflag > 0) --yyerrflag; 1055 goto yyloop; 1056 } 1057 if (((yyn = yyrindex[yystate]) != 0) && (yyn += yychar) >= 0 && 1058 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar) 1059 { 1060 yyn = yytable[yyn]; 1061 goto yyreduce; 1062 } 1063 if (yyerrflag != 0) goto yyinrecovery; 1064 #if YYBTYACC 1065 1066 yynewerrflag = 1; 1067 goto yyerrhandler; 1068 goto yyerrlab; 1069 1070 yyerrlab: 1071 yynewerrflag = 0; 1072 yyerrhandler: 1073 while (yyps->save) 1074 { 1075 int ctry; 1076 YYParseState *save = yyps->save; 1077 #if YYDEBUG 1078 if (yydebug) 1079 fprintf(stderr, "%s[%d]: ERROR in state %d, CONFLICT BACKTRACKING to state %d, %d tokens\n", 1080 YYDEBUGSTR, yydepth, yystate, yyps->save->state, 1081 (int)(yylvp - yylvals - yyps->save->lexeme)); 1082 #endif 1083 /* Memorize most forward-looking error state in case it's really an error. */ 1084 if (yyerrctx == NULL || yyerrctx->lexeme < yylvp - yylvals) 1085 { 1086 /* Free old saved error context state */ 1087 if (yyerrctx) yyFreeState(yyerrctx); 1088 /* Create and fill out new saved error context state */ 1089 yyerrctx = yyNewState((unsigned)(yystack.s_mark - yystack.s_base + 1)); 1090 if (yyerrctx == NULL) goto yyenomem; 1091 yyerrctx->save = yyps->save; 1092 yyerrctx->state = yystate; 1093 yyerrctx->errflag = yyerrflag; 1094 yyerrctx->yystack.s_mark = yyerrctx->yystack.s_base + (yystack.s_mark - yystack.s_base); 1095 memcpy (yyerrctx->yystack.s_base, yystack.s_base, (yystack.s_mark - yystack.s_base + 1) * sizeof(short)); 1096 yyerrctx->yystack.l_mark = yyerrctx->yystack.l_base + (yystack.l_mark - yystack.l_base); 1097 memcpy (yyerrctx->yystack.l_base, yystack.l_base, (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE)); 1098 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1099 yyerrctx->yystack.p_mark = yyerrctx->yystack.p_base + (yystack.p_mark - yystack.p_base); 1100 memcpy (yyerrctx->yystack.p_base, yystack.p_base, (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE)); 1101 #endif 1102 yyerrctx->lexeme = yylvp - yylvals; 1103 } 1104 yylvp = yylvals + save->lexeme; 1105 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1106 yylpp = yylpsns + save->lexeme; 1107 #endif 1108 yylexp = yylexemes + save->lexeme; 1109 yychar = YYEMPTY; 1110 yystack.s_mark = yystack.s_base + (save->yystack.s_mark - save->yystack.s_base); 1111 memcpy (yystack.s_base, save->yystack.s_base, (yystack.s_mark - yystack.s_base + 1) * sizeof(short)); 1112 yystack.l_mark = yystack.l_base + (save->yystack.l_mark - save->yystack.l_base); 1113 memcpy (yystack.l_base, save->yystack.l_base, (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE)); 1114 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1115 yystack.p_mark = yystack.p_base + (save->yystack.p_mark - save->yystack.p_base); 1116 memcpy (yystack.p_base, save->yystack.p_base, (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE)); 1117 #endif 1118 ctry = ++save->ctry; 1119 yystate = save->state; 1120 /* We tried shift, try reduce now */ 1121 if ((yyn = yyctable[ctry]) >= 0) goto yyreduce; 1122 yyps->save = save->save; 1123 save->save = NULL; 1124 yyFreeState(save); 1125 1126 /* Nothing left on the stack -- error */ 1127 if (!yyps->save) 1128 { 1129 #if YYDEBUG 1130 if (yydebug) 1131 fprintf(stderr, "%sdebug[%d,trial]: trial parse FAILED, entering ERROR mode\n", 1132 YYPREFIX, yydepth); 1133 #endif 1134 /* Restore state as it was in the most forward-advanced error */ 1135 yylvp = yylvals + yyerrctx->lexeme; 1136 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1137 yylpp = yylpsns + yyerrctx->lexeme; 1138 #endif 1139 yylexp = yylexemes + yyerrctx->lexeme; 1140 yychar = yylexp[-1]; 1141 yylval = yylvp[-1]; 1142 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1143 yylloc = yylpp[-1]; 1144 #endif 1145 yystack.s_mark = yystack.s_base + (yyerrctx->yystack.s_mark - yyerrctx->yystack.s_base); 1146 memcpy (yystack.s_base, yyerrctx->yystack.s_base, (yystack.s_mark - yystack.s_base + 1) * sizeof(short)); 1147 yystack.l_mark = yystack.l_base + (yyerrctx->yystack.l_mark - yyerrctx->yystack.l_base); 1148 memcpy (yystack.l_base, yyerrctx->yystack.l_base, (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE)); 1149 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1150 yystack.p_mark = yystack.p_base + (yyerrctx->yystack.p_mark - yyerrctx->yystack.p_base); 1151 memcpy (yystack.p_base, yyerrctx->yystack.p_base, (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE)); 1152 #endif 1153 yystate = yyerrctx->state; 1154 yyFreeState(yyerrctx); 1155 yyerrctx = NULL; 1156 } 1157 yynewerrflag = 1; 1158 } 1159 if (yynewerrflag == 0) goto yyinrecovery; 1160 #endif /* YYBTYACC */ 1161 1162 YYERROR_CALL("syntax error"); 1163 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1164 yyerror_loc_range[0] = yylloc; /* lookahead position is error start position */ 1165 #endif 1166 1167 #if !YYBTYACC 1168 goto yyerrlab; 1169 yyerrlab: 1170 #endif 1171 ++yynerrs; 1172 1173 yyinrecovery: 1174 if (yyerrflag < 3) 1175 { 1176 yyerrflag = 3; 1177 for (;;) 1178 { 1179 if (((yyn = yysindex[*yystack.s_mark]) != 0) && (yyn += YYERRCODE) >= 0 && 1180 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) YYERRCODE) 1181 { 1182 #if YYDEBUG 1183 if (yydebug) 1184 fprintf(stderr, "%s[%d]: state %d, error recovery shifting to state %d\n", 1185 YYDEBUGSTR, yydepth, *yystack.s_mark, yytable[yyn]); 1186 #endif 1187 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow; 1188 yystate = yytable[yyn]; 1189 *++yystack.s_mark = yytable[yyn]; 1190 *++yystack.l_mark = yylval; 1191 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1192 /* lookahead position is error end position */ 1193 yyerror_loc_range[1] = yylloc; 1194 YYLLOC_DEFAULT(yyloc, yyerror_loc_range, 2); /* position of error span */ 1195 *++yystack.p_mark = yyloc; 1196 #endif 1197 goto yyloop; 1198 } 1199 else 1200 { 1201 #if YYDEBUG 1202 if (yydebug) 1203 fprintf(stderr, "%s[%d]: error recovery discarding state %d\n", 1204 YYDEBUGSTR, yydepth, *yystack.s_mark); 1205 #endif 1206 if (yystack.s_mark <= yystack.s_base) goto yyabort; 1207 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1208 /* the current TOS position is the error start position */ 1209 yyerror_loc_range[0] = *yystack.p_mark; 1210 #endif 1211 #if defined(YYDESTRUCT_CALL) 1212 #if YYBTYACC 1213 if (!yytrial) 1214 #endif /* YYBTYACC */ 1215 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1216 YYDESTRUCT_CALL("error: discarding state", 1217 yystos[*yystack.s_mark], yystack.l_mark, yystack.p_mark); 1218 #else 1219 YYDESTRUCT_CALL("error: discarding state", 1220 yystos[*yystack.s_mark], yystack.l_mark); 1221 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */ 1222 #endif /* defined(YYDESTRUCT_CALL) */ 1223 --yystack.s_mark; 1224 --yystack.l_mark; 1225 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1226 --yystack.p_mark; 1227 #endif 1228 } 1229 } 1230 } 1231 else 1232 { 1233 if (yychar == YYEOF) goto yyabort; 1234 #if YYDEBUG 1235 if (yydebug) 1236 { 1237 yys = yyname[YYTRANSLATE(yychar)]; 1238 fprintf(stderr, "%s[%d]: state %d, error recovery discarding token %d (%s)\n", 1239 YYDEBUGSTR, yydepth, yystate, yychar, yys); 1240 } 1241 #endif 1242 #if defined(YYDESTRUCT_CALL) 1243 #if YYBTYACC 1244 if (!yytrial) 1245 #endif /* YYBTYACC */ 1246 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1247 YYDESTRUCT_CALL("error: discarding token", yychar, &yylval, &yylloc); 1248 #else 1249 YYDESTRUCT_CALL("error: discarding token", yychar, &yylval); 1250 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */ 1251 #endif /* defined(YYDESTRUCT_CALL) */ 1252 yychar = YYEMPTY; 1253 goto yyloop; 1254 } 1255 1256 yyreduce: 1257 yym = yylen[yyn]; 1258 #if YYDEBUG 1259 if (yydebug) 1260 { 1261 fprintf(stderr, "%s[%d]: state %d, reducing by rule %d (%s)", 1262 YYDEBUGSTR, yydepth, yystate, yyn, yyrule[yyn]); 1263 #ifdef YYSTYPE_TOSTRING 1264 #if YYBTYACC 1265 if (!yytrial) 1266 #endif /* YYBTYACC */ 1267 if (yym > 0) 1268 { 1269 int i; 1270 fputc('<', stderr); 1271 for (i = yym; i > 0; i--) 1272 { 1273 if (i != yym) fputs(", ", stderr); 1274 fputs(YYSTYPE_TOSTRING(yystos[yystack.s_mark[1-i]], 1275 yystack.l_mark[1-i]), stderr); 1276 } 1277 fputc('>', stderr); 1278 } 1279 #endif 1280 fputc('\n', stderr); 1281 } 1282 #endif 1283 if (yym > 0) 1284 yyval = yystack.l_mark[1-yym]; 1285 else 1286 memset(&yyval, 0, sizeof yyval); 1287 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1288 1289 /* Perform position reduction */ 1290 memset(&yyloc, 0, sizeof(yyloc)); 1291 #if YYBTYACC 1292 if (!yytrial) 1293 #endif /* YYBTYACC */ 1294 { 1295 YYLLOC_DEFAULT(yyloc, &yystack.p_mark[1-yym], yym); 1296 /* just in case YYERROR is invoked within the action, save 1297 the start of the rhs as the error start position */ 1298 yyerror_loc_range[0] = yystack.p_mark[1-yym]; 1299 } 1300 #endif 1301 1302 switch (yyn) 1303 { 1304 case 2: 1305 #line 51 "btyacc_calc1.y" 1306 {YYVALID;} 1307 break; 1308 case 3: 1309 #line 52 "btyacc_calc1.y" 1310 {YYVALID;} if (!yytrial) 1311 #line 53 "btyacc_calc1.y" 1312 { 1313 yyerrok; 1314 } 1315 break; 1316 case 4: 1317 if (!yytrial) 1318 #line 59 "btyacc_calc1.y" 1319 { 1320 (void) printf("%15.8f\n", yystack.l_mark[0].dval); 1321 } 1322 break; 1323 case 5: 1324 if (!yytrial) 1325 #line 63 "btyacc_calc1.y" 1326 { 1327 (void) printf("(%15.8f, %15.8f)\n", yystack.l_mark[0].vval.lo, yystack.l_mark[0].vval.hi); 1328 } 1329 break; 1330 case 6: 1331 if (!yytrial) 1332 #line 67 "btyacc_calc1.y" 1333 { 1334 dreg[yystack.l_mark[-2].ival] = yystack.l_mark[0].dval; 1335 } 1336 break; 1337 case 7: 1338 if (!yytrial) 1339 #line 71 "btyacc_calc1.y" 1340 { 1341 vreg[yystack.l_mark[-2].ival] = yystack.l_mark[0].vval; 1342 } 1343 break; 1344 case 9: 1345 if (!yytrial) 1346 #line 78 "btyacc_calc1.y" 1347 { 1348 yyval.dval = dreg[yystack.l_mark[0].ival]; 1349 } 1350 break; 1351 case 10: 1352 if (!yytrial) 1353 #line 82 "btyacc_calc1.y" 1354 { 1355 yyval.dval = yystack.l_mark[-2].dval + yystack.l_mark[0].dval; 1356 } 1357 break; 1358 case 11: 1359 if (!yytrial) 1360 #line 86 "btyacc_calc1.y" 1361 { 1362 yyval.dval = yystack.l_mark[-2].dval - yystack.l_mark[0].dval; 1363 } 1364 break; 1365 case 12: 1366 if (!yytrial) 1367 #line 90 "btyacc_calc1.y" 1368 { 1369 yyval.dval = yystack.l_mark[-2].dval * yystack.l_mark[0].dval; 1370 } 1371 break; 1372 case 13: 1373 if (!yytrial) 1374 #line 94 "btyacc_calc1.y" 1375 { 1376 yyval.dval = yystack.l_mark[-2].dval / yystack.l_mark[0].dval; 1377 } 1378 break; 1379 case 14: 1380 if (!yytrial) 1381 #line 98 "btyacc_calc1.y" 1382 { 1383 yyval.dval = -yystack.l_mark[0].dval; 1384 } 1385 break; 1386 case 15: 1387 if (!yytrial) 1388 #line 102 "btyacc_calc1.y" 1389 { 1390 yyval.dval = yystack.l_mark[-1].dval; 1391 } 1392 break; 1393 case 16: 1394 if (!yytrial) 1395 #line 108 "btyacc_calc1.y" 1396 { 1397 yyval.vval.hi = yyval.vval.lo = yystack.l_mark[0].dval; 1398 } 1399 break; 1400 case 17: 1401 if (!yytrial) 1402 #line 112 "btyacc_calc1.y" 1403 { 1404 yyval.vval.lo = yystack.l_mark[-3].dval; 1405 yyval.vval.hi = yystack.l_mark[-1].dval; 1406 if ( yyval.vval.lo > yyval.vval.hi ) 1407 { 1408 (void) printf("interval out of order\n"); 1409 YYERROR; 1410 } 1411 } 1412 break; 1413 case 18: 1414 if (!yytrial) 1415 #line 122 "btyacc_calc1.y" 1416 { 1417 yyval.vval = vreg[yystack.l_mark[0].ival]; 1418 } 1419 break; 1420 case 19: 1421 if (!yytrial) 1422 #line 126 "btyacc_calc1.y" 1423 { 1424 yyval.vval.hi = yystack.l_mark[-2].vval.hi + yystack.l_mark[0].vval.hi; 1425 yyval.vval.lo = yystack.l_mark[-2].vval.lo + yystack.l_mark[0].vval.lo; 1426 } 1427 break; 1428 case 20: 1429 if (!yytrial) 1430 #line 131 "btyacc_calc1.y" 1431 { 1432 yyval.vval.hi = yystack.l_mark[-2].dval + yystack.l_mark[0].vval.hi; 1433 yyval.vval.lo = yystack.l_mark[-2].dval + yystack.l_mark[0].vval.lo; 1434 } 1435 break; 1436 case 21: 1437 if (!yytrial) 1438 #line 136 "btyacc_calc1.y" 1439 { 1440 yyval.vval.hi = yystack.l_mark[-2].vval.hi - yystack.l_mark[0].vval.lo; 1441 yyval.vval.lo = yystack.l_mark[-2].vval.lo - yystack.l_mark[0].vval.hi; 1442 } 1443 break; 1444 case 22: 1445 if (!yytrial) 1446 #line 141 "btyacc_calc1.y" 1447 { 1448 yyval.vval.hi = yystack.l_mark[-2].dval - yystack.l_mark[0].vval.lo; 1449 yyval.vval.lo = yystack.l_mark[-2].dval - yystack.l_mark[0].vval.hi; 1450 } 1451 break; 1452 case 23: 1453 if (!yytrial) 1454 #line 146 "btyacc_calc1.y" 1455 { 1456 yyval.vval = vmul( yystack.l_mark[-2].vval.lo, yystack.l_mark[-2].vval.hi, yystack.l_mark[0].vval ); 1457 } 1458 break; 1459 case 24: 1460 if (!yytrial) 1461 #line 150 "btyacc_calc1.y" 1462 { 1463 yyval.vval = vmul (yystack.l_mark[-2].dval, yystack.l_mark[-2].dval, yystack.l_mark[0].vval ); 1464 } 1465 break; 1466 case 25: 1467 if (!yytrial) 1468 #line 154 "btyacc_calc1.y" 1469 { 1470 if (dcheck(yystack.l_mark[0].vval)) YYERROR; 1471 yyval.vval = vdiv ( yystack.l_mark[-2].vval.lo, yystack.l_mark[-2].vval.hi, yystack.l_mark[0].vval ); 1472 } 1473 break; 1474 case 26: 1475 if (!yytrial) 1476 #line 159 "btyacc_calc1.y" 1477 { 1478 if (dcheck ( yystack.l_mark[0].vval )) YYERROR; 1479 yyval.vval = vdiv (yystack.l_mark[-2].dval, yystack.l_mark[-2].dval, yystack.l_mark[0].vval ); 1480 } 1481 break; 1482 case 27: 1483 if (!yytrial) 1484 #line 164 "btyacc_calc1.y" 1485 { 1486 yyval.vval.hi = -yystack.l_mark[0].vval.lo; 1487 yyval.vval.lo = -yystack.l_mark[0].vval.hi; 1488 } 1489 break; 1490 case 28: 1491 if (!yytrial) 1492 #line 169 "btyacc_calc1.y" 1493 { 1494 yyval.vval = yystack.l_mark[-1].vval; 1495 } 1496 break; 1497 #line 1498 "btyacc_calc1.tab.c" 1498 default: 1499 break; 1500 } 1501 yystack.s_mark -= yym; 1502 yystate = *yystack.s_mark; 1503 yystack.l_mark -= yym; 1504 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1505 yystack.p_mark -= yym; 1506 #endif 1507 yym = yylhs[yyn]; 1508 if (yystate == 0 && yym == 0) 1509 { 1510 #if YYDEBUG 1511 if (yydebug) 1512 { 1513 fprintf(stderr, "%s[%d]: after reduction, ", YYDEBUGSTR, yydepth); 1514 #ifdef YYSTYPE_TOSTRING 1515 #if YYBTYACC 1516 if (!yytrial) 1517 #endif /* YYBTYACC */ 1518 fprintf(stderr, "result is <%s>, ", YYSTYPE_TOSTRING(yystos[YYFINAL], yyval)); 1519 #endif 1520 fprintf(stderr, "shifting from state 0 to final state %d\n", YYFINAL); 1521 } 1522 #endif 1523 yystate = YYFINAL; 1524 *++yystack.s_mark = YYFINAL; 1525 *++yystack.l_mark = yyval; 1526 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1527 *++yystack.p_mark = yyloc; 1528 #endif 1529 if (yychar < 0) 1530 { 1531 #if YYBTYACC 1532 do { 1533 if (yylvp < yylve) 1534 { 1535 /* we're currently re-reading tokens */ 1536 yylval = *yylvp++; 1537 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1538 yylloc = *yylpp++; 1539 #endif 1540 yychar = *yylexp++; 1541 break; 1542 } 1543 if (yyps->save) 1544 { 1545 /* in trial mode; save scanner results for future parse attempts */ 1546 if (yylvp == yylvlim) 1547 { /* Enlarge lexical value queue */ 1548 int p = yylvp - yylvals; 1549 int s = yylvlim - yylvals; 1550 1551 s += YYLVQUEUEGROWTH; 1552 if ((yylexemes = (short *) realloc(yylexemes, s * sizeof(short))) == NULL) 1553 goto yyenomem; 1554 if ((yylvals = (YYSTYPE *) realloc(yylvals, s * sizeof(YYSTYPE))) == NULL) 1555 goto yyenomem; 1556 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1557 if ((yylpsns = (YYLTYPE *) realloc(yylpsns, s * sizeof(YYLTYPE))) == NULL) 1558 goto yyenomem; 1559 #endif 1560 yylvp = yylve = yylvals + p; 1561 yylvlim = yylvals + s; 1562 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1563 yylpp = yylpe = yylpsns + p; 1564 yylplim = yylpsns + s; 1565 #endif 1566 yylexp = yylexemes + p; 1567 } 1568 *yylexp = (short) YYLEX; 1569 *yylvp++ = yylval; 1570 yylve++; 1571 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1572 *yylpp++ = yylloc; 1573 yylpe++; 1574 #endif 1575 yychar = *yylexp++; 1576 break; 1577 } 1578 /* normal operation, no conflict encountered */ 1579 #endif /* YYBTYACC */ 1580 yychar = YYLEX; 1581 #if YYBTYACC 1582 } while (0); 1583 #endif /* YYBTYACC */ 1584 if (yychar < 0) yychar = YYEOF; 1585 /* if ((yychar = YYLEX) < 0) yychar = YYEOF; */ 1586 #if YYDEBUG 1587 if (yydebug) 1588 { 1589 yys = yyname[YYTRANSLATE(yychar)]; 1590 fprintf(stderr, "%s[%d]: state %d, reading %d (%s)\n", 1591 YYDEBUGSTR, yydepth, YYFINAL, yychar, yys); 1592 } 1593 #endif 1594 } 1595 if (yychar == YYEOF) goto yyaccept; 1596 goto yyloop; 1597 } 1598 if (((yyn = yygindex[yym]) != 0) && (yyn += yystate) >= 0 && 1599 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yystate) 1600 yystate = yytable[yyn]; 1601 else 1602 yystate = yydgoto[yym]; 1603 #if YYDEBUG 1604 if (yydebug) 1605 { 1606 fprintf(stderr, "%s[%d]: after reduction, ", YYDEBUGSTR, yydepth); 1607 #ifdef YYSTYPE_TOSTRING 1608 #if YYBTYACC 1609 if (!yytrial) 1610 #endif /* YYBTYACC */ 1611 fprintf(stderr, "result is <%s>, ", YYSTYPE_TOSTRING(yystos[yystate], yyval)); 1612 #endif 1613 fprintf(stderr, "shifting from state %d to state %d\n", *yystack.s_mark, yystate); 1614 } 1615 #endif 1616 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow; 1617 *++yystack.s_mark = (short) yystate; 1618 *++yystack.l_mark = yyval; 1619 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1620 *++yystack.p_mark = yyloc; 1621 #endif 1622 goto yyloop; 1623 #if YYBTYACC 1624 1625 /* Reduction declares that this path is valid. Set yypath and do a full parse */ 1626 yyvalid: 1627 if (yypath) YYABORT; 1628 while (yyps->save) 1629 { 1630 YYParseState *save = yyps->save; 1631 yyps->save = save->save; 1632 save->save = yypath; 1633 yypath = save; 1634 } 1635 #if YYDEBUG 1636 if (yydebug) 1637 fprintf(stderr, "%s[%d]: state %d, CONFLICT trial successful, backtracking to state %d, %d tokens\n", 1638 YYDEBUGSTR, yydepth, yystate, yypath->state, (int)(yylvp - yylvals - yypath->lexeme)); 1639 #endif 1640 if (yyerrctx) 1641 { 1642 yyFreeState(yyerrctx); 1643 yyerrctx = NULL; 1644 } 1645 yylvp = yylvals + yypath->lexeme; 1646 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1647 yylpp = yylpsns + yypath->lexeme; 1648 #endif 1649 yylexp = yylexemes + yypath->lexeme; 1650 yychar = YYEMPTY; 1651 yystack.s_mark = yystack.s_base + (yypath->yystack.s_mark - yypath->yystack.s_base); 1652 memcpy (yystack.s_base, yypath->yystack.s_base, (yystack.s_mark - yystack.s_base + 1) * sizeof(short)); 1653 yystack.l_mark = yystack.l_base + (yypath->yystack.l_mark - yypath->yystack.l_base); 1654 memcpy (yystack.l_base, yypath->yystack.l_base, (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE)); 1655 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1656 yystack.p_mark = yystack.p_base + (yypath->yystack.p_mark - yypath->yystack.p_base); 1657 memcpy (yystack.p_base, yypath->yystack.p_base, (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE)); 1658 #endif 1659 yystate = yypath->state; 1660 goto yyloop; 1661 #endif /* YYBTYACC */ 1662 1663 yyoverflow: 1664 YYERROR_CALL("yacc stack overflow"); 1665 #if YYBTYACC 1666 goto yyabort_nomem; 1667 yyenomem: 1668 YYERROR_CALL("memory exhausted"); 1669 yyabort_nomem: 1670 #endif /* YYBTYACC */ 1671 yyresult = 2; 1672 goto yyreturn; 1673 1674 yyabort: 1675 yyresult = 1; 1676 goto yyreturn; 1677 1678 yyaccept: 1679 #if YYBTYACC 1680 if (yyps->save) goto yyvalid; 1681 #endif /* YYBTYACC */ 1682 yyresult = 0; 1683 1684 yyreturn: 1685 #if defined(YYDESTRUCT_CALL) 1686 if (yychar != YYEOF && yychar != YYEMPTY) 1687 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1688 YYDESTRUCT_CALL("cleanup: discarding token", yychar, &yylval, &yylloc); 1689 #else 1690 YYDESTRUCT_CALL("cleanup: discarding token", yychar, &yylval); 1691 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */ 1692 1693 { 1694 YYSTYPE *pv; 1695 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1696 YYLTYPE *pp; 1697 1698 for (pv = yystack.l_base, pp = yystack.p_base; pv <= yystack.l_mark; ++pv, ++pp) 1699 YYDESTRUCT_CALL("cleanup: discarding state", 1700 yystos[*(yystack.s_base + (pv - yystack.l_base))], pv, pp); 1701 #else 1702 for (pv = yystack.l_base; pv <= yystack.l_mark; ++pv) 1703 YYDESTRUCT_CALL("cleanup: discarding state", 1704 yystos[*(yystack.s_base + (pv - yystack.l_base))], pv); 1705 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */ 1706 } 1707 #endif /* defined(YYDESTRUCT_CALL) */ 1708 1709 #if YYBTYACC 1710 if (yyerrctx) 1711 { 1712 yyFreeState(yyerrctx); 1713 yyerrctx = NULL; 1714 } 1715 while (yyps) 1716 { 1717 YYParseState *save = yyps; 1718 yyps = save->save; 1719 save->save = NULL; 1720 yyFreeState(save); 1721 } 1722 while (yypath) 1723 { 1724 YYParseState *save = yypath; 1725 yypath = save->save; 1726 save->save = NULL; 1727 yyFreeState(save); 1728 } 1729 #endif /* YYBTYACC */ 1730 yyfreestack(&yystack); 1731 return (yyresult); 1732 } 1733