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