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