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