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