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