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