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