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