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 #line 31 "calc1.y" 127 #ifdef YYSTYPE 128 #undef YYSTYPE_IS_DECLARED 129 #define YYSTYPE_IS_DECLARED 1 130 #endif 131 #ifndef YYSTYPE_IS_DECLARED 132 #define YYSTYPE_IS_DECLARED 1 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 int yydebug; 327 int yynerrs; 328 329 int yyerrflag; 330 int yychar; 331 YYSTYPE yyval; 332 YYSTYPE yylval; 333 334 /* define the initial stack-sizes */ 335 #ifdef YYSTACKSIZE 336 #undef YYMAXDEPTH 337 #define YYMAXDEPTH YYSTACKSIZE 338 #else 339 #ifdef YYMAXDEPTH 340 #define YYSTACKSIZE YYMAXDEPTH 341 #else 342 #define YYSTACKSIZE 10000 343 #define YYMAXDEPTH 10000 344 #endif 345 #endif 346 347 #define YYINITSTACKSIZE 200 348 349 typedef struct { 350 unsigned stacksize; 351 YYINT *s_base; 352 YYINT *s_mark; 353 YYINT *s_last; 354 YYSTYPE *l_base; 355 YYSTYPE *l_mark; 356 } YYSTACKDATA; 357 /* variables for the parser stack */ 358 static YYSTACKDATA yystack; 359 #line 176 "calc1.y" 360 /* beginning of subroutines section */ 361 362 #define BSZ 50 /* buffer size for floating point numbers */ 363 364 /* lexical analysis */ 365 366 static void 367 yyerror(const char *s) 368 { 369 fprintf(stderr, "%s\n", s); 370 } 371 372 int 373 yylex(void) 374 { 375 int c; 376 377 while ((c = getchar()) == ' ') 378 { /* skip over blanks */ 379 } 380 381 if (isupper(c)) 382 { 383 yylval.ival = c - 'A'; 384 return (VREG); 385 } 386 if (islower(c)) 387 { 388 yylval.ival = c - 'a'; 389 return (DREG); 390 } 391 392 if (isdigit(c) || c == '.') 393 { 394 /* gobble up digits, points, exponents */ 395 char buf[BSZ + 1], *cp = buf; 396 int dot = 0, expr = 0; 397 398 for (; (cp - buf) < BSZ; ++cp, c = getchar()) 399 { 400 401 *cp = (char) c; 402 if (isdigit(c)) 403 continue; 404 if (c == '.') 405 { 406 if (dot++ || expr) 407 return ('.'); /* will cause syntax error */ 408 continue; 409 } 410 411 if (c == 'e') 412 { 413 if (expr++) 414 return ('e'); /* will cause syntax error */ 415 continue; 416 } 417 418 /* end of number */ 419 break; 420 } 421 *cp = '\0'; 422 423 if ((cp - buf) >= BSZ) 424 printf("constant too long: truncated\n"); 425 else 426 ungetc(c, stdin); /* push back last char read */ 427 yylval.dval = atof(buf); 428 return (CONST); 429 } 430 return (c); 431 } 432 433 static INTERVAL 434 hilo(double a, double b, double c, double d) 435 { 436 /* returns the smallest interval containing a, b, c, and d */ 437 /* used by *, / routines */ 438 INTERVAL v; 439 440 if (a > b) 441 { 442 v.hi = a; 443 v.lo = b; 444 } 445 else 446 { 447 v.hi = b; 448 v.lo = a; 449 } 450 451 if (c > d) 452 { 453 if (c > v.hi) 454 v.hi = c; 455 if (d < v.lo) 456 v.lo = d; 457 } 458 else 459 { 460 if (d > v.hi) 461 v.hi = d; 462 if (c < v.lo) 463 v.lo = c; 464 } 465 return (v); 466 } 467 468 INTERVAL 469 vmul(double a, double b, INTERVAL v) 470 { 471 return (hilo(a * v.hi, a * v.lo, b * v.hi, b * v.lo)); 472 } 473 474 int 475 dcheck(INTERVAL v) 476 { 477 if (v.hi >= 0. && v.lo <= 0.) 478 { 479 printf("divisor interval contains 0.\n"); 480 return (1); 481 } 482 return (0); 483 } 484 485 INTERVAL 486 vdiv(double a, double b, INTERVAL v) 487 { 488 return (hilo(a / v.hi, a / v.lo, b / v.hi, b / v.lo)); 489 } 490 #line 491 "calc1.tab.c" 491 492 #if YYDEBUG 493 #include <stdio.h> /* needed for printf */ 494 #endif 495 496 #include <stdlib.h> /* needed for malloc, etc */ 497 #include <string.h> /* needed for memset */ 498 499 /* allocate initial stack or double stack size, up to YYMAXDEPTH */ 500 static int yygrowstack(YYSTACKDATA *data) 501 { 502 int i; 503 unsigned newsize; 504 YYINT *newss; 505 YYSTYPE *newvs; 506 507 if ((newsize = data->stacksize) == 0) 508 newsize = YYINITSTACKSIZE; 509 else if (newsize >= YYMAXDEPTH) 510 return YYENOMEM; 511 else if ((newsize *= 2) > YYMAXDEPTH) 512 newsize = YYMAXDEPTH; 513 514 i = (int) (data->s_mark - data->s_base); 515 newss = (YYINT *)realloc(data->s_base, newsize * sizeof(*newss)); 516 if (newss == 0) 517 return YYENOMEM; 518 519 data->s_base = newss; 520 data->s_mark = newss + i; 521 522 newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs)); 523 if (newvs == 0) 524 return YYENOMEM; 525 526 data->l_base = newvs; 527 data->l_mark = newvs + i; 528 529 data->stacksize = newsize; 530 data->s_last = data->s_base + newsize - 1; 531 return 0; 532 } 533 534 #if YYPURE || defined(YY_NO_LEAKS) 535 static void yyfreestack(YYSTACKDATA *data) 536 { 537 free(data->s_base); 538 free(data->l_base); 539 memset(data, 0, sizeof(*data)); 540 } 541 #else 542 #define yyfreestack(data) /* nothing */ 543 #endif 544 545 #define YYABORT goto yyabort 546 #define YYREJECT goto yyabort 547 #define YYACCEPT goto yyaccept 548 #define YYERROR goto yyerrlab 549 550 int 551 YYPARSE_DECL() 552 { 553 int yym, yyn, yystate; 554 #if YYDEBUG 555 const char *yys; 556 557 if ((yys = getenv("YYDEBUG")) != 0) 558 { 559 yyn = *yys; 560 if (yyn >= '0' && yyn <= '9') 561 yydebug = yyn - '0'; 562 } 563 #endif 564 565 yynerrs = 0; 566 yyerrflag = 0; 567 yychar = YYEMPTY; 568 yystate = 0; 569 570 #if YYPURE 571 memset(&yystack, 0, sizeof(yystack)); 572 #endif 573 574 if (yystack.s_base == NULL && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow; 575 yystack.s_mark = yystack.s_base; 576 yystack.l_mark = yystack.l_base; 577 yystate = 0; 578 *yystack.s_mark = 0; 579 580 yyloop: 581 if ((yyn = yydefred[yystate]) != 0) goto yyreduce; 582 if (yychar < 0) 583 { 584 if ((yychar = YYLEX) < 0) yychar = YYEOF; 585 #if YYDEBUG 586 if (yydebug) 587 { 588 yys = yyname[YYTRANSLATE(yychar)]; 589 printf("%sdebug: state %d, reading %d (%s)\n", 590 YYPREFIX, yystate, yychar, yys); 591 } 592 #endif 593 } 594 if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 && 595 yyn <= YYTABLESIZE && yycheck[yyn] == yychar) 596 { 597 #if YYDEBUG 598 if (yydebug) 599 printf("%sdebug: state %d, shifting to state %d\n", 600 YYPREFIX, yystate, yytable[yyn]); 601 #endif 602 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) 603 { 604 goto yyoverflow; 605 } 606 yystate = yytable[yyn]; 607 *++yystack.s_mark = yytable[yyn]; 608 *++yystack.l_mark = yylval; 609 yychar = YYEMPTY; 610 if (yyerrflag > 0) --yyerrflag; 611 goto yyloop; 612 } 613 if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 && 614 yyn <= YYTABLESIZE && yycheck[yyn] == yychar) 615 { 616 yyn = yytable[yyn]; 617 goto yyreduce; 618 } 619 if (yyerrflag) goto yyinrecovery; 620 621 YYERROR_CALL("syntax error"); 622 623 goto yyerrlab; 624 625 yyerrlab: 626 ++yynerrs; 627 628 yyinrecovery: 629 if (yyerrflag < 3) 630 { 631 yyerrflag = 3; 632 for (;;) 633 { 634 if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 && 635 yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE) 636 { 637 #if YYDEBUG 638 if (yydebug) 639 printf("%sdebug: state %d, error recovery shifting\ 640 to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]); 641 #endif 642 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) 643 { 644 goto yyoverflow; 645 } 646 yystate = yytable[yyn]; 647 *++yystack.s_mark = yytable[yyn]; 648 *++yystack.l_mark = yylval; 649 goto yyloop; 650 } 651 else 652 { 653 #if YYDEBUG 654 if (yydebug) 655 printf("%sdebug: error recovery discarding state %d\n", 656 YYPREFIX, *yystack.s_mark); 657 #endif 658 if (yystack.s_mark <= yystack.s_base) goto yyabort; 659 --yystack.s_mark; 660 --yystack.l_mark; 661 } 662 } 663 } 664 else 665 { 666 if (yychar == YYEOF) goto yyabort; 667 #if YYDEBUG 668 if (yydebug) 669 { 670 yys = yyname[YYTRANSLATE(yychar)]; 671 printf("%sdebug: state %d, error recovery discards token %d (%s)\n", 672 YYPREFIX, yystate, yychar, yys); 673 } 674 #endif 675 yychar = YYEMPTY; 676 goto yyloop; 677 } 678 679 yyreduce: 680 #if YYDEBUG 681 if (yydebug) 682 printf("%sdebug: state %d, reducing by rule %d (%s)\n", 683 YYPREFIX, yystate, yyn, yyrule[yyn]); 684 #endif 685 yym = yylen[yyn]; 686 if (yym) 687 yyval = yystack.l_mark[1-yym]; 688 else 689 memset(&yyval, 0, sizeof yyval); 690 switch (yyn) 691 { 692 case 3: 693 #line 57 "calc1.y" 694 { 695 (void) printf("%15.8f\n", yystack.l_mark[-1].dval); 696 } 697 break; 698 case 4: 699 #line 61 "calc1.y" 700 { 701 (void) printf("(%15.8f, %15.8f)\n", yystack.l_mark[-1].vval.lo, yystack.l_mark[-1].vval.hi); 702 } 703 break; 704 case 5: 705 #line 65 "calc1.y" 706 { 707 dreg[yystack.l_mark[-3].ival] = yystack.l_mark[-1].dval; 708 } 709 break; 710 case 6: 711 #line 69 "calc1.y" 712 { 713 vreg[yystack.l_mark[-3].ival] = yystack.l_mark[-1].vval; 714 } 715 break; 716 case 7: 717 #line 73 "calc1.y" 718 { 719 yyerrok; 720 } 721 break; 722 case 9: 723 #line 80 "calc1.y" 724 { 725 yyval.dval = dreg[yystack.l_mark[0].ival]; 726 } 727 break; 728 case 10: 729 #line 84 "calc1.y" 730 { 731 yyval.dval = yystack.l_mark[-2].dval + yystack.l_mark[0].dval; 732 } 733 break; 734 case 11: 735 #line 88 "calc1.y" 736 { 737 yyval.dval = yystack.l_mark[-2].dval - yystack.l_mark[0].dval; 738 } 739 break; 740 case 12: 741 #line 92 "calc1.y" 742 { 743 yyval.dval = yystack.l_mark[-2].dval * yystack.l_mark[0].dval; 744 } 745 break; 746 case 13: 747 #line 96 "calc1.y" 748 { 749 yyval.dval = yystack.l_mark[-2].dval / yystack.l_mark[0].dval; 750 } 751 break; 752 case 14: 753 #line 100 "calc1.y" 754 { 755 yyval.dval = -yystack.l_mark[0].dval; 756 } 757 break; 758 case 15: 759 #line 104 "calc1.y" 760 { 761 yyval.dval = yystack.l_mark[-1].dval; 762 } 763 break; 764 case 16: 765 #line 110 "calc1.y" 766 { 767 yyval.vval.hi = yyval.vval.lo = yystack.l_mark[0].dval; 768 } 769 break; 770 case 17: 771 #line 114 "calc1.y" 772 { 773 yyval.vval.lo = yystack.l_mark[-3].dval; 774 yyval.vval.hi = yystack.l_mark[-1].dval; 775 if ( yyval.vval.lo > yyval.vval.hi ) 776 { 777 (void) printf("interval out of order\n"); 778 YYERROR; 779 } 780 } 781 break; 782 case 18: 783 #line 124 "calc1.y" 784 { 785 yyval.vval = vreg[yystack.l_mark[0].ival]; 786 } 787 break; 788 case 19: 789 #line 128 "calc1.y" 790 { 791 yyval.vval.hi = yystack.l_mark[-2].vval.hi + yystack.l_mark[0].vval.hi; 792 yyval.vval.lo = yystack.l_mark[-2].vval.lo + yystack.l_mark[0].vval.lo; 793 } 794 break; 795 case 20: 796 #line 133 "calc1.y" 797 { 798 yyval.vval.hi = yystack.l_mark[-2].dval + yystack.l_mark[0].vval.hi; 799 yyval.vval.lo = yystack.l_mark[-2].dval + yystack.l_mark[0].vval.lo; 800 } 801 break; 802 case 21: 803 #line 138 "calc1.y" 804 { 805 yyval.vval.hi = yystack.l_mark[-2].vval.hi - yystack.l_mark[0].vval.lo; 806 yyval.vval.lo = yystack.l_mark[-2].vval.lo - yystack.l_mark[0].vval.hi; 807 } 808 break; 809 case 22: 810 #line 143 "calc1.y" 811 { 812 yyval.vval.hi = yystack.l_mark[-2].dval - yystack.l_mark[0].vval.lo; 813 yyval.vval.lo = yystack.l_mark[-2].dval - yystack.l_mark[0].vval.hi; 814 } 815 break; 816 case 23: 817 #line 148 "calc1.y" 818 { 819 yyval.vval = vmul( yystack.l_mark[-2].vval.lo, yystack.l_mark[-2].vval.hi, yystack.l_mark[0].vval ); 820 } 821 break; 822 case 24: 823 #line 152 "calc1.y" 824 { 825 yyval.vval = vmul (yystack.l_mark[-2].dval, yystack.l_mark[-2].dval, yystack.l_mark[0].vval ); 826 } 827 break; 828 case 25: 829 #line 156 "calc1.y" 830 { 831 if (dcheck(yystack.l_mark[0].vval)) YYERROR; 832 yyval.vval = vdiv ( yystack.l_mark[-2].vval.lo, yystack.l_mark[-2].vval.hi, yystack.l_mark[0].vval ); 833 } 834 break; 835 case 26: 836 #line 161 "calc1.y" 837 { 838 if (dcheck ( yystack.l_mark[0].vval )) YYERROR; 839 yyval.vval = vdiv (yystack.l_mark[-2].dval, yystack.l_mark[-2].dval, yystack.l_mark[0].vval ); 840 } 841 break; 842 case 27: 843 #line 166 "calc1.y" 844 { 845 yyval.vval.hi = -yystack.l_mark[0].vval.lo; 846 yyval.vval.lo = -yystack.l_mark[0].vval.hi; 847 } 848 break; 849 case 28: 850 #line 171 "calc1.y" 851 { 852 yyval.vval = yystack.l_mark[-1].vval; 853 } 854 break; 855 #line 856 "calc1.tab.c" 856 } 857 yystack.s_mark -= yym; 858 yystate = *yystack.s_mark; 859 yystack.l_mark -= yym; 860 yym = yylhs[yyn]; 861 if (yystate == 0 && yym == 0) 862 { 863 #if YYDEBUG 864 if (yydebug) 865 printf("%sdebug: after reduction, shifting from state 0 to\ 866 state %d\n", YYPREFIX, YYFINAL); 867 #endif 868 yystate = YYFINAL; 869 *++yystack.s_mark = YYFINAL; 870 *++yystack.l_mark = yyval; 871 if (yychar < 0) 872 { 873 if ((yychar = YYLEX) < 0) yychar = YYEOF; 874 #if YYDEBUG 875 if (yydebug) 876 { 877 yys = yyname[YYTRANSLATE(yychar)]; 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]) && (yyn += yystate) >= 0 && 887 yyn <= YYTABLESIZE && yycheck[yyn] == 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) 897 { 898 goto yyoverflow; 899 } 900 *++yystack.s_mark = (YYINT) yystate; 901 *++yystack.l_mark = yyval; 902 goto yyloop; 903 904 yyoverflow: 905 YYERROR_CALL("yacc stack overflow"); 906 907 yyabort: 908 yyfreestack(&yystack); 909 return (1); 910 911 yyaccept: 912 yyfreestack(&yystack); 913 return (0); 914 } 915