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