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_"
120 #line 4 "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
174 #define yytname yyname
175 #define YYTABLESIZE 220
180 #define YYMAXTOKEN 259
181 #define YYUNDFTOKEN 265
182 #define YYTRANSLATE(a) ((a) > YYMAXTOKEN ? YYUNDFTOKEN : (a))
184 extern int YYPARSE_DECL();
186 extern const YYINT yylhs[];
187 extern const YYINT yylen[];
188 extern const YYINT yydefred[];
189 extern const YYINT yystos[];
190 extern const YYINT yydgoto[];
191 extern const YYINT yysindex[];
192 extern const YYINT yyrindex[];
194 extern const YYINT yycindex[];
195 #endif /* YYBTYACC */
196 extern const YYINT yygindex[];
197 extern const YYINT yytable[];
198 extern const YYINT yycheck[];
200 extern const YYINT yyctable[];
201 #endif /* YYBTYACC */
203 #if YYDEBUG || defined(yytname)
204 extern const char *const yyname[];
207 extern const char *const yyrule[];
220 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
221 YYLTYPE yyloc; /* position returned by actions */
222 YYLTYPE yylloc; /* position from the lexer */
225 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
226 #ifndef YYLLOC_DEFAULT
227 #define YYLLOC_DEFAULT(loc, rhs, n) \
232 (loc).first_line = YYRHSLOC(rhs, 0).last_line; \
233 (loc).first_column = YYRHSLOC(rhs, 0).last_column; \
234 (loc).last_line = YYRHSLOC(rhs, 0).last_line; \
235 (loc).last_column = YYRHSLOC(rhs, 0).last_column; \
239 (loc).first_line = YYRHSLOC(rhs, 1).first_line; \
240 (loc).first_column = YYRHSLOC(rhs, 1).first_column; \
241 (loc).last_line = YYRHSLOC(rhs, n).last_line; \
242 (loc).last_column = YYRHSLOC(rhs, n).last_column; \
245 #endif /* YYLLOC_DEFAULT */
246 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
249 #ifndef YYLVQUEUEGROWTH
250 #define YYLVQUEUEGROWTH 32
252 #endif /* YYBTYACC */
254 /* define the initial stack-sizes */
257 #define YYMAXDEPTH YYSTACKSIZE
260 #define YYSTACKSIZE YYMAXDEPTH
262 #define YYSTACKSIZE 10000
263 #define YYMAXDEPTH 10000
267 #ifndef YYINITSTACKSIZE
268 #define YYINITSTACKSIZE 200
278 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
285 struct YYParseState_s
287 struct YYParseState_s *save; /* Previously saved parser state */
288 YYSTACKDATA yystack; /* saved parser stack */
289 int state; /* saved parser state */
290 int errflag; /* saved error recovery status */
291 int lexeme; /* saved index of the conflict lexeme in the lexical queue */
292 YYINT ctry; /* saved index in yyctable[] for this conflict */
294 typedef struct YYParseState_s YYParseState;
295 #endif /* YYBTYACC */
296 /* variables for the parser stack */
297 static YYSTACKDATA yystack;
300 /* Current parser state */
301 static YYParseState *yyps = 0;
303 /* yypath != NULL: do the full parse, starting at *yypath parser state. */
304 static YYParseState *yypath = 0;
306 /* Base of the lexical value queue */
307 static YYSTYPE *yylvals = 0;
309 /* Current position at lexical value queue */
310 static YYSTYPE *yylvp = 0;
312 /* End position of lexical value queue */
313 static YYSTYPE *yylve = 0;
315 /* The last allocated position at the lexical value queue */
316 static YYSTYPE *yylvlim = 0;
318 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
319 /* Base of the lexical position queue */
320 static YYLTYPE *yylpsns = 0;
322 /* Current position at lexical position queue */
323 static YYLTYPE *yylpp = 0;
325 /* End position of lexical position queue */
326 static YYLTYPE *yylpe = 0;
328 /* The last allocated position at the lexical position queue */
329 static YYLTYPE *yylplim = 0;
332 /* Current position at lexical token queue */
333 static YYINT *yylexp = 0;
335 static YYINT *yylexemes = 0;
336 #endif /* YYBTYACC */
337 #line 70 "code_calc.y"
338 /* start of programs */
341 extern int YYLEX_DECL();
347 while(!feof(stdin)) {
354 yyerror(const char *s)
356 fprintf(stderr, "%s\n", s);
362 /* lexical analysis routine */
363 /* returns LETTER for a lower case letter, yylval = 0 through 25 */
364 /* return DIGIT for a digit, yylval = 0 through 9 */
365 /* all other characters are returned immediately */
369 while( (c=getchar()) == ' ' ) { /* skip blanks */ }
371 /* c is now nonblank */
383 #line 384 "code_calc.code.c"
385 /* For use in generated program */
386 #define yydepth (int)(yystack.s_mark - yystack.s_base)
388 #define yytrial (yyps->save)
389 #endif /* YYBTYACC */
392 #include <stdio.h> /* needed for printf */
395 #include <stdlib.h> /* needed for malloc, etc */
396 #include <string.h> /* needed for memset */
398 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
399 static int yygrowstack(YYSTACKDATA *data)
405 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
409 if ((newsize = data->stacksize) == 0)
410 newsize = YYINITSTACKSIZE;
411 else if (newsize >= YYMAXDEPTH)
413 else if ((newsize *= 2) > YYMAXDEPTH)
414 newsize = YYMAXDEPTH;
416 i = (int) (data->s_mark - data->s_base);
417 newss = (YYINT *)realloc(data->s_base, newsize * sizeof(*newss));
421 data->s_base = newss;
422 data->s_mark = newss + i;
424 newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));
428 data->l_base = newvs;
429 data->l_mark = newvs + i;
431 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
432 newps = (YYLTYPE *)realloc(data->p_base, newsize * sizeof(*newps));
436 data->p_base = newps;
437 data->p_mark = newps + i;
440 data->stacksize = newsize;
441 data->s_last = data->s_base + newsize - 1;
445 fprintf(stderr, "%sdebug: stack size increased to %d\n", YYPREFIX, newsize);
450 #if YYPURE || defined(YY_NO_LEAKS)
451 static void yyfreestack(YYSTACKDATA *data)
455 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
458 memset(data, 0, sizeof(*data));
461 #define yyfreestack(data) /* nothing */
462 #endif /* YYPURE || defined(YY_NO_LEAKS) */
465 static YYParseState *
466 yyNewState(unsigned size)
468 YYParseState *p = (YYParseState *) malloc(sizeof(YYParseState));
469 if (p == NULL) return NULL;
471 p->yystack.stacksize = size;
474 p->yystack.s_base = NULL;
475 p->yystack.l_base = NULL;
476 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
477 p->yystack.p_base = NULL;
481 p->yystack.s_base = (YYINT *) malloc(size * sizeof(YYINT));
482 if (p->yystack.s_base == NULL) return NULL;
483 p->yystack.l_base = (YYSTYPE *) malloc(size * sizeof(YYSTYPE));
484 if (p->yystack.l_base == NULL) return NULL;
485 memset(p->yystack.l_base, 0, size * sizeof(YYSTYPE));
486 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
487 p->yystack.p_base = (YYLTYPE *) malloc(size * sizeof(YYLTYPE));
488 if (p->yystack.p_base == NULL) return NULL;
489 memset(p->yystack.p_base, 0, size * sizeof(YYLTYPE));
496 yyFreeState(YYParseState *p)
498 yyfreestack(&p->yystack);
501 #endif /* YYBTYACC */
503 #define YYABORT goto yyabort
504 #define YYREJECT goto yyabort
505 #define YYACCEPT goto yyaccept
506 #define YYERROR goto yyerrlab
508 #define YYVALID do { if (yyps->save) goto yyvalid; } while(0)
509 #define YYVALID_NESTED do { if (yyps->save && \
510 yyps->save->save == 0) goto yyvalid; } while(0)
511 #endif /* YYBTYACC */
516 int yym, yyn, yystate, yyresult;
519 YYParseState *yyerrctx = NULL;
520 #endif /* YYBTYACC */
521 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
522 YYLTYPE yyerror_loc_range[3]; /* position of error start/end (0 unused) */
527 if ((yys = getenv("YYDEBUG")) != 0)
530 if (yyn >= '0' && yyn <= '9')
534 fprintf(stderr, "%sdebug[<# of symbols on state stack>]\n", YYPREFIX);
536 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
537 memset(yyerror_loc_range, 0, sizeof(yyerror_loc_range));
541 yyps = yyNewState(0); if (yyps == 0) goto yyenomem;
543 #endif /* YYBTYACC */
552 memset(&yystack, 0, sizeof(yystack));
555 if (yystack.s_base == NULL && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
556 yystack.s_mark = yystack.s_base;
557 yystack.l_mark = yystack.l_base;
558 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
559 yystack.p_mark = yystack.p_base;
565 if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
572 /* we're currently re-reading tokens */
574 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
582 /* in trial mode; save scanner results for future parse attempts */
583 if (yylvp == yylvlim)
584 { /* Enlarge lexical value queue */
585 size_t p = (size_t) (yylvp - yylvals);
586 size_t s = (size_t) (yylvlim - yylvals);
588 s += YYLVQUEUEGROWTH;
589 if ((yylexemes = (YYINT *)realloc(yylexemes, s * sizeof(YYINT))) == NULL) goto yyenomem;
590 if ((yylvals = (YYSTYPE *)realloc(yylvals, s * sizeof(YYSTYPE))) == NULL) goto yyenomem;
591 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
592 if ((yylpsns = (YYLTYPE *)realloc(yylpsns, s * sizeof(YYLTYPE))) == NULL) goto yyenomem;
594 yylvp = yylve = yylvals + p;
595 yylvlim = yylvals + s;
596 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
597 yylpp = yylpe = yylpsns + p;
598 yylplim = yylpsns + s;
600 yylexp = yylexemes + p;
602 *yylexp = (YYINT) YYLEX;
605 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
612 /* normal operation, no conflict encountered */
613 #endif /* YYBTYACC */
617 #endif /* YYBTYACC */
618 if (yychar < 0) yychar = YYEOF;
622 if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN];
623 fprintf(stderr, "%s[%d]: state %d, reading token %d (%s)",
624 YYDEBUGSTR, yydepth, yystate, yychar, yys);
625 #ifdef YYSTYPE_TOSTRING
628 #endif /* YYBTYACC */
629 fprintf(stderr, " <%s>", YYSTYPE_TOSTRING(yychar, yylval));
637 /* Do we have a conflict? */
638 if (((yyn = yycindex[yystate]) != 0) && (yyn += yychar) >= 0 &&
639 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar)
648 fprintf(stderr, "%s[%d]: CONFLICT in state %d: following successful trial parse\n",
649 YYDEBUGSTR, yydepth, yystate);
651 /* Switch to the next conflict context */
656 if (save->state != yystate) YYABORT;
663 /* Unresolved conflict - start/continue trial parse */
668 fprintf(stderr, "%s[%d]: CONFLICT in state %d. ", YYDEBUGSTR, yydepth, yystate);
670 fputs("ALREADY in conflict, continuing trial parse.\n", stderr);
672 fputs("Starting trial parse.\n", stderr);
675 save = yyNewState((unsigned)(yystack.s_mark - yystack.s_base + 1));
676 if (save == NULL) goto yyenomem;
677 save->save = yyps->save;
678 save->state = yystate;
679 save->errflag = yyerrflag;
680 save->yystack.s_mark = save->yystack.s_base + (yystack.s_mark - yystack.s_base);
681 memcpy (save->yystack.s_base, yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(YYINT));
682 save->yystack.l_mark = save->yystack.l_base + (yystack.l_mark - yystack.l_base);
683 memcpy (save->yystack.l_base, yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
684 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
685 save->yystack.p_mark = save->yystack.p_base + (yystack.p_mark - yystack.p_base);
686 memcpy (save->yystack.p_base, yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
689 if (yyctable[ctry] == -1)
692 if (yydebug && yychar >= YYEOF)
693 fprintf(stderr, "%s[%d]: backtracking 1 token\n", YYDEBUGSTR, yydepth);
698 if (yyps->save == NULL)
700 /* If this is a first conflict in the stack, start saving lexemes */
703 yylexemes = (YYINT *) malloc((YYLVQUEUEGROWTH) * sizeof(YYINT));
704 if (yylexemes == NULL) goto yyenomem;
705 yylvals = (YYSTYPE *) malloc((YYLVQUEUEGROWTH) * sizeof(YYSTYPE));
706 if (yylvals == NULL) goto yyenomem;
707 yylvlim = yylvals + YYLVQUEUEGROWTH;
708 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
709 yylpsns = (YYLTYPE *) malloc((YYLVQUEUEGROWTH) * sizeof(YYLTYPE));
710 if (yylpsns == NULL) goto yyenomem;
711 yylplim = yylpsns + YYLVQUEUEGROWTH;
716 yylvp = yylve = yylvals;
717 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
718 yylpp = yylpe = yylpsns;
724 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
727 *yylexp = (YYINT) yychar;
735 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
741 save->lexeme = (int) (yylvp - yylvals);
744 if (yytable[yyn] == ctry)
748 fprintf(stderr, "%s[%d]: state %d, shifting to state %d\n",
749 YYDEBUGSTR, yydepth, yystate, yyctable[ctry]);
754 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
759 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM)
761 yystate = yyctable[ctry];
762 *++yystack.s_mark = (YYINT) yystate;
763 *++yystack.l_mark = yylval;
764 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
765 *++yystack.p_mark = yylloc;
768 if (yyerrflag > 0) --yyerrflag;
773 yyn = yyctable[ctry];
776 } /* End of code dealing with conflicts */
777 #endif /* YYBTYACC */
778 if (((yyn = yysindex[yystate]) != 0) && (yyn += yychar) >= 0 &&
779 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar)
783 fprintf(stderr, "%s[%d]: state %d, shifting to state %d\n",
784 YYDEBUGSTR, yydepth, yystate, yytable[yyn]);
786 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
787 yystate = yytable[yyn];
788 *++yystack.s_mark = yytable[yyn];
789 *++yystack.l_mark = yylval;
790 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
791 *++yystack.p_mark = yylloc;
794 if (yyerrflag > 0) --yyerrflag;
797 if (((yyn = yyrindex[yystate]) != 0) && (yyn += yychar) >= 0 &&
798 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar)
803 if (yyerrflag != 0) goto yyinrecovery;
808 goto yyerrlab; /* redundant goto avoids 'unused label' warning */
811 /* explicit YYERROR from an action -- pop the rhs of the rule reduced
812 * before looking for error recovery */
813 yystack.s_mark -= yym;
814 yystate = *yystack.s_mark;
815 yystack.l_mark -= yym;
816 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
817 yystack.p_mark -= yym;
825 YYParseState *save = yyps->save;
828 fprintf(stderr, "%s[%d]: ERROR in state %d, CONFLICT BACKTRACKING to state %d, %d tokens\n",
829 YYDEBUGSTR, yydepth, yystate, yyps->save->state,
830 (int)(yylvp - yylvals - yyps->save->lexeme));
832 /* Memorize most forward-looking error state in case it's really an error. */
833 if (yyerrctx == NULL || yyerrctx->lexeme < yylvp - yylvals)
835 /* Free old saved error context state */
836 if (yyerrctx) yyFreeState(yyerrctx);
837 /* Create and fill out new saved error context state */
838 yyerrctx = yyNewState((unsigned)(yystack.s_mark - yystack.s_base + 1));
839 if (yyerrctx == NULL) goto yyenomem;
840 yyerrctx->save = yyps->save;
841 yyerrctx->state = yystate;
842 yyerrctx->errflag = yyerrflag;
843 yyerrctx->yystack.s_mark = yyerrctx->yystack.s_base + (yystack.s_mark - yystack.s_base);
844 memcpy (yyerrctx->yystack.s_base, yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(YYINT));
845 yyerrctx->yystack.l_mark = yyerrctx->yystack.l_base + (yystack.l_mark - yystack.l_base);
846 memcpy (yyerrctx->yystack.l_base, yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
847 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
848 yyerrctx->yystack.p_mark = yyerrctx->yystack.p_base + (yystack.p_mark - yystack.p_base);
849 memcpy (yyerrctx->yystack.p_base, yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
851 yyerrctx->lexeme = (int) (yylvp - yylvals);
853 yylvp = yylvals + save->lexeme;
854 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
855 yylpp = yylpsns + save->lexeme;
857 yylexp = yylexemes + save->lexeme;
859 yystack.s_mark = yystack.s_base + (save->yystack.s_mark - save->yystack.s_base);
860 memcpy (yystack.s_base, save->yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(YYINT));
861 yystack.l_mark = yystack.l_base + (save->yystack.l_mark - save->yystack.l_base);
862 memcpy (yystack.l_base, save->yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
863 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
864 yystack.p_mark = yystack.p_base + (save->yystack.p_mark - save->yystack.p_base);
865 memcpy (yystack.p_base, save->yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
868 yystate = save->state;
869 /* We tried shift, try reduce now */
870 if ((yyn = yyctable[ctry]) >= 0) goto yyreduce;
871 yyps->save = save->save;
875 /* Nothing left on the stack -- error */
880 fprintf(stderr, "%sdebug[%d,trial]: trial parse FAILED, entering ERROR mode\n",
883 /* Restore state as it was in the most forward-advanced error */
884 yylvp = yylvals + yyerrctx->lexeme;
885 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
886 yylpp = yylpsns + yyerrctx->lexeme;
888 yylexp = yylexemes + yyerrctx->lexeme;
891 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
894 yystack.s_mark = yystack.s_base + (yyerrctx->yystack.s_mark - yyerrctx->yystack.s_base);
895 memcpy (yystack.s_base, yyerrctx->yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(YYINT));
896 yystack.l_mark = yystack.l_base + (yyerrctx->yystack.l_mark - yyerrctx->yystack.l_base);
897 memcpy (yystack.l_base, yyerrctx->yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
898 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
899 yystack.p_mark = yystack.p_base + (yyerrctx->yystack.p_mark - yyerrctx->yystack.p_base);
900 memcpy (yystack.p_base, yyerrctx->yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
902 yystate = yyerrctx->state;
903 yyFreeState(yyerrctx);
908 if (yynewerrflag == 0) goto yyinrecovery;
909 #endif /* YYBTYACC */
911 YYERROR_CALL("syntax error");
912 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
913 yyerror_loc_range[1] = yylloc; /* lookahead position is error start position */
917 goto yyerrlab; /* redundant goto avoids 'unused label' warning */
928 if (((yyn = yysindex[*yystack.s_mark]) != 0) && (yyn += YYERRCODE) >= 0 &&
929 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) YYERRCODE)
933 fprintf(stderr, "%s[%d]: state %d, error recovery shifting to state %d\n",
934 YYDEBUGSTR, yydepth, *yystack.s_mark, yytable[yyn]);
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 /* lookahead position is error end position */
942 yyerror_loc_range[2] = yylloc;
943 YYLLOC_DEFAULT(yyloc, yyerror_loc_range, 2); /* position of error span */
944 *++yystack.p_mark = yyloc;
952 fprintf(stderr, "%s[%d]: error recovery discarding state %d\n",
953 YYDEBUGSTR, yydepth, *yystack.s_mark);
955 if (yystack.s_mark <= yystack.s_base) goto yyabort;
956 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
957 /* the current TOS position is the error start position */
958 yyerror_loc_range[1] = *yystack.p_mark;
960 #if defined(YYDESTRUCT_CALL)
963 #endif /* YYBTYACC */
964 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
965 YYDESTRUCT_CALL("error: discarding state",
966 yystos[*yystack.s_mark], yystack.l_mark, yystack.p_mark);
968 YYDESTRUCT_CALL("error: discarding state",
969 yystos[*yystack.s_mark], yystack.l_mark);
970 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
971 #endif /* defined(YYDESTRUCT_CALL) */
974 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
982 if (yychar == YYEOF) goto yyabort;
986 if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN];
987 fprintf(stderr, "%s[%d]: state %d, error recovery discarding token %d (%s)\n",
988 YYDEBUGSTR, yydepth, yystate, yychar, yys);
991 #if defined(YYDESTRUCT_CALL)
994 #endif /* YYBTYACC */
995 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
996 YYDESTRUCT_CALL("error: discarding token", yychar, &yylval, &yylloc);
998 YYDESTRUCT_CALL("error: discarding token", yychar, &yylval);
999 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
1000 #endif /* defined(YYDESTRUCT_CALL) */
1010 fprintf(stderr, "%s[%d]: state %d, reducing by rule %d (%s)",
1011 YYDEBUGSTR, yydepth, yystate, yyn, yyrule[yyn]);
1012 #ifdef YYSTYPE_TOSTRING
1015 #endif /* YYBTYACC */
1020 for (i = yym; i > 0; i--)
1022 if (i != yym) fputs(", ", stderr);
1023 fputs(YYSTYPE_TOSTRING(yystos[yystack.s_mark[1-i]],
1024 yystack.l_mark[1-i]), stderr);
1029 fputc('\n', stderr);
1033 yyval = yystack.l_mark[1-yym];
1035 memset(&yyval, 0, sizeof yyval);
1036 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1038 /* Perform position reduction */
1039 memset(&yyloc, 0, sizeof(yyloc));
1042 #endif /* YYBTYACC */
1044 YYLLOC_DEFAULT(yyloc, &yystack.p_mark[-yym], yym);
1045 /* just in case YYERROR is invoked within the action, save
1046 the start of the rhs as the error start position */
1047 yyerror_loc_range[1] = yystack.p_mark[1-yym];
1054 #line 32 "code_calc.y"
1058 #line 36 "code_calc.y"
1059 { printf("%d\n",yystack.l_mark[0]);}
1062 #line 38 "code_calc.y"
1063 { regs[yystack.l_mark[-2]] = yystack.l_mark[0]; }
1066 #line 42 "code_calc.y"
1067 { yyval = yystack.l_mark[-1]; }
1070 #line 44 "code_calc.y"
1071 { yyval = yystack.l_mark[-2] + yystack.l_mark[0]; }
1074 #line 46 "code_calc.y"
1075 { yyval = yystack.l_mark[-2] - yystack.l_mark[0]; }
1078 #line 48 "code_calc.y"
1079 { yyval = yystack.l_mark[-2] * yystack.l_mark[0]; }
1082 #line 50 "code_calc.y"
1083 { yyval = yystack.l_mark[-2] / yystack.l_mark[0]; }
1086 #line 52 "code_calc.y"
1087 { yyval = yystack.l_mark[-2] % yystack.l_mark[0]; }
1090 #line 54 "code_calc.y"
1091 { yyval = yystack.l_mark[-2] & yystack.l_mark[0]; }
1094 #line 56 "code_calc.y"
1095 { yyval = yystack.l_mark[-2] | yystack.l_mark[0]; }
1098 #line 58 "code_calc.y"
1099 { yyval = - yystack.l_mark[0]; }
1102 #line 60 "code_calc.y"
1103 { yyval = regs[yystack.l_mark[0]]; }
1106 #line 65 "code_calc.y"
1107 { yyval = yystack.l_mark[0]; base = (yystack.l_mark[0]==0) ? 8 : 10; }
1110 #line 67 "code_calc.y"
1111 { yyval = base * yystack.l_mark[-1] + yystack.l_mark[0]; }
1113 #line 1114 "code_calc.code.c"
1117 yystack.s_mark -= yym;
1118 yystate = *yystack.s_mark;
1119 yystack.l_mark -= yym;
1120 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1121 yystack.p_mark -= yym;
1124 if (yystate == 0 && yym == 0)
1129 fprintf(stderr, "%s[%d]: after reduction, ", YYDEBUGSTR, yydepth);
1130 #ifdef YYSTYPE_TOSTRING
1133 #endif /* YYBTYACC */
1134 fprintf(stderr, "result is <%s>, ", YYSTYPE_TOSTRING(yystos[YYFINAL], yyval));
1136 fprintf(stderr, "shifting from state 0 to final state %d\n", YYFINAL);
1140 *++yystack.s_mark = YYFINAL;
1141 *++yystack.l_mark = yyval;
1142 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1143 *++yystack.p_mark = yyloc;
1151 /* we're currently re-reading tokens */
1153 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1161 /* in trial mode; save scanner results for future parse attempts */
1162 if (yylvp == yylvlim)
1163 { /* Enlarge lexical value queue */
1164 size_t p = (size_t) (yylvp - yylvals);
1165 size_t s = (size_t) (yylvlim - yylvals);
1167 s += YYLVQUEUEGROWTH;
1168 if ((yylexemes = (YYINT *)realloc(yylexemes, s * sizeof(YYINT))) == NULL)
1170 if ((yylvals = (YYSTYPE *)realloc(yylvals, s * sizeof(YYSTYPE))) == NULL)
1172 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1173 if ((yylpsns = (YYLTYPE *)realloc(yylpsns, s * sizeof(YYLTYPE))) == NULL)
1176 yylvp = yylve = yylvals + p;
1177 yylvlim = yylvals + s;
1178 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1179 yylpp = yylpe = yylpsns + p;
1180 yylplim = yylpsns + s;
1182 yylexp = yylexemes + p;
1184 *yylexp = (YYINT) YYLEX;
1187 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1194 /* normal operation, no conflict encountered */
1195 #endif /* YYBTYACC */
1199 #endif /* YYBTYACC */
1200 if (yychar < 0) yychar = YYEOF;
1204 if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN];
1205 fprintf(stderr, "%s[%d]: state %d, reading token %d (%s)\n",
1206 YYDEBUGSTR, yydepth, YYFINAL, yychar, yys);
1210 if (yychar == YYEOF) goto yyaccept;
1213 if (((yyn = yygindex[yym]) != 0) && (yyn += yystate) >= 0 &&
1214 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yystate)
1215 yystate = yytable[yyn];
1217 yystate = yydgoto[yym];
1221 fprintf(stderr, "%s[%d]: after reduction, ", YYDEBUGSTR, yydepth);
1222 #ifdef YYSTYPE_TOSTRING
1225 #endif /* YYBTYACC */
1226 fprintf(stderr, "result is <%s>, ", YYSTYPE_TOSTRING(yystos[yystate], yyval));
1228 fprintf(stderr, "shifting from state %d to state %d\n", *yystack.s_mark, yystate);
1231 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
1232 *++yystack.s_mark = (YYINT) yystate;
1233 *++yystack.l_mark = yyval;
1234 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1235 *++yystack.p_mark = yyloc;
1240 /* Reduction declares that this path is valid. Set yypath and do a full parse */
1242 if (yypath) YYABORT;
1245 YYParseState *save = yyps->save;
1246 yyps->save = save->save;
1247 save->save = yypath;
1252 fprintf(stderr, "%s[%d]: state %d, CONFLICT trial successful, backtracking to state %d, %d tokens\n",
1253 YYDEBUGSTR, yydepth, yystate, yypath->state, (int)(yylvp - yylvals - yypath->lexeme));
1257 yyFreeState(yyerrctx);
1260 yylvp = yylvals + yypath->lexeme;
1261 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1262 yylpp = yylpsns + yypath->lexeme;
1264 yylexp = yylexemes + yypath->lexeme;
1266 yystack.s_mark = yystack.s_base + (yypath->yystack.s_mark - yypath->yystack.s_base);
1267 memcpy (yystack.s_base, yypath->yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(YYINT));
1268 yystack.l_mark = yystack.l_base + (yypath->yystack.l_mark - yypath->yystack.l_base);
1269 memcpy (yystack.l_base, yypath->yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
1270 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1271 yystack.p_mark = yystack.p_base + (yypath->yystack.p_mark - yypath->yystack.p_base);
1272 memcpy (yystack.p_base, yypath->yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
1274 yystate = yypath->state;
1276 #endif /* YYBTYACC */
1279 YYERROR_CALL("yacc stack overflow");
1283 YYERROR_CALL("memory exhausted");
1285 #endif /* YYBTYACC */
1295 if (yyps->save) goto yyvalid;
1296 #endif /* YYBTYACC */
1300 #if defined(YYDESTRUCT_CALL)
1301 if (yychar != YYEOF && yychar != YYEMPTY)
1302 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1303 YYDESTRUCT_CALL("cleanup: discarding token", yychar, &yylval, &yylloc);
1305 YYDESTRUCT_CALL("cleanup: discarding token", yychar, &yylval);
1306 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
1310 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1313 for (pv = yystack.l_base, pp = yystack.p_base; pv <= yystack.l_mark; ++pv, ++pp)
1314 YYDESTRUCT_CALL("cleanup: discarding state",
1315 yystos[*(yystack.s_base + (pv - yystack.l_base))], pv, pp);
1317 for (pv = yystack.l_base; pv <= yystack.l_mark; ++pv)
1318 YYDESTRUCT_CALL("cleanup: discarding state",
1319 yystos[*(yystack.s_base + (pv - yystack.l_base))], pv);
1320 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
1322 #endif /* defined(YYDESTRUCT_CALL) */
1327 yyFreeState(yyerrctx);
1332 YYParseState *save = yyps;
1339 YYParseState *save = yypath;
1340 yypath = save->save;
1344 #endif /* YYBTYACC */
1345 yyfreestack(&yystack);