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