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