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 calc2_parse
25 #define yylex calc2_lex
29 #define yyerror calc2_error
33 #define yychar calc2_char
37 #define yyval calc2_val
41 #define yylval calc2_lval
45 #define yydebug calc2_debug
49 #define yynerrs calc2_nerrs
53 #define yyerrflag calc2_errflag
54 #endif /* yyerrflag */
57 #define yylhs calc2_lhs
61 #define yylen calc2_len
65 #define yydefred calc2_defred
69 #define yystos calc2_stos
73 #define yydgoto calc2_dgoto
77 #define yysindex calc2_sindex
81 #define yyrindex calc2_rindex
85 #define yygindex calc2_gindex
89 #define yytable calc2_table
93 #define yycheck calc2_check
97 #define yyname calc2_name
101 #define yyrule calc2_rule
107 #define yycindex calc2_cindex
108 #endif /* yycindex */
111 #define yyctable calc2_ctable
112 #endif /* yyctable */
114 #endif /* YYBTYACC */
116 #define YYPREFIX "calc2_"
125 #define YYLEX_PARAM base
126 #define YYLEX_DECL() yylex(int *YYLEX_PARAM)
127 #define YYERROR_DECL() yyerror(int regs[26], int *base, const char *s)
129 static void YYERROR_DECL();
132 #line 133 "calc2.tab.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(int regs[26], int *base)
152 /* Parameters sent to lex. */
154 # define YYLEX_DECL() yylex(void *YYLEX_PARAM)
155 # define YYLEX yylex(YYLEX_PARAM)
157 # define YYLEX_DECL() yylex(int *base)
158 # define YYLEX yylex(base)
161 /* Parameters sent to yyerror. */
163 #define YYERROR_DECL() yyerror(int regs[26], int *base, const char *s)
166 #define YYERROR_CALL(msg) yyerror(regs, base, msg)
169 extern int YYPARSE_DECL();
174 #define YYERRCODE 256
176 static const YYINT calc2_lhs[] = { -1,
177 0, 0, 0, 1, 1, 2, 2, 2, 2, 2,
178 2, 2, 2, 2, 2, 2, 3, 3,
180 static const YYINT calc2_len[] = { 2,
181 0, 3, 3, 1, 3, 3, 3, 3, 3, 3,
182 3, 3, 3, 2, 1, 1, 1, 2,
184 static const YYINT calc2_defred[] = { 1,
185 0, 0, 17, 0, 0, 0, 0, 0, 0, 3,
186 0, 15, 14, 0, 2, 0, 0, 0, 0, 0,
187 0, 0, 18, 0, 6, 0, 0, 0, 0, 9,
190 #if defined(YYDESTRUCT_CALL) || defined(YYSTYPE_TOSTRING)
191 static const YYINT calc2_stos[] = { 0,
192 261, 256, 257, 258, 45, 40, 262, 263, 264, 10,
193 61, 258, 263, 263, 10, 124, 38, 43, 45, 42,
194 47, 37, 257, 263, 41, 263, 263, 263, 263, 263,
197 #endif /* YYDESTRUCT_CALL || YYSTYPE_TOSTRING */
198 static const YYINT calc2_dgoto[] = { 1,
201 static const YYINT calc2_sindex[] = { 0,
202 -40, -7, 0, -55, -38, -38, 1, -29, -247, 0,
203 -38, 0, 0, 22, 0, -38, -38, -38, -38, -38,
204 -38, -38, 0, -29, 0, 51, 60, -20, -20, 0,
207 static const YYINT calc2_rindex[] = { 0,
208 0, 0, 0, 2, 0, 0, 0, 9, -9, 0,
209 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
210 0, 0, 0, 10, 0, -6, 14, 5, 13, 0,
214 static const YYINT calc2_cindex[] = { 0,
215 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
216 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
217 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
221 static const YYINT calc2_gindex[] = { 0,
224 #define YYTABLESIZE 220
225 static const YYINT calc2_table[] = { 6,
226 16, 6, 10, 13, 5, 11, 5, 22, 17, 23,
227 15, 15, 20, 18, 7, 19, 22, 21, 4, 5,
228 0, 20, 8, 12, 0, 0, 21, 16, 16, 0,
229 0, 16, 16, 16, 13, 16, 0, 16, 15, 15,
230 0, 0, 7, 15, 15, 7, 15, 7, 15, 7,
231 8, 12, 0, 8, 12, 8, 0, 8, 22, 17,
232 0, 0, 25, 20, 18, 0, 19, 0, 21, 13,
233 14, 0, 0, 0, 0, 24, 0, 0, 0, 0,
234 26, 27, 28, 29, 30, 31, 32, 22, 17, 0,
235 0, 0, 20, 18, 16, 19, 22, 21, 0, 0,
236 0, 20, 18, 0, 19, 0, 21, 0, 0, 0,
237 0, 0, 0, 0, 16, 0, 0, 13, 0, 0,
238 0, 0, 0, 0, 0, 15, 0, 0, 7, 0,
239 0, 0, 0, 0, 0, 0, 8, 12, 0, 0,
240 0, 0, 0, 0, 0, 16, 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, 0, 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, 2, 3, 4, 3, 12,
249 static const YYINT calc2_check[] = { 40,
250 10, 40, 10, 10, 45, 61, 45, 37, 38, 257,
251 10, 10, 42, 43, 10, 45, 37, 47, 10, 10,
252 -1, 42, 10, 10, -1, -1, 47, 37, 38, -1,
253 -1, 41, 42, 43, 41, 45, -1, 47, 37, 38,
254 -1, -1, 38, 42, 43, 41, 45, 43, 47, 45,
255 38, 38, -1, 41, 41, 43, -1, 45, 37, 38,
256 -1, -1, 41, 42, 43, -1, 45, -1, 47, 5,
257 6, -1, -1, -1, -1, 11, -1, -1, -1, -1,
258 16, 17, 18, 19, 20, 21, 22, 37, 38, -1,
259 -1, -1, 42, 43, 124, 45, 37, 47, -1, -1,
260 -1, 42, 43, -1, 45, -1, 47, -1, -1, -1,
261 -1, -1, -1, -1, 124, -1, -1, 124, -1, -1,
262 -1, -1, -1, -1, -1, 124, -1, -1, 124, -1,
263 -1, -1, -1, -1, -1, -1, 124, 124, -1, -1,
264 -1, -1, -1, -1, -1, 124, -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, -1, -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, 256, 257, 258, 257, 258,
274 static const YYINT calc2_ctable[] = { -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, -1,
293 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
294 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
295 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
296 -1, -1, -1, -1, -1, -1, -1, -1, -1,
303 #define YYMAXTOKEN 259
304 #define YYUNDFTOKEN 265
305 #define YYTRANSLATE(a) ((a) > YYMAXTOKEN ? YYUNDFTOKEN : (a))
307 static const char *const calc2_name[] = {
309 "$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,
310 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,
312 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,
313 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,
314 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,
315 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,
316 0,0,"error","DIGIT","LETTER","UMINUS","$accept","list","stat","expr","number",
319 static const char *const calc2_rule[] = {
322 "list : list stat '\\n'",
323 "list : list error '\\n'",
325 "stat : LETTER '=' expr",
326 "expr : '(' expr ')'",
327 "expr : expr '+' expr",
328 "expr : expr '-' expr",
329 "expr : expr '*' expr",
330 "expr : expr '/' expr",
331 "expr : expr '%' expr",
332 "expr : expr '&' expr",
333 "expr : expr '|' expr",
338 "number : number DIGIT",
353 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
354 YYLTYPE yyloc; /* position returned by actions */
355 YYLTYPE yylloc; /* position from the lexer */
358 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
359 #ifndef YYLLOC_DEFAULT
360 #define YYLLOC_DEFAULT(loc, rhs, n) \
365 (loc).first_line = YYRHSLOC(rhs, 0).last_line; \
366 (loc).first_column = YYRHSLOC(rhs, 0).last_column; \
367 (loc).last_line = YYRHSLOC(rhs, 0).last_line; \
368 (loc).last_column = YYRHSLOC(rhs, 0).last_column; \
372 (loc).first_line = YYRHSLOC(rhs, 1).first_line; \
373 (loc).first_column = YYRHSLOC(rhs, 1).first_column; \
374 (loc).last_line = YYRHSLOC(rhs, n).last_line; \
375 (loc).last_column = YYRHSLOC(rhs, n).last_column; \
378 #endif /* YYLLOC_DEFAULT */
379 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
382 #ifndef YYLVQUEUEGROWTH
383 #define YYLVQUEUEGROWTH 32
385 #endif /* YYBTYACC */
387 /* define the initial stack-sizes */
390 #define YYMAXDEPTH YYSTACKSIZE
393 #define YYSTACKSIZE YYMAXDEPTH
395 #define YYSTACKSIZE 10000
396 #define YYMAXDEPTH 10000
400 #ifndef YYINITSTACKSIZE
401 #define YYINITSTACKSIZE 200
411 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
418 struct YYParseState_s
420 struct YYParseState_s *save; /* Previously saved parser state */
421 YYSTACKDATA yystack; /* saved parser stack */
422 int state; /* saved parser state */
423 int errflag; /* saved error recovery status */
424 int lexeme; /* saved index of the conflict lexeme in the lexical queue */
425 YYINT ctry; /* saved index in yyctable[] for this conflict */
427 typedef struct YYParseState_s YYParseState;
428 #endif /* YYBTYACC */
429 /* variables for the parser stack */
430 static YYSTACKDATA yystack;
433 /* Current parser state */
434 static YYParseState *yyps = 0;
436 /* yypath != NULL: do the full parse, starting at *yypath parser state. */
437 static YYParseState *yypath = 0;
439 /* Base of the lexical value queue */
440 static YYSTYPE *yylvals = 0;
442 /* Current position at lexical value queue */
443 static YYSTYPE *yylvp = 0;
445 /* End position of lexical value queue */
446 static YYSTYPE *yylve = 0;
448 /* The last allocated position at the lexical value queue */
449 static YYSTYPE *yylvlim = 0;
451 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
452 /* Base of the lexical position queue */
453 static YYLTYPE *yylpsns = 0;
455 /* Current position at lexical position queue */
456 static YYLTYPE *yylpp = 0;
458 /* End position of lexical position queue */
459 static YYLTYPE *yylpe = 0;
461 /* The last allocated position at the lexical position queue */
462 static YYLTYPE *yylplim = 0;
465 /* Current position at lexical token queue */
466 static YYINT *yylexp = 0;
468 static YYINT *yylexemes = 0;
469 #endif /* YYBTYACC */
471 /* start of programs */
474 extern int YYLEX_DECL();
483 while(!feof(stdin)) {
484 yyparse(regs, &base);
489 #define UNUSED(x) ((void)(x))
494 UNUSED(regs); /* %parse-param regs is not actually used here */
495 UNUSED(base); /* %parse-param base is not actually used here */
496 fprintf(stderr, "%s\n", s);
502 /* lexical analysis routine */
503 /* returns LETTER for a lower case letter, yylval = 0 through 25 */
504 /* return DIGIT for a digit, yylval = 0 through 9 */
505 /* all other characters are returned immediately */
509 while( (c=getchar()) == ' ' ) { /* skip blanks */ }
511 /* c is now nonblank */
518 yylval = (c - '0') % (*base);
523 #line 524 "calc2.tab.c"
525 /* For use in generated program */
526 #define yydepth (int)(yystack.s_mark - yystack.s_base)
528 #define yytrial (yyps->save)
529 #endif /* YYBTYACC */
532 #include <stdio.h> /* needed for printf */
535 #include <stdlib.h> /* needed for malloc, etc */
536 #include <string.h> /* needed for memset */
538 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
539 static int yygrowstack(YYSTACKDATA *data)
545 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
549 if ((newsize = data->stacksize) == 0)
550 newsize = YYINITSTACKSIZE;
551 else if (newsize >= YYMAXDEPTH)
553 else if ((newsize *= 2) > YYMAXDEPTH)
554 newsize = YYMAXDEPTH;
556 i = (int) (data->s_mark - data->s_base);
557 newss = (YYINT *)realloc(data->s_base, newsize * sizeof(*newss));
561 data->s_base = newss;
562 data->s_mark = newss + i;
564 newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));
568 data->l_base = newvs;
569 data->l_mark = newvs + i;
571 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
572 newps = (YYLTYPE *)realloc(data->p_base, newsize * sizeof(*newps));
576 data->p_base = newps;
577 data->p_mark = newps + i;
580 data->stacksize = newsize;
581 data->s_last = data->s_base + newsize - 1;
585 fprintf(stderr, "%sdebug: stack size increased to %d\n", YYPREFIX, newsize);
590 #if YYPURE || defined(YY_NO_LEAKS)
591 static void yyfreestack(YYSTACKDATA *data)
595 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
598 memset(data, 0, sizeof(*data));
601 #define yyfreestack(data) /* nothing */
602 #endif /* YYPURE || defined(YY_NO_LEAKS) */
605 static YYParseState *
606 yyNewState(unsigned size)
608 YYParseState *p = (YYParseState *) malloc(sizeof(YYParseState));
609 if (p == NULL) return NULL;
611 p->yystack.stacksize = size;
614 p->yystack.s_base = NULL;
615 p->yystack.l_base = NULL;
616 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
617 p->yystack.p_base = NULL;
621 p->yystack.s_base = (YYINT *) malloc(size * sizeof(YYINT));
622 if (p->yystack.s_base == NULL) return NULL;
623 p->yystack.l_base = (YYSTYPE *) malloc(size * sizeof(YYSTYPE));
624 if (p->yystack.l_base == NULL) return NULL;
625 memset(p->yystack.l_base, 0, size * sizeof(YYSTYPE));
626 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
627 p->yystack.p_base = (YYLTYPE *) malloc(size * sizeof(YYLTYPE));
628 if (p->yystack.p_base == NULL) return NULL;
629 memset(p->yystack.p_base, 0, size * sizeof(YYLTYPE));
636 yyFreeState(YYParseState *p)
638 yyfreestack(&p->yystack);
641 #endif /* YYBTYACC */
643 #define YYABORT goto yyabort
644 #define YYREJECT goto yyabort
645 #define YYACCEPT goto yyaccept
646 #define YYERROR goto yyerrlab
648 #define YYVALID do { if (yyps->save) goto yyvalid; } while(0)
649 #define YYVALID_NESTED do { if (yyps->save && \
650 yyps->save->save == 0) goto yyvalid; } while(0)
651 #endif /* YYBTYACC */
656 int yym, yyn, yystate, yyresult;
659 YYParseState *yyerrctx = NULL;
660 #endif /* YYBTYACC */
661 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
662 YYLTYPE yyerror_loc_range[3]; /* position of error start/end (0 unused) */
667 if ((yys = getenv("YYDEBUG")) != 0)
670 if (yyn >= '0' && yyn <= '9')
674 fprintf(stderr, "%sdebug[<# of symbols on state stack>]\n", YYPREFIX);
676 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
677 memset(yyerror_loc_range, 0, sizeof(yyerror_loc_range));
681 yyps = yyNewState(0); if (yyps == 0) goto yyenomem;
683 #endif /* YYBTYACC */
692 memset(&yystack, 0, sizeof(yystack));
695 if (yystack.s_base == NULL && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
696 yystack.s_mark = yystack.s_base;
697 yystack.l_mark = yystack.l_base;
698 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
699 yystack.p_mark = yystack.p_base;
705 if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
712 /* we're currently re-reading tokens */
714 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
722 /* in trial mode; save scanner results for future parse attempts */
723 if (yylvp == yylvlim)
724 { /* Enlarge lexical value queue */
725 size_t p = (size_t) (yylvp - yylvals);
726 size_t s = (size_t) (yylvlim - yylvals);
728 s += YYLVQUEUEGROWTH;
729 if ((yylexemes = (YYINT *)realloc(yylexemes, s * sizeof(YYINT))) == NULL) goto yyenomem;
730 if ((yylvals = (YYSTYPE *)realloc(yylvals, s * sizeof(YYSTYPE))) == NULL) goto yyenomem;
731 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
732 if ((yylpsns = (YYLTYPE *)realloc(yylpsns, s * sizeof(YYLTYPE))) == NULL) goto yyenomem;
734 yylvp = yylve = yylvals + p;
735 yylvlim = yylvals + s;
736 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
737 yylpp = yylpe = yylpsns + p;
738 yylplim = yylpsns + s;
740 yylexp = yylexemes + p;
742 *yylexp = (YYINT) YYLEX;
745 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
752 /* normal operation, no conflict encountered */
753 #endif /* YYBTYACC */
757 #endif /* YYBTYACC */
758 if (yychar < 0) yychar = YYEOF;
762 if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN];
763 fprintf(stderr, "%s[%d]: state %d, reading token %d (%s)",
764 YYDEBUGSTR, yydepth, yystate, yychar, yys);
765 #ifdef YYSTYPE_TOSTRING
768 #endif /* YYBTYACC */
769 fprintf(stderr, " <%s>", YYSTYPE_TOSTRING(yychar, yylval));
777 /* Do we have a conflict? */
778 if (((yyn = yycindex[yystate]) != 0) && (yyn += yychar) >= 0 &&
779 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar)
788 fprintf(stderr, "%s[%d]: CONFLICT in state %d: following successful trial parse\n",
789 YYDEBUGSTR, yydepth, yystate);
791 /* Switch to the next conflict context */
796 if (save->state != yystate) YYABORT;
803 /* Unresolved conflict - start/continue trial parse */
808 fprintf(stderr, "%s[%d]: CONFLICT in state %d. ", YYDEBUGSTR, yydepth, yystate);
810 fputs("ALREADY in conflict, continuing trial parse.\n", stderr);
812 fputs("Starting trial parse.\n", stderr);
815 save = yyNewState((unsigned)(yystack.s_mark - yystack.s_base + 1));
816 if (save == NULL) goto yyenomem;
817 save->save = yyps->save;
818 save->state = yystate;
819 save->errflag = yyerrflag;
820 save->yystack.s_mark = save->yystack.s_base + (yystack.s_mark - yystack.s_base);
821 memcpy (save->yystack.s_base, yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(YYINT));
822 save->yystack.l_mark = save->yystack.l_base + (yystack.l_mark - yystack.l_base);
823 memcpy (save->yystack.l_base, yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
824 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
825 save->yystack.p_mark = save->yystack.p_base + (yystack.p_mark - yystack.p_base);
826 memcpy (save->yystack.p_base, yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
829 if (yyctable[ctry] == -1)
832 if (yydebug && yychar >= YYEOF)
833 fprintf(stderr, "%s[%d]: backtracking 1 token\n", YYDEBUGSTR, yydepth);
838 if (yyps->save == NULL)
840 /* If this is a first conflict in the stack, start saving lexemes */
843 yylexemes = (YYINT *) malloc((YYLVQUEUEGROWTH) * sizeof(YYINT));
844 if (yylexemes == NULL) goto yyenomem;
845 yylvals = (YYSTYPE *) malloc((YYLVQUEUEGROWTH) * sizeof(YYSTYPE));
846 if (yylvals == NULL) goto yyenomem;
847 yylvlim = yylvals + YYLVQUEUEGROWTH;
848 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
849 yylpsns = (YYLTYPE *) malloc((YYLVQUEUEGROWTH) * sizeof(YYLTYPE));
850 if (yylpsns == NULL) goto yyenomem;
851 yylplim = yylpsns + YYLVQUEUEGROWTH;
856 yylvp = yylve = yylvals;
857 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
858 yylpp = yylpe = yylpsns;
864 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
867 *yylexp = (YYINT) yychar;
875 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
881 save->lexeme = (int) (yylvp - yylvals);
884 if (yytable[yyn] == ctry)
888 fprintf(stderr, "%s[%d]: state %d, shifting to state %d\n",
889 YYDEBUGSTR, yydepth, yystate, yyctable[ctry]);
894 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
899 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM)
901 yystate = yyctable[ctry];
902 *++yystack.s_mark = (YYINT) yystate;
903 *++yystack.l_mark = yylval;
904 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
905 *++yystack.p_mark = yylloc;
908 if (yyerrflag > 0) --yyerrflag;
913 yyn = yyctable[ctry];
916 } /* End of code dealing with conflicts */
917 #endif /* YYBTYACC */
918 if (((yyn = yysindex[yystate]) != 0) && (yyn += yychar) >= 0 &&
919 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar)
923 fprintf(stderr, "%s[%d]: state %d, shifting to state %d\n",
924 YYDEBUGSTR, yydepth, yystate, yytable[yyn]);
926 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
927 yystate = yytable[yyn];
928 *++yystack.s_mark = yytable[yyn];
929 *++yystack.l_mark = yylval;
930 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
931 *++yystack.p_mark = yylloc;
934 if (yyerrflag > 0) --yyerrflag;
937 if (((yyn = yyrindex[yystate]) != 0) && (yyn += yychar) >= 0 &&
938 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar)
943 if (yyerrflag != 0) goto yyinrecovery;
948 goto yyerrlab; /* redundant goto avoids 'unused label' warning */
951 /* explicit YYERROR from an action -- pop the rhs of the rule reduced
952 * before looking for error recovery */
953 yystack.s_mark -= yym;
954 yystate = *yystack.s_mark;
955 yystack.l_mark -= yym;
956 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
957 yystack.p_mark -= yym;
965 YYParseState *save = yyps->save;
968 fprintf(stderr, "%s[%d]: ERROR in state %d, CONFLICT BACKTRACKING to state %d, %d tokens\n",
969 YYDEBUGSTR, yydepth, yystate, yyps->save->state,
970 (int)(yylvp - yylvals - yyps->save->lexeme));
972 /* Memorize most forward-looking error state in case it's really an error. */
973 if (yyerrctx == NULL || yyerrctx->lexeme < yylvp - yylvals)
975 /* Free old saved error context state */
976 if (yyerrctx) yyFreeState(yyerrctx);
977 /* Create and fill out new saved error context state */
978 yyerrctx = yyNewState((unsigned)(yystack.s_mark - yystack.s_base + 1));
979 if (yyerrctx == NULL) goto yyenomem;
980 yyerrctx->save = yyps->save;
981 yyerrctx->state = yystate;
982 yyerrctx->errflag = yyerrflag;
983 yyerrctx->yystack.s_mark = yyerrctx->yystack.s_base + (yystack.s_mark - yystack.s_base);
984 memcpy (yyerrctx->yystack.s_base, yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(YYINT));
985 yyerrctx->yystack.l_mark = yyerrctx->yystack.l_base + (yystack.l_mark - yystack.l_base);
986 memcpy (yyerrctx->yystack.l_base, yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
987 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
988 yyerrctx->yystack.p_mark = yyerrctx->yystack.p_base + (yystack.p_mark - yystack.p_base);
989 memcpy (yyerrctx->yystack.p_base, yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
991 yyerrctx->lexeme = (int) (yylvp - yylvals);
993 yylvp = yylvals + save->lexeme;
994 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
995 yylpp = yylpsns + save->lexeme;
997 yylexp = yylexemes + save->lexeme;
999 yystack.s_mark = yystack.s_base + (save->yystack.s_mark - save->yystack.s_base);
1000 memcpy (yystack.s_base, save->yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(YYINT));
1001 yystack.l_mark = yystack.l_base + (save->yystack.l_mark - save->yystack.l_base);
1002 memcpy (yystack.l_base, save->yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
1003 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1004 yystack.p_mark = yystack.p_base + (save->yystack.p_mark - save->yystack.p_base);
1005 memcpy (yystack.p_base, save->yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
1007 ctry = ++save->ctry;
1008 yystate = save->state;
1009 /* We tried shift, try reduce now */
1010 if ((yyn = yyctable[ctry]) >= 0) goto yyreduce;
1011 yyps->save = save->save;
1015 /* Nothing left on the stack -- error */
1020 fprintf(stderr, "%sdebug[%d,trial]: trial parse FAILED, entering ERROR mode\n",
1023 /* Restore state as it was in the most forward-advanced error */
1024 yylvp = yylvals + yyerrctx->lexeme;
1025 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1026 yylpp = yylpsns + yyerrctx->lexeme;
1028 yylexp = yylexemes + yyerrctx->lexeme;
1029 yychar = yylexp[-1];
1031 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1034 yystack.s_mark = yystack.s_base + (yyerrctx->yystack.s_mark - yyerrctx->yystack.s_base);
1035 memcpy (yystack.s_base, yyerrctx->yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(YYINT));
1036 yystack.l_mark = yystack.l_base + (yyerrctx->yystack.l_mark - yyerrctx->yystack.l_base);
1037 memcpy (yystack.l_base, yyerrctx->yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
1038 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1039 yystack.p_mark = yystack.p_base + (yyerrctx->yystack.p_mark - yyerrctx->yystack.p_base);
1040 memcpy (yystack.p_base, yyerrctx->yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
1042 yystate = yyerrctx->state;
1043 yyFreeState(yyerrctx);
1048 if (yynewerrflag == 0) goto yyinrecovery;
1049 #endif /* YYBTYACC */
1051 YYERROR_CALL("syntax error");
1052 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1053 yyerror_loc_range[1] = yylloc; /* lookahead position is error start position */
1057 goto yyerrlab; /* redundant goto avoids 'unused label' warning */
1068 if (((yyn = yysindex[*yystack.s_mark]) != 0) && (yyn += YYERRCODE) >= 0 &&
1069 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) YYERRCODE)
1073 fprintf(stderr, "%s[%d]: state %d, error recovery shifting to state %d\n",
1074 YYDEBUGSTR, yydepth, *yystack.s_mark, yytable[yyn]);
1076 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
1077 yystate = yytable[yyn];
1078 *++yystack.s_mark = yytable[yyn];
1079 *++yystack.l_mark = yylval;
1080 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1081 /* lookahead position is error end position */
1082 yyerror_loc_range[2] = yylloc;
1083 YYLLOC_DEFAULT(yyloc, yyerror_loc_range, 2); /* position of error span */
1084 *++yystack.p_mark = yyloc;
1092 fprintf(stderr, "%s[%d]: error recovery discarding state %d\n",
1093 YYDEBUGSTR, yydepth, *yystack.s_mark);
1095 if (yystack.s_mark <= yystack.s_base) goto yyabort;
1096 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1097 /* the current TOS position is the error start position */
1098 yyerror_loc_range[1] = *yystack.p_mark;
1100 #if defined(YYDESTRUCT_CALL)
1103 #endif /* YYBTYACC */
1104 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1105 YYDESTRUCT_CALL("error: discarding state",
1106 yystos[*yystack.s_mark], yystack.l_mark, yystack.p_mark);
1108 YYDESTRUCT_CALL("error: discarding state",
1109 yystos[*yystack.s_mark], yystack.l_mark);
1110 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
1111 #endif /* defined(YYDESTRUCT_CALL) */
1114 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1122 if (yychar == YYEOF) goto yyabort;
1126 if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN];
1127 fprintf(stderr, "%s[%d]: state %d, error recovery discarding token %d (%s)\n",
1128 YYDEBUGSTR, yydepth, yystate, yychar, yys);
1131 #if defined(YYDESTRUCT_CALL)
1134 #endif /* YYBTYACC */
1135 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1136 YYDESTRUCT_CALL("error: discarding token", yychar, &yylval, &yylloc);
1138 YYDESTRUCT_CALL("error: discarding token", yychar, &yylval);
1139 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
1140 #endif /* defined(YYDESTRUCT_CALL) */
1150 fprintf(stderr, "%s[%d]: state %d, reducing by rule %d (%s)",
1151 YYDEBUGSTR, yydepth, yystate, yyn, yyrule[yyn]);
1152 #ifdef YYSTYPE_TOSTRING
1155 #endif /* YYBTYACC */
1160 for (i = yym; i > 0; i--)
1162 if (i != yym) fputs(", ", stderr);
1163 fputs(YYSTYPE_TOSTRING(yystos[yystack.s_mark[1-i]],
1164 yystack.l_mark[1-i]), stderr);
1169 fputc('\n', stderr);
1173 yyval = yystack.l_mark[1-yym];
1175 memset(&yyval, 0, sizeof yyval);
1176 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1178 /* Perform position reduction */
1179 memset(&yyloc, 0, sizeof(yyloc));
1182 #endif /* YYBTYACC */
1184 YYLLOC_DEFAULT(yyloc, &yystack.p_mark[-yym], yym);
1185 /* just in case YYERROR is invoked within the action, save
1186 the start of the rhs as the error start position */
1187 yyerror_loc_range[1] = yystack.p_mark[1-yym];
1199 { printf("%d\n",yystack.l_mark[0]);}
1203 { regs[yystack.l_mark[-2]] = yystack.l_mark[0]; }
1207 { yyval = yystack.l_mark[-1]; }
1211 { yyval = yystack.l_mark[-2] + yystack.l_mark[0]; }
1215 { yyval = yystack.l_mark[-2] - yystack.l_mark[0]; }
1219 { yyval = yystack.l_mark[-2] * yystack.l_mark[0]; }
1223 { yyval = yystack.l_mark[-2] / yystack.l_mark[0]; }
1227 { yyval = yystack.l_mark[-2] % yystack.l_mark[0]; }
1231 { yyval = yystack.l_mark[-2] & yystack.l_mark[0]; }
1235 { yyval = yystack.l_mark[-2] | yystack.l_mark[0]; }
1239 { yyval = - yystack.l_mark[0]; }
1243 { yyval = regs[yystack.l_mark[0]]; }
1247 { yyval = yystack.l_mark[0]; (*base) = (yystack.l_mark[0]==0) ? 8 : 10; }
1251 { yyval = (*base) * yystack.l_mark[-1] + yystack.l_mark[0]; }
1253 #line 1254 "calc2.tab.c"
1257 yystack.s_mark -= yym;
1258 yystate = *yystack.s_mark;
1259 yystack.l_mark -= yym;
1260 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1261 yystack.p_mark -= yym;
1264 if (yystate == 0 && yym == 0)
1269 fprintf(stderr, "%s[%d]: after reduction, ", YYDEBUGSTR, yydepth);
1270 #ifdef YYSTYPE_TOSTRING
1273 #endif /* YYBTYACC */
1274 fprintf(stderr, "result is <%s>, ", YYSTYPE_TOSTRING(yystos[YYFINAL], yyval));
1276 fprintf(stderr, "shifting from state 0 to final state %d\n", YYFINAL);
1280 *++yystack.s_mark = YYFINAL;
1281 *++yystack.l_mark = yyval;
1282 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1283 *++yystack.p_mark = yyloc;
1291 /* we're currently re-reading tokens */
1293 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1301 /* in trial mode; save scanner results for future parse attempts */
1302 if (yylvp == yylvlim)
1303 { /* Enlarge lexical value queue */
1304 size_t p = (size_t) (yylvp - yylvals);
1305 size_t s = (size_t) (yylvlim - yylvals);
1307 s += YYLVQUEUEGROWTH;
1308 if ((yylexemes = (YYINT *)realloc(yylexemes, s * sizeof(YYINT))) == NULL)
1310 if ((yylvals = (YYSTYPE *)realloc(yylvals, s * sizeof(YYSTYPE))) == NULL)
1312 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1313 if ((yylpsns = (YYLTYPE *)realloc(yylpsns, s * sizeof(YYLTYPE))) == NULL)
1316 yylvp = yylve = yylvals + p;
1317 yylvlim = yylvals + s;
1318 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1319 yylpp = yylpe = yylpsns + p;
1320 yylplim = yylpsns + s;
1322 yylexp = yylexemes + p;
1324 *yylexp = (YYINT) YYLEX;
1327 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1334 /* normal operation, no conflict encountered */
1335 #endif /* YYBTYACC */
1339 #endif /* YYBTYACC */
1340 if (yychar < 0) yychar = YYEOF;
1344 if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN];
1345 fprintf(stderr, "%s[%d]: state %d, reading token %d (%s)\n",
1346 YYDEBUGSTR, yydepth, YYFINAL, yychar, yys);
1350 if (yychar == YYEOF) goto yyaccept;
1353 if (((yyn = yygindex[yym]) != 0) && (yyn += yystate) >= 0 &&
1354 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yystate)
1355 yystate = yytable[yyn];
1357 yystate = yydgoto[yym];
1361 fprintf(stderr, "%s[%d]: after reduction, ", YYDEBUGSTR, yydepth);
1362 #ifdef YYSTYPE_TOSTRING
1365 #endif /* YYBTYACC */
1366 fprintf(stderr, "result is <%s>, ", YYSTYPE_TOSTRING(yystos[yystate], yyval));
1368 fprintf(stderr, "shifting from state %d to state %d\n", *yystack.s_mark, yystate);
1371 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
1372 *++yystack.s_mark = (YYINT) yystate;
1373 *++yystack.l_mark = yyval;
1374 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1375 *++yystack.p_mark = yyloc;
1380 /* Reduction declares that this path is valid. Set yypath and do a full parse */
1382 if (yypath) YYABORT;
1385 YYParseState *save = yyps->save;
1386 yyps->save = save->save;
1387 save->save = yypath;
1392 fprintf(stderr, "%s[%d]: state %d, CONFLICT trial successful, backtracking to state %d, %d tokens\n",
1393 YYDEBUGSTR, yydepth, yystate, yypath->state, (int)(yylvp - yylvals - yypath->lexeme));
1397 yyFreeState(yyerrctx);
1400 yylvp = yylvals + yypath->lexeme;
1401 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1402 yylpp = yylpsns + yypath->lexeme;
1404 yylexp = yylexemes + yypath->lexeme;
1406 yystack.s_mark = yystack.s_base + (yypath->yystack.s_mark - yypath->yystack.s_base);
1407 memcpy (yystack.s_base, yypath->yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(YYINT));
1408 yystack.l_mark = yystack.l_base + (yypath->yystack.l_mark - yypath->yystack.l_base);
1409 memcpy (yystack.l_base, yypath->yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
1410 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1411 yystack.p_mark = yystack.p_base + (yypath->yystack.p_mark - yypath->yystack.p_base);
1412 memcpy (yystack.p_base, yypath->yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
1414 yystate = yypath->state;
1416 #endif /* YYBTYACC */
1419 YYERROR_CALL("yacc stack overflow");
1423 YYERROR_CALL("memory exhausted");
1425 #endif /* YYBTYACC */
1435 if (yyps->save) goto yyvalid;
1436 #endif /* YYBTYACC */
1440 #if defined(YYDESTRUCT_CALL)
1441 if (yychar != YYEOF && yychar != YYEMPTY)
1442 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1443 YYDESTRUCT_CALL("cleanup: discarding token", yychar, &yylval, &yylloc);
1445 YYDESTRUCT_CALL("cleanup: discarding token", yychar, &yylval);
1446 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
1450 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1453 for (pv = yystack.l_base, pp = yystack.p_base; pv <= yystack.l_mark; ++pv, ++pp)
1454 YYDESTRUCT_CALL("cleanup: discarding state",
1455 yystos[*(yystack.s_base + (pv - yystack.l_base))], pv, pp);
1457 for (pv = yystack.l_base; pv <= yystack.l_mark; ++pv)
1458 YYDESTRUCT_CALL("cleanup: discarding state",
1459 yystos[*(yystack.s_base + (pv - yystack.l_base))], pv);
1460 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
1462 #endif /* defined(YYDESTRUCT_CALL) */
1467 yyFreeState(yyerrctx);
1472 YYParseState *save = yyps;
1479 YYParseState *save = yypath;
1480 yypath = save->save;
1484 #endif /* YYBTYACC */
1485 yyfreestack(&yystack);