1 /* original parser id follows */ 2 /* yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93" */ 3 /* (use YYMAJOR/YYMINOR for ifdefs dependent on parser version) */ 4 5 #define YYBYACC 1 6 #define YYMAJOR 1 7 #define YYMINOR 9 8 #define YYCHECK "yyyymmdd" 9 10 #define YYEMPTY (-1) 11 #define yyclearin (yychar = YYEMPTY) 12 #define yyerrok (yyerrflag = 0) 13 #define YYRECOVERING() (yyerrflag != 0) 14 #define YYENOMEM (-2) 15 #define YYEOF 0 16 #ident "check variant syntax features" 17 #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 #ifdef YYSTYPE 148 #undef YYSTYPE_IS_DECLARED 149 #define YYSTYPE_IS_DECLARED 1 150 #endif 151 #ifndef YYSTYPE_IS_DECLARED 152 #define YYSTYPE_IS_DECLARED 1 153 #line 32 "varsyntax_calc1.y" 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 YYINT *s_base; 456 YYINT *s_mark; 457 YYINT *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 YYINT *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 = (YYINT *)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 = (YYINT *) malloc(size * sizeof(YYINT)); 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 yym = 0; 809 yyn = 0; 810 yynerrs = 0; 811 yyerrflag = 0; 812 yychar = YYEMPTY; 813 yystate = 0; 814 815 #if YYPURE 816 memset(&yystack, 0, sizeof(yystack)); 817 #endif 818 819 if (yystack.s_base == NULL && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow; 820 yystack.s_mark = yystack.s_base; 821 yystack.l_mark = yystack.l_base; 822 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 823 yystack.p_mark = yystack.p_base; 824 #endif 825 yystate = 0; 826 *yystack.s_mark = 0; 827 828 yyloop: 829 if ((yyn = yydefred[yystate]) != 0) goto yyreduce; 830 if (yychar < 0) 831 { 832 #if YYBTYACC 833 do { 834 if (yylvp < yylve) 835 { 836 /* we're currently re-reading tokens */ 837 yylval = *yylvp++; 838 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 839 yylloc = *yylpp++; 840 #endif 841 yychar = *yylexp++; 842 break; 843 } 844 if (yyps->save) 845 { 846 /* in trial mode; save scanner results for future parse attempts */ 847 if (yylvp == yylvlim) 848 { /* Enlarge lexical value queue */ 849 size_t p = (size_t) (yylvp - yylvals); 850 size_t s = (size_t) (yylvlim - yylvals); 851 852 s += YYLVQUEUEGROWTH; 853 if ((yylexemes = (short *) realloc(yylexemes, s * sizeof(short))) == NULL) goto yyenomem; 854 if ((yylvals = (YYSTYPE *) realloc(yylvals, s * sizeof(YYSTYPE))) == NULL) goto yyenomem; 855 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 856 if ((yylpsns = (YYLTYPE *) realloc(yylpsns, s * sizeof(YYLTYPE))) == NULL) goto yyenomem; 857 #endif 858 yylvp = yylve = yylvals + p; 859 yylvlim = yylvals + s; 860 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 861 yylpp = yylpe = yylpsns + p; 862 yylplim = yylpsns + s; 863 #endif 864 yylexp = yylexemes + p; 865 } 866 *yylexp = (short) YYLEX; 867 *yylvp++ = yylval; 868 yylve++; 869 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 870 *yylpp++ = yylloc; 871 yylpe++; 872 #endif 873 yychar = *yylexp++; 874 break; 875 } 876 /* normal operation, no conflict encountered */ 877 #endif /* YYBTYACC */ 878 yychar = YYLEX; 879 #if YYBTYACC 880 } while (0); 881 #endif /* YYBTYACC */ 882 if (yychar < 0) yychar = YYEOF; 883 #if YYDEBUG 884 if (yydebug) 885 { 886 if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN]; 887 fprintf(stderr, "%s[%d]: state %d, reading token %d (%s)", 888 YYDEBUGSTR, yydepth, yystate, yychar, yys); 889 #ifdef YYSTYPE_TOSTRING 890 #if YYBTYACC 891 if (!yytrial) 892 #endif /* YYBTYACC */ 893 fprintf(stderr, " <%s>", YYSTYPE_TOSTRING(yychar, yylval)); 894 #endif 895 fputc('\n', stderr); 896 } 897 #endif 898 } 899 #if YYBTYACC 900 901 /* Do we have a conflict? */ 902 if (((yyn = yycindex[yystate]) != 0) && (yyn += yychar) >= 0 && 903 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar) 904 { 905 YYINT ctry; 906 907 if (yypath) 908 { 909 YYParseState *save; 910 #if YYDEBUG 911 if (yydebug) 912 fprintf(stderr, "%s[%d]: CONFLICT in state %d: following successful trial parse\n", 913 YYDEBUGSTR, yydepth, yystate); 914 #endif 915 /* Switch to the next conflict context */ 916 save = yypath; 917 yypath = save->save; 918 save->save = NULL; 919 ctry = save->ctry; 920 if (save->state != yystate) YYABORT; 921 yyFreeState(save); 922 923 } 924 else 925 { 926 927 /* Unresolved conflict - start/continue trial parse */ 928 YYParseState *save; 929 #if YYDEBUG 930 if (yydebug) 931 { 932 fprintf(stderr, "%s[%d]: CONFLICT in state %d. ", YYDEBUGSTR, yydepth, yystate); 933 if (yyps->save) 934 fputs("ALREADY in conflict, continuing trial parse.\n", stderr); 935 else 936 fputs("Starting trial parse.\n", stderr); 937 } 938 #endif 939 save = yyNewState((unsigned)(yystack.s_mark - yystack.s_base + 1)); 940 if (save == NULL) goto yyenomem; 941 save->save = yyps->save; 942 save->state = yystate; 943 save->errflag = yyerrflag; 944 save->yystack.s_mark = save->yystack.s_base + (yystack.s_mark - yystack.s_base); 945 memcpy (save->yystack.s_base, yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(YYINT)); 946 save->yystack.l_mark = save->yystack.l_base + (yystack.l_mark - yystack.l_base); 947 memcpy (save->yystack.l_base, yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE)); 948 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 949 save->yystack.p_mark = save->yystack.p_base + (yystack.p_mark - yystack.p_base); 950 memcpy (save->yystack.p_base, yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE)); 951 #endif 952 ctry = yytable[yyn]; 953 if (yyctable[ctry] == -1) 954 { 955 #if YYDEBUG 956 if (yydebug && yychar >= YYEOF) 957 fprintf(stderr, "%s[%d]: backtracking 1 token\n", YYDEBUGSTR, yydepth); 958 #endif 959 ctry++; 960 } 961 save->ctry = ctry; 962 if (yyps->save == NULL) 963 { 964 /* If this is a first conflict in the stack, start saving lexemes */ 965 if (!yylexemes) 966 { 967 yylexemes = (short *) malloc((YYLVQUEUEGROWTH) * sizeof(short)); 968 if (yylexemes == NULL) goto yyenomem; 969 yylvals = (YYSTYPE *) malloc((YYLVQUEUEGROWTH) * sizeof(YYSTYPE)); 970 if (yylvals == NULL) goto yyenomem; 971 yylvlim = yylvals + YYLVQUEUEGROWTH; 972 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 973 yylpsns = (YYLTYPE *) malloc((YYLVQUEUEGROWTH) * sizeof(YYLTYPE)); 974 if (yylpsns == NULL) goto yyenomem; 975 yylplim = yylpsns + YYLVQUEUEGROWTH; 976 #endif 977 } 978 if (yylvp == yylve) 979 { 980 yylvp = yylve = yylvals; 981 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 982 yylpp = yylpe = yylpsns; 983 #endif 984 yylexp = yylexemes; 985 if (yychar >= YYEOF) 986 { 987 *yylve++ = yylval; 988 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 989 *yylpe++ = yylloc; 990 #endif 991 *yylexp = (short) yychar; 992 yychar = YYEMPTY; 993 } 994 } 995 } 996 if (yychar >= YYEOF) 997 { 998 yylvp--; 999 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1000 yylpp--; 1001 #endif 1002 yylexp--; 1003 yychar = YYEMPTY; 1004 } 1005 save->lexeme = (int) (yylvp - yylvals); 1006 yyps->save = save; 1007 } 1008 if (yytable[yyn] == ctry) 1009 { 1010 #if YYDEBUG 1011 if (yydebug) 1012 fprintf(stderr, "%s[%d]: state %d, shifting to state %d\n", 1013 YYDEBUGSTR, yydepth, yystate, yyctable[ctry]); 1014 #endif 1015 if (yychar < 0) 1016 { 1017 yylvp++; 1018 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1019 yylpp++; 1020 #endif 1021 yylexp++; 1022 } 1023 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) 1024 goto yyoverflow; 1025 yystate = yyctable[ctry]; 1026 *++yystack.s_mark = (YYINT) yystate; 1027 *++yystack.l_mark = yylval; 1028 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1029 *++yystack.p_mark = yylloc; 1030 #endif 1031 yychar = YYEMPTY; 1032 if (yyerrflag > 0) --yyerrflag; 1033 goto yyloop; 1034 } 1035 else 1036 { 1037 yyn = yyctable[ctry]; 1038 goto yyreduce; 1039 } 1040 } /* End of code dealing with conflicts */ 1041 #endif /* YYBTYACC */ 1042 if (((yyn = yysindex[yystate]) != 0) && (yyn += yychar) >= 0 && 1043 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar) 1044 { 1045 #if YYDEBUG 1046 if (yydebug) 1047 fprintf(stderr, "%s[%d]: state %d, shifting to state %d\n", 1048 YYDEBUGSTR, yydepth, yystate, yytable[yyn]); 1049 #endif 1050 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow; 1051 yystate = yytable[yyn]; 1052 *++yystack.s_mark = yytable[yyn]; 1053 *++yystack.l_mark = yylval; 1054 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1055 *++yystack.p_mark = yylloc; 1056 #endif 1057 yychar = YYEMPTY; 1058 if (yyerrflag > 0) --yyerrflag; 1059 goto yyloop; 1060 } 1061 if (((yyn = yyrindex[yystate]) != 0) && (yyn += yychar) >= 0 && 1062 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar) 1063 { 1064 yyn = yytable[yyn]; 1065 goto yyreduce; 1066 } 1067 if (yyerrflag != 0) goto yyinrecovery; 1068 #if YYBTYACC 1069 1070 yynewerrflag = 1; 1071 goto yyerrhandler; 1072 goto yyerrlab; /* redundant goto avoids 'unused label' warning */ 1073 1074 yyerrlab: 1075 /* explicit YYERROR from an action -- pop the rhs of the rule reduced 1076 * before looking for error recovery */ 1077 yystack.s_mark -= yym; 1078 yystate = *yystack.s_mark; 1079 yystack.l_mark -= yym; 1080 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1081 yystack.p_mark -= yym; 1082 #endif 1083 1084 yynewerrflag = 0; 1085 yyerrhandler: 1086 while (yyps->save) 1087 { 1088 int ctry; 1089 YYParseState *save = yyps->save; 1090 #if YYDEBUG 1091 if (yydebug) 1092 fprintf(stderr, "%s[%d]: ERROR in state %d, CONFLICT BACKTRACKING to state %d, %d tokens\n", 1093 YYDEBUGSTR, yydepth, yystate, yyps->save->state, 1094 (int)(yylvp - yylvals - yyps->save->lexeme)); 1095 #endif 1096 /* Memorize most forward-looking error state in case it's really an error. */ 1097 if (yyerrctx == NULL || yyerrctx->lexeme < yylvp - yylvals) 1098 { 1099 /* Free old saved error context state */ 1100 if (yyerrctx) yyFreeState(yyerrctx); 1101 /* Create and fill out new saved error context state */ 1102 yyerrctx = yyNewState((unsigned)(yystack.s_mark - yystack.s_base + 1)); 1103 if (yyerrctx == NULL) goto yyenomem; 1104 yyerrctx->save = yyps->save; 1105 yyerrctx->state = yystate; 1106 yyerrctx->errflag = yyerrflag; 1107 yyerrctx->yystack.s_mark = yyerrctx->yystack.s_base + (yystack.s_mark - yystack.s_base); 1108 memcpy (yyerrctx->yystack.s_base, yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(YYINT)); 1109 yyerrctx->yystack.l_mark = yyerrctx->yystack.l_base + (yystack.l_mark - yystack.l_base); 1110 memcpy (yyerrctx->yystack.l_base, yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE)); 1111 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1112 yyerrctx->yystack.p_mark = yyerrctx->yystack.p_base + (yystack.p_mark - yystack.p_base); 1113 memcpy (yyerrctx->yystack.p_base, yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE)); 1114 #endif 1115 yyerrctx->lexeme = (int) (yylvp - yylvals); 1116 } 1117 yylvp = yylvals + save->lexeme; 1118 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1119 yylpp = yylpsns + save->lexeme; 1120 #endif 1121 yylexp = yylexemes + save->lexeme; 1122 yychar = YYEMPTY; 1123 yystack.s_mark = yystack.s_base + (save->yystack.s_mark - save->yystack.s_base); 1124 memcpy (yystack.s_base, save->yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(YYINT)); 1125 yystack.l_mark = yystack.l_base + (save->yystack.l_mark - save->yystack.l_base); 1126 memcpy (yystack.l_base, save->yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE)); 1127 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1128 yystack.p_mark = yystack.p_base + (save->yystack.p_mark - save->yystack.p_base); 1129 memcpy (yystack.p_base, save->yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE)); 1130 #endif 1131 ctry = ++save->ctry; 1132 yystate = save->state; 1133 /* We tried shift, try reduce now */ 1134 if ((yyn = yyctable[ctry]) >= 0) goto yyreduce; 1135 yyps->save = save->save; 1136 save->save = NULL; 1137 yyFreeState(save); 1138 1139 /* Nothing left on the stack -- error */ 1140 if (!yyps->save) 1141 { 1142 #if YYDEBUG 1143 if (yydebug) 1144 fprintf(stderr, "%sdebug[%d,trial]: trial parse FAILED, entering ERROR mode\n", 1145 YYPREFIX, yydepth); 1146 #endif 1147 /* Restore state as it was in the most forward-advanced error */ 1148 yylvp = yylvals + yyerrctx->lexeme; 1149 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1150 yylpp = yylpsns + yyerrctx->lexeme; 1151 #endif 1152 yylexp = yylexemes + yyerrctx->lexeme; 1153 yychar = yylexp[-1]; 1154 yylval = yylvp[-1]; 1155 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1156 yylloc = yylpp[-1]; 1157 #endif 1158 yystack.s_mark = yystack.s_base + (yyerrctx->yystack.s_mark - yyerrctx->yystack.s_base); 1159 memcpy (yystack.s_base, yyerrctx->yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(YYINT)); 1160 yystack.l_mark = yystack.l_base + (yyerrctx->yystack.l_mark - yyerrctx->yystack.l_base); 1161 memcpy (yystack.l_base, yyerrctx->yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE)); 1162 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1163 yystack.p_mark = yystack.p_base + (yyerrctx->yystack.p_mark - yyerrctx->yystack.p_base); 1164 memcpy (yystack.p_base, yyerrctx->yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE)); 1165 #endif 1166 yystate = yyerrctx->state; 1167 yyFreeState(yyerrctx); 1168 yyerrctx = NULL; 1169 } 1170 yynewerrflag = 1; 1171 } 1172 if (yynewerrflag == 0) goto yyinrecovery; 1173 #endif /* YYBTYACC */ 1174 1175 YYERROR_CALL("syntax error"); 1176 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1177 yyerror_loc_range[0] = yylloc; /* lookahead position is error start position */ 1178 #endif 1179 1180 #if !YYBTYACC 1181 goto yyerrlab; /* redundant goto avoids 'unused label' warning */ 1182 yyerrlab: 1183 #endif 1184 ++yynerrs; 1185 1186 yyinrecovery: 1187 if (yyerrflag < 3) 1188 { 1189 yyerrflag = 3; 1190 for (;;) 1191 { 1192 if (((yyn = yysindex[*yystack.s_mark]) != 0) && (yyn += YYERRCODE) >= 0 && 1193 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) YYERRCODE) 1194 { 1195 #if YYDEBUG 1196 if (yydebug) 1197 fprintf(stderr, "%s[%d]: state %d, error recovery shifting to state %d\n", 1198 YYDEBUGSTR, yydepth, *yystack.s_mark, yytable[yyn]); 1199 #endif 1200 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow; 1201 yystate = yytable[yyn]; 1202 *++yystack.s_mark = yytable[yyn]; 1203 *++yystack.l_mark = yylval; 1204 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1205 /* lookahead position is error end position */ 1206 yyerror_loc_range[1] = yylloc; 1207 YYLLOC_DEFAULT(yyloc, yyerror_loc_range, 2); /* position of error span */ 1208 *++yystack.p_mark = yyloc; 1209 #endif 1210 goto yyloop; 1211 } 1212 else 1213 { 1214 #if YYDEBUG 1215 if (yydebug) 1216 fprintf(stderr, "%s[%d]: error recovery discarding state %d\n", 1217 YYDEBUGSTR, yydepth, *yystack.s_mark); 1218 #endif 1219 if (yystack.s_mark <= yystack.s_base) goto yyabort; 1220 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1221 /* the current TOS position is the error start position */ 1222 yyerror_loc_range[0] = *yystack.p_mark; 1223 #endif 1224 #if defined(YYDESTRUCT_CALL) 1225 #if YYBTYACC 1226 if (!yytrial) 1227 #endif /* YYBTYACC */ 1228 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1229 YYDESTRUCT_CALL("error: discarding state", 1230 yystos[*yystack.s_mark], yystack.l_mark, yystack.p_mark); 1231 #else 1232 YYDESTRUCT_CALL("error: discarding state", 1233 yystos[*yystack.s_mark], yystack.l_mark); 1234 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */ 1235 #endif /* defined(YYDESTRUCT_CALL) */ 1236 --yystack.s_mark; 1237 --yystack.l_mark; 1238 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1239 --yystack.p_mark; 1240 #endif 1241 } 1242 } 1243 } 1244 else 1245 { 1246 if (yychar == YYEOF) goto yyabort; 1247 #if YYDEBUG 1248 if (yydebug) 1249 { 1250 if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN]; 1251 fprintf(stderr, "%s[%d]: state %d, error recovery discarding token %d (%s)\n", 1252 YYDEBUGSTR, yydepth, yystate, yychar, yys); 1253 } 1254 #endif 1255 #if defined(YYDESTRUCT_CALL) 1256 #if YYBTYACC 1257 if (!yytrial) 1258 #endif /* YYBTYACC */ 1259 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1260 YYDESTRUCT_CALL("error: discarding token", yychar, &yylval, &yylloc); 1261 #else 1262 YYDESTRUCT_CALL("error: discarding token", yychar, &yylval); 1263 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */ 1264 #endif /* defined(YYDESTRUCT_CALL) */ 1265 yychar = YYEMPTY; 1266 goto yyloop; 1267 } 1268 1269 yyreduce: 1270 yym = yylen[yyn]; 1271 #if YYDEBUG 1272 if (yydebug) 1273 { 1274 fprintf(stderr, "%s[%d]: state %d, reducing by rule %d (%s)", 1275 YYDEBUGSTR, yydepth, yystate, yyn, yyrule[yyn]); 1276 #ifdef YYSTYPE_TOSTRING 1277 #if YYBTYACC 1278 if (!yytrial) 1279 #endif /* YYBTYACC */ 1280 if (yym > 0) 1281 { 1282 int i; 1283 fputc('<', stderr); 1284 for (i = yym; i > 0; i--) 1285 { 1286 if (i != yym) fputs(", ", stderr); 1287 fputs(YYSTYPE_TOSTRING(yystos[yystack.s_mark[1-i]], 1288 yystack.l_mark[1-i]), stderr); 1289 } 1290 fputc('>', stderr); 1291 } 1292 #endif 1293 fputc('\n', stderr); 1294 } 1295 #endif 1296 if (yym > 0) 1297 yyval = yystack.l_mark[1-yym]; 1298 else 1299 memset(&yyval, 0, sizeof yyval); 1300 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1301 1302 /* Perform position reduction */ 1303 memset(&yyloc, 0, sizeof(yyloc)); 1304 #if YYBTYACC 1305 if (!yytrial) 1306 #endif /* YYBTYACC */ 1307 { 1308 YYLLOC_DEFAULT(yyloc, &yystack.p_mark[1-yym], yym); 1309 /* just in case YYERROR is invoked within the action, save 1310 the start of the rhs as the error start position */ 1311 yyerror_loc_range[0] = yystack.p_mark[1-yym]; 1312 } 1313 #endif 1314 1315 switch (yyn) 1316 { 1317 case 3: 1318 #line 59 "varsyntax_calc1.y" 1319 { 1320 (void) printf("%15.8f\n", yystack.l_mark[-1].dval); 1321 } 1322 break; 1323 case 4: 1324 #line 63 "varsyntax_calc1.y" 1325 { 1326 (void) printf("(%15.8f, %15.8f)\n", yystack.l_mark[-1].vval.lo, yystack.l_mark[-1].vval.hi); 1327 } 1328 break; 1329 case 5: 1330 #line 67 "varsyntax_calc1.y" 1331 { 1332 dreg[yystack.l_mark[-3].ival] = yystack.l_mark[-1].dval; 1333 } 1334 break; 1335 case 6: 1336 #line 71 "varsyntax_calc1.y" 1337 { 1338 vreg[yystack.l_mark[-3].ival] = yystack.l_mark[-1].vval; 1339 } 1340 break; 1341 case 7: 1342 #line 75 "varsyntax_calc1.y" 1343 { 1344 yyerrok; 1345 } 1346 break; 1347 case 9: 1348 #line 82 "varsyntax_calc1.y" 1349 { 1350 yyval.dval = dreg[yystack.l_mark[0].ival]; /* $$ & $1 are sufficient here*/ 1351 } 1352 break; 1353 case 10: 1354 #line 86 "varsyntax_calc1.y" 1355 { 1356 yyval.dval = yystack.l_mark[-2].dval + yystack.l_mark[0].dval; 1357 } 1358 break; 1359 case 11: 1360 #line 90 "varsyntax_calc1.y" 1361 { 1362 yyval.dval = yystack.l_mark[-2].dval - yystack.l_mark[0].dval; 1363 } 1364 break; 1365 case 12: 1366 #line 94 "varsyntax_calc1.y" 1367 { 1368 yyval.dval = yystack.l_mark[-2].dval * yystack.l_mark[0].dval; 1369 } 1370 break; 1371 case 13: 1372 #line 98 "varsyntax_calc1.y" 1373 { 1374 yyval.dval = yystack.l_mark[-2].dval / yystack.l_mark[0].dval; 1375 } 1376 break; 1377 case 14: 1378 #line 102 "varsyntax_calc1.y" 1379 { 1380 yyval.dval = -yystack.l_mark[0].dval; 1381 } 1382 break; 1383 case 15: 1384 #line 106 "varsyntax_calc1.y" 1385 { 1386 yyval.dval = yystack.l_mark[-1].dval; 1387 } 1388 break; 1389 case 16: 1390 #line 112 "varsyntax_calc1.y" 1391 { 1392 yyval.vval.hi = yyval.vval.lo = yystack.l_mark[0].dval; 1393 } 1394 break; 1395 case 17: 1396 #line 116 "varsyntax_calc1.y" 1397 { 1398 yyval.vval.lo = yystack.l_mark[-3].dval; 1399 yyval.vval.hi = yystack.l_mark[-1].dval; 1400 if ( yyval.vval.lo > yyval.vval.hi ) 1401 { 1402 (void) printf("interval out of order\n"); 1403 YYERROR; 1404 } 1405 } 1406 break; 1407 case 18: 1408 #line 126 "varsyntax_calc1.y" 1409 { 1410 yyval.vval = vreg[yystack.l_mark[0].ival]; 1411 } 1412 break; 1413 case 19: 1414 #line 130 "varsyntax_calc1.y" 1415 { 1416 yyval.vval.hi = yystack.l_mark[-2].vval.hi + yystack.l_mark[0].vval.hi; 1417 yyval.vval.lo = yystack.l_mark[-2].vval.lo + yystack.l_mark[0].vval.lo; 1418 } 1419 break; 1420 case 20: 1421 #line 135 "varsyntax_calc1.y" 1422 { 1423 yyval.vval.hi = yystack.l_mark[-2].dval + yystack.l_mark[0].vval.hi; 1424 yyval.vval.lo = yystack.l_mark[-2].dval + yystack.l_mark[0].vval.lo; 1425 } 1426 break; 1427 case 21: 1428 #line 140 "varsyntax_calc1.y" 1429 { 1430 yyval.vval.hi = yystack.l_mark[-2].vval.hi - yystack.l_mark[0].vval.lo; 1431 yyval.vval.lo = yystack.l_mark[-2].vval.lo - yystack.l_mark[0].vval.hi; 1432 } 1433 break; 1434 case 22: 1435 #line 145 "varsyntax_calc1.y" 1436 { 1437 yyval.vval.hi = yystack.l_mark[-2].dval - yystack.l_mark[0].vval.lo; 1438 yyval.vval.lo = yystack.l_mark[-2].dval - yystack.l_mark[0].vval.hi; 1439 } 1440 break; 1441 case 23: 1442 #line 150 "varsyntax_calc1.y" 1443 { 1444 yyval.vval = vmul( yystack.l_mark[-2].vval.lo, yystack.l_mark[-2].vval.hi, yystack.l_mark[0].vval ); 1445 } 1446 break; 1447 case 24: 1448 #line 154 "varsyntax_calc1.y" 1449 { 1450 yyval.vval = vmul (yystack.l_mark[-2].dval, yystack.l_mark[-2].dval, yystack.l_mark[0].vval ); 1451 } 1452 break; 1453 case 25: 1454 #line 158 "varsyntax_calc1.y" 1455 { 1456 if (dcheck(yystack.l_mark[0].vval)) YYERROR; 1457 yyval.vval = vdiv ( yystack.l_mark[-2].vval.lo, yystack.l_mark[-2].vval.hi, yystack.l_mark[0].vval ); 1458 } 1459 break; 1460 case 26: 1461 #line 163 "varsyntax_calc1.y" 1462 { 1463 if (dcheck ( yystack.l_mark[0].vval )) YYERROR; 1464 yyval.vval = vdiv (yystack.l_mark[-2].dval, yystack.l_mark[-2].dval, yystack.l_mark[0].vval ); 1465 } 1466 break; 1467 case 27: 1468 #line 168 "varsyntax_calc1.y" 1469 { 1470 yyval.vval.hi = -yystack.l_mark[0].vval.lo; 1471 yyval.vval.lo = -yystack.l_mark[0].vval.hi; 1472 } 1473 break; 1474 case 28: 1475 #line 173 "varsyntax_calc1.y" 1476 { 1477 yyval.vval = yystack.l_mark[-1].vval; 1478 } 1479 break; 1480 #line 1481 "varsyntax_calc1.tab.c" 1481 default: 1482 break; 1483 } 1484 yystack.s_mark -= yym; 1485 yystate = *yystack.s_mark; 1486 yystack.l_mark -= yym; 1487 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1488 yystack.p_mark -= yym; 1489 #endif 1490 yym = yylhs[yyn]; 1491 if (yystate == 0 && yym == 0) 1492 { 1493 #if YYDEBUG 1494 if (yydebug) 1495 { 1496 fprintf(stderr, "%s[%d]: after reduction, ", YYDEBUGSTR, yydepth); 1497 #ifdef YYSTYPE_TOSTRING 1498 #if YYBTYACC 1499 if (!yytrial) 1500 #endif /* YYBTYACC */ 1501 fprintf(stderr, "result is <%s>, ", YYSTYPE_TOSTRING(yystos[YYFINAL], yyval)); 1502 #endif 1503 fprintf(stderr, "shifting from state 0 to final state %d\n", YYFINAL); 1504 } 1505 #endif 1506 yystate = YYFINAL; 1507 *++yystack.s_mark = YYFINAL; 1508 *++yystack.l_mark = yyval; 1509 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1510 *++yystack.p_mark = yyloc; 1511 #endif 1512 if (yychar < 0) 1513 { 1514 #if YYBTYACC 1515 do { 1516 if (yylvp < yylve) 1517 { 1518 /* we're currently re-reading tokens */ 1519 yylval = *yylvp++; 1520 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1521 yylloc = *yylpp++; 1522 #endif 1523 yychar = *yylexp++; 1524 break; 1525 } 1526 if (yyps->save) 1527 { 1528 /* in trial mode; save scanner results for future parse attempts */ 1529 if (yylvp == yylvlim) 1530 { /* Enlarge lexical value queue */ 1531 size_t p = (size_t) (yylvp - yylvals); 1532 size_t s = (size_t) (yylvlim - yylvals); 1533 1534 s += YYLVQUEUEGROWTH; 1535 if ((yylexemes = (short *) realloc(yylexemes, s * sizeof(short))) == NULL) 1536 goto yyenomem; 1537 if ((yylvals = (YYSTYPE *) realloc(yylvals, s * sizeof(YYSTYPE))) == NULL) 1538 goto yyenomem; 1539 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1540 if ((yylpsns = (YYLTYPE *) realloc(yylpsns, s * sizeof(YYLTYPE))) == NULL) 1541 goto yyenomem; 1542 #endif 1543 yylvp = yylve = yylvals + p; 1544 yylvlim = yylvals + s; 1545 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1546 yylpp = yylpe = yylpsns + p; 1547 yylplim = yylpsns + s; 1548 #endif 1549 yylexp = yylexemes + p; 1550 } 1551 *yylexp = (short) YYLEX; 1552 *yylvp++ = yylval; 1553 yylve++; 1554 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1555 *yylpp++ = yylloc; 1556 yylpe++; 1557 #endif 1558 yychar = *yylexp++; 1559 break; 1560 } 1561 /* normal operation, no conflict encountered */ 1562 #endif /* YYBTYACC */ 1563 yychar = YYLEX; 1564 #if YYBTYACC 1565 } while (0); 1566 #endif /* YYBTYACC */ 1567 if (yychar < 0) yychar = YYEOF; 1568 #if YYDEBUG 1569 if (yydebug) 1570 { 1571 if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN]; 1572 fprintf(stderr, "%s[%d]: state %d, reading token %d (%s)\n", 1573 YYDEBUGSTR, yydepth, YYFINAL, yychar, yys); 1574 } 1575 #endif 1576 } 1577 if (yychar == YYEOF) goto yyaccept; 1578 goto yyloop; 1579 } 1580 if (((yyn = yygindex[yym]) != 0) && (yyn += yystate) >= 0 && 1581 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yystate) 1582 yystate = yytable[yyn]; 1583 else 1584 yystate = yydgoto[yym]; 1585 #if YYDEBUG 1586 if (yydebug) 1587 { 1588 fprintf(stderr, "%s[%d]: after reduction, ", YYDEBUGSTR, yydepth); 1589 #ifdef YYSTYPE_TOSTRING 1590 #if YYBTYACC 1591 if (!yytrial) 1592 #endif /* YYBTYACC */ 1593 fprintf(stderr, "result is <%s>, ", YYSTYPE_TOSTRING(yystos[yystate], yyval)); 1594 #endif 1595 fprintf(stderr, "shifting from state %d to state %d\n", *yystack.s_mark, yystate); 1596 } 1597 #endif 1598 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow; 1599 *++yystack.s_mark = (YYINT) yystate; 1600 *++yystack.l_mark = yyval; 1601 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1602 *++yystack.p_mark = yyloc; 1603 #endif 1604 goto yyloop; 1605 #if YYBTYACC 1606 1607 /* Reduction declares that this path is valid. Set yypath and do a full parse */ 1608 yyvalid: 1609 if (yypath) YYABORT; 1610 while (yyps->save) 1611 { 1612 YYParseState *save = yyps->save; 1613 yyps->save = save->save; 1614 save->save = yypath; 1615 yypath = save; 1616 } 1617 #if YYDEBUG 1618 if (yydebug) 1619 fprintf(stderr, "%s[%d]: state %d, CONFLICT trial successful, backtracking to state %d, %d tokens\n", 1620 YYDEBUGSTR, yydepth, yystate, yypath->state, (int)(yylvp - yylvals - yypath->lexeme)); 1621 #endif 1622 if (yyerrctx) 1623 { 1624 yyFreeState(yyerrctx); 1625 yyerrctx = NULL; 1626 } 1627 yylvp = yylvals + yypath->lexeme; 1628 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1629 yylpp = yylpsns + yypath->lexeme; 1630 #endif 1631 yylexp = yylexemes + yypath->lexeme; 1632 yychar = YYEMPTY; 1633 yystack.s_mark = yystack.s_base + (yypath->yystack.s_mark - yypath->yystack.s_base); 1634 memcpy (yystack.s_base, yypath->yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(YYINT)); 1635 yystack.l_mark = yystack.l_base + (yypath->yystack.l_mark - yypath->yystack.l_base); 1636 memcpy (yystack.l_base, yypath->yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE)); 1637 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1638 yystack.p_mark = yystack.p_base + (yypath->yystack.p_mark - yypath->yystack.p_base); 1639 memcpy (yystack.p_base, yypath->yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE)); 1640 #endif 1641 yystate = yypath->state; 1642 goto yyloop; 1643 #endif /* YYBTYACC */ 1644 1645 yyoverflow: 1646 YYERROR_CALL("yacc stack overflow"); 1647 #if YYBTYACC 1648 goto yyabort_nomem; 1649 yyenomem: 1650 YYERROR_CALL("memory exhausted"); 1651 yyabort_nomem: 1652 #endif /* YYBTYACC */ 1653 yyresult = 2; 1654 goto yyreturn; 1655 1656 yyabort: 1657 yyresult = 1; 1658 goto yyreturn; 1659 1660 yyaccept: 1661 #if YYBTYACC 1662 if (yyps->save) goto yyvalid; 1663 #endif /* YYBTYACC */ 1664 yyresult = 0; 1665 1666 yyreturn: 1667 #if defined(YYDESTRUCT_CALL) 1668 if (yychar != YYEOF && yychar != YYEMPTY) 1669 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1670 YYDESTRUCT_CALL("cleanup: discarding token", yychar, &yylval, &yylloc); 1671 #else 1672 YYDESTRUCT_CALL("cleanup: discarding token", yychar, &yylval); 1673 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */ 1674 1675 { 1676 YYSTYPE *pv; 1677 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1678 YYLTYPE *pp; 1679 1680 for (pv = yystack.l_base, pp = yystack.p_base; pv <= yystack.l_mark; ++pv, ++pp) 1681 YYDESTRUCT_CALL("cleanup: discarding state", 1682 yystos[*(yystack.s_base + (pv - yystack.l_base))], pv, pp); 1683 #else 1684 for (pv = yystack.l_base; pv <= yystack.l_mark; ++pv) 1685 YYDESTRUCT_CALL("cleanup: discarding state", 1686 yystos[*(yystack.s_base + (pv - yystack.l_base))], pv); 1687 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */ 1688 } 1689 #endif /* defined(YYDESTRUCT_CALL) */ 1690 1691 #if YYBTYACC 1692 if (yyerrctx) 1693 { 1694 yyFreeState(yyerrctx); 1695 yyerrctx = NULL; 1696 } 1697 while (yyps) 1698 { 1699 YYParseState *save = yyps; 1700 yyps = save->save; 1701 save->save = NULL; 1702 yyFreeState(save); 1703 } 1704 while (yypath) 1705 { 1706 YYParseState *save = yypath; 1707 yypath = save->save; 1708 save->save = NULL; 1709 yyFreeState(save); 1710 } 1711 #endif /* YYBTYACC */ 1712 yyfreestack(&yystack); 1713 return (yyresult); 1714 } 1715