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 calc3_parse
25 #define yylex calc3_lex
29 #define yyerror calc3_error
33 #define yychar calc3_char
37 #define yyval calc3_val
41 #define yylval calc3_lval
45 #define yydebug calc3_debug
49 #define yynerrs calc3_nerrs
53 #define yyerrflag calc3_errflag
54 #endif /* yyerrflag */
57 #define yylhs calc3_lhs
61 #define yylen calc3_len
65 #define yydefred calc3_defred
69 #define yystos calc3_stos
73 #define yydgoto calc3_dgoto
77 #define yysindex calc3_sindex
81 #define yyrindex calc3_rindex
85 #define yygindex calc3_gindex
89 #define yytable calc3_table
93 #define yycheck calc3_check
97 #define yyname calc3_name
101 #define yyrule calc3_rule
107 #define yycindex calc3_cindex
108 #endif /* yycindex */
111 #define yyctable calc3_ctable
112 #endif /* yyctable */
114 #endif /* YYBTYACC */
116 #define YYPREFIX "calc3_"
126 #define YYLEX_PARAM base
127 #define YYLEX_DECL() yylex(YYSTYPE *yylval, int *YYLEX_PARAM)
128 #define YYERROR_DECL() yyerror(int regs[26], int *base, const char *s)
130 static void YYERROR_DECL();
133 #line 134 "calc3.tab.c"
135 #if ! defined(YYSTYPE) && ! defined(YYSTYPE_IS_DECLARED)
136 /* Default: YYSTYPE is the semantic value type. */
138 # define YYSTYPE_IS_DECLARED 1
141 /* compatibility with bison */
143 /* compatibility with FreeBSD */
144 # ifdef YYPARSE_PARAM_TYPE
145 # define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
147 # define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
150 # define YYPARSE_DECL() yyparse(int regs[26], int * base)
153 /* Parameters sent to lex. */
155 # ifdef YYLEX_PARAM_TYPE
156 # define YYLEX_DECL() yylex(YYSTYPE *yylval, YYLEX_PARAM_TYPE YYLEX_PARAM)
158 # define YYLEX_DECL() yylex(YYSTYPE *yylval, void * YYLEX_PARAM)
160 # define YYLEX yylex(&yylval, YYLEX_PARAM)
162 # define YYLEX_DECL() yylex(YYSTYPE *yylval, int * base)
163 # define YYLEX yylex(&yylval, base)
166 /* Parameters sent to yyerror. */
168 #define YYERROR_DECL() yyerror(int regs[26], int * base, const char *s)
171 #define YYERROR_CALL(msg) yyerror(regs, base, msg)
174 extern int YYPARSE_DECL();
179 #define YYERRCODE 256
181 static const YYINT calc3_lhs[] = { -1,
182 0, 0, 0, 1, 1, 2, 2, 2, 2, 2,
183 2, 2, 2, 2, 2, 2, 3, 3,
185 static const YYINT calc3_len[] = { 2,
186 0, 3, 3, 1, 3, 3, 3, 3, 3, 3,
187 3, 3, 3, 2, 1, 1, 1, 2,
189 static const YYINT calc3_defred[] = { 1,
190 0, 0, 17, 0, 0, 0, 0, 0, 0, 3,
191 0, 15, 14, 0, 2, 0, 0, 0, 0, 0,
192 0, 0, 18, 0, 6, 0, 0, 0, 0, 9,
195 static const YYINT calc3_stos[] = { 0,
196 261, 256, 257, 258, 45, 40, 262, 263, 264, 10,
197 61, 258, 263, 263, 10, 124, 38, 43, 45, 42,
198 47, 37, 257, 263, 41, 263, 263, 263, 263, 263,
201 static const YYINT calc3_dgoto[] = { 1,
204 static const YYINT calc3_sindex[] = { 0,
205 -40, -7, 0, -55, -38, -38, 1, -29, -247, 0,
206 -38, 0, 0, 22, 0, -38, -38, -38, -38, -38,
207 -38, -38, 0, -29, 0, 51, 60, -20, -20, 0,
210 static const YYINT calc3_rindex[] = { 0,
211 0, 0, 0, 2, 0, 0, 0, 9, -9, 0,
212 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
213 0, 0, 0, 10, 0, -6, 14, 5, 13, 0,
217 static const YYINT calc3_cindex[] = { 0,
218 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
219 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
220 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
224 static const YYINT calc3_gindex[] = { 0,
227 #define YYTABLESIZE 220
228 static const YYINT calc3_table[] = { 6,
229 16, 6, 10, 13, 5, 11, 5, 22, 17, 23,
230 15, 15, 20, 18, 7, 19, 22, 21, 4, 5,
231 0, 20, 8, 12, 0, 0, 21, 16, 16, 0,
232 0, 16, 16, 16, 13, 16, 0, 16, 15, 15,
233 0, 0, 7, 15, 15, 7, 15, 7, 15, 7,
234 8, 12, 0, 8, 12, 8, 0, 8, 22, 17,
235 0, 0, 25, 20, 18, 0, 19, 0, 21, 13,
236 14, 0, 0, 0, 0, 24, 0, 0, 0, 0,
237 26, 27, 28, 29, 30, 31, 32, 22, 17, 0,
238 0, 0, 20, 18, 16, 19, 22, 21, 0, 0,
239 0, 20, 18, 0, 19, 0, 21, 0, 0, 0,
240 0, 0, 0, 0, 16, 0, 0, 13, 0, 0,
241 0, 0, 0, 0, 0, 15, 0, 0, 7, 0,
242 0, 0, 0, 0, 0, 0, 8, 12, 0, 0,
243 0, 0, 0, 0, 0, 16, 0, 0, 0, 0,
244 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
245 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
246 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
247 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
248 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
249 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
250 0, 0, 0, 0, 0, 2, 3, 4, 3, 12,
252 static const YYINT calc3_check[] = { 40,
253 10, 40, 10, 10, 45, 61, 45, 37, 38, 257,
254 10, 10, 42, 43, 10, 45, 37, 47, 10, 10,
255 -1, 42, 10, 10, -1, -1, 47, 37, 38, -1,
256 -1, 41, 42, 43, 41, 45, -1, 47, 37, 38,
257 -1, -1, 38, 42, 43, 41, 45, 43, 47, 45,
258 38, 38, -1, 41, 41, 43, -1, 45, 37, 38,
259 -1, -1, 41, 42, 43, -1, 45, -1, 47, 5,
260 6, -1, -1, -1, -1, 11, -1, -1, -1, -1,
261 16, 17, 18, 19, 20, 21, 22, 37, 38, -1,
262 -1, -1, 42, 43, 124, 45, 37, 47, -1, -1,
263 -1, 42, 43, -1, 45, -1, 47, -1, -1, -1,
264 -1, -1, -1, -1, 124, -1, -1, 124, -1, -1,
265 -1, -1, -1, -1, -1, 124, -1, -1, 124, -1,
266 -1, -1, -1, -1, -1, -1, 124, 124, -1, -1,
267 -1, -1, -1, -1, -1, 124, -1, -1, -1, -1,
268 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
269 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
270 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
271 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
272 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
273 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
274 -1, -1, -1, -1, -1, 256, 257, 258, 257, 258,
280 #define YYMAXTOKEN 259
281 #define YYUNDFTOKEN 265
282 #define YYTRANSLATE(a) ((a) > YYMAXTOKEN ? YYUNDFTOKEN : (a))
284 static const char *const calc3_name[] = {
286 "$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,
287 0,0,0,"'%'","'&'",0,"'('","')'","'*'","'+'",0,"'-'",0,"'/'",0,0,0,0,0,0,0,0,0,0,
288 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,
289 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,
290 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,
291 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,
292 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,
293 0,0,"error","DIGIT","LETTER","UMINUS","$accept","list","stat","expr","number",
296 static const char *const calc3_rule[] = {
299 "list : list stat '\\n'",
300 "list : list error '\\n'",
302 "stat : LETTER '=' expr",
303 "expr : '(' expr ')'",
304 "expr : expr '+' expr",
305 "expr : expr '-' expr",
306 "expr : expr '*' expr",
307 "expr : expr '/' expr",
308 "expr : expr '%' expr",
309 "expr : expr '&' expr",
310 "expr : expr '|' expr",
315 "number : number DIGIT",
323 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
324 #ifndef YYLLOC_DEFAULT
325 #define YYLLOC_DEFAULT(loc, rhs, n) \
330 (loc).first_line = ((rhs)[-1]).last_line; \
331 (loc).first_column = ((rhs)[-1]).last_column; \
332 (loc).last_line = ((rhs)[-1]).last_line; \
333 (loc).last_column = ((rhs)[-1]).last_column; \
337 (loc).first_line = ((rhs)[ 0 ]).first_line; \
338 (loc).first_column = ((rhs)[ 0 ]).first_column; \
339 (loc).last_line = ((rhs)[n-1]).last_line; \
340 (loc).last_column = ((rhs)[n-1]).last_column; \
343 #endif /* YYLLOC_DEFAULT */
344 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
347 #ifndef YYLVQUEUEGROWTH
348 #define YYLVQUEUEGROWTH 32
350 #endif /* YYBTYACC */
352 /* define the initial stack-sizes */
355 #define YYMAXDEPTH YYSTACKSIZE
358 #define YYSTACKSIZE YYMAXDEPTH
360 #define YYSTACKSIZE 10000
361 #define YYMAXDEPTH 10000
365 #ifndef YYINITSTACKSIZE
366 #define YYINITSTACKSIZE 200
376 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
383 struct YYParseState_s
385 struct YYParseState_s *save; /* Previously saved parser state */
386 YYSTACKDATA yystack; /* saved parser stack */
387 int state; /* saved parser state */
388 int errflag; /* saved error recovery status */
389 int lexeme; /* saved index of the conflict lexeme in the lexical queue */
390 YYINT ctry; /* saved index in yyctable[] for this conflict */
392 typedef struct YYParseState_s YYParseState;
393 #endif /* YYBTYACC */
395 /* start of programs */
398 extern int YYLEX_DECL();
407 while(!feof(stdin)) {
408 yyparse(regs, &base);
413 #define UNUSED(x) ((void)(x))
418 UNUSED(regs); /* %parse-param regs is not actually used here */
419 UNUSED(base); /* %parse-param base is not actually used here */
420 fprintf(stderr, "%s\n", s);
426 /* lexical analysis routine */
427 /* returns LETTER for a lower case letter, yylval = 0 through 25 */
428 /* return DIGIT for a digit, yylval = 0 through 9 */
429 /* all other characters are returned immediately */
433 while( (c=getchar()) == ' ' ) { /* skip blanks */ }
435 /* c is now nonblank */
442 *yylval = (c - '0') % (*base);
447 #line 448 "calc3.tab.c"
449 /* For use in generated program */
450 #define yydepth (int)(yystack.s_mark - yystack.s_base)
452 #define yytrial (yyps->save)
453 #endif /* YYBTYACC */
456 #include <stdio.h> /* needed for printf */
459 #include <stdlib.h> /* needed for malloc, etc */
460 #include <string.h> /* needed for memset */
462 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
463 static int yygrowstack(YYSTACKDATA *data)
469 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
473 if ((newsize = data->stacksize) == 0)
474 newsize = YYINITSTACKSIZE;
475 else if (newsize >= YYMAXDEPTH)
477 else if ((newsize *= 2) > YYMAXDEPTH)
478 newsize = YYMAXDEPTH;
480 i = (int) (data->s_mark - data->s_base);
481 newss = (short *)realloc(data->s_base, newsize * sizeof(*newss));
485 data->s_base = newss;
486 data->s_mark = newss + i;
488 newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));
492 data->l_base = newvs;
493 data->l_mark = newvs + i;
495 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
496 newps = (YYLTYPE *)realloc(data->p_base, newsize * sizeof(*newps));
500 data->p_base = newps;
501 data->p_mark = newps + i;
504 data->stacksize = newsize;
505 data->s_last = data->s_base + newsize - 1;
509 fprintf(stderr, "%sdebug: stack size increased to %d\n", YYPREFIX, newsize);
514 #if YYPURE || defined(YY_NO_LEAKS)
515 static void yyfreestack(YYSTACKDATA *data)
519 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
522 memset(data, 0, sizeof(*data));
525 #define yyfreestack(data) /* nothing */
526 #endif /* YYPURE || defined(YY_NO_LEAKS) */
529 static YYParseState *
530 yyNewState(unsigned size)
532 YYParseState *p = (YYParseState *) malloc(sizeof(YYParseState));
533 if (p == NULL) return NULL;
535 p->yystack.stacksize = size;
538 p->yystack.s_base = NULL;
539 p->yystack.l_base = NULL;
540 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
541 p->yystack.p_base = NULL;
545 p->yystack.s_base = (short *) malloc(size * sizeof(short));
546 if (p->yystack.s_base == NULL) return NULL;
547 p->yystack.l_base = (YYSTYPE *) malloc(size * sizeof(YYSTYPE));
548 if (p->yystack.l_base == NULL) return NULL;
549 memset(p->yystack.l_base, 0, size * sizeof(YYSTYPE));
550 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
551 p->yystack.p_base = (YYLTYPE *) malloc(size * sizeof(YYLTYPE));
552 if (p->yystack.p_base == NULL) return NULL;
553 memset(p->yystack.p_base, 0, size * sizeof(YYLTYPE));
560 yyFreeState(YYParseState *p)
562 yyfreestack(&p->yystack);
565 #endif /* YYBTYACC */
567 #define YYABORT goto yyabort
568 #define YYREJECT goto yyabort
569 #define YYACCEPT goto yyaccept
570 #define YYERROR goto yyerrlab
572 #define YYVALID do { if (yyps->save) goto yyvalid; } while(0)
573 #define YYVALID_NESTED do { if (yyps->save && \
574 yyps->save->save == 0) goto yyvalid; } while(0)
575 #endif /* YYBTYACC */
584 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
585 YYLTYPE yyloc; /* position returned by actions */
586 YYLTYPE yylloc; /* position from the lexer */
589 /* variables for the parser stack */
593 /* Current parser state */
594 static YYParseState *yyps = 0;
596 /* yypath != NULL: do the full parse, starting at *yypath parser state. */
597 static YYParseState *yypath = 0;
599 /* Base of the lexical value queue */
600 static YYSTYPE *yylvals = 0;
602 /* Current position at lexical value queue */
603 static YYSTYPE *yylvp = 0;
605 /* End position of lexical value queue */
606 static YYSTYPE *yylve = 0;
608 /* The last allocated position at the lexical value queue */
609 static YYSTYPE *yylvlim = 0;
611 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
612 /* Base of the lexical position queue */
613 static YYLTYPE *yylpsns = 0;
615 /* Current position at lexical position queue */
616 static YYLTYPE *yylpp = 0;
618 /* End position of lexical position queue */
619 static YYLTYPE *yylpe = 0;
621 /* The last allocated position at the lexical position queue */
622 static YYLTYPE *yylplim = 0;
625 /* Current position at lexical token queue */
626 static short *yylexp = 0;
628 static short *yylexemes = 0;
629 #endif /* YYBTYACC */
630 int yym, yyn, yystate, yyresult;
633 YYParseState *yyerrctx = NULL;
634 #endif /* YYBTYACC */
635 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
636 YYLTYPE yyerror_loc_range[2]; /* position of error start & end */
641 if ((yys = getenv("YYDEBUG")) != 0)
644 if (yyn >= '0' && yyn <= '9')
648 fprintf(stderr, "%sdebug[<# of symbols on state stack>]\n", YYPREFIX);
652 yyps = yyNewState(0); if (yyps == 0) goto yyenomem;
654 #endif /* YYBTYACC */
661 memset(&yystack, 0, sizeof(yystack));
664 if (yystack.s_base == NULL && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
665 yystack.s_mark = yystack.s_base;
666 yystack.l_mark = yystack.l_base;
667 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
668 yystack.p_mark = yystack.p_base;
674 if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
681 /* we're currently re-reading tokens */
683 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
691 /* in trial mode; save scanner results for future parse attempts */
692 if (yylvp == yylvlim)
693 { /* Enlarge lexical value queue */
694 int p = yylvp - yylvals;
695 int s = yylvlim - yylvals;
697 s += YYLVQUEUEGROWTH;
698 if ((yylexemes = (short *) realloc(yylexemes, s * sizeof(short))) == NULL) goto yyenomem;
699 if ((yylvals = (YYSTYPE *) realloc(yylvals, s * sizeof(YYSTYPE))) == NULL) goto yyenomem;
700 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
701 if ((yylpsns = (YYLTYPE *) realloc(yylpsns, s * sizeof(YYLTYPE))) == NULL) goto yyenomem;
703 yylvp = yylve = yylvals + p;
704 yylvlim = yylvals + s;
705 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
706 yylpp = yylpe = yylpsns + p;
707 yylplim = yylpsns + s;
709 yylexp = yylexemes + p;
711 *yylexp = (short) YYLEX;
714 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
721 /* normal operation, no conflict encountered */
722 #endif /* YYBTYACC */
726 #endif /* YYBTYACC */
727 if (yychar < 0) yychar = YYEOF;
728 /* if ((yychar = YYLEX) < 0) yychar = YYEOF; */
732 yys = yyname[YYTRANSLATE(yychar)];
733 fprintf(stderr, "%s[%d]: state %d, reading token %d (%s)",
734 YYDEBUGSTR, yydepth, yystate, yychar, yys);
735 #ifdef YYSTYPE_TOSTRING
738 #endif /* YYBTYACC */
739 fprintf(stderr, " <%s>", YYSTYPE_TOSTRING(yychar, yylval));
747 /* Do we have a conflict? */
748 if (((yyn = yycindex[yystate]) != 0) && (yyn += yychar) >= 0 &&
749 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar)
758 fprintf(stderr, "%s[%d]: CONFLICT in state %d: following successful trial parse\n",
759 YYDEBUGSTR, yydepth, yystate);
761 /* Switch to the next conflict context */
766 if (save->state != yystate) YYABORT;
773 /* Unresolved conflict - start/continue trial parse */
778 fprintf(stderr, "%s[%d]: CONFLICT in state %d. ", YYDEBUGSTR, yydepth, yystate);
780 fputs("ALREADY in conflict, continuing trial parse.\n", stderr);
782 fputs("Starting trial parse.\n", stderr);
785 save = yyNewState((unsigned)(yystack.s_mark - yystack.s_base + 1));
786 if (save == NULL) goto yyenomem;
787 save->save = yyps->save;
788 save->state = yystate;
789 save->errflag = yyerrflag;
790 save->yystack.s_mark = save->yystack.s_base + (yystack.s_mark - yystack.s_base);
791 memcpy (save->yystack.s_base, yystack.s_base, (yystack.s_mark - yystack.s_base + 1) * sizeof(short));
792 save->yystack.l_mark = save->yystack.l_base + (yystack.l_mark - yystack.l_base);
793 memcpy (save->yystack.l_base, yystack.l_base, (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
794 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
795 save->yystack.p_mark = save->yystack.p_base + (yystack.p_mark - yystack.p_base);
796 memcpy (save->yystack.p_base, yystack.p_base, (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
799 if (yyctable[ctry] == -1)
802 if (yydebug && yychar >= YYEOF)
803 fprintf(stderr, "%s[%d]: backtracking 1 token\n", YYDEBUGSTR, yydepth);
808 if (yyps->save == NULL)
810 /* If this is a first conflict in the stack, start saving lexemes */
813 yylexemes = (short *) malloc((YYLVQUEUEGROWTH) * sizeof(short));
814 if (yylexemes == NULL) goto yyenomem;
815 yylvals = (YYSTYPE *) malloc((YYLVQUEUEGROWTH) * sizeof(YYSTYPE));
816 if (yylvals == NULL) goto yyenomem;
817 yylvlim = yylvals + YYLVQUEUEGROWTH;
818 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
819 yylpsns = (YYLTYPE *) malloc((YYLVQUEUEGROWTH) * sizeof(YYLTYPE));
820 if (yylpsns == NULL) goto yyenomem;
821 yylplim = yylpsns + YYLVQUEUEGROWTH;
826 yylvp = yylve = yylvals;
827 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
828 yylpp = yylpe = yylpsns;
834 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
837 *yylexp = (short) yychar;
845 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
851 save->lexeme = yylvp - yylvals;
854 if (yytable[yyn] == ctry)
858 fprintf(stderr, "%s[%d]: state %d, shifting to state %d\n",
859 YYDEBUGSTR, yydepth, yystate, yyctable[ctry]);
864 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
869 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM)
871 yystate = yyctable[ctry];
872 *++yystack.s_mark = (short) yystate;
873 *++yystack.l_mark = yylval;
874 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
875 *++yystack.p_mark = yylloc;
878 if (yyerrflag > 0) --yyerrflag;
883 yyn = yyctable[ctry];
886 } /* End of code dealing with conflicts */
887 #endif /* YYBTYACC */
888 if (((yyn = yysindex[yystate]) != 0) && (yyn += yychar) >= 0 &&
889 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar)
893 fprintf(stderr, "%s[%d]: state %d, shifting to state %d\n",
894 YYDEBUGSTR, yydepth, yystate, yytable[yyn]);
896 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
897 yystate = yytable[yyn];
898 *++yystack.s_mark = yytable[yyn];
899 *++yystack.l_mark = yylval;
900 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
901 *++yystack.p_mark = yylloc;
904 if (yyerrflag > 0) --yyerrflag;
907 if (((yyn = yyrindex[yystate]) != 0) && (yyn += yychar) >= 0 &&
908 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar)
913 if (yyerrflag != 0) goto yyinrecovery;
926 YYParseState *save = yyps->save;
929 fprintf(stderr, "%s[%d]: ERROR in state %d, CONFLICT BACKTRACKING to state %d, %d tokens\n",
930 YYDEBUGSTR, yydepth, yystate, yyps->save->state,
931 (int)(yylvp - yylvals - yyps->save->lexeme));
933 /* Memorize most forward-looking error state in case it's really an error. */
934 if (yyerrctx == NULL || yyerrctx->lexeme < yylvp - yylvals)
936 /* Free old saved error context state */
937 if (yyerrctx) yyFreeState(yyerrctx);
938 /* Create and fill out new saved error context state */
939 yyerrctx = yyNewState((unsigned)(yystack.s_mark - yystack.s_base + 1));
940 if (yyerrctx == NULL) goto yyenomem;
941 yyerrctx->save = yyps->save;
942 yyerrctx->state = yystate;
943 yyerrctx->errflag = yyerrflag;
944 yyerrctx->yystack.s_mark = yyerrctx->yystack.s_base + (yystack.s_mark - yystack.s_base);
945 memcpy (yyerrctx->yystack.s_base, yystack.s_base, (yystack.s_mark - yystack.s_base + 1) * sizeof(short));
946 yyerrctx->yystack.l_mark = yyerrctx->yystack.l_base + (yystack.l_mark - yystack.l_base);
947 memcpy (yyerrctx->yystack.l_base, yystack.l_base, (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
948 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
949 yyerrctx->yystack.p_mark = yyerrctx->yystack.p_base + (yystack.p_mark - yystack.p_base);
950 memcpy (yyerrctx->yystack.p_base, yystack.p_base, (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
952 yyerrctx->lexeme = yylvp - yylvals;
954 yylvp = yylvals + save->lexeme;
955 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
956 yylpp = yylpsns + save->lexeme;
958 yylexp = yylexemes + save->lexeme;
960 yystack.s_mark = yystack.s_base + (save->yystack.s_mark - save->yystack.s_base);
961 memcpy (yystack.s_base, save->yystack.s_base, (yystack.s_mark - yystack.s_base + 1) * sizeof(short));
962 yystack.l_mark = yystack.l_base + (save->yystack.l_mark - save->yystack.l_base);
963 memcpy (yystack.l_base, save->yystack.l_base, (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
964 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
965 yystack.p_mark = yystack.p_base + (save->yystack.p_mark - save->yystack.p_base);
966 memcpy (yystack.p_base, save->yystack.p_base, (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
969 yystate = save->state;
970 /* We tried shift, try reduce now */
971 if ((yyn = yyctable[ctry]) >= 0) goto yyreduce;
972 yyps->save = save->save;
976 /* Nothing left on the stack -- error */
981 fprintf(stderr, "%sdebug[%d,trial]: trial parse FAILED, entering ERROR mode\n",
984 /* Restore state as it was in the most forward-advanced error */
985 yylvp = yylvals + yyerrctx->lexeme;
986 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
987 yylpp = yylpsns + yyerrctx->lexeme;
989 yylexp = yylexemes + yyerrctx->lexeme;
992 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
995 yystack.s_mark = yystack.s_base + (yyerrctx->yystack.s_mark - yyerrctx->yystack.s_base);
996 memcpy (yystack.s_base, yyerrctx->yystack.s_base, (yystack.s_mark - yystack.s_base + 1) * sizeof(short));
997 yystack.l_mark = yystack.l_base + (yyerrctx->yystack.l_mark - yyerrctx->yystack.l_base);
998 memcpy (yystack.l_base, yyerrctx->yystack.l_base, (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
999 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1000 yystack.p_mark = yystack.p_base + (yyerrctx->yystack.p_mark - yyerrctx->yystack.p_base);
1001 memcpy (yystack.p_base, yyerrctx->yystack.p_base, (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
1003 yystate = yyerrctx->state;
1004 yyFreeState(yyerrctx);
1009 if (yynewerrflag == 0) goto yyinrecovery;
1010 #endif /* YYBTYACC */
1012 YYERROR_CALL("syntax error");
1013 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1014 yyerror_loc_range[0] = yylloc; /* lookahead position is error start position */
1029 if (((yyn = yysindex[*yystack.s_mark]) != 0) && (yyn += YYERRCODE) >= 0 &&
1030 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) YYERRCODE)
1034 fprintf(stderr, "%s[%d]: state %d, error recovery shifting to state %d\n",
1035 YYDEBUGSTR, yydepth, *yystack.s_mark, yytable[yyn]);
1037 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
1038 yystate = yytable[yyn];
1039 *++yystack.s_mark = yytable[yyn];
1040 *++yystack.l_mark = yylval;
1041 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1042 /* lookahead position is error end position */
1043 yyerror_loc_range[1] = yylloc;
1044 YYLLOC_DEFAULT(yyloc, yyerror_loc_range, 2); /* position of error span */
1045 *++yystack.p_mark = yyloc;
1053 fprintf(stderr, "%s[%d]: error recovery discarding state %d\n",
1054 YYDEBUGSTR, yydepth, *yystack.s_mark);
1056 if (yystack.s_mark <= yystack.s_base) goto yyabort;
1057 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1058 /* the current TOS position is the error start position */
1059 yyerror_loc_range[0] = *yystack.p_mark;
1061 #if defined(YYDESTRUCT_CALL)
1064 #endif /* YYBTYACC */
1065 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1066 YYDESTRUCT_CALL("error: discarding state",
1067 yystos[*yystack.s_mark], yystack.l_mark, yystack.p_mark);
1069 YYDESTRUCT_CALL("error: discarding state",
1070 yystos[*yystack.s_mark], yystack.l_mark);
1071 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
1072 #endif /* defined(YYDESTRUCT_CALL) */
1075 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1083 if (yychar == YYEOF) goto yyabort;
1087 yys = yyname[YYTRANSLATE(yychar)];
1088 fprintf(stderr, "%s[%d]: state %d, error recovery discarding token %d (%s)\n",
1089 YYDEBUGSTR, yydepth, yystate, yychar, yys);
1092 #if defined(YYDESTRUCT_CALL)
1095 #endif /* YYBTYACC */
1096 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1097 YYDESTRUCT_CALL("error: discarding token", yychar, &yylval, &yylloc);
1099 YYDESTRUCT_CALL("error: discarding token", yychar, &yylval);
1100 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
1101 #endif /* defined(YYDESTRUCT_CALL) */
1111 fprintf(stderr, "%s[%d]: state %d, reducing by rule %d (%s)",
1112 YYDEBUGSTR, yydepth, yystate, yyn, yyrule[yyn]);
1113 #ifdef YYSTYPE_TOSTRING
1116 #endif /* YYBTYACC */
1121 for (i = yym; i > 0; i--)
1123 if (i != yym) fputs(", ", stderr);
1124 fputs(YYSTYPE_TOSTRING(yystos[yystack.s_mark[1-i]],
1125 yystack.l_mark[1-i]), stderr);
1130 fputc('\n', stderr);
1134 yyval = yystack.l_mark[1-yym];
1136 memset(&yyval, 0, sizeof yyval);
1137 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1139 /* Perform position reduction */
1140 memset(&yyloc, 0, sizeof(yyloc));
1143 #endif /* YYBTYACC */
1145 YYLLOC_DEFAULT(yyloc, &yystack.p_mark[1-yym], yym);
1146 /* just in case YYERROR is invoked within the action, save
1147 the start of the rhs as the error start position */
1148 yyerror_loc_range[0] = yystack.p_mark[1-yym];
1160 { printf("%d\n",yystack.l_mark[0]);}
1164 { regs[yystack.l_mark[-2]] = yystack.l_mark[0]; }
1168 { yyval = yystack.l_mark[-1]; }
1172 { yyval = yystack.l_mark[-2] + yystack.l_mark[0]; }
1176 { yyval = yystack.l_mark[-2] - yystack.l_mark[0]; }
1180 { yyval = yystack.l_mark[-2] * yystack.l_mark[0]; }
1184 { yyval = yystack.l_mark[-2] / yystack.l_mark[0]; }
1188 { yyval = yystack.l_mark[-2] % yystack.l_mark[0]; }
1192 { yyval = yystack.l_mark[-2] & yystack.l_mark[0]; }
1196 { yyval = yystack.l_mark[-2] | yystack.l_mark[0]; }
1200 { yyval = - yystack.l_mark[0]; }
1204 { yyval = regs[yystack.l_mark[0]]; }
1208 { yyval = yystack.l_mark[0]; (*base) = (yystack.l_mark[0]==0) ? 8 : 10; }
1212 { yyval = (*base) * yystack.l_mark[-1] + yystack.l_mark[0]; }
1214 #line 1215 "calc3.tab.c"
1218 yystack.s_mark -= yym;
1219 yystate = *yystack.s_mark;
1220 yystack.l_mark -= yym;
1221 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1222 yystack.p_mark -= yym;
1225 if (yystate == 0 && yym == 0)
1230 fprintf(stderr, "%s[%d]: after reduction, ", YYDEBUGSTR, yydepth);
1231 #ifdef YYSTYPE_TOSTRING
1234 #endif /* YYBTYACC */
1235 fprintf(stderr, "result is <%s>, ", YYSTYPE_TOSTRING(yystos[YYFINAL], yyval));
1237 fprintf(stderr, "shifting from state 0 to final state %d\n", YYFINAL);
1241 *++yystack.s_mark = YYFINAL;
1242 *++yystack.l_mark = yyval;
1243 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1244 *++yystack.p_mark = yyloc;
1252 /* we're currently re-reading tokens */
1254 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1262 /* in trial mode; save scanner results for future parse attempts */
1263 if (yylvp == yylvlim)
1264 { /* Enlarge lexical value queue */
1265 int p = yylvp - yylvals;
1266 int s = yylvlim - yylvals;
1268 s += YYLVQUEUEGROWTH;
1269 if ((yylexemes = (short *) realloc(yylexemes, s * sizeof(short))) == NULL)
1271 if ((yylvals = (YYSTYPE *) realloc(yylvals, s * sizeof(YYSTYPE))) == NULL)
1273 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1274 if ((yylpsns = (YYLTYPE *) realloc(yylpsns, s * sizeof(YYLTYPE))) == NULL)
1277 yylvp = yylve = yylvals + p;
1278 yylvlim = yylvals + s;
1279 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1280 yylpp = yylpe = yylpsns + p;
1281 yylplim = yylpsns + s;
1283 yylexp = yylexemes + p;
1285 *yylexp = (short) YYLEX;
1288 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1295 /* normal operation, no conflict encountered */
1296 #endif /* YYBTYACC */
1300 #endif /* YYBTYACC */
1301 if (yychar < 0) yychar = YYEOF;
1302 /* if ((yychar = YYLEX) < 0) yychar = YYEOF; */
1306 yys = yyname[YYTRANSLATE(yychar)];
1307 fprintf(stderr, "%s[%d]: state %d, reading %d (%s)\n",
1308 YYDEBUGSTR, yydepth, YYFINAL, yychar, yys);
1312 if (yychar == YYEOF) goto yyaccept;
1315 if (((yyn = yygindex[yym]) != 0) && (yyn += yystate) >= 0 &&
1316 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yystate)
1317 yystate = yytable[yyn];
1319 yystate = yydgoto[yym];
1323 fprintf(stderr, "%s[%d]: after reduction, ", YYDEBUGSTR, yydepth);
1324 #ifdef YYSTYPE_TOSTRING
1327 #endif /* YYBTYACC */
1328 fprintf(stderr, "result is <%s>, ", YYSTYPE_TOSTRING(yystos[yystate], yyval));
1330 fprintf(stderr, "shifting from state %d to state %d\n", *yystack.s_mark, yystate);
1333 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
1334 *++yystack.s_mark = (short) yystate;
1335 *++yystack.l_mark = yyval;
1336 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1337 *++yystack.p_mark = yyloc;
1342 /* Reduction declares that this path is valid. Set yypath and do a full parse */
1344 if (yypath) YYABORT;
1347 YYParseState *save = yyps->save;
1348 yyps->save = save->save;
1349 save->save = yypath;
1354 fprintf(stderr, "%s[%d]: state %d, CONFLICT trial successful, backtracking to state %d, %d tokens\n",
1355 YYDEBUGSTR, yydepth, yystate, yypath->state, (int)(yylvp - yylvals - yypath->lexeme));
1359 yyFreeState(yyerrctx);
1362 yylvp = yylvals + yypath->lexeme;
1363 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1364 yylpp = yylpsns + yypath->lexeme;
1366 yylexp = yylexemes + yypath->lexeme;
1368 yystack.s_mark = yystack.s_base + (yypath->yystack.s_mark - yypath->yystack.s_base);
1369 memcpy (yystack.s_base, yypath->yystack.s_base, (yystack.s_mark - yystack.s_base + 1) * sizeof(short));
1370 yystack.l_mark = yystack.l_base + (yypath->yystack.l_mark - yypath->yystack.l_base);
1371 memcpy (yystack.l_base, yypath->yystack.l_base, (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
1372 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1373 yystack.p_mark = yystack.p_base + (yypath->yystack.p_mark - yypath->yystack.p_base);
1374 memcpy (yystack.p_base, yypath->yystack.p_base, (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
1376 yystate = yypath->state;
1378 #endif /* YYBTYACC */
1381 YYERROR_CALL("yacc stack overflow");
1385 YYERROR_CALL("memory exhausted");
1387 #endif /* YYBTYACC */
1397 if (yyps->save) goto yyvalid;
1398 #endif /* YYBTYACC */
1402 #if defined(YYDESTRUCT_CALL)
1403 if (yychar != YYEOF && yychar != YYEMPTY)
1404 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1405 YYDESTRUCT_CALL("cleanup: discarding token", yychar, &yylval, &yylloc);
1407 YYDESTRUCT_CALL("cleanup: discarding token", yychar, &yylval);
1408 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
1412 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1415 for (pv = yystack.l_base, pp = yystack.p_base; pv <= yystack.l_mark; ++pv, ++pp)
1416 YYDESTRUCT_CALL("cleanup: discarding state",
1417 yystos[*(yystack.s_base + (pv - yystack.l_base))], pv, pp);
1419 for (pv = yystack.l_base; pv <= yystack.l_mark; ++pv)
1420 YYDESTRUCT_CALL("cleanup: discarding state",
1421 yystos[*(yystack.s_base + (pv - yystack.l_base))], pv);
1422 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
1424 #endif /* defined(YYDESTRUCT_CALL) */
1429 yyFreeState(yyerrctx);
1434 YYParseState *save = yyps;
1441 YYParseState *save = yypath;
1442 yypath = save->save;
1446 #endif /* YYBTYACC */
1447 yyfreestack(&yystack);