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