1 /* original parser id follows */
2 /* yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93" */
3 /* (use YYMAJOR/YYMINOR for ifdefs dependent of 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_"
120 #line 2 "code_calc.y"
129 static void yyerror(const char *s);
132 #line 133 "code_calc.code.c"
134 #if ! defined(YYSTYPE) && ! defined(YYSTYPE_IS_DECLARED)
135 /* Default: YYSTYPE is the semantic value type. */
137 # define YYSTYPE_IS_DECLARED 1
140 /* compatibility with bison */
142 /* compatibility with FreeBSD */
143 # ifdef YYPARSE_PARAM_TYPE
144 # define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
146 # define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
149 # define YYPARSE_DECL() yyparse(void)
152 /* Parameters sent to lex. */
154 # define YYLEX_DECL() yylex(void *YYLEX_PARAM)
155 # define YYLEX yylex(YYLEX_PARAM)
157 # define YYLEX_DECL() yylex(void)
158 # define YYLEX yylex()
161 /* Parameters sent to yyerror. */
163 #define YYERROR_DECL() yyerror(const char *s)
166 #define YYERROR_CALL(msg) yyerror(msg)
172 #define YYERRCODE 256
173 #define YYTABLESIZE 220
178 #define YYMAXTOKEN 259
179 #define YYUNDFTOKEN 265
180 #define YYTRANSLATE(a) ((a) > YYMAXTOKEN ? YYUNDFTOKEN : (a))
182 extern int YYPARSE_DECL();
184 extern const YYINT yylhs[];
185 extern const YYINT yylen[];
186 extern const YYINT yydefred[];
187 extern const YYINT yystos[];
188 extern const YYINT yydgoto[];
189 extern const YYINT yysindex[];
190 extern const YYINT yyrindex[];
192 extern const YYINT yycindex[];
193 #endif /* YYBTYACC */
194 extern const YYINT yygindex[];
195 extern const YYINT yytable[];
196 extern const YYINT yycheck[];
198 extern const YYINT yyctable[];
199 #endif /* YYBTYACC */
202 extern const char *const yyname[];
203 extern const char *const yyrule[];
213 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
214 YYLTYPE yyloc; /* position returned by actions */
215 YYLTYPE yylloc; /* position from the lexer */
218 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
219 #ifndef YYLLOC_DEFAULT
220 #define YYLLOC_DEFAULT(loc, rhs, n) \
225 (loc).first_line = ((rhs)[-1]).last_line; \
226 (loc).first_column = ((rhs)[-1]).last_column; \
227 (loc).last_line = ((rhs)[-1]).last_line; \
228 (loc).last_column = ((rhs)[-1]).last_column; \
232 (loc).first_line = ((rhs)[ 0 ]).first_line; \
233 (loc).first_column = ((rhs)[ 0 ]).first_column; \
234 (loc).last_line = ((rhs)[n-1]).last_line; \
235 (loc).last_column = ((rhs)[n-1]).last_column; \
238 #endif /* YYLLOC_DEFAULT */
239 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
242 #ifndef YYLVQUEUEGROWTH
243 #define YYLVQUEUEGROWTH 32
245 #endif /* YYBTYACC */
247 /* define the initial stack-sizes */
250 #define YYMAXDEPTH YYSTACKSIZE
253 #define YYSTACKSIZE YYMAXDEPTH
255 #define YYSTACKSIZE 10000
256 #define YYMAXDEPTH 10000
260 #ifndef YYINITSTACKSIZE
261 #define YYINITSTACKSIZE 200
271 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
278 struct YYParseState_s
280 struct YYParseState_s *save; /* Previously saved parser state */
281 YYSTACKDATA yystack; /* saved parser stack */
282 int state; /* saved parser state */
283 int errflag; /* saved error recovery status */
284 int lexeme; /* saved index of the conflict lexeme in the lexical queue */
285 YYINT ctry; /* saved index in yyctable[] for this conflict */
287 typedef struct YYParseState_s YYParseState;
288 #endif /* YYBTYACC */
289 /* variables for the parser stack */
290 static YYSTACKDATA yystack;
293 /* Current parser state */
294 static YYParseState *yyps = 0;
296 /* yypath != NULL: do the full parse, starting at *yypath parser state. */
297 static YYParseState *yypath = 0;
299 /* Base of the lexical value queue */
300 static YYSTYPE *yylvals = 0;
302 /* Current position at lexical value queue */
303 static YYSTYPE *yylvp = 0;
305 /* End position of lexical value queue */
306 static YYSTYPE *yylve = 0;
308 /* The last allocated position at the lexical value queue */
309 static YYSTYPE *yylvlim = 0;
311 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
312 /* Base of the lexical position queue */
313 static YYLTYPE *yylpsns = 0;
315 /* Current position at lexical position queue */
316 static YYLTYPE *yylpp = 0;
318 /* End position of lexical position queue */
319 static YYLTYPE *yylpe = 0;
321 /* The last allocated position at the lexical position queue */
322 static YYLTYPE *yylplim = 0;
325 /* Current position at lexical token queue */
326 static short *yylexp = 0;
328 static short *yylexemes = 0;
329 #endif /* YYBTYACC */
330 #line 68 "code_calc.y"
331 /* start of programs */
334 extern int YYLEX_DECL();
340 while(!feof(stdin)) {
347 yyerror(const char *s)
349 fprintf(stderr, "%s\n", s);
355 /* lexical analysis routine */
356 /* returns LETTER for a lower case letter, yylval = 0 through 25 */
357 /* return DIGIT for a digit, yylval = 0 through 9 */
358 /* all other characters are returned immediately */
362 while( (c=getchar()) == ' ' ) { /* skip blanks */ }
364 /* c is now nonblank */
376 #line 377 "code_calc.code.c"
378 /* For use in generated program */
379 #define yydepth (int)(yystack.s_mark - yystack.s_base)
381 #define yytrial (yyps->save)
382 #endif /* YYBTYACC */
385 #include <stdio.h> /* needed for printf */
388 #include <stdlib.h> /* needed for malloc, etc */
389 #include <string.h> /* needed for memset */
391 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
392 static int yygrowstack(YYSTACKDATA *data)
398 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
402 if ((newsize = data->stacksize) == 0)
403 newsize = YYINITSTACKSIZE;
404 else if (newsize >= YYMAXDEPTH)
406 else if ((newsize *= 2) > YYMAXDEPTH)
407 newsize = YYMAXDEPTH;
409 i = (int) (data->s_mark - data->s_base);
410 newss = (short *)realloc(data->s_base, newsize * sizeof(*newss));
414 data->s_base = newss;
415 data->s_mark = newss + i;
417 newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));
421 data->l_base = newvs;
422 data->l_mark = newvs + i;
424 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
425 newps = (YYLTYPE *)realloc(data->p_base, newsize * sizeof(*newps));
429 data->p_base = newps;
430 data->p_mark = newps + i;
433 data->stacksize = newsize;
434 data->s_last = data->s_base + newsize - 1;
438 fprintf(stderr, "%sdebug: stack size increased to %d\n", YYPREFIX, newsize);
443 #if YYPURE || defined(YY_NO_LEAKS)
444 static void yyfreestack(YYSTACKDATA *data)
448 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
451 memset(data, 0, sizeof(*data));
454 #define yyfreestack(data) /* nothing */
455 #endif /* YYPURE || defined(YY_NO_LEAKS) */
458 static YYParseState *
459 yyNewState(unsigned size)
461 YYParseState *p = (YYParseState *) malloc(sizeof(YYParseState));
462 if (p == NULL) return NULL;
464 p->yystack.stacksize = size;
467 p->yystack.s_base = NULL;
468 p->yystack.l_base = NULL;
469 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
470 p->yystack.p_base = NULL;
474 p->yystack.s_base = (short *) malloc(size * sizeof(short));
475 if (p->yystack.s_base == NULL) return NULL;
476 p->yystack.l_base = (YYSTYPE *) malloc(size * sizeof(YYSTYPE));
477 if (p->yystack.l_base == NULL) return NULL;
478 memset(p->yystack.l_base, 0, size * sizeof(YYSTYPE));
479 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
480 p->yystack.p_base = (YYLTYPE *) malloc(size * sizeof(YYLTYPE));
481 if (p->yystack.p_base == NULL) return NULL;
482 memset(p->yystack.p_base, 0, size * sizeof(YYLTYPE));
489 yyFreeState(YYParseState *p)
491 yyfreestack(&p->yystack);
494 #endif /* YYBTYACC */
496 #define YYABORT goto yyabort
497 #define YYREJECT goto yyabort
498 #define YYACCEPT goto yyaccept
499 #define YYERROR goto yyerrlab
501 #define YYVALID do { if (yyps->save) goto yyvalid; } while(0)
502 #define YYVALID_NESTED do { if (yyps->save && \
503 yyps->save->save == 0) goto yyvalid; } while(0)
504 #endif /* YYBTYACC */
509 int yym, yyn, yystate, yyresult;
512 YYParseState *yyerrctx = NULL;
513 #endif /* YYBTYACC */
514 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
515 YYLTYPE yyerror_loc_range[2]; /* position of error start & end */
520 if ((yys = getenv("YYDEBUG")) != 0)
523 if (yyn >= '0' && yyn <= '9')
527 fprintf(stderr, "%sdebug[<# of symbols on state stack>]\n", YYPREFIX);
531 yyps = yyNewState(0); if (yyps == 0) goto yyenomem;
533 #endif /* YYBTYACC */
540 memset(&yystack, 0, sizeof(yystack));
543 if (yystack.s_base == NULL && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
544 yystack.s_mark = yystack.s_base;
545 yystack.l_mark = yystack.l_base;
546 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
547 yystack.p_mark = yystack.p_base;
553 if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
560 /* we're currently re-reading tokens */
562 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
570 /* in trial mode; save scanner results for future parse attempts */
571 if (yylvp == yylvlim)
572 { /* Enlarge lexical value queue */
573 size_t p = (size_t) (yylvp - yylvals);
574 size_t s = (size_t) (yylvlim - yylvals);
576 s += YYLVQUEUEGROWTH;
577 if ((yylexemes = (short *) realloc(yylexemes, s * sizeof(short))) == NULL) goto yyenomem;
578 if ((yylvals = (YYSTYPE *) realloc(yylvals, s * sizeof(YYSTYPE))) == NULL) goto yyenomem;
579 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
580 if ((yylpsns = (YYLTYPE *) realloc(yylpsns, s * sizeof(YYLTYPE))) == NULL) goto yyenomem;
582 yylvp = yylve = yylvals + p;
583 yylvlim = yylvals + s;
584 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
585 yylpp = yylpe = yylpsns + p;
586 yylplim = yylpsns + s;
588 yylexp = yylexemes + p;
590 *yylexp = (short) YYLEX;
593 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
600 /* normal operation, no conflict encountered */
601 #endif /* YYBTYACC */
605 #endif /* YYBTYACC */
606 if (yychar < 0) yychar = YYEOF;
607 /* if ((yychar = YYLEX) < 0) yychar = YYEOF; */
611 yys = yyname[YYTRANSLATE(yychar)];
612 fprintf(stderr, "%s[%d]: state %d, reading token %d (%s)",
613 YYDEBUGSTR, yydepth, yystate, yychar, yys);
614 #ifdef YYSTYPE_TOSTRING
617 #endif /* YYBTYACC */
618 fprintf(stderr, " <%s>", YYSTYPE_TOSTRING(yychar, yylval));
626 /* Do we have a conflict? */
627 if (((yyn = yycindex[yystate]) != 0) && (yyn += yychar) >= 0 &&
628 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar)
637 fprintf(stderr, "%s[%d]: CONFLICT in state %d: following successful trial parse\n",
638 YYDEBUGSTR, yydepth, yystate);
640 /* Switch to the next conflict context */
645 if (save->state != yystate) YYABORT;
652 /* Unresolved conflict - start/continue trial parse */
657 fprintf(stderr, "%s[%d]: CONFLICT in state %d. ", YYDEBUGSTR, yydepth, yystate);
659 fputs("ALREADY in conflict, continuing trial parse.\n", stderr);
661 fputs("Starting trial parse.\n", stderr);
664 save = yyNewState((unsigned)(yystack.s_mark - yystack.s_base + 1));
665 if (save == NULL) goto yyenomem;
666 save->save = yyps->save;
667 save->state = yystate;
668 save->errflag = yyerrflag;
669 save->yystack.s_mark = save->yystack.s_base + (yystack.s_mark - yystack.s_base);
670 memcpy (save->yystack.s_base, yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(short));
671 save->yystack.l_mark = save->yystack.l_base + (yystack.l_mark - yystack.l_base);
672 memcpy (save->yystack.l_base, yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
673 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
674 save->yystack.p_mark = save->yystack.p_base + (yystack.p_mark - yystack.p_base);
675 memcpy (save->yystack.p_base, yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
678 if (yyctable[ctry] == -1)
681 if (yydebug && yychar >= YYEOF)
682 fprintf(stderr, "%s[%d]: backtracking 1 token\n", YYDEBUGSTR, yydepth);
687 if (yyps->save == NULL)
689 /* If this is a first conflict in the stack, start saving lexemes */
692 yylexemes = (short *) malloc((YYLVQUEUEGROWTH) * sizeof(short));
693 if (yylexemes == NULL) goto yyenomem;
694 yylvals = (YYSTYPE *) malloc((YYLVQUEUEGROWTH) * sizeof(YYSTYPE));
695 if (yylvals == NULL) goto yyenomem;
696 yylvlim = yylvals + YYLVQUEUEGROWTH;
697 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
698 yylpsns = (YYLTYPE *) malloc((YYLVQUEUEGROWTH) * sizeof(YYLTYPE));
699 if (yylpsns == NULL) goto yyenomem;
700 yylplim = yylpsns + YYLVQUEUEGROWTH;
705 yylvp = yylve = yylvals;
706 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
707 yylpp = yylpe = yylpsns;
713 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
716 *yylexp = (short) yychar;
724 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
730 save->lexeme = (int) (yylvp - yylvals);
733 if (yytable[yyn] == ctry)
737 fprintf(stderr, "%s[%d]: state %d, shifting to state %d\n",
738 YYDEBUGSTR, yydepth, yystate, yyctable[ctry]);
743 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
748 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM)
750 yystate = yyctable[ctry];
751 *++yystack.s_mark = (short) yystate;
752 *++yystack.l_mark = yylval;
753 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
754 *++yystack.p_mark = yylloc;
757 if (yyerrflag > 0) --yyerrflag;
762 yyn = yyctable[ctry];
765 } /* End of code dealing with conflicts */
766 #endif /* YYBTYACC */
767 if (((yyn = yysindex[yystate]) != 0) && (yyn += yychar) >= 0 &&
768 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar)
772 fprintf(stderr, "%s[%d]: state %d, shifting to state %d\n",
773 YYDEBUGSTR, yydepth, yystate, yytable[yyn]);
775 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
776 yystate = yytable[yyn];
777 *++yystack.s_mark = yytable[yyn];
778 *++yystack.l_mark = yylval;
779 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
780 *++yystack.p_mark = yylloc;
783 if (yyerrflag > 0) --yyerrflag;
786 if (((yyn = yyrindex[yystate]) != 0) && (yyn += yychar) >= 0 &&
787 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar)
792 if (yyerrflag != 0) goto yyinrecovery;
805 YYParseState *save = yyps->save;
808 fprintf(stderr, "%s[%d]: ERROR in state %d, CONFLICT BACKTRACKING to state %d, %d tokens\n",
809 YYDEBUGSTR, yydepth, yystate, yyps->save->state,
810 (int)(yylvp - yylvals - yyps->save->lexeme));
812 /* Memorize most forward-looking error state in case it's really an error. */
813 if (yyerrctx == NULL || yyerrctx->lexeme < yylvp - yylvals)
815 /* Free old saved error context state */
816 if (yyerrctx) yyFreeState(yyerrctx);
817 /* Create and fill out new saved error context state */
818 yyerrctx = yyNewState((unsigned)(yystack.s_mark - yystack.s_base + 1));
819 if (yyerrctx == NULL) goto yyenomem;
820 yyerrctx->save = yyps->save;
821 yyerrctx->state = yystate;
822 yyerrctx->errflag = yyerrflag;
823 yyerrctx->yystack.s_mark = yyerrctx->yystack.s_base + (yystack.s_mark - yystack.s_base);
824 memcpy (yyerrctx->yystack.s_base, yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(short));
825 yyerrctx->yystack.l_mark = yyerrctx->yystack.l_base + (yystack.l_mark - yystack.l_base);
826 memcpy (yyerrctx->yystack.l_base, yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
827 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
828 yyerrctx->yystack.p_mark = yyerrctx->yystack.p_base + (yystack.p_mark - yystack.p_base);
829 memcpy (yyerrctx->yystack.p_base, yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
831 yyerrctx->lexeme = (int) (yylvp - yylvals);
833 yylvp = yylvals + save->lexeme;
834 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
835 yylpp = yylpsns + save->lexeme;
837 yylexp = yylexemes + save->lexeme;
839 yystack.s_mark = yystack.s_base + (save->yystack.s_mark - save->yystack.s_base);
840 memcpy (yystack.s_base, save->yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(short));
841 yystack.l_mark = yystack.l_base + (save->yystack.l_mark - save->yystack.l_base);
842 memcpy (yystack.l_base, save->yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
843 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
844 yystack.p_mark = yystack.p_base + (save->yystack.p_mark - save->yystack.p_base);
845 memcpy (yystack.p_base, save->yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
848 yystate = save->state;
849 /* We tried shift, try reduce now */
850 if ((yyn = yyctable[ctry]) >= 0) goto yyreduce;
851 yyps->save = save->save;
855 /* Nothing left on the stack -- error */
860 fprintf(stderr, "%sdebug[%d,trial]: trial parse FAILED, entering ERROR mode\n",
863 /* Restore state as it was in the most forward-advanced error */
864 yylvp = yylvals + yyerrctx->lexeme;
865 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
866 yylpp = yylpsns + yyerrctx->lexeme;
868 yylexp = yylexemes + yyerrctx->lexeme;
871 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
874 yystack.s_mark = yystack.s_base + (yyerrctx->yystack.s_mark - yyerrctx->yystack.s_base);
875 memcpy (yystack.s_base, yyerrctx->yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(short));
876 yystack.l_mark = yystack.l_base + (yyerrctx->yystack.l_mark - yyerrctx->yystack.l_base);
877 memcpy (yystack.l_base, yyerrctx->yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
878 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
879 yystack.p_mark = yystack.p_base + (yyerrctx->yystack.p_mark - yyerrctx->yystack.p_base);
880 memcpy (yystack.p_base, yyerrctx->yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
882 yystate = yyerrctx->state;
883 yyFreeState(yyerrctx);
888 if (yynewerrflag == 0) goto yyinrecovery;
889 #endif /* YYBTYACC */
891 YYERROR_CALL("syntax error");
892 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
893 yyerror_loc_range[0] = yylloc; /* lookahead position is error start position */
908 if (((yyn = yysindex[*yystack.s_mark]) != 0) && (yyn += YYERRCODE) >= 0 &&
909 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) YYERRCODE)
913 fprintf(stderr, "%s[%d]: state %d, error recovery shifting to state %d\n",
914 YYDEBUGSTR, yydepth, *yystack.s_mark, yytable[yyn]);
916 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
917 yystate = yytable[yyn];
918 *++yystack.s_mark = yytable[yyn];
919 *++yystack.l_mark = yylval;
920 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
921 /* lookahead position is error end position */
922 yyerror_loc_range[1] = yylloc;
923 YYLLOC_DEFAULT(yyloc, yyerror_loc_range, 2); /* position of error span */
924 *++yystack.p_mark = yyloc;
932 fprintf(stderr, "%s[%d]: error recovery discarding state %d\n",
933 YYDEBUGSTR, yydepth, *yystack.s_mark);
935 if (yystack.s_mark <= yystack.s_base) goto yyabort;
936 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
937 /* the current TOS position is the error start position */
938 yyerror_loc_range[0] = *yystack.p_mark;
940 #if defined(YYDESTRUCT_CALL)
943 #endif /* YYBTYACC */
944 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
945 YYDESTRUCT_CALL("error: discarding state",
946 yystos[*yystack.s_mark], yystack.l_mark, yystack.p_mark);
948 YYDESTRUCT_CALL("error: discarding state",
949 yystos[*yystack.s_mark], yystack.l_mark);
950 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
951 #endif /* defined(YYDESTRUCT_CALL) */
954 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
962 if (yychar == YYEOF) goto yyabort;
966 yys = yyname[YYTRANSLATE(yychar)];
967 fprintf(stderr, "%s[%d]: state %d, error recovery discarding token %d (%s)\n",
968 YYDEBUGSTR, yydepth, yystate, yychar, yys);
971 #if defined(YYDESTRUCT_CALL)
974 #endif /* YYBTYACC */
975 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
976 YYDESTRUCT_CALL("error: discarding token", yychar, &yylval, &yylloc);
978 YYDESTRUCT_CALL("error: discarding token", yychar, &yylval);
979 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
980 #endif /* defined(YYDESTRUCT_CALL) */
990 fprintf(stderr, "%s[%d]: state %d, reducing by rule %d (%s)",
991 YYDEBUGSTR, yydepth, yystate, yyn, yyrule[yyn]);
992 #ifdef YYSTYPE_TOSTRING
995 #endif /* YYBTYACC */
1000 for (i = yym; i > 0; i--)
1002 if (i != yym) fputs(", ", stderr);
1003 fputs(YYSTYPE_TOSTRING(yystos[yystack.s_mark[1-i]],
1004 yystack.l_mark[1-i]), stderr);
1009 fputc('\n', stderr);
1013 yyval = yystack.l_mark[1-yym];
1015 memset(&yyval, 0, sizeof yyval);
1016 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1018 /* Perform position reduction */
1019 memset(&yyloc, 0, sizeof(yyloc));
1022 #endif /* YYBTYACC */
1024 YYLLOC_DEFAULT(yyloc, &yystack.p_mark[1-yym], yym);
1025 /* just in case YYERROR is invoked within the action, save
1026 the start of the rhs as the error start position */
1027 yyerror_loc_range[0] = yystack.p_mark[1-yym];
1034 #line 30 "code_calc.y"
1038 #line 34 "code_calc.y"
1039 { printf("%d\n",yystack.l_mark[0]);}
1042 #line 36 "code_calc.y"
1043 { regs[yystack.l_mark[-2]] = yystack.l_mark[0]; }
1046 #line 40 "code_calc.y"
1047 { yyval = yystack.l_mark[-1]; }
1050 #line 42 "code_calc.y"
1051 { yyval = yystack.l_mark[-2] + yystack.l_mark[0]; }
1054 #line 44 "code_calc.y"
1055 { yyval = yystack.l_mark[-2] - yystack.l_mark[0]; }
1058 #line 46 "code_calc.y"
1059 { yyval = yystack.l_mark[-2] * yystack.l_mark[0]; }
1062 #line 48 "code_calc.y"
1063 { yyval = yystack.l_mark[-2] / yystack.l_mark[0]; }
1066 #line 50 "code_calc.y"
1067 { yyval = yystack.l_mark[-2] % yystack.l_mark[0]; }
1070 #line 52 "code_calc.y"
1071 { yyval = yystack.l_mark[-2] & yystack.l_mark[0]; }
1074 #line 54 "code_calc.y"
1075 { yyval = yystack.l_mark[-2] | yystack.l_mark[0]; }
1078 #line 56 "code_calc.y"
1079 { yyval = - yystack.l_mark[0]; }
1082 #line 58 "code_calc.y"
1083 { yyval = regs[yystack.l_mark[0]]; }
1086 #line 63 "code_calc.y"
1087 { yyval = yystack.l_mark[0]; base = (yystack.l_mark[0]==0) ? 8 : 10; }
1090 #line 65 "code_calc.y"
1091 { yyval = base * yystack.l_mark[-1] + yystack.l_mark[0]; }
1093 #line 1094 "code_calc.code.c"
1097 yystack.s_mark -= yym;
1098 yystate = *yystack.s_mark;
1099 yystack.l_mark -= yym;
1100 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1101 yystack.p_mark -= yym;
1104 if (yystate == 0 && yym == 0)
1109 fprintf(stderr, "%s[%d]: after reduction, ", YYDEBUGSTR, yydepth);
1110 #ifdef YYSTYPE_TOSTRING
1113 #endif /* YYBTYACC */
1114 fprintf(stderr, "result is <%s>, ", YYSTYPE_TOSTRING(yystos[YYFINAL], yyval));
1116 fprintf(stderr, "shifting from state 0 to final state %d\n", YYFINAL);
1120 *++yystack.s_mark = YYFINAL;
1121 *++yystack.l_mark = yyval;
1122 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1123 *++yystack.p_mark = yyloc;
1131 /* we're currently re-reading tokens */
1133 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1141 /* in trial mode; save scanner results for future parse attempts */
1142 if (yylvp == yylvlim)
1143 { /* Enlarge lexical value queue */
1144 size_t p = (size_t) (yylvp - yylvals);
1145 size_t s = (size_t) (yylvlim - yylvals);
1147 s += YYLVQUEUEGROWTH;
1148 if ((yylexemes = (short *) realloc(yylexemes, s * sizeof(short))) == NULL)
1150 if ((yylvals = (YYSTYPE *) realloc(yylvals, s * sizeof(YYSTYPE))) == NULL)
1152 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1153 if ((yylpsns = (YYLTYPE *) realloc(yylpsns, s * sizeof(YYLTYPE))) == NULL)
1156 yylvp = yylve = yylvals + p;
1157 yylvlim = yylvals + s;
1158 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1159 yylpp = yylpe = yylpsns + p;
1160 yylplim = yylpsns + s;
1162 yylexp = yylexemes + p;
1164 *yylexp = (short) YYLEX;
1167 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1174 /* normal operation, no conflict encountered */
1175 #endif /* YYBTYACC */
1179 #endif /* YYBTYACC */
1180 if (yychar < 0) yychar = YYEOF;
1181 /* if ((yychar = YYLEX) < 0) yychar = YYEOF; */
1185 yys = yyname[YYTRANSLATE(yychar)];
1186 fprintf(stderr, "%s[%d]: state %d, reading %d (%s)\n",
1187 YYDEBUGSTR, yydepth, YYFINAL, yychar, yys);
1191 if (yychar == YYEOF) goto yyaccept;
1194 if (((yyn = yygindex[yym]) != 0) && (yyn += yystate) >= 0 &&
1195 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yystate)
1196 yystate = yytable[yyn];
1198 yystate = yydgoto[yym];
1202 fprintf(stderr, "%s[%d]: after reduction, ", YYDEBUGSTR, yydepth);
1203 #ifdef YYSTYPE_TOSTRING
1206 #endif /* YYBTYACC */
1207 fprintf(stderr, "result is <%s>, ", YYSTYPE_TOSTRING(yystos[yystate], yyval));
1209 fprintf(stderr, "shifting from state %d to state %d\n", *yystack.s_mark, yystate);
1212 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
1213 *++yystack.s_mark = (short) yystate;
1214 *++yystack.l_mark = yyval;
1215 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1216 *++yystack.p_mark = yyloc;
1221 /* Reduction declares that this path is valid. Set yypath and do a full parse */
1223 if (yypath) YYABORT;
1226 YYParseState *save = yyps->save;
1227 yyps->save = save->save;
1228 save->save = yypath;
1233 fprintf(stderr, "%s[%d]: state %d, CONFLICT trial successful, backtracking to state %d, %d tokens\n",
1234 YYDEBUGSTR, yydepth, yystate, yypath->state, (int)(yylvp - yylvals - yypath->lexeme));
1238 yyFreeState(yyerrctx);
1241 yylvp = yylvals + yypath->lexeme;
1242 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1243 yylpp = yylpsns + yypath->lexeme;
1245 yylexp = yylexemes + yypath->lexeme;
1247 yystack.s_mark = yystack.s_base + (yypath->yystack.s_mark - yypath->yystack.s_base);
1248 memcpy (yystack.s_base, yypath->yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(short));
1249 yystack.l_mark = yystack.l_base + (yypath->yystack.l_mark - yypath->yystack.l_base);
1250 memcpy (yystack.l_base, yypath->yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
1251 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1252 yystack.p_mark = yystack.p_base + (yypath->yystack.p_mark - yypath->yystack.p_base);
1253 memcpy (yystack.p_base, yypath->yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
1255 yystate = yypath->state;
1257 #endif /* YYBTYACC */
1260 YYERROR_CALL("yacc stack overflow");
1264 YYERROR_CALL("memory exhausted");
1266 #endif /* YYBTYACC */
1276 if (yyps->save) goto yyvalid;
1277 #endif /* YYBTYACC */
1281 #if defined(YYDESTRUCT_CALL)
1282 if (yychar != YYEOF && yychar != YYEMPTY)
1283 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1284 YYDESTRUCT_CALL("cleanup: discarding token", yychar, &yylval, &yylloc);
1286 YYDESTRUCT_CALL("cleanup: discarding token", yychar, &yylval);
1287 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
1291 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1294 for (pv = yystack.l_base, pp = yystack.p_base; pv <= yystack.l_mark; ++pv, ++pp)
1295 YYDESTRUCT_CALL("cleanup: discarding state",
1296 yystos[*(yystack.s_base + (pv - yystack.l_base))], pv, pp);
1298 for (pv = yystack.l_base; pv <= yystack.l_mark; ++pv)
1299 YYDESTRUCT_CALL("cleanup: discarding state",
1300 yystos[*(yystack.s_base + (pv - yystack.l_base))], pv);
1301 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
1303 #endif /* defined(YYDESTRUCT_CALL) */
1308 yyFreeState(yyerrctx);
1313 YYParseState *save = yyps;
1320 YYParseState *save = yypath;
1321 yypath = save->save;
1325 #endif /* YYBTYACC */
1326 yyfreestack(&yystack);