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