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