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 17 #ifndef yyparse 18 #define yyparse calc1_parse 19 #endif /* yyparse */ 20 21 #ifndef yylex 22 #define yylex calc1_lex 23 #endif /* yylex */ 24 25 #ifndef yyerror 26 #define yyerror calc1_error 27 #endif /* yyerror */ 28 29 #ifndef yychar 30 #define yychar calc1_char 31 #endif /* yychar */ 32 33 #ifndef yyval 34 #define yyval calc1_val 35 #endif /* yyval */ 36 37 #ifndef yylval 38 #define yylval calc1_lval 39 #endif /* yylval */ 40 41 #ifndef yydebug 42 #define yydebug calc1_debug 43 #endif /* yydebug */ 44 45 #ifndef yynerrs 46 #define yynerrs calc1_nerrs 47 #endif /* yynerrs */ 48 49 #ifndef yyerrflag 50 #define yyerrflag calc1_errflag 51 #endif /* yyerrflag */ 52 53 #ifndef yylhs 54 #define yylhs calc1_lhs 55 #endif /* yylhs */ 56 57 #ifndef yylen 58 #define yylen calc1_len 59 #endif /* yylen */ 60 61 #ifndef yydefred 62 #define yydefred calc1_defred 63 #endif /* yydefred */ 64 65 #ifndef yydgoto 66 #define yydgoto calc1_dgoto 67 #endif /* yydgoto */ 68 69 #ifndef yysindex 70 #define yysindex calc1_sindex 71 #endif /* yysindex */ 72 73 #ifndef yyrindex 74 #define yyrindex calc1_rindex 75 #endif /* yyrindex */ 76 77 #ifndef yygindex 78 #define yygindex calc1_gindex 79 #endif /* yygindex */ 80 81 #ifndef yytable 82 #define yytable calc1_table 83 #endif /* yytable */ 84 85 #ifndef yycheck 86 #define yycheck calc1_check 87 #endif /* yycheck */ 88 89 #ifndef yyname 90 #define yyname calc1_name 91 #endif /* yyname */ 92 93 #ifndef yyrule 94 #define yyrule calc1_rule 95 #endif /* yyrule */ 96 #define YYPREFIX "calc1_" 97 98 #define YYPURE 0 99 100 #line 2 "calc1.y" 101 102 /* http://dinosaur.compilertools.net/yacc/index.html */ 103 104 #include <stdlib.h> 105 #include <stdio.h> 106 #include <ctype.h> 107 #include <math.h> 108 109 typedef struct interval 110 { 111 double lo, hi; 112 } 113 INTERVAL; 114 115 INTERVAL vmul(double, double, INTERVAL); 116 INTERVAL vdiv(double, double, INTERVAL); 117 118 extern int yylex(void); 119 static void yyerror(const char *s); 120 121 int dcheck(INTERVAL); 122 123 double dreg[26]; 124 INTERVAL vreg[26]; 125 126 #ifdef YYSTYPE 127 #undef YYSTYPE_IS_DECLARED 128 #define YYSTYPE_IS_DECLARED 1 129 #endif 130 #ifndef YYSTYPE_IS_DECLARED 131 #define YYSTYPE_IS_DECLARED 1 132 #line 31 "calc1.y" 133 typedef union 134 { 135 int ival; 136 double dval; 137 INTERVAL vval; 138 } YYSTYPE; 139 #endif /* !YYSTYPE_IS_DECLARED */ 140 #line 141 "calc1.tab.c" 141 142 /* compatibility with bison */ 143 #ifdef YYPARSE_PARAM 144 /* compatibility with FreeBSD */ 145 # ifdef YYPARSE_PARAM_TYPE 146 # define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM) 147 # else 148 # define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM) 149 # endif 150 #else 151 # define YYPARSE_DECL() yyparse(void) 152 #endif 153 154 /* Parameters sent to lex. */ 155 #ifdef YYLEX_PARAM 156 # define YYLEX_DECL() yylex(void *YYLEX_PARAM) 157 # define YYLEX yylex(YYLEX_PARAM) 158 #else 159 # define YYLEX_DECL() yylex(void) 160 # define YYLEX yylex() 161 #endif 162 163 /* Parameters sent to yyerror. */ 164 #ifndef YYERROR_DECL 165 #define YYERROR_DECL() yyerror(const char *s) 166 #endif 167 #ifndef YYERROR_CALL 168 #define YYERROR_CALL(msg) yyerror(msg) 169 #endif 170 171 extern int YYPARSE_DECL(); 172 173 #define DREG 257 174 #define VREG 258 175 #define CONST 259 176 #define UMINUS 260 177 #define YYERRCODE 256 178 typedef int YYINT; 179 static const YYINT calc1_lhs[] = { -1, 180 3, 3, 0, 0, 0, 0, 0, 1, 1, 1, 181 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 182 2, 2, 2, 2, 2, 2, 2, 2, 183 }; 184 static const YYINT calc1_len[] = { 2, 185 0, 2, 2, 2, 4, 4, 2, 1, 1, 3, 186 3, 3, 3, 2, 3, 1, 5, 1, 3, 3, 187 3, 3, 3, 3, 3, 3, 2, 3, 188 }; 189 static const YYINT calc1_defred[] = { 0, 190 0, 0, 0, 8, 0, 0, 0, 0, 0, 7, 191 0, 0, 9, 18, 14, 27, 0, 0, 0, 0, 192 0, 0, 3, 0, 0, 0, 0, 4, 0, 0, 193 0, 0, 0, 15, 0, 28, 0, 0, 0, 0, 194 12, 24, 13, 26, 0, 0, 23, 25, 14, 0, 195 0, 0, 0, 0, 5, 6, 0, 0, 0, 12, 196 13, 17, 197 }; 198 static const YYINT calc1_dgoto[] = { 7, 199 32, 9, 0, 200 }; 201 static const YYINT calc1_sindex[] = { -40, 202 -8, -48, -47, 0, -37, -37, 0, 2, 17, 0, 203 -34, -37, 0, 0, 0, 0, -25, 90, -37, -37, 204 -37, -37, 0, -37, -37, -37, -37, 0, -34, -34, 205 25, 125, 31, 0, -34, 0, -11, 37, -11, 37, 206 0, 0, 0, 0, 37, 37, 0, 0, 0, 111, 207 -34, -34, -34, -34, 0, 0, 118, 69, 69, 0, 208 0, 0, 209 }; 210 static const YYINT calc1_rindex[] = { 0, 211 0, 38, 44, 0, 0, 0, 0, 0, 0, 0, 212 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 213 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 214 0, -9, 0, 0, 0, 0, 51, -3, 56, 61, 215 0, 0, 0, 0, 67, 72, 0, 0, 0, 0, 216 0, 0, 0, 0, 0, 0, 0, 78, 83, 0, 217 0, 0, 218 }; 219 static const YYINT calc1_gindex[] = { 0, 220 4, 124, 0, 221 }; 222 #define YYTABLESIZE 225 223 static const YYINT calc1_table[] = { 6, 224 16, 10, 6, 8, 5, 30, 20, 5, 15, 17, 225 29, 23, 11, 12, 31, 34, 21, 19, 35, 20, 226 0, 22, 37, 39, 41, 43, 28, 0, 0, 0, 227 21, 16, 49, 50, 55, 22, 0, 20, 57, 20, 228 56, 20, 0, 21, 19, 0, 20, 9, 22, 0, 229 0, 0, 0, 18, 58, 59, 60, 61, 26, 24, 230 10, 25, 0, 27, 0, 11, 53, 51, 0, 52, 231 22, 54, 26, 24, 0, 25, 19, 27, 26, 9, 232 9, 21, 9, 27, 9, 18, 18, 10, 18, 0, 233 18, 10, 11, 10, 10, 10, 11, 0, 11, 11, 234 11, 22, 0, 22, 0, 22, 0, 19, 0, 19, 235 53, 19, 21, 0, 21, 54, 21, 0, 10, 0, 236 10, 0, 10, 11, 0, 11, 0, 11, 16, 18, 237 36, 26, 24, 0, 25, 33, 27, 0, 0, 0, 238 0, 0, 38, 40, 42, 44, 0, 45, 46, 47, 239 48, 34, 53, 51, 0, 52, 0, 54, 62, 53, 240 51, 0, 52, 0, 54, 0, 21, 19, 0, 20, 241 0, 22, 0, 0, 0, 0, 0, 0, 0, 0, 242 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 243 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 244 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 245 0, 0, 0, 0, 0, 1, 2, 3, 4, 13, 246 14, 4, 13, 0, 4, 247 }; 248 static const YYINT calc1_check[] = { 40, 249 10, 10, 40, 0, 45, 40, 10, 45, 5, 6, 250 45, 10, 61, 61, 11, 41, 42, 43, 44, 45, 251 -1, 47, 19, 20, 21, 22, 10, -1, -1, -1, 252 42, 41, 29, 30, 10, 47, -1, 41, 35, 43, 253 10, 45, -1, 42, 43, -1, 45, 10, 47, -1, 254 -1, -1, -1, 10, 51, 52, 53, 54, 42, 43, 255 10, 45, -1, 47, -1, 10, 42, 43, -1, 45, 256 10, 47, 42, 43, -1, 45, 10, 47, 42, 42, 257 43, 10, 45, 47, 47, 42, 43, 10, 45, -1, 258 47, 41, 10, 43, 44, 45, 41, -1, 43, 44, 259 45, 41, -1, 43, -1, 45, -1, 41, -1, 43, 260 42, 45, 41, -1, 43, 47, 45, -1, 41, -1, 261 43, -1, 45, 41, -1, 43, -1, 45, 5, 6, 262 41, 42, 43, -1, 45, 12, 47, -1, -1, -1, 263 -1, -1, 19, 20, 21, 22, -1, 24, 25, 26, 264 27, 41, 42, 43, -1, 45, -1, 47, 41, 42, 265 43, -1, 45, -1, 47, -1, 42, 43, -1, 45, 266 -1, 47, -1, -1, -1, -1, -1, -1, -1, -1, 267 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 268 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 269 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 270 -1, -1, -1, -1, -1, 256, 257, 258, 259, 257, 271 258, 259, 257, -1, 259, 272 }; 273 #define YYFINAL 7 274 #ifndef YYDEBUG 275 #define YYDEBUG 0 276 #endif 277 #define YYMAXTOKEN 260 278 #define YYUNDFTOKEN 266 279 #define YYTRANSLATE(a) ((a) > YYMAXTOKEN ? YYUNDFTOKEN : (a)) 280 #if YYDEBUG 281 static const char *const calc1_name[] = { 282 283 "end-of-file",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, 284 0,0,0,0,0,0,0,0,0,"'('","')'","'*'","'+'","','","'-'",0,"'/'",0,0,0,0,0,0,0,0,0, 285 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, 286 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, 287 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, 288 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, 289 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, 290 0,0,"DREG","VREG","CONST","UMINUS",0,0,0,0,0,"illegal-symbol", 291 }; 292 static const char *const calc1_rule[] = { 293 "$accept : line", 294 "lines :", 295 "lines : lines line", 296 "line : dexp '\\n'", 297 "line : vexp '\\n'", 298 "line : DREG '=' dexp '\\n'", 299 "line : VREG '=' vexp '\\n'", 300 "line : error '\\n'", 301 "dexp : CONST", 302 "dexp : DREG", 303 "dexp : dexp '+' dexp", 304 "dexp : dexp '-' dexp", 305 "dexp : dexp '*' dexp", 306 "dexp : dexp '/' dexp", 307 "dexp : '-' dexp", 308 "dexp : '(' dexp ')'", 309 "vexp : dexp", 310 "vexp : '(' dexp ',' dexp ')'", 311 "vexp : VREG", 312 "vexp : vexp '+' vexp", 313 "vexp : dexp '+' vexp", 314 "vexp : vexp '-' vexp", 315 "vexp : dexp '-' vexp", 316 "vexp : vexp '*' vexp", 317 "vexp : dexp '*' vexp", 318 "vexp : vexp '/' vexp", 319 "vexp : dexp '/' vexp", 320 "vexp : '-' vexp", 321 "vexp : '(' vexp ')'", 322 323 }; 324 #endif 325 326 #if YYDEBUG 327 int yydebug; 328 #endif 329 330 int yyerrflag; 331 int yychar; 332 YYSTYPE yyval; 333 YYSTYPE yylval; 334 int yynerrs; 335 336 /* define the initial stack-sizes */ 337 #ifdef YYSTACKSIZE 338 #undef YYMAXDEPTH 339 #define YYMAXDEPTH YYSTACKSIZE 340 #else 341 #ifdef YYMAXDEPTH 342 #define YYSTACKSIZE YYMAXDEPTH 343 #else 344 #define YYSTACKSIZE 10000 345 #define YYMAXDEPTH 10000 346 #endif 347 #endif 348 349 #define YYINITSTACKSIZE 200 350 351 typedef struct { 352 unsigned stacksize; 353 YYINT *s_base; 354 YYINT *s_mark; 355 YYINT *s_last; 356 YYSTYPE *l_base; 357 YYSTYPE *l_mark; 358 } YYSTACKDATA; 359 /* variables for the parser stack */ 360 static YYSTACKDATA yystack; 361 #line 176 "calc1.y" 362 /* beginning of subroutines section */ 363 364 #define BSZ 50 /* buffer size for floating point numbers */ 365 366 /* lexical analysis */ 367 368 static void 369 yyerror(const char *s) 370 { 371 fprintf(stderr, "%s\n", s); 372 } 373 374 int 375 yylex(void) 376 { 377 int c; 378 379 while ((c = getchar()) == ' ') 380 { /* skip over blanks */ 381 } 382 383 if (isupper(c)) 384 { 385 yylval.ival = c - 'A'; 386 return (VREG); 387 } 388 if (islower(c)) 389 { 390 yylval.ival = c - 'a'; 391 return (DREG); 392 } 393 394 if (isdigit(c) || c == '.') 395 { 396 /* gobble up digits, points, exponents */ 397 char buf[BSZ + 1], *cp = buf; 398 int dot = 0, expr = 0; 399 400 for (; (cp - buf) < BSZ; ++cp, c = getchar()) 401 { 402 403 *cp = (char) c; 404 if (isdigit(c)) 405 continue; 406 if (c == '.') 407 { 408 if (dot++ || expr) 409 return ('.'); /* will cause syntax error */ 410 continue; 411 } 412 413 if (c == 'e') 414 { 415 if (expr++) 416 return ('e'); /* will cause syntax error */ 417 continue; 418 } 419 420 /* end of number */ 421 break; 422 } 423 *cp = '\0'; 424 425 if ((cp - buf) >= BSZ) 426 printf("constant too long: truncated\n"); 427 else 428 ungetc(c, stdin); /* push back last char read */ 429 yylval.dval = atof(buf); 430 return (CONST); 431 } 432 return (c); 433 } 434 435 static INTERVAL 436 hilo(double a, double b, double c, double d) 437 { 438 /* returns the smallest interval containing a, b, c, and d */ 439 /* used by *, / routines */ 440 INTERVAL v; 441 442 if (a > b) 443 { 444 v.hi = a; 445 v.lo = b; 446 } 447 else 448 { 449 v.hi = b; 450 v.lo = a; 451 } 452 453 if (c > d) 454 { 455 if (c > v.hi) 456 v.hi = c; 457 if (d < v.lo) 458 v.lo = d; 459 } 460 else 461 { 462 if (d > v.hi) 463 v.hi = d; 464 if (c < v.lo) 465 v.lo = c; 466 } 467 return (v); 468 } 469 470 INTERVAL 471 vmul(double a, double b, INTERVAL v) 472 { 473 return (hilo(a * v.hi, a * v.lo, b * v.hi, b * v.lo)); 474 } 475 476 int 477 dcheck(INTERVAL v) 478 { 479 if (v.hi >= 0. && v.lo <= 0.) 480 { 481 printf("divisor interval contains 0.\n"); 482 return (1); 483 } 484 return (0); 485 } 486 487 INTERVAL 488 vdiv(double a, double b, INTERVAL v) 489 { 490 return (hilo(a / v.hi, a / v.lo, b / v.hi, b / v.lo)); 491 } 492 #line 493 "calc1.tab.c" 493 494 #if YYDEBUG 495 #include <stdio.h> /* needed for printf */ 496 #endif 497 498 #include <stdlib.h> /* needed for malloc, etc */ 499 #include <string.h> /* needed for memset */ 500 501 /* allocate initial stack or double stack size, up to YYMAXDEPTH */ 502 static int yygrowstack(YYSTACKDATA *data) 503 { 504 int i; 505 unsigned newsize; 506 YYINT *newss; 507 YYSTYPE *newvs; 508 509 if ((newsize = data->stacksize) == 0) 510 newsize = YYINITSTACKSIZE; 511 else if (newsize >= YYMAXDEPTH) 512 return YYENOMEM; 513 else if ((newsize *= 2) > YYMAXDEPTH) 514 newsize = YYMAXDEPTH; 515 516 i = (int) (data->s_mark - data->s_base); 517 newss = (YYINT *)realloc(data->s_base, newsize * sizeof(*newss)); 518 if (newss == NULL) 519 return YYENOMEM; 520 521 data->s_base = newss; 522 data->s_mark = newss + i; 523 524 newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs)); 525 if (newvs == NULL) 526 return YYENOMEM; 527 528 data->l_base = newvs; 529 data->l_mark = newvs + i; 530 531 data->stacksize = newsize; 532 data->s_last = data->s_base + newsize - 1; 533 return 0; 534 } 535 536 #if YYPURE || defined(YY_NO_LEAKS) 537 static void yyfreestack(YYSTACKDATA *data) 538 { 539 free(data->s_base); 540 free(data->l_base); 541 memset(data, 0, sizeof(*data)); 542 } 543 #else 544 #define yyfreestack(data) /* nothing */ 545 #endif 546 547 #define YYABORT goto yyabort 548 #define YYREJECT goto yyabort 549 #define YYACCEPT goto yyaccept 550 #define YYERROR goto yyerrlab 551 552 int 553 YYPARSE_DECL() 554 { 555 int yym, yyn, yystate; 556 #if YYDEBUG 557 const char *yys; 558 559 if ((yys = getenv("YYDEBUG")) != NULL) 560 { 561 yyn = *yys; 562 if (yyn >= '0' && yyn <= '9') 563 yydebug = yyn - '0'; 564 } 565 #endif 566 567 yym = 0; 568 yyn = 0; 569 yynerrs = 0; 570 yyerrflag = 0; 571 yychar = YYEMPTY; 572 yystate = 0; 573 574 #if YYPURE 575 memset(&yystack, 0, sizeof(yystack)); 576 #endif 577 578 if (yystack.s_base == NULL && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow; 579 yystack.s_mark = yystack.s_base; 580 yystack.l_mark = yystack.l_base; 581 yystate = 0; 582 *yystack.s_mark = 0; 583 584 yyloop: 585 if ((yyn = yydefred[yystate]) != 0) goto yyreduce; 586 if (yychar < 0) 587 { 588 yychar = YYLEX; 589 if (yychar < 0) yychar = YYEOF; 590 #if YYDEBUG 591 if (yydebug) 592 { 593 if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN]; 594 printf("%sdebug: state %d, reading %d (%s)\n", 595 YYPREFIX, yystate, yychar, yys); 596 } 597 #endif 598 } 599 if (((yyn = yysindex[yystate]) != 0) && (yyn += yychar) >= 0 && 600 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar) 601 { 602 #if YYDEBUG 603 if (yydebug) 604 printf("%sdebug: state %d, shifting to state %d\n", 605 YYPREFIX, yystate, yytable[yyn]); 606 #endif 607 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow; 608 yystate = yytable[yyn]; 609 *++yystack.s_mark = yytable[yyn]; 610 *++yystack.l_mark = yylval; 611 yychar = YYEMPTY; 612 if (yyerrflag > 0) --yyerrflag; 613 goto yyloop; 614 } 615 if (((yyn = yyrindex[yystate]) != 0) && (yyn += yychar) >= 0 && 616 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar) 617 { 618 yyn = yytable[yyn]; 619 goto yyreduce; 620 } 621 if (yyerrflag != 0) goto yyinrecovery; 622 623 YYERROR_CALL("syntax error"); 624 625 goto yyerrlab; /* redundant goto avoids 'unused label' warning */ 626 yyerrlab: 627 ++yynerrs; 628 629 yyinrecovery: 630 if (yyerrflag < 3) 631 { 632 yyerrflag = 3; 633 for (;;) 634 { 635 if (((yyn = yysindex[*yystack.s_mark]) != 0) && (yyn += YYERRCODE) >= 0 && 636 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) YYERRCODE) 637 { 638 #if YYDEBUG 639 if (yydebug) 640 printf("%sdebug: state %d, error recovery shifting\ 641 to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]); 642 #endif 643 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow; 644 yystate = yytable[yyn]; 645 *++yystack.s_mark = yytable[yyn]; 646 *++yystack.l_mark = yylval; 647 goto yyloop; 648 } 649 else 650 { 651 #if YYDEBUG 652 if (yydebug) 653 printf("%sdebug: error recovery discarding state %d\n", 654 YYPREFIX, *yystack.s_mark); 655 #endif 656 if (yystack.s_mark <= yystack.s_base) goto yyabort; 657 --yystack.s_mark; 658 --yystack.l_mark; 659 } 660 } 661 } 662 else 663 { 664 if (yychar == YYEOF) goto yyabort; 665 #if YYDEBUG 666 if (yydebug) 667 { 668 if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN]; 669 printf("%sdebug: state %d, error recovery discards token %d (%s)\n", 670 YYPREFIX, yystate, yychar, yys); 671 } 672 #endif 673 yychar = YYEMPTY; 674 goto yyloop; 675 } 676 677 yyreduce: 678 #if YYDEBUG 679 if (yydebug) 680 printf("%sdebug: state %d, reducing by rule %d (%s)\n", 681 YYPREFIX, yystate, yyn, yyrule[yyn]); 682 #endif 683 yym = yylen[yyn]; 684 if (yym > 0) 685 yyval = yystack.l_mark[1-yym]; 686 else 687 memset(&yyval, 0, sizeof yyval); 688 689 switch (yyn) 690 { 691 case 3: 692 #line 57 "calc1.y" 693 { 694 (void) printf("%15.8f\n", yystack.l_mark[-1].dval); 695 } 696 break; 697 case 4: 698 #line 61 "calc1.y" 699 { 700 (void) printf("(%15.8f, %15.8f)\n", yystack.l_mark[-1].vval.lo, yystack.l_mark[-1].vval.hi); 701 } 702 break; 703 case 5: 704 #line 65 "calc1.y" 705 { 706 dreg[yystack.l_mark[-3].ival] = yystack.l_mark[-1].dval; 707 } 708 break; 709 case 6: 710 #line 69 "calc1.y" 711 { 712 vreg[yystack.l_mark[-3].ival] = yystack.l_mark[-1].vval; 713 } 714 break; 715 case 7: 716 #line 73 "calc1.y" 717 { 718 yyerrok; 719 } 720 break; 721 case 9: 722 #line 80 "calc1.y" 723 { 724 yyval.dval = dreg[yystack.l_mark[0].ival]; 725 } 726 break; 727 case 10: 728 #line 84 "calc1.y" 729 { 730 yyval.dval = yystack.l_mark[-2].dval + yystack.l_mark[0].dval; 731 } 732 break; 733 case 11: 734 #line 88 "calc1.y" 735 { 736 yyval.dval = yystack.l_mark[-2].dval - yystack.l_mark[0].dval; 737 } 738 break; 739 case 12: 740 #line 92 "calc1.y" 741 { 742 yyval.dval = yystack.l_mark[-2].dval * yystack.l_mark[0].dval; 743 } 744 break; 745 case 13: 746 #line 96 "calc1.y" 747 { 748 yyval.dval = yystack.l_mark[-2].dval / yystack.l_mark[0].dval; 749 } 750 break; 751 case 14: 752 #line 100 "calc1.y" 753 { 754 yyval.dval = -yystack.l_mark[0].dval; 755 } 756 break; 757 case 15: 758 #line 104 "calc1.y" 759 { 760 yyval.dval = yystack.l_mark[-1].dval; 761 } 762 break; 763 case 16: 764 #line 110 "calc1.y" 765 { 766 yyval.vval.hi = yyval.vval.lo = yystack.l_mark[0].dval; 767 } 768 break; 769 case 17: 770 #line 114 "calc1.y" 771 { 772 yyval.vval.lo = yystack.l_mark[-3].dval; 773 yyval.vval.hi = yystack.l_mark[-1].dval; 774 if ( yyval.vval.lo > yyval.vval.hi ) 775 { 776 (void) printf("interval out of order\n"); 777 YYERROR; 778 } 779 } 780 break; 781 case 18: 782 #line 124 "calc1.y" 783 { 784 yyval.vval = vreg[yystack.l_mark[0].ival]; 785 } 786 break; 787 case 19: 788 #line 128 "calc1.y" 789 { 790 yyval.vval.hi = yystack.l_mark[-2].vval.hi + yystack.l_mark[0].vval.hi; 791 yyval.vval.lo = yystack.l_mark[-2].vval.lo + yystack.l_mark[0].vval.lo; 792 } 793 break; 794 case 20: 795 #line 133 "calc1.y" 796 { 797 yyval.vval.hi = yystack.l_mark[-2].dval + yystack.l_mark[0].vval.hi; 798 yyval.vval.lo = yystack.l_mark[-2].dval + yystack.l_mark[0].vval.lo; 799 } 800 break; 801 case 21: 802 #line 138 "calc1.y" 803 { 804 yyval.vval.hi = yystack.l_mark[-2].vval.hi - yystack.l_mark[0].vval.lo; 805 yyval.vval.lo = yystack.l_mark[-2].vval.lo - yystack.l_mark[0].vval.hi; 806 } 807 break; 808 case 22: 809 #line 143 "calc1.y" 810 { 811 yyval.vval.hi = yystack.l_mark[-2].dval - yystack.l_mark[0].vval.lo; 812 yyval.vval.lo = yystack.l_mark[-2].dval - yystack.l_mark[0].vval.hi; 813 } 814 break; 815 case 23: 816 #line 148 "calc1.y" 817 { 818 yyval.vval = vmul( yystack.l_mark[-2].vval.lo, yystack.l_mark[-2].vval.hi, yystack.l_mark[0].vval ); 819 } 820 break; 821 case 24: 822 #line 152 "calc1.y" 823 { 824 yyval.vval = vmul (yystack.l_mark[-2].dval, yystack.l_mark[-2].dval, yystack.l_mark[0].vval ); 825 } 826 break; 827 case 25: 828 #line 156 "calc1.y" 829 { 830 if (dcheck(yystack.l_mark[0].vval)) YYERROR; 831 yyval.vval = vdiv ( yystack.l_mark[-2].vval.lo, yystack.l_mark[-2].vval.hi, yystack.l_mark[0].vval ); 832 } 833 break; 834 case 26: 835 #line 161 "calc1.y" 836 { 837 if (dcheck ( yystack.l_mark[0].vval )) YYERROR; 838 yyval.vval = vdiv (yystack.l_mark[-2].dval, yystack.l_mark[-2].dval, yystack.l_mark[0].vval ); 839 } 840 break; 841 case 27: 842 #line 166 "calc1.y" 843 { 844 yyval.vval.hi = -yystack.l_mark[0].vval.lo; 845 yyval.vval.lo = -yystack.l_mark[0].vval.hi; 846 } 847 break; 848 case 28: 849 #line 171 "calc1.y" 850 { 851 yyval.vval = yystack.l_mark[-1].vval; 852 } 853 break; 854 #line 855 "calc1.tab.c" 855 } 856 yystack.s_mark -= yym; 857 yystate = *yystack.s_mark; 858 yystack.l_mark -= yym; 859 yym = yylhs[yyn]; 860 if (yystate == 0 && yym == 0) 861 { 862 #if YYDEBUG 863 if (yydebug) 864 printf("%sdebug: after reduction, shifting from state 0 to\ 865 state %d\n", YYPREFIX, YYFINAL); 866 #endif 867 yystate = YYFINAL; 868 *++yystack.s_mark = YYFINAL; 869 *++yystack.l_mark = yyval; 870 if (yychar < 0) 871 { 872 yychar = YYLEX; 873 if (yychar < 0) yychar = YYEOF; 874 #if YYDEBUG 875 if (yydebug) 876 { 877 if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN]; 878 printf("%sdebug: state %d, reading %d (%s)\n", 879 YYPREFIX, YYFINAL, yychar, yys); 880 } 881 #endif 882 } 883 if (yychar == YYEOF) goto yyaccept; 884 goto yyloop; 885 } 886 if (((yyn = yygindex[yym]) != 0) && (yyn += yystate) >= 0 && 887 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yystate) 888 yystate = yytable[yyn]; 889 else 890 yystate = yydgoto[yym]; 891 #if YYDEBUG 892 if (yydebug) 893 printf("%sdebug: after reduction, shifting from state %d \ 894 to state %d\n", YYPREFIX, *yystack.s_mark, yystate); 895 #endif 896 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow; 897 *++yystack.s_mark = (YYINT) yystate; 898 *++yystack.l_mark = yyval; 899 goto yyloop; 900 901 yyoverflow: 902 YYERROR_CALL("yacc stack overflow"); 903 904 yyabort: 905 yyfreestack(&yystack); 906 return (1); 907 908 yyaccept: 909 yyfreestack(&yystack); 910 return (0); 911 } 912