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