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