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 2 7 #define YYMINOR 0 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 is set below */ 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 #line 1330 "calc1.tab.c" 1330 break; 1331 case 4: 1332 #line 61 "calc1.y" 1333 { 1334 (void) printf("(%15.8f, %15.8f)\n", yystack.l_mark[-1].vval.lo, yystack.l_mark[-1].vval.hi); 1335 } 1336 #line 1337 "calc1.tab.c" 1337 break; 1338 case 5: 1339 #line 65 "calc1.y" 1340 { 1341 dreg[yystack.l_mark[-3].ival] = yystack.l_mark[-1].dval; 1342 } 1343 #line 1344 "calc1.tab.c" 1344 break; 1345 case 6: 1346 #line 69 "calc1.y" 1347 { 1348 vreg[yystack.l_mark[-3].ival] = yystack.l_mark[-1].vval; 1349 } 1350 #line 1351 "calc1.tab.c" 1351 break; 1352 case 7: 1353 #line 73 "calc1.y" 1354 { 1355 yyerrok; 1356 } 1357 #line 1358 "calc1.tab.c" 1358 break; 1359 case 9: 1360 #line 80 "calc1.y" 1361 { 1362 yyval.dval = dreg[yystack.l_mark[0].ival]; 1363 } 1364 #line 1365 "calc1.tab.c" 1365 break; 1366 case 10: 1367 #line 84 "calc1.y" 1368 { 1369 yyval.dval = yystack.l_mark[-2].dval + yystack.l_mark[0].dval; 1370 } 1371 #line 1372 "calc1.tab.c" 1372 break; 1373 case 11: 1374 #line 88 "calc1.y" 1375 { 1376 yyval.dval = yystack.l_mark[-2].dval - yystack.l_mark[0].dval; 1377 } 1378 #line 1379 "calc1.tab.c" 1379 break; 1380 case 12: 1381 #line 92 "calc1.y" 1382 { 1383 yyval.dval = yystack.l_mark[-2].dval * yystack.l_mark[0].dval; 1384 } 1385 #line 1386 "calc1.tab.c" 1386 break; 1387 case 13: 1388 #line 96 "calc1.y" 1389 { 1390 yyval.dval = yystack.l_mark[-2].dval / yystack.l_mark[0].dval; 1391 } 1392 #line 1393 "calc1.tab.c" 1393 break; 1394 case 14: 1395 #line 100 "calc1.y" 1396 { 1397 yyval.dval = -yystack.l_mark[0].dval; 1398 } 1399 #line 1400 "calc1.tab.c" 1400 break; 1401 case 15: 1402 #line 104 "calc1.y" 1403 { 1404 yyval.dval = yystack.l_mark[-1].dval; 1405 } 1406 #line 1407 "calc1.tab.c" 1407 break; 1408 case 16: 1409 #line 110 "calc1.y" 1410 { 1411 yyval.vval.hi = yyval.vval.lo = yystack.l_mark[0].dval; 1412 } 1413 #line 1414 "calc1.tab.c" 1414 break; 1415 case 17: 1416 #line 114 "calc1.y" 1417 { 1418 yyval.vval.lo = yystack.l_mark[-3].dval; 1419 yyval.vval.hi = yystack.l_mark[-1].dval; 1420 if ( yyval.vval.lo > yyval.vval.hi ) 1421 { 1422 (void) printf("interval out of order\n"); 1423 YYERROR; 1424 } 1425 } 1426 #line 1427 "calc1.tab.c" 1427 break; 1428 case 18: 1429 #line 124 "calc1.y" 1430 { 1431 yyval.vval = vreg[yystack.l_mark[0].ival]; 1432 } 1433 #line 1434 "calc1.tab.c" 1434 break; 1435 case 19: 1436 #line 128 "calc1.y" 1437 { 1438 yyval.vval.hi = yystack.l_mark[-2].vval.hi + yystack.l_mark[0].vval.hi; 1439 yyval.vval.lo = yystack.l_mark[-2].vval.lo + yystack.l_mark[0].vval.lo; 1440 } 1441 #line 1442 "calc1.tab.c" 1442 break; 1443 case 20: 1444 #line 133 "calc1.y" 1445 { 1446 yyval.vval.hi = yystack.l_mark[-2].dval + yystack.l_mark[0].vval.hi; 1447 yyval.vval.lo = yystack.l_mark[-2].dval + yystack.l_mark[0].vval.lo; 1448 } 1449 #line 1450 "calc1.tab.c" 1450 break; 1451 case 21: 1452 #line 138 "calc1.y" 1453 { 1454 yyval.vval.hi = yystack.l_mark[-2].vval.hi - yystack.l_mark[0].vval.lo; 1455 yyval.vval.lo = yystack.l_mark[-2].vval.lo - yystack.l_mark[0].vval.hi; 1456 } 1457 #line 1458 "calc1.tab.c" 1458 break; 1459 case 22: 1460 #line 143 "calc1.y" 1461 { 1462 yyval.vval.hi = yystack.l_mark[-2].dval - yystack.l_mark[0].vval.lo; 1463 yyval.vval.lo = yystack.l_mark[-2].dval - yystack.l_mark[0].vval.hi; 1464 } 1465 #line 1466 "calc1.tab.c" 1466 break; 1467 case 23: 1468 #line 148 "calc1.y" 1469 { 1470 yyval.vval = vmul( yystack.l_mark[-2].vval.lo, yystack.l_mark[-2].vval.hi, yystack.l_mark[0].vval ); 1471 } 1472 #line 1473 "calc1.tab.c" 1473 break; 1474 case 24: 1475 #line 152 "calc1.y" 1476 { 1477 yyval.vval = vmul (yystack.l_mark[-2].dval, yystack.l_mark[-2].dval, yystack.l_mark[0].vval ); 1478 } 1479 #line 1480 "calc1.tab.c" 1480 break; 1481 case 25: 1482 #line 156 "calc1.y" 1483 { 1484 if (dcheck(yystack.l_mark[0].vval)) YYERROR; 1485 yyval.vval = vdiv ( yystack.l_mark[-2].vval.lo, yystack.l_mark[-2].vval.hi, yystack.l_mark[0].vval ); 1486 } 1487 #line 1488 "calc1.tab.c" 1488 break; 1489 case 26: 1490 #line 161 "calc1.y" 1491 { 1492 if (dcheck ( yystack.l_mark[0].vval )) YYERROR; 1493 yyval.vval = vdiv (yystack.l_mark[-2].dval, yystack.l_mark[-2].dval, yystack.l_mark[0].vval ); 1494 } 1495 #line 1496 "calc1.tab.c" 1496 break; 1497 case 27: 1498 #line 166 "calc1.y" 1499 { 1500 yyval.vval.hi = -yystack.l_mark[0].vval.lo; 1501 yyval.vval.lo = -yystack.l_mark[0].vval.hi; 1502 } 1503 #line 1504 "calc1.tab.c" 1504 break; 1505 case 28: 1506 #line 171 "calc1.y" 1507 { 1508 yyval.vval = yystack.l_mark[-1].vval; 1509 } 1510 #line 1511 "calc1.tab.c" 1511 break; 1512 #line 1513 "calc1.tab.c" 1513 default: 1514 break; 1515 } 1516 yystack.s_mark -= yym; 1517 yystate = *yystack.s_mark; 1518 yystack.l_mark -= yym; 1519 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1520 yystack.p_mark -= yym; 1521 #endif 1522 yym = yylhs[yyn]; 1523 if (yystate == 0 && yym == 0) 1524 { 1525 #if YYDEBUG 1526 if (yydebug) 1527 { 1528 fprintf(stderr, "%s[%d]: after reduction, ", YYDEBUGSTR, yydepth); 1529 #ifdef YYSTYPE_TOSTRING 1530 #if YYBTYACC 1531 if (!yytrial) 1532 #endif /* YYBTYACC */ 1533 fprintf(stderr, "result is <%s>, ", YYSTYPE_TOSTRING(yystos[YYFINAL], yyval)); 1534 #endif 1535 fprintf(stderr, "shifting from state 0 to final state %d\n", YYFINAL); 1536 } 1537 #endif 1538 yystate = YYFINAL; 1539 *++yystack.s_mark = YYFINAL; 1540 *++yystack.l_mark = yyval; 1541 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1542 *++yystack.p_mark = yyloc; 1543 #endif 1544 if (yychar < 0) 1545 { 1546 #if YYBTYACC 1547 do { 1548 if (yylvp < yylve) 1549 { 1550 /* we're currently re-reading tokens */ 1551 yylval = *yylvp++; 1552 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1553 yylloc = *yylpp++; 1554 #endif 1555 yychar = *yylexp++; 1556 break; 1557 } 1558 if (yyps->save) 1559 { 1560 /* in trial mode; save scanner results for future parse attempts */ 1561 if (yylvp == yylvlim) 1562 { /* Enlarge lexical value queue */ 1563 size_t p = (size_t) (yylvp - yylvals); 1564 size_t s = (size_t) (yylvlim - yylvals); 1565 1566 s += YYLVQUEUEGROWTH; 1567 if ((yylexemes = (YYINT *)realloc(yylexemes, s * sizeof(YYINT))) == NULL) 1568 goto yyenomem; 1569 if ((yylvals = (YYSTYPE *)realloc(yylvals, s * sizeof(YYSTYPE))) == NULL) 1570 goto yyenomem; 1571 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1572 if ((yylpsns = (YYLTYPE *)realloc(yylpsns, s * sizeof(YYLTYPE))) == NULL) 1573 goto yyenomem; 1574 #endif 1575 yylvp = yylve = yylvals + p; 1576 yylvlim = yylvals + s; 1577 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1578 yylpp = yylpe = yylpsns + p; 1579 yylplim = yylpsns + s; 1580 #endif 1581 yylexp = yylexemes + p; 1582 } 1583 *yylexp = (YYINT) YYLEX; 1584 *yylvp++ = yylval; 1585 yylve++; 1586 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1587 *yylpp++ = yylloc; 1588 yylpe++; 1589 #endif 1590 yychar = *yylexp++; 1591 break; 1592 } 1593 /* normal operation, no conflict encountered */ 1594 #endif /* YYBTYACC */ 1595 yychar = YYLEX; 1596 #if YYBTYACC 1597 } while (0); 1598 #endif /* YYBTYACC */ 1599 if (yychar < 0) yychar = YYEOF; 1600 #if YYDEBUG 1601 if (yydebug) 1602 { 1603 if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN]; 1604 fprintf(stderr, "%s[%d]: state %d, reading token %d (%s)\n", 1605 YYDEBUGSTR, yydepth, YYFINAL, yychar, yys); 1606 } 1607 #endif 1608 } 1609 if (yychar == YYEOF) goto yyaccept; 1610 goto yyloop; 1611 } 1612 if (((yyn = yygindex[yym]) != 0) && (yyn += yystate) >= 0 && 1613 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yystate) 1614 yystate = yytable[yyn]; 1615 else 1616 yystate = yydgoto[yym]; 1617 #if YYDEBUG 1618 if (yydebug) 1619 { 1620 fprintf(stderr, "%s[%d]: after reduction, ", YYDEBUGSTR, yydepth); 1621 #ifdef YYSTYPE_TOSTRING 1622 #if YYBTYACC 1623 if (!yytrial) 1624 #endif /* YYBTYACC */ 1625 fprintf(stderr, "result is <%s>, ", YYSTYPE_TOSTRING(yystos[yystate], yyval)); 1626 #endif 1627 fprintf(stderr, "shifting from state %d to state %d\n", *yystack.s_mark, yystate); 1628 } 1629 #endif 1630 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow; 1631 *++yystack.s_mark = (YYINT) yystate; 1632 *++yystack.l_mark = yyval; 1633 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1634 *++yystack.p_mark = yyloc; 1635 #endif 1636 goto yyloop; 1637 #if YYBTYACC 1638 1639 /* Reduction declares that this path is valid. Set yypath and do a full parse */ 1640 yyvalid: 1641 if (yypath) YYABORT; 1642 while (yyps->save) 1643 { 1644 YYParseState *save = yyps->save; 1645 yyps->save = save->save; 1646 save->save = yypath; 1647 yypath = save; 1648 } 1649 #if YYDEBUG 1650 if (yydebug) 1651 fprintf(stderr, "%s[%d]: state %d, CONFLICT trial successful, backtracking to state %d, %d tokens\n", 1652 YYDEBUGSTR, yydepth, yystate, yypath->state, (int)(yylvp - yylvals - yypath->lexeme)); 1653 #endif 1654 if (yyerrctx) 1655 { 1656 yyFreeState(yyerrctx); 1657 yyerrctx = NULL; 1658 } 1659 yylvp = yylvals + yypath->lexeme; 1660 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1661 yylpp = yylpsns + yypath->lexeme; 1662 #endif 1663 yylexp = yylexemes + yypath->lexeme; 1664 yychar = YYEMPTY; 1665 yystack.s_mark = yystack.s_base + (yypath->yystack.s_mark - yypath->yystack.s_base); 1666 memcpy (yystack.s_base, yypath->yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(YYINT)); 1667 yystack.l_mark = yystack.l_base + (yypath->yystack.l_mark - yypath->yystack.l_base); 1668 memcpy (yystack.l_base, yypath->yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE)); 1669 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1670 yystack.p_mark = yystack.p_base + (yypath->yystack.p_mark - yypath->yystack.p_base); 1671 memcpy (yystack.p_base, yypath->yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE)); 1672 #endif 1673 yystate = yypath->state; 1674 goto yyloop; 1675 #endif /* YYBTYACC */ 1676 1677 yyoverflow: 1678 YYERROR_CALL("yacc stack overflow"); 1679 #if YYBTYACC 1680 goto yyabort_nomem; 1681 yyenomem: 1682 YYERROR_CALL("memory exhausted"); 1683 yyabort_nomem: 1684 #endif /* YYBTYACC */ 1685 yyresult = 2; 1686 goto yyreturn; 1687 1688 yyabort: 1689 yyresult = 1; 1690 goto yyreturn; 1691 1692 yyaccept: 1693 #if YYBTYACC 1694 if (yyps->save) goto yyvalid; 1695 #endif /* YYBTYACC */ 1696 yyresult = 0; 1697 1698 yyreturn: 1699 #if defined(YYDESTRUCT_CALL) 1700 if (yychar != YYEOF && yychar != YYEMPTY) 1701 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1702 YYDESTRUCT_CALL("cleanup: discarding token", yychar, &yylval, &yylloc); 1703 #else 1704 YYDESTRUCT_CALL("cleanup: discarding token", yychar, &yylval); 1705 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */ 1706 1707 { 1708 YYSTYPE *pv; 1709 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1710 YYLTYPE *pp; 1711 1712 for (pv = yystack.l_base, pp = yystack.p_base; pv <= yystack.l_mark; ++pv, ++pp) 1713 YYDESTRUCT_CALL("cleanup: discarding state", 1714 yystos[*(yystack.s_base + (pv - yystack.l_base))], pv, pp); 1715 #else 1716 for (pv = yystack.l_base; pv <= yystack.l_mark; ++pv) 1717 YYDESTRUCT_CALL("cleanup: discarding state", 1718 yystos[*(yystack.s_base + (pv - yystack.l_base))], pv); 1719 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */ 1720 } 1721 #endif /* defined(YYDESTRUCT_CALL) */ 1722 1723 #if YYBTYACC 1724 if (yyerrctx) 1725 { 1726 yyFreeState(yyerrctx); 1727 yyerrctx = NULL; 1728 } 1729 while (yyps) 1730 { 1731 YYParseState *save = yyps; 1732 yyps = save->save; 1733 save->save = NULL; 1734 yyFreeState(save); 1735 } 1736 while (yypath) 1737 { 1738 YYParseState *save = yypath; 1739 yypath = save->save; 1740 save->save = NULL; 1741 yyFreeState(save); 1742 } 1743 #endif /* YYBTYACC */ 1744 yyfreestack(&yystack); 1745 return (yyresult); 1746 } 1747