1 /* original parser id follows */
2 /* yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93" */
3 /* (use YYMAJOR/YYMINOR for ifdefs dependent on parser version) */
8 #define YYCHECK "yyyymmdd"
11 #define yyclearin (yychar = YYEMPTY)
12 #define yyerrok (yyerrflag = 0)
13 #define YYRECOVERING() (yyerrflag != 0)
18 #define YYDEBUGSTR YYPREFIX "debug"
21 #define yyparse calc_parse
25 #define yylex calc_lex
29 #define yyerror calc_error
33 #define yychar calc_char
37 #define yyval calc_val
41 #define yylval calc_lval
45 #define yydebug calc_debug
49 #define yynerrs calc_nerrs
53 #define yyerrflag calc_errflag
54 #endif /* yyerrflag */
57 #define yylhs calc_lhs
61 #define yylen calc_len
65 #define yydefred calc_defred
69 #define yystos calc_stos
73 #define yydgoto calc_dgoto
77 #define yysindex calc_sindex
81 #define yyrindex calc_rindex
85 #define yygindex calc_gindex
89 #define yytable calc_table
93 #define yycheck calc_check
97 #define yyname calc_name
101 #define yyrule calc_rule
107 #define yycindex calc_cindex
108 #endif /* yycindex */
111 #define yyctable calc_ctable
112 #endif /* yyctable */
114 #endif /* YYBTYACC */
116 #define YYPREFIX "calc_"
127 extern int yylex(void);
128 static void yyerror(const char *s);
130 #line 131 "calc.tab.c"
132 #if ! defined(YYSTYPE) && ! defined(YYSTYPE_IS_DECLARED)
133 /* Default: YYSTYPE is the semantic value type. */
135 # define YYSTYPE_IS_DECLARED 1
138 /* compatibility with bison */
140 /* compatibility with FreeBSD */
141 # ifdef YYPARSE_PARAM_TYPE
142 # define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
144 # define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
147 # define YYPARSE_DECL() yyparse(void)
150 /* Parameters sent to lex. */
152 # define YYLEX_DECL() yylex(void *YYLEX_PARAM)
153 # define YYLEX yylex(YYLEX_PARAM)
155 # define YYLEX_DECL() yylex(void)
156 # define YYLEX yylex()
159 /* Parameters sent to yyerror. */
161 #define YYERROR_DECL() yyerror(const char *s)
164 #define YYERROR_CALL(msg) yyerror(msg)
167 extern int YYPARSE_DECL();
172 #define YYERRCODE 256
174 static const YYINT calc_lhs[] = { -1,
175 0, 0, 0, 1, 1, 2, 2, 2, 2, 2,
176 2, 2, 2, 2, 2, 2, 3, 3,
178 static const YYINT calc_len[] = { 2,
179 0, 3, 3, 1, 3, 3, 3, 3, 3, 3,
180 3, 3, 3, 2, 1, 1, 1, 2,
182 static const YYINT calc_defred[] = { 1,
183 0, 0, 17, 0, 0, 0, 0, 0, 0, 3,
184 0, 15, 14, 0, 2, 0, 0, 0, 0, 0,
185 0, 0, 18, 0, 6, 0, 0, 0, 0, 9,
188 static const YYINT calc_stos[] = { 0,
189 261, 256, 257, 258, 45, 40, 262, 263, 264, 10,
190 61, 258, 263, 263, 10, 124, 38, 43, 45, 42,
191 47, 37, 257, 263, 41, 263, 263, 263, 263, 263,
194 static const YYINT calc_dgoto[] = { 1,
197 static const YYINT calc_sindex[] = { 0,
198 -40, -7, 0, -55, -38, -38, 1, -29, -247, 0,
199 -38, 0, 0, 22, 0, -38, -38, -38, -38, -38,
200 -38, -38, 0, -29, 0, 51, 60, -20, -20, 0,
203 static const YYINT calc_rindex[] = { 0,
204 0, 0, 0, 2, 0, 0, 0, 9, -9, 0,
205 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
206 0, 0, 0, 10, 0, -6, 14, 5, 13, 0,
210 static const YYINT calc_cindex[] = { 0,
211 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
212 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
213 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
217 static const YYINT calc_gindex[] = { 0,
220 #define YYTABLESIZE 220
221 static const YYINT calc_table[] = { 6,
222 16, 6, 10, 13, 5, 11, 5, 22, 17, 23,
223 15, 15, 20, 18, 7, 19, 22, 21, 4, 5,
224 0, 20, 8, 12, 0, 0, 21, 16, 16, 0,
225 0, 16, 16, 16, 13, 16, 0, 16, 15, 15,
226 0, 0, 7, 15, 15, 7, 15, 7, 15, 7,
227 8, 12, 0, 8, 12, 8, 0, 8, 22, 17,
228 0, 0, 25, 20, 18, 0, 19, 0, 21, 13,
229 14, 0, 0, 0, 0, 24, 0, 0, 0, 0,
230 26, 27, 28, 29, 30, 31, 32, 22, 17, 0,
231 0, 0, 20, 18, 16, 19, 22, 21, 0, 0,
232 0, 20, 18, 0, 19, 0, 21, 0, 0, 0,
233 0, 0, 0, 0, 16, 0, 0, 13, 0, 0,
234 0, 0, 0, 0, 0, 15, 0, 0, 7, 0,
235 0, 0, 0, 0, 0, 0, 8, 12, 0, 0,
236 0, 0, 0, 0, 0, 16, 0, 0, 0, 0,
237 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
238 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
239 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
240 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
241 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
242 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
243 0, 0, 0, 0, 0, 2, 3, 4, 3, 12,
245 static const YYINT calc_check[] = { 40,
246 10, 40, 10, 10, 45, 61, 45, 37, 38, 257,
247 10, 10, 42, 43, 10, 45, 37, 47, 10, 10,
248 -1, 42, 10, 10, -1, -1, 47, 37, 38, -1,
249 -1, 41, 42, 43, 41, 45, -1, 47, 37, 38,
250 -1, -1, 38, 42, 43, 41, 45, 43, 47, 45,
251 38, 38, -1, 41, 41, 43, -1, 45, 37, 38,
252 -1, -1, 41, 42, 43, -1, 45, -1, 47, 5,
253 6, -1, -1, -1, -1, 11, -1, -1, -1, -1,
254 16, 17, 18, 19, 20, 21, 22, 37, 38, -1,
255 -1, -1, 42, 43, 124, 45, 37, 47, -1, -1,
256 -1, 42, 43, -1, 45, -1, 47, -1, -1, -1,
257 -1, -1, -1, -1, 124, -1, -1, 124, -1, -1,
258 -1, -1, -1, -1, -1, 124, -1, -1, 124, -1,
259 -1, -1, -1, -1, -1, -1, 124, 124, -1, -1,
260 -1, -1, -1, -1, -1, 124, -1, -1, -1, -1,
261 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
262 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
263 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
264 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
265 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
266 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
267 -1, -1, -1, -1, -1, 256, 257, 258, 257, 258,
270 static const YYINT calc_ctable[] = { -1,
271 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
272 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
273 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
274 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
275 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
276 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
277 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
278 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
279 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
280 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
281 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
282 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
283 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
284 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
285 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
286 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
287 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
288 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
289 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
290 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
291 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
292 -1, -1, -1, -1, -1, -1, -1, -1, -1,
299 #define YYMAXTOKEN 259
300 #define YYUNDFTOKEN 265
301 #define YYTRANSLATE(a) ((a) > YYMAXTOKEN ? YYUNDFTOKEN : (a))
303 static const char *const calc_name[] = {
305 "$end",0,0,0,0,0,0,0,0,0,"'\\n'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
306 0,0,0,"'%'","'&'",0,"'('","')'","'*'","'+'",0,"'-'",0,"'/'",0,0,0,0,0,0,0,0,0,0,
307 0,0,0,"'='",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
308 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"'|'",0,0,0,0,0,0,0,0,0,
309 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
310 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
311 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
312 0,0,"error","DIGIT","LETTER","UMINUS","$accept","list","stat","expr","number",
315 static const char *const calc_rule[] = {
318 "list : list stat '\\n'",
319 "list : list error '\\n'",
321 "stat : LETTER '=' expr",
322 "expr : '(' expr ')'",
323 "expr : expr '+' expr",
324 "expr : expr '-' expr",
325 "expr : expr '*' expr",
326 "expr : expr '/' expr",
327 "expr : expr '%' expr",
328 "expr : expr '&' expr",
329 "expr : expr '|' expr",
334 "number : number DIGIT",
346 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
347 YYLTYPE yyloc; /* position returned by actions */
348 YYLTYPE yylloc; /* position from the lexer */
351 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
352 #ifndef YYLLOC_DEFAULT
353 #define YYLLOC_DEFAULT(loc, rhs, n) \
358 (loc).first_line = ((rhs)[-1]).last_line; \
359 (loc).first_column = ((rhs)[-1]).last_column; \
360 (loc).last_line = ((rhs)[-1]).last_line; \
361 (loc).last_column = ((rhs)[-1]).last_column; \
365 (loc).first_line = ((rhs)[ 0 ]).first_line; \
366 (loc).first_column = ((rhs)[ 0 ]).first_column; \
367 (loc).last_line = ((rhs)[n-1]).last_line; \
368 (loc).last_column = ((rhs)[n-1]).last_column; \
371 #endif /* YYLLOC_DEFAULT */
372 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
375 #ifndef YYLVQUEUEGROWTH
376 #define YYLVQUEUEGROWTH 32
378 #endif /* YYBTYACC */
380 /* define the initial stack-sizes */
383 #define YYMAXDEPTH YYSTACKSIZE
386 #define YYSTACKSIZE YYMAXDEPTH
388 #define YYSTACKSIZE 10000
389 #define YYMAXDEPTH 10000
393 #ifndef YYINITSTACKSIZE
394 #define YYINITSTACKSIZE 200
404 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
411 struct YYParseState_s
413 struct YYParseState_s *save; /* Previously saved parser state */
414 YYSTACKDATA yystack; /* saved parser stack */
415 int state; /* saved parser state */
416 int errflag; /* saved error recovery status */
417 int lexeme; /* saved index of the conflict lexeme in the lexical queue */
418 YYINT ctry; /* saved index in yyctable[] for this conflict */
420 typedef struct YYParseState_s YYParseState;
421 #endif /* YYBTYACC */
422 /* variables for the parser stack */
423 static YYSTACKDATA yystack;
426 /* Current parser state */
427 static YYParseState *yyps = 0;
429 /* yypath != NULL: do the full parse, starting at *yypath parser state. */
430 static YYParseState *yypath = 0;
432 /* Base of the lexical value queue */
433 static YYSTYPE *yylvals = 0;
435 /* Current position at lexical value queue */
436 static YYSTYPE *yylvp = 0;
438 /* End position of lexical value queue */
439 static YYSTYPE *yylve = 0;
441 /* The last allocated position at the lexical value queue */
442 static YYSTYPE *yylvlim = 0;
444 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
445 /* Base of the lexical position queue */
446 static YYLTYPE *yylpsns = 0;
448 /* Current position at lexical position queue */
449 static YYLTYPE *yylpp = 0;
451 /* End position of lexical position queue */
452 static YYLTYPE *yylpe = 0;
454 /* The last allocated position at the lexical position queue */
455 static YYLTYPE *yylplim = 0;
458 /* Current position at lexical token queue */
459 static short *yylexp = 0;
461 static short *yylexemes = 0;
462 #endif /* YYBTYACC */
464 /* start of programs */
469 while(!feof(stdin)) {
476 yyerror(const char *s)
478 fprintf(stderr, "%s\n", s);
484 /* lexical analysis routine */
485 /* returns LETTER for a lower case letter, yylval = 0 through 25 */
486 /* return DIGIT for a digit, yylval = 0 through 9 */
487 /* all other characters are returned immediately */
491 while( (c=getchar()) == ' ' ) { /* skip blanks */ }
493 /* c is now nonblank */
505 #line 506 "calc.tab.c"
507 /* For use in generated program */
508 #define yydepth (int)(yystack.s_mark - yystack.s_base)
510 #define yytrial (yyps->save)
511 #endif /* YYBTYACC */
514 #include <stdio.h> /* needed for printf */
517 #include <stdlib.h> /* needed for malloc, etc */
518 #include <string.h> /* needed for memset */
520 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
521 static int yygrowstack(YYSTACKDATA *data)
527 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
531 if ((newsize = data->stacksize) == 0)
532 newsize = YYINITSTACKSIZE;
533 else if (newsize >= YYMAXDEPTH)
535 else if ((newsize *= 2) > YYMAXDEPTH)
536 newsize = YYMAXDEPTH;
538 i = (int) (data->s_mark - data->s_base);
539 newss = (YYINT *)realloc(data->s_base, newsize * sizeof(*newss));
543 data->s_base = newss;
544 data->s_mark = newss + i;
546 newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));
550 data->l_base = newvs;
551 data->l_mark = newvs + i;
553 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
554 newps = (YYLTYPE *)realloc(data->p_base, newsize * sizeof(*newps));
558 data->p_base = newps;
559 data->p_mark = newps + i;
562 data->stacksize = newsize;
563 data->s_last = data->s_base + newsize - 1;
567 fprintf(stderr, "%sdebug: stack size increased to %d\n", YYPREFIX, newsize);
572 #if YYPURE || defined(YY_NO_LEAKS)
573 static void yyfreestack(YYSTACKDATA *data)
577 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
580 memset(data, 0, sizeof(*data));
583 #define yyfreestack(data) /* nothing */
584 #endif /* YYPURE || defined(YY_NO_LEAKS) */
587 static YYParseState *
588 yyNewState(unsigned size)
590 YYParseState *p = (YYParseState *) malloc(sizeof(YYParseState));
591 if (p == NULL) return NULL;
593 p->yystack.stacksize = size;
596 p->yystack.s_base = NULL;
597 p->yystack.l_base = NULL;
598 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
599 p->yystack.p_base = NULL;
603 p->yystack.s_base = (YYINT *) malloc(size * sizeof(YYINT));
604 if (p->yystack.s_base == NULL) return NULL;
605 p->yystack.l_base = (YYSTYPE *) malloc(size * sizeof(YYSTYPE));
606 if (p->yystack.l_base == NULL) return NULL;
607 memset(p->yystack.l_base, 0, size * sizeof(YYSTYPE));
608 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
609 p->yystack.p_base = (YYLTYPE *) malloc(size * sizeof(YYLTYPE));
610 if (p->yystack.p_base == NULL) return NULL;
611 memset(p->yystack.p_base, 0, size * sizeof(YYLTYPE));
618 yyFreeState(YYParseState *p)
620 yyfreestack(&p->yystack);
623 #endif /* YYBTYACC */
625 #define YYABORT goto yyabort
626 #define YYREJECT goto yyabort
627 #define YYACCEPT goto yyaccept
628 #define YYERROR goto yyerrlab
630 #define YYVALID do { if (yyps->save) goto yyvalid; } while(0)
631 #define YYVALID_NESTED do { if (yyps->save && \
632 yyps->save->save == 0) goto yyvalid; } while(0)
633 #endif /* YYBTYACC */
638 int yym, yyn, yystate, yyresult;
641 YYParseState *yyerrctx = NULL;
642 #endif /* YYBTYACC */
643 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
644 YYLTYPE yyerror_loc_range[2]; /* position of error start & end */
649 if ((yys = getenv("YYDEBUG")) != 0)
652 if (yyn >= '0' && yyn <= '9')
656 fprintf(stderr, "%sdebug[<# of symbols on state stack>]\n", YYPREFIX);
660 yyps = yyNewState(0); if (yyps == 0) goto yyenomem;
662 #endif /* YYBTYACC */
671 memset(&yystack, 0, sizeof(yystack));
674 if (yystack.s_base == NULL && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
675 yystack.s_mark = yystack.s_base;
676 yystack.l_mark = yystack.l_base;
677 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
678 yystack.p_mark = yystack.p_base;
684 if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
691 /* we're currently re-reading tokens */
693 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
701 /* in trial mode; save scanner results for future parse attempts */
702 if (yylvp == yylvlim)
703 { /* Enlarge lexical value queue */
704 size_t p = (size_t) (yylvp - yylvals);
705 size_t s = (size_t) (yylvlim - yylvals);
707 s += YYLVQUEUEGROWTH;
708 if ((yylexemes = (short *) realloc(yylexemes, s * sizeof(short))) == NULL) goto yyenomem;
709 if ((yylvals = (YYSTYPE *) realloc(yylvals, s * sizeof(YYSTYPE))) == NULL) goto yyenomem;
710 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
711 if ((yylpsns = (YYLTYPE *) realloc(yylpsns, s * sizeof(YYLTYPE))) == NULL) goto yyenomem;
713 yylvp = yylve = yylvals + p;
714 yylvlim = yylvals + s;
715 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
716 yylpp = yylpe = yylpsns + p;
717 yylplim = yylpsns + s;
719 yylexp = yylexemes + p;
721 *yylexp = (short) YYLEX;
724 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
731 /* normal operation, no conflict encountered */
732 #endif /* YYBTYACC */
736 #endif /* YYBTYACC */
737 if (yychar < 0) yychar = YYEOF;
741 if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN];
742 fprintf(stderr, "%s[%d]: state %d, reading token %d (%s)",
743 YYDEBUGSTR, yydepth, yystate, yychar, yys);
744 #ifdef YYSTYPE_TOSTRING
747 #endif /* YYBTYACC */
748 fprintf(stderr, " <%s>", YYSTYPE_TOSTRING(yychar, yylval));
756 /* Do we have a conflict? */
757 if (((yyn = yycindex[yystate]) != 0) && (yyn += yychar) >= 0 &&
758 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar)
767 fprintf(stderr, "%s[%d]: CONFLICT in state %d: following successful trial parse\n",
768 YYDEBUGSTR, yydepth, yystate);
770 /* Switch to the next conflict context */
775 if (save->state != yystate) YYABORT;
782 /* Unresolved conflict - start/continue trial parse */
787 fprintf(stderr, "%s[%d]: CONFLICT in state %d. ", YYDEBUGSTR, yydepth, yystate);
789 fputs("ALREADY in conflict, continuing trial parse.\n", stderr);
791 fputs("Starting trial parse.\n", stderr);
794 save = yyNewState((unsigned)(yystack.s_mark - yystack.s_base + 1));
795 if (save == NULL) goto yyenomem;
796 save->save = yyps->save;
797 save->state = yystate;
798 save->errflag = yyerrflag;
799 save->yystack.s_mark = save->yystack.s_base + (yystack.s_mark - yystack.s_base);
800 memcpy (save->yystack.s_base, yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(YYINT));
801 save->yystack.l_mark = save->yystack.l_base + (yystack.l_mark - yystack.l_base);
802 memcpy (save->yystack.l_base, yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
803 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
804 save->yystack.p_mark = save->yystack.p_base + (yystack.p_mark - yystack.p_base);
805 memcpy (save->yystack.p_base, yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
808 if (yyctable[ctry] == -1)
811 if (yydebug && yychar >= YYEOF)
812 fprintf(stderr, "%s[%d]: backtracking 1 token\n", YYDEBUGSTR, yydepth);
817 if (yyps->save == NULL)
819 /* If this is a first conflict in the stack, start saving lexemes */
822 yylexemes = (short *) malloc((YYLVQUEUEGROWTH) * sizeof(short));
823 if (yylexemes == NULL) goto yyenomem;
824 yylvals = (YYSTYPE *) malloc((YYLVQUEUEGROWTH) * sizeof(YYSTYPE));
825 if (yylvals == NULL) goto yyenomem;
826 yylvlim = yylvals + YYLVQUEUEGROWTH;
827 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
828 yylpsns = (YYLTYPE *) malloc((YYLVQUEUEGROWTH) * sizeof(YYLTYPE));
829 if (yylpsns == NULL) goto yyenomem;
830 yylplim = yylpsns + YYLVQUEUEGROWTH;
835 yylvp = yylve = yylvals;
836 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
837 yylpp = yylpe = yylpsns;
843 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
846 *yylexp = (short) yychar;
854 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
860 save->lexeme = (int) (yylvp - yylvals);
863 if (yytable[yyn] == ctry)
867 fprintf(stderr, "%s[%d]: state %d, shifting to state %d\n",
868 YYDEBUGSTR, yydepth, yystate, yyctable[ctry]);
873 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
878 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM)
880 yystate = yyctable[ctry];
881 *++yystack.s_mark = (YYINT) yystate;
882 *++yystack.l_mark = yylval;
883 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
884 *++yystack.p_mark = yylloc;
887 if (yyerrflag > 0) --yyerrflag;
892 yyn = yyctable[ctry];
895 } /* End of code dealing with conflicts */
896 #endif /* YYBTYACC */
897 if (((yyn = yysindex[yystate]) != 0) && (yyn += yychar) >= 0 &&
898 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar)
902 fprintf(stderr, "%s[%d]: state %d, shifting to state %d\n",
903 YYDEBUGSTR, yydepth, yystate, yytable[yyn]);
905 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
906 yystate = yytable[yyn];
907 *++yystack.s_mark = yytable[yyn];
908 *++yystack.l_mark = yylval;
909 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
910 *++yystack.p_mark = yylloc;
913 if (yyerrflag > 0) --yyerrflag;
916 if (((yyn = yyrindex[yystate]) != 0) && (yyn += yychar) >= 0 &&
917 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar)
922 if (yyerrflag != 0) goto yyinrecovery;
927 goto yyerrlab; /* redundant goto avoids 'unused label' warning */
930 /* explicit YYERROR from an action -- pop the rhs of the rule reduced
931 * before looking for error recovery */
932 yystack.s_mark -= yym;
933 yystate = *yystack.s_mark;
934 yystack.l_mark -= yym;
935 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
936 yystack.p_mark -= yym;
944 YYParseState *save = yyps->save;
947 fprintf(stderr, "%s[%d]: ERROR in state %d, CONFLICT BACKTRACKING to state %d, %d tokens\n",
948 YYDEBUGSTR, yydepth, yystate, yyps->save->state,
949 (int)(yylvp - yylvals - yyps->save->lexeme));
951 /* Memorize most forward-looking error state in case it's really an error. */
952 if (yyerrctx == NULL || yyerrctx->lexeme < yylvp - yylvals)
954 /* Free old saved error context state */
955 if (yyerrctx) yyFreeState(yyerrctx);
956 /* Create and fill out new saved error context state */
957 yyerrctx = yyNewState((unsigned)(yystack.s_mark - yystack.s_base + 1));
958 if (yyerrctx == NULL) goto yyenomem;
959 yyerrctx->save = yyps->save;
960 yyerrctx->state = yystate;
961 yyerrctx->errflag = yyerrflag;
962 yyerrctx->yystack.s_mark = yyerrctx->yystack.s_base + (yystack.s_mark - yystack.s_base);
963 memcpy (yyerrctx->yystack.s_base, yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(YYINT));
964 yyerrctx->yystack.l_mark = yyerrctx->yystack.l_base + (yystack.l_mark - yystack.l_base);
965 memcpy (yyerrctx->yystack.l_base, yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
966 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
967 yyerrctx->yystack.p_mark = yyerrctx->yystack.p_base + (yystack.p_mark - yystack.p_base);
968 memcpy (yyerrctx->yystack.p_base, yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
970 yyerrctx->lexeme = (int) (yylvp - yylvals);
972 yylvp = yylvals + save->lexeme;
973 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
974 yylpp = yylpsns + save->lexeme;
976 yylexp = yylexemes + save->lexeme;
978 yystack.s_mark = yystack.s_base + (save->yystack.s_mark - save->yystack.s_base);
979 memcpy (yystack.s_base, save->yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(YYINT));
980 yystack.l_mark = yystack.l_base + (save->yystack.l_mark - save->yystack.l_base);
981 memcpy (yystack.l_base, save->yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
982 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
983 yystack.p_mark = yystack.p_base + (save->yystack.p_mark - save->yystack.p_base);
984 memcpy (yystack.p_base, save->yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
987 yystate = save->state;
988 /* We tried shift, try reduce now */
989 if ((yyn = yyctable[ctry]) >= 0) goto yyreduce;
990 yyps->save = save->save;
994 /* Nothing left on the stack -- error */
999 fprintf(stderr, "%sdebug[%d,trial]: trial parse FAILED, entering ERROR mode\n",
1002 /* Restore state as it was in the most forward-advanced error */
1003 yylvp = yylvals + yyerrctx->lexeme;
1004 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1005 yylpp = yylpsns + yyerrctx->lexeme;
1007 yylexp = yylexemes + yyerrctx->lexeme;
1008 yychar = yylexp[-1];
1010 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1013 yystack.s_mark = yystack.s_base + (yyerrctx->yystack.s_mark - yyerrctx->yystack.s_base);
1014 memcpy (yystack.s_base, yyerrctx->yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(YYINT));
1015 yystack.l_mark = yystack.l_base + (yyerrctx->yystack.l_mark - yyerrctx->yystack.l_base);
1016 memcpy (yystack.l_base, yyerrctx->yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
1017 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1018 yystack.p_mark = yystack.p_base + (yyerrctx->yystack.p_mark - yyerrctx->yystack.p_base);
1019 memcpy (yystack.p_base, yyerrctx->yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
1021 yystate = yyerrctx->state;
1022 yyFreeState(yyerrctx);
1027 if (yynewerrflag == 0) goto yyinrecovery;
1028 #endif /* YYBTYACC */
1030 YYERROR_CALL("syntax error");
1031 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1032 yyerror_loc_range[0] = yylloc; /* lookahead position is error start position */
1036 goto yyerrlab; /* redundant goto avoids 'unused label' warning */
1047 if (((yyn = yysindex[*yystack.s_mark]) != 0) && (yyn += YYERRCODE) >= 0 &&
1048 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) YYERRCODE)
1052 fprintf(stderr, "%s[%d]: state %d, error recovery shifting to state %d\n",
1053 YYDEBUGSTR, yydepth, *yystack.s_mark, yytable[yyn]);
1055 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
1056 yystate = yytable[yyn];
1057 *++yystack.s_mark = yytable[yyn];
1058 *++yystack.l_mark = yylval;
1059 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1060 /* lookahead position is error end position */
1061 yyerror_loc_range[1] = yylloc;
1062 YYLLOC_DEFAULT(yyloc, yyerror_loc_range, 2); /* position of error span */
1063 *++yystack.p_mark = yyloc;
1071 fprintf(stderr, "%s[%d]: error recovery discarding state %d\n",
1072 YYDEBUGSTR, yydepth, *yystack.s_mark);
1074 if (yystack.s_mark <= yystack.s_base) goto yyabort;
1075 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1076 /* the current TOS position is the error start position */
1077 yyerror_loc_range[0] = *yystack.p_mark;
1079 #if defined(YYDESTRUCT_CALL)
1082 #endif /* YYBTYACC */
1083 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1084 YYDESTRUCT_CALL("error: discarding state",
1085 yystos[*yystack.s_mark], yystack.l_mark, yystack.p_mark);
1087 YYDESTRUCT_CALL("error: discarding state",
1088 yystos[*yystack.s_mark], yystack.l_mark);
1089 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
1090 #endif /* defined(YYDESTRUCT_CALL) */
1093 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1101 if (yychar == YYEOF) goto yyabort;
1105 if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN];
1106 fprintf(stderr, "%s[%d]: state %d, error recovery discarding token %d (%s)\n",
1107 YYDEBUGSTR, yydepth, yystate, yychar, yys);
1110 #if defined(YYDESTRUCT_CALL)
1113 #endif /* YYBTYACC */
1114 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1115 YYDESTRUCT_CALL("error: discarding token", yychar, &yylval, &yylloc);
1117 YYDESTRUCT_CALL("error: discarding token", yychar, &yylval);
1118 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
1119 #endif /* defined(YYDESTRUCT_CALL) */
1129 fprintf(stderr, "%s[%d]: state %d, reducing by rule %d (%s)",
1130 YYDEBUGSTR, yydepth, yystate, yyn, yyrule[yyn]);
1131 #ifdef YYSTYPE_TOSTRING
1134 #endif /* YYBTYACC */
1139 for (i = yym; i > 0; i--)
1141 if (i != yym) fputs(", ", stderr);
1142 fputs(YYSTYPE_TOSTRING(yystos[yystack.s_mark[1-i]],
1143 yystack.l_mark[1-i]), stderr);
1148 fputc('\n', stderr);
1152 yyval = yystack.l_mark[1-yym];
1154 memset(&yyval, 0, sizeof yyval);
1155 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1157 /* Perform position reduction */
1158 memset(&yyloc, 0, sizeof(yyloc));
1161 #endif /* YYBTYACC */
1163 YYLLOC_DEFAULT(yyloc, &yystack.p_mark[1-yym], yym);
1164 /* just in case YYERROR is invoked within the action, save
1165 the start of the rhs as the error start position */
1166 yyerror_loc_range[0] = yystack.p_mark[1-yym];
1178 { printf("%d\n",yystack.l_mark[0]);}
1182 { regs[yystack.l_mark[-2]] = yystack.l_mark[0]; }
1186 { yyval = yystack.l_mark[-1]; }
1190 { yyval = yystack.l_mark[-2] + yystack.l_mark[0]; }
1194 { yyval = yystack.l_mark[-2] - yystack.l_mark[0]; }
1198 { yyval = yystack.l_mark[-2] * yystack.l_mark[0]; }
1202 { yyval = yystack.l_mark[-2] / yystack.l_mark[0]; }
1206 { yyval = yystack.l_mark[-2] % yystack.l_mark[0]; }
1210 { yyval = yystack.l_mark[-2] & yystack.l_mark[0]; }
1214 { yyval = yystack.l_mark[-2] | yystack.l_mark[0]; }
1218 { yyval = - yystack.l_mark[0]; }
1222 { yyval = regs[yystack.l_mark[0]]; }
1226 { yyval = yystack.l_mark[0]; base = (yystack.l_mark[0]==0) ? 8 : 10; }
1230 { yyval = base * yystack.l_mark[-1] + yystack.l_mark[0]; }
1232 #line 1233 "calc.tab.c"
1236 yystack.s_mark -= yym;
1237 yystate = *yystack.s_mark;
1238 yystack.l_mark -= yym;
1239 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1240 yystack.p_mark -= yym;
1243 if (yystate == 0 && yym == 0)
1248 fprintf(stderr, "%s[%d]: after reduction, ", YYDEBUGSTR, yydepth);
1249 #ifdef YYSTYPE_TOSTRING
1252 #endif /* YYBTYACC */
1253 fprintf(stderr, "result is <%s>, ", YYSTYPE_TOSTRING(yystos[YYFINAL], yyval));
1255 fprintf(stderr, "shifting from state 0 to final state %d\n", YYFINAL);
1259 *++yystack.s_mark = YYFINAL;
1260 *++yystack.l_mark = yyval;
1261 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1262 *++yystack.p_mark = yyloc;
1270 /* we're currently re-reading tokens */
1272 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1280 /* in trial mode; save scanner results for future parse attempts */
1281 if (yylvp == yylvlim)
1282 { /* Enlarge lexical value queue */
1283 size_t p = (size_t) (yylvp - yylvals);
1284 size_t s = (size_t) (yylvlim - yylvals);
1286 s += YYLVQUEUEGROWTH;
1287 if ((yylexemes = (short *) realloc(yylexemes, s * sizeof(short))) == NULL)
1289 if ((yylvals = (YYSTYPE *) realloc(yylvals, s * sizeof(YYSTYPE))) == NULL)
1291 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1292 if ((yylpsns = (YYLTYPE *) realloc(yylpsns, s * sizeof(YYLTYPE))) == NULL)
1295 yylvp = yylve = yylvals + p;
1296 yylvlim = yylvals + s;
1297 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1298 yylpp = yylpe = yylpsns + p;
1299 yylplim = yylpsns + s;
1301 yylexp = yylexemes + p;
1303 *yylexp = (short) YYLEX;
1306 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1313 /* normal operation, no conflict encountered */
1314 #endif /* YYBTYACC */
1318 #endif /* YYBTYACC */
1319 if (yychar < 0) yychar = YYEOF;
1323 if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN];
1324 fprintf(stderr, "%s[%d]: state %d, reading token %d (%s)\n",
1325 YYDEBUGSTR, yydepth, YYFINAL, yychar, yys);
1329 if (yychar == YYEOF) goto yyaccept;
1332 if (((yyn = yygindex[yym]) != 0) && (yyn += yystate) >= 0 &&
1333 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yystate)
1334 yystate = yytable[yyn];
1336 yystate = yydgoto[yym];
1340 fprintf(stderr, "%s[%d]: after reduction, ", YYDEBUGSTR, yydepth);
1341 #ifdef YYSTYPE_TOSTRING
1344 #endif /* YYBTYACC */
1345 fprintf(stderr, "result is <%s>, ", YYSTYPE_TOSTRING(yystos[yystate], yyval));
1347 fprintf(stderr, "shifting from state %d to state %d\n", *yystack.s_mark, yystate);
1350 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
1351 *++yystack.s_mark = (YYINT) yystate;
1352 *++yystack.l_mark = yyval;
1353 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1354 *++yystack.p_mark = yyloc;
1359 /* Reduction declares that this path is valid. Set yypath and do a full parse */
1361 if (yypath) YYABORT;
1364 YYParseState *save = yyps->save;
1365 yyps->save = save->save;
1366 save->save = yypath;
1371 fprintf(stderr, "%s[%d]: state %d, CONFLICT trial successful, backtracking to state %d, %d tokens\n",
1372 YYDEBUGSTR, yydepth, yystate, yypath->state, (int)(yylvp - yylvals - yypath->lexeme));
1376 yyFreeState(yyerrctx);
1379 yylvp = yylvals + yypath->lexeme;
1380 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1381 yylpp = yylpsns + yypath->lexeme;
1383 yylexp = yylexemes + yypath->lexeme;
1385 yystack.s_mark = yystack.s_base + (yypath->yystack.s_mark - yypath->yystack.s_base);
1386 memcpy (yystack.s_base, yypath->yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(YYINT));
1387 yystack.l_mark = yystack.l_base + (yypath->yystack.l_mark - yypath->yystack.l_base);
1388 memcpy (yystack.l_base, yypath->yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
1389 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1390 yystack.p_mark = yystack.p_base + (yypath->yystack.p_mark - yypath->yystack.p_base);
1391 memcpy (yystack.p_base, yypath->yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
1393 yystate = yypath->state;
1395 #endif /* YYBTYACC */
1398 YYERROR_CALL("yacc stack overflow");
1402 YYERROR_CALL("memory exhausted");
1404 #endif /* YYBTYACC */
1414 if (yyps->save) goto yyvalid;
1415 #endif /* YYBTYACC */
1419 #if defined(YYDESTRUCT_CALL)
1420 if (yychar != YYEOF && yychar != YYEMPTY)
1421 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1422 YYDESTRUCT_CALL("cleanup: discarding token", yychar, &yylval, &yylloc);
1424 YYDESTRUCT_CALL("cleanup: discarding token", yychar, &yylval);
1425 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
1429 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1432 for (pv = yystack.l_base, pp = yystack.p_base; pv <= yystack.l_mark; ++pv, ++pp)
1433 YYDESTRUCT_CALL("cleanup: discarding state",
1434 yystos[*(yystack.s_base + (pv - yystack.l_base))], pv, pp);
1436 for (pv = yystack.l_base; pv <= yystack.l_mark; ++pv)
1437 YYDESTRUCT_CALL("cleanup: discarding state",
1438 yystos[*(yystack.s_base + (pv - yystack.l_base))], pv);
1439 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
1441 #endif /* defined(YYDESTRUCT_CALL) */
1446 yyFreeState(yyerrctx);
1451 YYParseState *save = yyps;
1458 YYParseState *save = yypath;
1459 yypath = save->save;
1463 #endif /* YYBTYACC */
1464 yyfreestack(&yystack);