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