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 661 #if YYBTYACC 662 yyps = yyNewState(0); if (yyps == 0) goto yyenomem; 663 yyps->save = 0; 664 #endif /* YYBTYACC */ 665 yym = 0; 666 yyn = 0; 667 yynerrs = 0; 668 yyerrflag = 0; 669 yychar = YYEMPTY; 670 yystate = 0; 671 672 #if YYPURE 673 memset(&yystack, 0, sizeof(yystack)); 674 #endif 675 676 if (yystack.s_base == NULL && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow; 677 yystack.s_mark = yystack.s_base; 678 yystack.l_mark = yystack.l_base; 679 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 680 yystack.p_mark = yystack.p_base; 681 #endif 682 yystate = 0; 683 *yystack.s_mark = 0; 684 685 yyloop: 686 if ((yyn = yydefred[yystate]) != 0) goto yyreduce; 687 if (yychar < 0) 688 { 689 #if YYBTYACC 690 do { 691 if (yylvp < yylve) 692 { 693 /* we're currently re-reading tokens */ 694 yylval = *yylvp++; 695 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 696 yylloc = *yylpp++; 697 #endif 698 yychar = *yylexp++; 699 break; 700 } 701 if (yyps->save) 702 { 703 /* in trial mode; save scanner results for future parse attempts */ 704 if (yylvp == yylvlim) 705 { /* Enlarge lexical value queue */ 706 size_t p = (size_t) (yylvp - yylvals); 707 size_t s = (size_t) (yylvlim - yylvals); 708 709 s += YYLVQUEUEGROWTH; 710 if ((yylexemes = realloc(yylexemes, s * sizeof(YYINT))) == NULL) goto yyenomem; 711 if ((yylvals = realloc(yylvals, s * sizeof(YYSTYPE))) == NULL) goto yyenomem; 712 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 713 if ((yylpsns = realloc(yylpsns, s * sizeof(YYLTYPE))) == NULL) goto yyenomem; 714 #endif 715 yylvp = yylve = yylvals + p; 716 yylvlim = yylvals + s; 717 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 718 yylpp = yylpe = yylpsns + p; 719 yylplim = yylpsns + s; 720 #endif 721 yylexp = yylexemes + p; 722 } 723 *yylexp = (YYINT) YYLEX; 724 *yylvp++ = yylval; 725 yylve++; 726 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 727 *yylpp++ = yylloc; 728 yylpe++; 729 #endif 730 yychar = *yylexp++; 731 break; 732 } 733 /* normal operation, no conflict encountered */ 734 #endif /* YYBTYACC */ 735 yychar = YYLEX; 736 #if YYBTYACC 737 } while (0); 738 #endif /* YYBTYACC */ 739 if (yychar < 0) yychar = YYEOF; 740 #if YYDEBUG 741 if (yydebug) 742 { 743 if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN]; 744 fprintf(stderr, "%s[%d]: state %d, reading token %d (%s)", 745 YYDEBUGSTR, yydepth, yystate, yychar, yys); 746 #ifdef YYSTYPE_TOSTRING 747 #if YYBTYACC 748 if (!yytrial) 749 #endif /* YYBTYACC */ 750 fprintf(stderr, " <%s>", YYSTYPE_TOSTRING(yychar, yylval)); 751 #endif 752 fputc('\n', stderr); 753 } 754 #endif 755 } 756 #if YYBTYACC 757 758 /* Do we have a conflict? */ 759 if (((yyn = yycindex[yystate]) != 0) && (yyn += yychar) >= 0 && 760 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar) 761 { 762 YYINT ctry; 763 764 if (yypath) 765 { 766 YYParseState *save; 767 #if YYDEBUG 768 if (yydebug) 769 fprintf(stderr, "%s[%d]: CONFLICT in state %d: following successful trial parse\n", 770 YYDEBUGSTR, yydepth, yystate); 771 #endif 772 /* Switch to the next conflict context */ 773 save = yypath; 774 yypath = save->save; 775 save->save = NULL; 776 ctry = save->ctry; 777 if (save->state != yystate) YYABORT; 778 yyFreeState(save); 779 780 } 781 else 782 { 783 784 /* Unresolved conflict - start/continue trial parse */ 785 YYParseState *save; 786 #if YYDEBUG 787 if (yydebug) 788 { 789 fprintf(stderr, "%s[%d]: CONFLICT in state %d. ", YYDEBUGSTR, yydepth, yystate); 790 if (yyps->save) 791 fputs("ALREADY in conflict, continuing trial parse.\n", stderr); 792 else 793 fputs("Starting trial parse.\n", stderr); 794 } 795 #endif 796 save = yyNewState((unsigned)(yystack.s_mark - yystack.s_base + 1)); 797 if (save == NULL) goto yyenomem; 798 save->save = yyps->save; 799 save->state = yystate; 800 save->errflag = yyerrflag; 801 save->yystack.s_mark = save->yystack.s_base + (yystack.s_mark - yystack.s_base); 802 memcpy (save->yystack.s_base, yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(YYINT)); 803 save->yystack.l_mark = save->yystack.l_base + (yystack.l_mark - yystack.l_base); 804 memcpy (save->yystack.l_base, yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE)); 805 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 806 save->yystack.p_mark = save->yystack.p_base + (yystack.p_mark - yystack.p_base); 807 memcpy (save->yystack.p_base, yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE)); 808 #endif 809 ctry = yytable[yyn]; 810 if (yyctable[ctry] == -1) 811 { 812 #if YYDEBUG 813 if (yydebug && yychar >= YYEOF) 814 fprintf(stderr, "%s[%d]: backtracking 1 token\n", YYDEBUGSTR, yydepth); 815 #endif 816 ctry++; 817 } 818 save->ctry = ctry; 819 if (yyps->save == NULL) 820 { 821 /* If this is a first conflict in the stack, start saving lexemes */ 822 if (!yylexemes) 823 { 824 yylexemes = malloc((YYLVQUEUEGROWTH) * sizeof(YYINT)); 825 if (yylexemes == NULL) goto yyenomem; 826 yylvals = (YYSTYPE *) malloc((YYLVQUEUEGROWTH) * sizeof(YYSTYPE)); 827 if (yylvals == NULL) goto yyenomem; 828 yylvlim = yylvals + YYLVQUEUEGROWTH; 829 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 830 yylpsns = (YYLTYPE *) malloc((YYLVQUEUEGROWTH) * sizeof(YYLTYPE)); 831 if (yylpsns == NULL) goto yyenomem; 832 yylplim = yylpsns + YYLVQUEUEGROWTH; 833 #endif 834 } 835 if (yylvp == yylve) 836 { 837 yylvp = yylve = yylvals; 838 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 839 yylpp = yylpe = yylpsns; 840 #endif 841 yylexp = yylexemes; 842 if (yychar >= YYEOF) 843 { 844 *yylve++ = yylval; 845 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 846 *yylpe++ = yylloc; 847 #endif 848 *yylexp = (YYINT) yychar; 849 yychar = YYEMPTY; 850 } 851 } 852 } 853 if (yychar >= YYEOF) 854 { 855 yylvp--; 856 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 857 yylpp--; 858 #endif 859 yylexp--; 860 yychar = YYEMPTY; 861 } 862 save->lexeme = (int) (yylvp - yylvals); 863 yyps->save = save; 864 } 865 if (yytable[yyn] == ctry) 866 { 867 #if YYDEBUG 868 if (yydebug) 869 fprintf(stderr, "%s[%d]: state %d, shifting to state %d\n", 870 YYDEBUGSTR, yydepth, yystate, yyctable[ctry]); 871 #endif 872 if (yychar < 0) 873 { 874 yylvp++; 875 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 876 yylpp++; 877 #endif 878 yylexp++; 879 } 880 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) 881 goto yyoverflow; 882 yystate = yyctable[ctry]; 883 *++yystack.s_mark = (YYINT) yystate; 884 *++yystack.l_mark = yylval; 885 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 886 *++yystack.p_mark = yylloc; 887 #endif 888 yychar = YYEMPTY; 889 if (yyerrflag > 0) --yyerrflag; 890 goto yyloop; 891 } 892 else 893 { 894 yyn = yyctable[ctry]; 895 goto yyreduce; 896 } 897 } /* End of code dealing with conflicts */ 898 #endif /* YYBTYACC */ 899 if (((yyn = yysindex[yystate]) != 0) && (yyn += yychar) >= 0 && 900 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar) 901 { 902 #if YYDEBUG 903 if (yydebug) 904 fprintf(stderr, "%s[%d]: state %d, shifting to state %d\n", 905 YYDEBUGSTR, yydepth, yystate, yytable[yyn]); 906 #endif 907 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow; 908 yystate = yytable[yyn]; 909 *++yystack.s_mark = yytable[yyn]; 910 *++yystack.l_mark = yylval; 911 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 912 *++yystack.p_mark = yylloc; 913 #endif 914 yychar = YYEMPTY; 915 if (yyerrflag > 0) --yyerrflag; 916 goto yyloop; 917 } 918 if (((yyn = yyrindex[yystate]) != 0) && (yyn += yychar) >= 0 && 919 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar) 920 { 921 yyn = yytable[yyn]; 922 goto yyreduce; 923 } 924 if (yyerrflag != 0) goto yyinrecovery; 925 #if YYBTYACC 926 927 yynewerrflag = 1; 928 goto yyerrhandler; 929 goto yyerrlab; /* redundant goto avoids 'unused label' warning */ 930 931 yyerrlab: 932 /* explicit YYERROR from an action -- pop the rhs of the rule reduced 933 * before looking for error recovery */ 934 yystack.s_mark -= yym; 935 yystate = *yystack.s_mark; 936 yystack.l_mark -= yym; 937 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 938 yystack.p_mark -= yym; 939 #endif 940 941 yynewerrflag = 0; 942 yyerrhandler: 943 while (yyps->save) 944 { 945 int ctry; 946 YYParseState *save = yyps->save; 947 #if YYDEBUG 948 if (yydebug) 949 fprintf(stderr, "%s[%d]: ERROR in state %d, CONFLICT BACKTRACKING to state %d, %d tokens\n", 950 YYDEBUGSTR, yydepth, yystate, yyps->save->state, 951 (int)(yylvp - yylvals - yyps->save->lexeme)); 952 #endif 953 /* Memorize most forward-looking error state in case it's really an error. */ 954 if (yyerrctx == NULL || yyerrctx->lexeme < yylvp - yylvals) 955 { 956 /* Free old saved error context state */ 957 if (yyerrctx) yyFreeState(yyerrctx); 958 /* Create and fill out new saved error context state */ 959 yyerrctx = yyNewState((unsigned)(yystack.s_mark - yystack.s_base + 1)); 960 if (yyerrctx == NULL) goto yyenomem; 961 yyerrctx->save = yyps->save; 962 yyerrctx->state = yystate; 963 yyerrctx->errflag = yyerrflag; 964 yyerrctx->yystack.s_mark = yyerrctx->yystack.s_base + (yystack.s_mark - yystack.s_base); 965 memcpy (yyerrctx->yystack.s_base, yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(YYINT)); 966 yyerrctx->yystack.l_mark = yyerrctx->yystack.l_base + (yystack.l_mark - yystack.l_base); 967 memcpy (yyerrctx->yystack.l_base, yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE)); 968 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 969 yyerrctx->yystack.p_mark = yyerrctx->yystack.p_base + (yystack.p_mark - yystack.p_base); 970 memcpy (yyerrctx->yystack.p_base, yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE)); 971 #endif 972 yyerrctx->lexeme = (int) (yylvp - yylvals); 973 } 974 yylvp = yylvals + save->lexeme; 975 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 976 yylpp = yylpsns + save->lexeme; 977 #endif 978 yylexp = yylexemes + save->lexeme; 979 yychar = YYEMPTY; 980 yystack.s_mark = yystack.s_base + (save->yystack.s_mark - save->yystack.s_base); 981 memcpy (yystack.s_base, save->yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(YYINT)); 982 yystack.l_mark = yystack.l_base + (save->yystack.l_mark - save->yystack.l_base); 983 memcpy (yystack.l_base, save->yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE)); 984 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 985 yystack.p_mark = yystack.p_base + (save->yystack.p_mark - save->yystack.p_base); 986 memcpy (yystack.p_base, save->yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE)); 987 #endif 988 ctry = ++save->ctry; 989 yystate = save->state; 990 /* We tried shift, try reduce now */ 991 if ((yyn = yyctable[ctry]) >= 0) goto yyreduce; 992 yyps->save = save->save; 993 save->save = NULL; 994 yyFreeState(save); 995 996 /* Nothing left on the stack -- error */ 997 if (!yyps->save) 998 { 999 #if YYDEBUG 1000 if (yydebug) 1001 fprintf(stderr, "%sdebug[%d,trial]: trial parse FAILED, entering ERROR mode\n", 1002 YYPREFIX, yydepth); 1003 #endif 1004 /* Restore state as it was in the most forward-advanced error */ 1005 yylvp = yylvals + yyerrctx->lexeme; 1006 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1007 yylpp = yylpsns + yyerrctx->lexeme; 1008 #endif 1009 yylexp = yylexemes + yyerrctx->lexeme; 1010 yychar = yylexp[-1]; 1011 yylval = yylvp[-1]; 1012 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1013 yylloc = yylpp[-1]; 1014 #endif 1015 yystack.s_mark = yystack.s_base + (yyerrctx->yystack.s_mark - yyerrctx->yystack.s_base); 1016 memcpy (yystack.s_base, yyerrctx->yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(YYINT)); 1017 yystack.l_mark = yystack.l_base + (yyerrctx->yystack.l_mark - yyerrctx->yystack.l_base); 1018 memcpy (yystack.l_base, yyerrctx->yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE)); 1019 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1020 yystack.p_mark = yystack.p_base + (yyerrctx->yystack.p_mark - yyerrctx->yystack.p_base); 1021 memcpy (yystack.p_base, yyerrctx->yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE)); 1022 #endif 1023 yystate = yyerrctx->state; 1024 yyFreeState(yyerrctx); 1025 yyerrctx = NULL; 1026 } 1027 yynewerrflag = 1; 1028 } 1029 if (yynewerrflag == 0) goto yyinrecovery; 1030 #endif /* YYBTYACC */ 1031 1032 YYERROR_CALL("syntax error"); 1033 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1034 yyerror_loc_range[0] = yylloc; /* lookahead position is error start position */ 1035 #endif 1036 1037 #if !YYBTYACC 1038 goto yyerrlab; /* redundant goto avoids 'unused label' warning */ 1039 yyerrlab: 1040 #endif 1041 ++yynerrs; 1042 1043 yyinrecovery: 1044 if (yyerrflag < 3) 1045 { 1046 yyerrflag = 3; 1047 for (;;) 1048 { 1049 if (((yyn = yysindex[*yystack.s_mark]) != 0) && (yyn += YYERRCODE) >= 0 && 1050 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) YYERRCODE) 1051 { 1052 #if YYDEBUG 1053 if (yydebug) 1054 fprintf(stderr, "%s[%d]: state %d, error recovery shifting to state %d\n", 1055 YYDEBUGSTR, yydepth, *yystack.s_mark, yytable[yyn]); 1056 #endif 1057 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow; 1058 yystate = yytable[yyn]; 1059 *++yystack.s_mark = yytable[yyn]; 1060 *++yystack.l_mark = yylval; 1061 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1062 /* lookahead position is error end position */ 1063 yyerror_loc_range[1] = yylloc; 1064 YYLLOC_DEFAULT(yyloc, yyerror_loc_range, 2); /* position of error span */ 1065 *++yystack.p_mark = yyloc; 1066 #endif 1067 goto yyloop; 1068 } 1069 else 1070 { 1071 #if YYDEBUG 1072 if (yydebug) 1073 fprintf(stderr, "%s[%d]: error recovery discarding state %d\n", 1074 YYDEBUGSTR, yydepth, *yystack.s_mark); 1075 #endif 1076 if (yystack.s_mark <= yystack.s_base) goto yyabort; 1077 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1078 /* the current TOS position is the error start position */ 1079 yyerror_loc_range[0] = *yystack.p_mark; 1080 #endif 1081 #if defined(YYDESTRUCT_CALL) 1082 #if YYBTYACC 1083 if (!yytrial) 1084 #endif /* YYBTYACC */ 1085 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1086 YYDESTRUCT_CALL("error: discarding state", 1087 yystos[*yystack.s_mark], yystack.l_mark, yystack.p_mark); 1088 #else 1089 YYDESTRUCT_CALL("error: discarding state", 1090 yystos[*yystack.s_mark], yystack.l_mark); 1091 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */ 1092 #endif /* defined(YYDESTRUCT_CALL) */ 1093 --yystack.s_mark; 1094 --yystack.l_mark; 1095 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1096 --yystack.p_mark; 1097 #endif 1098 } 1099 } 1100 } 1101 else 1102 { 1103 if (yychar == YYEOF) goto yyabort; 1104 #if YYDEBUG 1105 if (yydebug) 1106 { 1107 if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN]; 1108 fprintf(stderr, "%s[%d]: state %d, error recovery discarding token %d (%s)\n", 1109 YYDEBUGSTR, yydepth, yystate, yychar, yys); 1110 } 1111 #endif 1112 #if defined(YYDESTRUCT_CALL) 1113 #if YYBTYACC 1114 if (!yytrial) 1115 #endif /* YYBTYACC */ 1116 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1117 YYDESTRUCT_CALL("error: discarding token", yychar, &yylval, &yylloc); 1118 #else 1119 YYDESTRUCT_CALL("error: discarding token", yychar, &yylval); 1120 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */ 1121 #endif /* defined(YYDESTRUCT_CALL) */ 1122 yychar = YYEMPTY; 1123 goto yyloop; 1124 } 1125 1126 yyreduce: 1127 yym = yylen[yyn]; 1128 #if YYDEBUG 1129 if (yydebug) 1130 { 1131 fprintf(stderr, "%s[%d]: state %d, reducing by rule %d (%s)", 1132 YYDEBUGSTR, yydepth, yystate, yyn, yyrule[yyn]); 1133 #ifdef YYSTYPE_TOSTRING 1134 #if YYBTYACC 1135 if (!yytrial) 1136 #endif /* YYBTYACC */ 1137 if (yym > 0) 1138 { 1139 int i; 1140 fputc('<', stderr); 1141 for (i = yym; i > 0; i--) 1142 { 1143 if (i != yym) fputs(", ", stderr); 1144 fputs(YYSTYPE_TOSTRING(yystos[yystack.s_mark[1-i]], 1145 yystack.l_mark[1-i]), stderr); 1146 } 1147 fputc('>', stderr); 1148 } 1149 #endif 1150 fputc('\n', stderr); 1151 } 1152 #endif 1153 if (yym > 0) 1154 yyval = yystack.l_mark[1-yym]; 1155 else 1156 memset(&yyval, 0, sizeof yyval); 1157 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1158 1159 /* Perform position reduction */ 1160 memset(&yyloc, 0, sizeof(yyloc)); 1161 #if YYBTYACC 1162 if (!yytrial) 1163 #endif /* YYBTYACC */ 1164 { 1165 YYLLOC_DEFAULT(yyloc, &yystack.p_mark[1-yym], yym); 1166 /* just in case YYERROR is invoked within the action, save 1167 the start of the rhs as the error start position */ 1168 yyerror_loc_range[0] = yystack.p_mark[1-yym]; 1169 } 1170 #endif 1171 1172 switch (yyn) 1173 { 1174 case 3: 1175 #line 28 "calc.y" 1176 { yyerrok ; } 1177 break; 1178 case 4: 1179 #line 32 "calc.y" 1180 { printf("%d\n",yystack.l_mark[0]);} 1181 break; 1182 case 5: 1183 #line 34 "calc.y" 1184 { regs[yystack.l_mark[-2]] = yystack.l_mark[0]; } 1185 break; 1186 case 6: 1187 #line 38 "calc.y" 1188 { yyval = yystack.l_mark[-1]; } 1189 break; 1190 case 7: 1191 #line 40 "calc.y" 1192 { yyval = yystack.l_mark[-2] + yystack.l_mark[0]; } 1193 break; 1194 case 8: 1195 #line 42 "calc.y" 1196 { yyval = yystack.l_mark[-2] - yystack.l_mark[0]; } 1197 break; 1198 case 9: 1199 #line 44 "calc.y" 1200 { yyval = yystack.l_mark[-2] * yystack.l_mark[0]; } 1201 break; 1202 case 10: 1203 #line 46 "calc.y" 1204 { yyval = yystack.l_mark[-2] / yystack.l_mark[0]; } 1205 break; 1206 case 11: 1207 #line 48 "calc.y" 1208 { yyval = yystack.l_mark[-2] % yystack.l_mark[0]; } 1209 break; 1210 case 12: 1211 #line 50 "calc.y" 1212 { yyval = yystack.l_mark[-2] & yystack.l_mark[0]; } 1213 break; 1214 case 13: 1215 #line 52 "calc.y" 1216 { yyval = yystack.l_mark[-2] | yystack.l_mark[0]; } 1217 break; 1218 case 14: 1219 #line 54 "calc.y" 1220 { yyval = - yystack.l_mark[0]; } 1221 break; 1222 case 15: 1223 #line 56 "calc.y" 1224 { yyval = regs[yystack.l_mark[0]]; } 1225 break; 1226 case 17: 1227 #line 61 "calc.y" 1228 { yyval = yystack.l_mark[0]; base = (yystack.l_mark[0]==0) ? 8 : 10; } 1229 break; 1230 case 18: 1231 #line 63 "calc.y" 1232 { yyval = base * yystack.l_mark[-1] + yystack.l_mark[0]; } 1233 break; 1234 #line 1235 "calc.tab.c" 1235 default: 1236 break; 1237 } 1238 yystack.s_mark -= yym; 1239 yystate = *yystack.s_mark; 1240 yystack.l_mark -= yym; 1241 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1242 yystack.p_mark -= yym; 1243 #endif 1244 yym = yylhs[yyn]; 1245 if (yystate == 0 && yym == 0) 1246 { 1247 #if YYDEBUG 1248 if (yydebug) 1249 { 1250 fprintf(stderr, "%s[%d]: after reduction, ", YYDEBUGSTR, yydepth); 1251 #ifdef YYSTYPE_TOSTRING 1252 #if YYBTYACC 1253 if (!yytrial) 1254 #endif /* YYBTYACC */ 1255 fprintf(stderr, "result is <%s>, ", YYSTYPE_TOSTRING(yystos[YYFINAL], yyval)); 1256 #endif 1257 fprintf(stderr, "shifting from state 0 to final state %d\n", YYFINAL); 1258 } 1259 #endif 1260 yystate = YYFINAL; 1261 *++yystack.s_mark = YYFINAL; 1262 *++yystack.l_mark = yyval; 1263 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1264 *++yystack.p_mark = yyloc; 1265 #endif 1266 if (yychar < 0) 1267 { 1268 #if YYBTYACC 1269 do { 1270 if (yylvp < yylve) 1271 { 1272 /* we're currently re-reading tokens */ 1273 yylval = *yylvp++; 1274 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1275 yylloc = *yylpp++; 1276 #endif 1277 yychar = *yylexp++; 1278 break; 1279 } 1280 if (yyps->save) 1281 { 1282 /* in trial mode; save scanner results for future parse attempts */ 1283 if (yylvp == yylvlim) 1284 { /* Enlarge lexical value queue */ 1285 size_t p = (size_t) (yylvp - yylvals); 1286 size_t s = (size_t) (yylvlim - yylvals); 1287 1288 s += YYLVQUEUEGROWTH; 1289 if ((yylexemes = realloc(yylexemes, s * sizeof(YYINT))) == NULL) 1290 goto yyenomem; 1291 if ((yylvals = realloc(yylvals, s * sizeof(YYSTYPE))) == NULL) 1292 goto yyenomem; 1293 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1294 if ((yylpsns = realloc(yylpsns, s * sizeof(YYLTYPE))) == NULL) 1295 goto yyenomem; 1296 #endif 1297 yylvp = yylve = yylvals + p; 1298 yylvlim = yylvals + s; 1299 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1300 yylpp = yylpe = yylpsns + p; 1301 yylplim = yylpsns + s; 1302 #endif 1303 yylexp = yylexemes + p; 1304 } 1305 *yylexp = (YYINT) YYLEX; 1306 *yylvp++ = yylval; 1307 yylve++; 1308 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1309 *yylpp++ = yylloc; 1310 yylpe++; 1311 #endif 1312 yychar = *yylexp++; 1313 break; 1314 } 1315 /* normal operation, no conflict encountered */ 1316 #endif /* YYBTYACC */ 1317 yychar = YYLEX; 1318 #if YYBTYACC 1319 } while (0); 1320 #endif /* YYBTYACC */ 1321 if (yychar < 0) yychar = YYEOF; 1322 #if YYDEBUG 1323 if (yydebug) 1324 { 1325 if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN]; 1326 fprintf(stderr, "%s[%d]: state %d, reading token %d (%s)\n", 1327 YYDEBUGSTR, yydepth, YYFINAL, yychar, yys); 1328 } 1329 #endif 1330 } 1331 if (yychar == YYEOF) goto yyaccept; 1332 goto yyloop; 1333 } 1334 if (((yyn = yygindex[yym]) != 0) && (yyn += yystate) >= 0 && 1335 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yystate) 1336 yystate = yytable[yyn]; 1337 else 1338 yystate = yydgoto[yym]; 1339 #if YYDEBUG 1340 if (yydebug) 1341 { 1342 fprintf(stderr, "%s[%d]: after reduction, ", YYDEBUGSTR, yydepth); 1343 #ifdef YYSTYPE_TOSTRING 1344 #if YYBTYACC 1345 if (!yytrial) 1346 #endif /* YYBTYACC */ 1347 fprintf(stderr, "result is <%s>, ", YYSTYPE_TOSTRING(yystos[yystate], yyval)); 1348 #endif 1349 fprintf(stderr, "shifting from state %d to state %d\n", *yystack.s_mark, yystate); 1350 } 1351 #endif 1352 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow; 1353 *++yystack.s_mark = (YYINT) yystate; 1354 *++yystack.l_mark = yyval; 1355 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1356 *++yystack.p_mark = yyloc; 1357 #endif 1358 goto yyloop; 1359 #if YYBTYACC 1360 1361 /* Reduction declares that this path is valid. Set yypath and do a full parse */ 1362 yyvalid: 1363 if (yypath) YYABORT; 1364 while (yyps->save) 1365 { 1366 YYParseState *save = yyps->save; 1367 yyps->save = save->save; 1368 save->save = yypath; 1369 yypath = save; 1370 } 1371 #if YYDEBUG 1372 if (yydebug) 1373 fprintf(stderr, "%s[%d]: state %d, CONFLICT trial successful, backtracking to state %d, %d tokens\n", 1374 YYDEBUGSTR, yydepth, yystate, yypath->state, (int)(yylvp - yylvals - yypath->lexeme)); 1375 #endif 1376 if (yyerrctx) 1377 { 1378 yyFreeState(yyerrctx); 1379 yyerrctx = NULL; 1380 } 1381 yylvp = yylvals + yypath->lexeme; 1382 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1383 yylpp = yylpsns + yypath->lexeme; 1384 #endif 1385 yylexp = yylexemes + yypath->lexeme; 1386 yychar = YYEMPTY; 1387 yystack.s_mark = yystack.s_base + (yypath->yystack.s_mark - yypath->yystack.s_base); 1388 memcpy (yystack.s_base, yypath->yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(YYINT)); 1389 yystack.l_mark = yystack.l_base + (yypath->yystack.l_mark - yypath->yystack.l_base); 1390 memcpy (yystack.l_base, yypath->yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE)); 1391 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1392 yystack.p_mark = yystack.p_base + (yypath->yystack.p_mark - yypath->yystack.p_base); 1393 memcpy (yystack.p_base, yypath->yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE)); 1394 #endif 1395 yystate = yypath->state; 1396 goto yyloop; 1397 #endif /* YYBTYACC */ 1398 1399 yyoverflow: 1400 YYERROR_CALL("yacc stack overflow"); 1401 #if YYBTYACC 1402 goto yyabort_nomem; 1403 yyenomem: 1404 YYERROR_CALL("memory exhausted"); 1405 yyabort_nomem: 1406 #endif /* YYBTYACC */ 1407 yyresult = 2; 1408 goto yyreturn; 1409 1410 yyabort: 1411 yyresult = 1; 1412 goto yyreturn; 1413 1414 yyaccept: 1415 #if YYBTYACC 1416 if (yyps->save) goto yyvalid; 1417 #endif /* YYBTYACC */ 1418 yyresult = 0; 1419 1420 yyreturn: 1421 #if defined(YYDESTRUCT_CALL) 1422 if (yychar != YYEOF && yychar != YYEMPTY) 1423 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1424 YYDESTRUCT_CALL("cleanup: discarding token", yychar, &yylval, &yylloc); 1425 #else 1426 YYDESTRUCT_CALL("cleanup: discarding token", yychar, &yylval); 1427 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */ 1428 1429 { 1430 YYSTYPE *pv; 1431 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) 1432 YYLTYPE *pp; 1433 1434 for (pv = yystack.l_base, pp = yystack.p_base; pv <= yystack.l_mark; ++pv, ++pp) 1435 YYDESTRUCT_CALL("cleanup: discarding state", 1436 yystos[*(yystack.s_base + (pv - yystack.l_base))], pv, pp); 1437 #else 1438 for (pv = yystack.l_base; pv <= yystack.l_mark; ++pv) 1439 YYDESTRUCT_CALL("cleanup: discarding state", 1440 yystos[*(yystack.s_base + (pv - yystack.l_base))], pv); 1441 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */ 1442 } 1443 #endif /* defined(YYDESTRUCT_CALL) */ 1444 1445 #if YYBTYACC 1446 if (yyerrctx) 1447 { 1448 yyFreeState(yyerrctx); 1449 yyerrctx = NULL; 1450 } 1451 while (yyps) 1452 { 1453 YYParseState *save = yyps; 1454 yyps = save->save; 1455 save->save = NULL; 1456 yyFreeState(save); 1457 } 1458 while (yypath) 1459 { 1460 YYParseState *save = yypath; 1461 yypath = save->save; 1462 save->save = NULL; 1463 yyFreeState(save); 1464 } 1465 #endif /* YYBTYACC */ 1466 yyfreestack(&yystack); 1467 return (yyresult); 1468 } 1469