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