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