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