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,
277 static const YYINT calc3_ctable[] = { -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, -1,
297 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
298 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
299 -1, -1, -1, -1, -1, -1, -1, -1, -1,
306 #define YYMAXTOKEN 259
307 #define YYUNDFTOKEN 265
308 #define YYTRANSLATE(a) ((a) > YYMAXTOKEN ? YYUNDFTOKEN : (a))
310 static const char *const calc3_name[] = {
312 "$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,
313 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,
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,
316 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,
317 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,
318 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,
319 0,0,"error","DIGIT","LETTER","UMINUS","$accept","list","stat","expr","number",
322 static const char *const calc3_rule[] = {
325 "list : list stat '\\n'",
326 "list : list error '\\n'",
328 "stat : LETTER '=' expr",
329 "expr : '(' expr ')'",
330 "expr : expr '+' expr",
331 "expr : expr '-' expr",
332 "expr : expr '*' expr",
333 "expr : expr '/' expr",
334 "expr : expr '%' expr",
335 "expr : expr '&' expr",
336 "expr : expr '|' expr",
341 "number : number DIGIT",
349 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
350 #ifndef YYLLOC_DEFAULT
351 #define YYLLOC_DEFAULT(loc, rhs, n) \
356 (loc).first_line = ((rhs)[-1]).last_line; \
357 (loc).first_column = ((rhs)[-1]).last_column; \
358 (loc).last_line = ((rhs)[-1]).last_line; \
359 (loc).last_column = ((rhs)[-1]).last_column; \
363 (loc).first_line = ((rhs)[ 0 ]).first_line; \
364 (loc).first_column = ((rhs)[ 0 ]).first_column; \
365 (loc).last_line = ((rhs)[n-1]).last_line; \
366 (loc).last_column = ((rhs)[n-1]).last_column; \
369 #endif /* YYLLOC_DEFAULT */
370 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
373 #ifndef YYLVQUEUEGROWTH
374 #define YYLVQUEUEGROWTH 32
376 #endif /* YYBTYACC */
378 /* define the initial stack-sizes */
381 #define YYMAXDEPTH YYSTACKSIZE
384 #define YYSTACKSIZE YYMAXDEPTH
386 #define YYSTACKSIZE 10000
387 #define YYMAXDEPTH 10000
391 #ifndef YYINITSTACKSIZE
392 #define YYINITSTACKSIZE 200
402 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
409 struct YYParseState_s
411 struct YYParseState_s *save; /* Previously saved parser state */
412 YYSTACKDATA yystack; /* saved parser stack */
413 int state; /* saved parser state */
414 int errflag; /* saved error recovery status */
415 int lexeme; /* saved index of the conflict lexeme in the lexical queue */
416 YYINT ctry; /* saved index in yyctable[] for this conflict */
418 typedef struct YYParseState_s YYParseState;
419 #endif /* YYBTYACC */
421 /* start of programs */
424 extern int YYLEX_DECL();
433 while(!feof(stdin)) {
434 yyparse(regs, &base);
439 #define UNUSED(x) ((void)(x))
444 UNUSED(regs); /* %parse-param regs is not actually used here */
445 UNUSED(base); /* %parse-param base is not actually used here */
446 fprintf(stderr, "%s\n", s);
452 /* lexical analysis routine */
453 /* returns LETTER for a lower case letter, yylval = 0 through 25 */
454 /* return DIGIT for a digit, yylval = 0 through 9 */
455 /* all other characters are returned immediately */
459 while( (c=getchar()) == ' ' ) { /* skip blanks */ }
461 /* c is now nonblank */
468 *yylval = (c - '0') % (*base);
473 #line 474 "calc3.tab.c"
475 /* For use in generated program */
476 #define yydepth (int)(yystack.s_mark - yystack.s_base)
478 #define yytrial (yyps->save)
479 #endif /* YYBTYACC */
482 #include <stdio.h> /* needed for printf */
485 #include <stdlib.h> /* needed for malloc, etc */
486 #include <string.h> /* needed for memset */
488 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
489 static int yygrowstack(YYSTACKDATA *data)
495 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
499 if ((newsize = data->stacksize) == 0)
500 newsize = YYINITSTACKSIZE;
501 else if (newsize >= YYMAXDEPTH)
503 else if ((newsize *= 2) > YYMAXDEPTH)
504 newsize = YYMAXDEPTH;
506 i = (int) (data->s_mark - data->s_base);
507 newss = (YYINT *)realloc(data->s_base, newsize * sizeof(*newss));
511 data->s_base = newss;
512 data->s_mark = newss + i;
514 newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));
518 data->l_base = newvs;
519 data->l_mark = newvs + i;
521 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
522 newps = (YYLTYPE *)realloc(data->p_base, newsize * sizeof(*newps));
526 data->p_base = newps;
527 data->p_mark = newps + i;
530 data->stacksize = newsize;
531 data->s_last = data->s_base + newsize - 1;
535 fprintf(stderr, "%sdebug: stack size increased to %d\n", YYPREFIX, newsize);
540 #if YYPURE || defined(YY_NO_LEAKS)
541 static void yyfreestack(YYSTACKDATA *data)
545 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
548 memset(data, 0, sizeof(*data));
551 #define yyfreestack(data) /* nothing */
552 #endif /* YYPURE || defined(YY_NO_LEAKS) */
555 static YYParseState *
556 yyNewState(unsigned size)
558 YYParseState *p = (YYParseState *) malloc(sizeof(YYParseState));
559 if (p == NULL) return NULL;
561 p->yystack.stacksize = size;
564 p->yystack.s_base = NULL;
565 p->yystack.l_base = NULL;
566 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
567 p->yystack.p_base = NULL;
571 p->yystack.s_base = (YYINT *) malloc(size * sizeof(YYINT));
572 if (p->yystack.s_base == NULL) return NULL;
573 p->yystack.l_base = (YYSTYPE *) malloc(size * sizeof(YYSTYPE));
574 if (p->yystack.l_base == NULL) return NULL;
575 memset(p->yystack.l_base, 0, size * sizeof(YYSTYPE));
576 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
577 p->yystack.p_base = (YYLTYPE *) malloc(size * sizeof(YYLTYPE));
578 if (p->yystack.p_base == NULL) return NULL;
579 memset(p->yystack.p_base, 0, size * sizeof(YYLTYPE));
586 yyFreeState(YYParseState *p)
588 yyfreestack(&p->yystack);
591 #endif /* YYBTYACC */
593 #define YYABORT goto yyabort
594 #define YYREJECT goto yyabort
595 #define YYACCEPT goto yyaccept
596 #define YYERROR goto yyerrlab
598 #define YYVALID do { if (yyps->save) goto yyvalid; } while(0)
599 #define YYVALID_NESTED do { if (yyps->save && \
600 yyps->save->save == 0) goto yyvalid; } while(0)
601 #endif /* YYBTYACC */
610 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
611 YYLTYPE yyloc; /* position returned by actions */
612 YYLTYPE yylloc; /* position from the lexer */
615 /* variables for the parser stack */
619 /* Current parser state */
620 static YYParseState *yyps = 0;
622 /* yypath != NULL: do the full parse, starting at *yypath parser state. */
623 static YYParseState *yypath = 0;
625 /* Base of the lexical value queue */
626 static YYSTYPE *yylvals = 0;
628 /* Current position at lexical value queue */
629 static YYSTYPE *yylvp = 0;
631 /* End position of lexical value queue */
632 static YYSTYPE *yylve = 0;
634 /* The last allocated position at the lexical value queue */
635 static YYSTYPE *yylvlim = 0;
637 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
638 /* Base of the lexical position queue */
639 static YYLTYPE *yylpsns = 0;
641 /* Current position at lexical position queue */
642 static YYLTYPE *yylpp = 0;
644 /* End position of lexical position queue */
645 static YYLTYPE *yylpe = 0;
647 /* The last allocated position at the lexical position queue */
648 static YYLTYPE *yylplim = 0;
651 /* Current position at lexical token queue */
652 static short *yylexp = 0;
654 static short *yylexemes = 0;
655 #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[2]; /* position of error start & end */
667 if ((yys = getenv("YYDEBUG")) != 0)
670 if (yyn >= '0' && yyn <= '9')
674 fprintf(stderr, "%sdebug[<# of symbols on state stack>]\n", YYPREFIX);
678 yyps = yyNewState(0); if (yyps == 0) goto yyenomem;
680 #endif /* YYBTYACC */
689 memset(&yystack, 0, sizeof(yystack));
692 if (yystack.s_base == NULL && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
693 yystack.s_mark = yystack.s_base;
694 yystack.l_mark = yystack.l_base;
695 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
696 yystack.p_mark = yystack.p_base;
702 if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
709 /* we're currently re-reading tokens */
711 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
719 /* in trial mode; save scanner results for future parse attempts */
720 if (yylvp == yylvlim)
721 { /* Enlarge lexical value queue */
722 size_t p = (size_t) (yylvp - yylvals);
723 size_t s = (size_t) (yylvlim - yylvals);
725 s += YYLVQUEUEGROWTH;
726 if ((yylexemes = (short *) realloc(yylexemes, s * sizeof(short))) == NULL) goto yyenomem;
727 if ((yylvals = (YYSTYPE *) realloc(yylvals, s * sizeof(YYSTYPE))) == NULL) goto yyenomem;
728 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
729 if ((yylpsns = (YYLTYPE *) realloc(yylpsns, s * sizeof(YYLTYPE))) == NULL) goto yyenomem;
731 yylvp = yylve = yylvals + p;
732 yylvlim = yylvals + s;
733 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
734 yylpp = yylpe = yylpsns + p;
735 yylplim = yylpsns + s;
737 yylexp = yylexemes + p;
739 *yylexp = (short) YYLEX;
742 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
749 /* normal operation, no conflict encountered */
750 #endif /* YYBTYACC */
754 #endif /* YYBTYACC */
755 if (yychar < 0) yychar = YYEOF;
759 if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN];
760 fprintf(stderr, "%s[%d]: state %d, reading token %d (%s)",
761 YYDEBUGSTR, yydepth, yystate, yychar, yys);
762 #ifdef YYSTYPE_TOSTRING
765 #endif /* YYBTYACC */
766 fprintf(stderr, " <%s>", YYSTYPE_TOSTRING(yychar, yylval));
774 /* Do we have a conflict? */
775 if (((yyn = yycindex[yystate]) != 0) && (yyn += yychar) >= 0 &&
776 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar)
785 fprintf(stderr, "%s[%d]: CONFLICT in state %d: following successful trial parse\n",
786 YYDEBUGSTR, yydepth, yystate);
788 /* Switch to the next conflict context */
793 if (save->state != yystate) YYABORT;
800 /* Unresolved conflict - start/continue trial parse */
805 fprintf(stderr, "%s[%d]: CONFLICT in state %d. ", YYDEBUGSTR, yydepth, yystate);
807 fputs("ALREADY in conflict, continuing trial parse.\n", stderr);
809 fputs("Starting trial parse.\n", stderr);
812 save = yyNewState((unsigned)(yystack.s_mark - yystack.s_base + 1));
813 if (save == NULL) goto yyenomem;
814 save->save = yyps->save;
815 save->state = yystate;
816 save->errflag = yyerrflag;
817 save->yystack.s_mark = save->yystack.s_base + (yystack.s_mark - yystack.s_base);
818 memcpy (save->yystack.s_base, yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(YYINT));
819 save->yystack.l_mark = save->yystack.l_base + (yystack.l_mark - yystack.l_base);
820 memcpy (save->yystack.l_base, yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
821 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
822 save->yystack.p_mark = save->yystack.p_base + (yystack.p_mark - yystack.p_base);
823 memcpy (save->yystack.p_base, yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
826 if (yyctable[ctry] == -1)
829 if (yydebug && yychar >= YYEOF)
830 fprintf(stderr, "%s[%d]: backtracking 1 token\n", YYDEBUGSTR, yydepth);
835 if (yyps->save == NULL)
837 /* If this is a first conflict in the stack, start saving lexemes */
840 yylexemes = (short *) malloc((YYLVQUEUEGROWTH) * sizeof(short));
841 if (yylexemes == NULL) goto yyenomem;
842 yylvals = (YYSTYPE *) malloc((YYLVQUEUEGROWTH) * sizeof(YYSTYPE));
843 if (yylvals == NULL) goto yyenomem;
844 yylvlim = yylvals + YYLVQUEUEGROWTH;
845 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
846 yylpsns = (YYLTYPE *) malloc((YYLVQUEUEGROWTH) * sizeof(YYLTYPE));
847 if (yylpsns == NULL) goto yyenomem;
848 yylplim = yylpsns + YYLVQUEUEGROWTH;
853 yylvp = yylve = yylvals;
854 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
855 yylpp = yylpe = yylpsns;
861 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
864 *yylexp = (short) yychar;
872 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
878 save->lexeme = (int) (yylvp - yylvals);
881 if (yytable[yyn] == ctry)
885 fprintf(stderr, "%s[%d]: state %d, shifting to state %d\n",
886 YYDEBUGSTR, yydepth, yystate, yyctable[ctry]);
891 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
896 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM)
898 yystate = yyctable[ctry];
899 *++yystack.s_mark = (YYINT) yystate;
900 *++yystack.l_mark = yylval;
901 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
902 *++yystack.p_mark = yylloc;
905 if (yyerrflag > 0) --yyerrflag;
910 yyn = yyctable[ctry];
913 } /* End of code dealing with conflicts */
914 #endif /* YYBTYACC */
915 if (((yyn = yysindex[yystate]) != 0) && (yyn += yychar) >= 0 &&
916 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar)
920 fprintf(stderr, "%s[%d]: state %d, shifting to state %d\n",
921 YYDEBUGSTR, yydepth, yystate, yytable[yyn]);
923 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
924 yystate = yytable[yyn];
925 *++yystack.s_mark = yytable[yyn];
926 *++yystack.l_mark = yylval;
927 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
928 *++yystack.p_mark = yylloc;
931 if (yyerrflag > 0) --yyerrflag;
934 if (((yyn = yyrindex[yystate]) != 0) && (yyn += yychar) >= 0 &&
935 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar)
940 if (yyerrflag != 0) goto yyinrecovery;
945 goto yyerrlab; /* redundant goto avoids 'unused label' warning */
948 /* explicit YYERROR from an action -- pop the rhs of the rule reduced
949 * before looking for error recovery */
950 yystack.s_mark -= yym;
951 yystate = *yystack.s_mark;
952 yystack.l_mark -= yym;
953 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
954 yystack.p_mark -= yym;
962 YYParseState *save = yyps->save;
965 fprintf(stderr, "%s[%d]: ERROR in state %d, CONFLICT BACKTRACKING to state %d, %d tokens\n",
966 YYDEBUGSTR, yydepth, yystate, yyps->save->state,
967 (int)(yylvp - yylvals - yyps->save->lexeme));
969 /* Memorize most forward-looking error state in case it's really an error. */
970 if (yyerrctx == NULL || yyerrctx->lexeme < yylvp - yylvals)
972 /* Free old saved error context state */
973 if (yyerrctx) yyFreeState(yyerrctx);
974 /* Create and fill out new saved error context state */
975 yyerrctx = yyNewState((unsigned)(yystack.s_mark - yystack.s_base + 1));
976 if (yyerrctx == NULL) goto yyenomem;
977 yyerrctx->save = yyps->save;
978 yyerrctx->state = yystate;
979 yyerrctx->errflag = yyerrflag;
980 yyerrctx->yystack.s_mark = yyerrctx->yystack.s_base + (yystack.s_mark - yystack.s_base);
981 memcpy (yyerrctx->yystack.s_base, yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(YYINT));
982 yyerrctx->yystack.l_mark = yyerrctx->yystack.l_base + (yystack.l_mark - yystack.l_base);
983 memcpy (yyerrctx->yystack.l_base, yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
984 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
985 yyerrctx->yystack.p_mark = yyerrctx->yystack.p_base + (yystack.p_mark - yystack.p_base);
986 memcpy (yyerrctx->yystack.p_base, yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
988 yyerrctx->lexeme = (int) (yylvp - yylvals);
990 yylvp = yylvals + save->lexeme;
991 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
992 yylpp = yylpsns + save->lexeme;
994 yylexp = yylexemes + save->lexeme;
996 yystack.s_mark = yystack.s_base + (save->yystack.s_mark - save->yystack.s_base);
997 memcpy (yystack.s_base, save->yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(YYINT));
998 yystack.l_mark = yystack.l_base + (save->yystack.l_mark - save->yystack.l_base);
999 memcpy (yystack.l_base, save->yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
1000 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1001 yystack.p_mark = yystack.p_base + (save->yystack.p_mark - save->yystack.p_base);
1002 memcpy (yystack.p_base, save->yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
1004 ctry = ++save->ctry;
1005 yystate = save->state;
1006 /* We tried shift, try reduce now */
1007 if ((yyn = yyctable[ctry]) >= 0) goto yyreduce;
1008 yyps->save = save->save;
1012 /* Nothing left on the stack -- error */
1017 fprintf(stderr, "%sdebug[%d,trial]: trial parse FAILED, entering ERROR mode\n",
1020 /* Restore state as it was in the most forward-advanced error */
1021 yylvp = yylvals + yyerrctx->lexeme;
1022 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1023 yylpp = yylpsns + yyerrctx->lexeme;
1025 yylexp = yylexemes + yyerrctx->lexeme;
1026 yychar = yylexp[-1];
1028 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1031 yystack.s_mark = yystack.s_base + (yyerrctx->yystack.s_mark - yyerrctx->yystack.s_base);
1032 memcpy (yystack.s_base, yyerrctx->yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(YYINT));
1033 yystack.l_mark = yystack.l_base + (yyerrctx->yystack.l_mark - yyerrctx->yystack.l_base);
1034 memcpy (yystack.l_base, yyerrctx->yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
1035 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1036 yystack.p_mark = yystack.p_base + (yyerrctx->yystack.p_mark - yyerrctx->yystack.p_base);
1037 memcpy (yystack.p_base, yyerrctx->yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
1039 yystate = yyerrctx->state;
1040 yyFreeState(yyerrctx);
1045 if (yynewerrflag == 0) goto yyinrecovery;
1046 #endif /* YYBTYACC */
1048 YYERROR_CALL("syntax error");
1049 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1050 yyerror_loc_range[0] = yylloc; /* lookahead position is error start position */
1054 goto yyerrlab; /* redundant goto avoids 'unused label' warning */
1065 if (((yyn = yysindex[*yystack.s_mark]) != 0) && (yyn += YYERRCODE) >= 0 &&
1066 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) YYERRCODE)
1070 fprintf(stderr, "%s[%d]: state %d, error recovery shifting to state %d\n",
1071 YYDEBUGSTR, yydepth, *yystack.s_mark, yytable[yyn]);
1073 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
1074 yystate = yytable[yyn];
1075 *++yystack.s_mark = yytable[yyn];
1076 *++yystack.l_mark = yylval;
1077 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1078 /* lookahead position is error end position */
1079 yyerror_loc_range[1] = yylloc;
1080 YYLLOC_DEFAULT(yyloc, yyerror_loc_range, 2); /* position of error span */
1081 *++yystack.p_mark = yyloc;
1089 fprintf(stderr, "%s[%d]: error recovery discarding state %d\n",
1090 YYDEBUGSTR, yydepth, *yystack.s_mark);
1092 if (yystack.s_mark <= yystack.s_base) goto yyabort;
1093 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1094 /* the current TOS position is the error start position */
1095 yyerror_loc_range[0] = *yystack.p_mark;
1097 #if defined(YYDESTRUCT_CALL)
1100 #endif /* YYBTYACC */
1101 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1102 YYDESTRUCT_CALL("error: discarding state",
1103 yystos[*yystack.s_mark], yystack.l_mark, yystack.p_mark);
1105 YYDESTRUCT_CALL("error: discarding state",
1106 yystos[*yystack.s_mark], yystack.l_mark);
1107 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
1108 #endif /* defined(YYDESTRUCT_CALL) */
1111 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1119 if (yychar == YYEOF) goto yyabort;
1123 if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN];
1124 fprintf(stderr, "%s[%d]: state %d, error recovery discarding token %d (%s)\n",
1125 YYDEBUGSTR, yydepth, yystate, yychar, yys);
1128 #if defined(YYDESTRUCT_CALL)
1131 #endif /* YYBTYACC */
1132 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1133 YYDESTRUCT_CALL("error: discarding token", yychar, &yylval, &yylloc);
1135 YYDESTRUCT_CALL("error: discarding token", yychar, &yylval);
1136 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
1137 #endif /* defined(YYDESTRUCT_CALL) */
1147 fprintf(stderr, "%s[%d]: state %d, reducing by rule %d (%s)",
1148 YYDEBUGSTR, yydepth, yystate, yyn, yyrule[yyn]);
1149 #ifdef YYSTYPE_TOSTRING
1152 #endif /* YYBTYACC */
1157 for (i = yym; i > 0; i--)
1159 if (i != yym) fputs(", ", stderr);
1160 fputs(YYSTYPE_TOSTRING(yystos[yystack.s_mark[1-i]],
1161 yystack.l_mark[1-i]), stderr);
1166 fputc('\n', stderr);
1170 yyval = yystack.l_mark[1-yym];
1172 memset(&yyval, 0, sizeof yyval);
1173 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1175 /* Perform position reduction */
1176 memset(&yyloc, 0, sizeof(yyloc));
1179 #endif /* YYBTYACC */
1181 YYLLOC_DEFAULT(yyloc, &yystack.p_mark[1-yym], yym);
1182 /* just in case YYERROR is invoked within the action, save
1183 the start of the rhs as the error start position */
1184 yyerror_loc_range[0] = yystack.p_mark[1-yym];
1196 { printf("%d\n",yystack.l_mark[0]);}
1200 { regs[yystack.l_mark[-2]] = yystack.l_mark[0]; }
1204 { yyval = yystack.l_mark[-1]; }
1208 { yyval = yystack.l_mark[-2] + yystack.l_mark[0]; }
1212 { yyval = yystack.l_mark[-2] - yystack.l_mark[0]; }
1216 { yyval = yystack.l_mark[-2] * yystack.l_mark[0]; }
1220 { yyval = yystack.l_mark[-2] / yystack.l_mark[0]; }
1224 { yyval = yystack.l_mark[-2] % yystack.l_mark[0]; }
1228 { yyval = yystack.l_mark[-2] & yystack.l_mark[0]; }
1232 { yyval = yystack.l_mark[-2] | yystack.l_mark[0]; }
1236 { yyval = - yystack.l_mark[0]; }
1240 { yyval = regs[yystack.l_mark[0]]; }
1244 { yyval = yystack.l_mark[0]; (*base) = (yystack.l_mark[0]==0) ? 8 : 10; }
1248 { yyval = (*base) * yystack.l_mark[-1] + yystack.l_mark[0]; }
1250 #line 1251 "calc3.tab.c"
1254 yystack.s_mark -= yym;
1255 yystate = *yystack.s_mark;
1256 yystack.l_mark -= yym;
1257 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1258 yystack.p_mark -= yym;
1261 if (yystate == 0 && yym == 0)
1266 fprintf(stderr, "%s[%d]: after reduction, ", YYDEBUGSTR, yydepth);
1267 #ifdef YYSTYPE_TOSTRING
1270 #endif /* YYBTYACC */
1271 fprintf(stderr, "result is <%s>, ", YYSTYPE_TOSTRING(yystos[YYFINAL], yyval));
1273 fprintf(stderr, "shifting from state 0 to final state %d\n", YYFINAL);
1277 *++yystack.s_mark = YYFINAL;
1278 *++yystack.l_mark = yyval;
1279 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1280 *++yystack.p_mark = yyloc;
1288 /* we're currently re-reading tokens */
1290 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1298 /* in trial mode; save scanner results for future parse attempts */
1299 if (yylvp == yylvlim)
1300 { /* Enlarge lexical value queue */
1301 size_t p = (size_t) (yylvp - yylvals);
1302 size_t s = (size_t) (yylvlim - yylvals);
1304 s += YYLVQUEUEGROWTH;
1305 if ((yylexemes = (short *) realloc(yylexemes, s * sizeof(short))) == NULL)
1307 if ((yylvals = (YYSTYPE *) realloc(yylvals, s * sizeof(YYSTYPE))) == NULL)
1309 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1310 if ((yylpsns = (YYLTYPE *) realloc(yylpsns, s * sizeof(YYLTYPE))) == NULL)
1313 yylvp = yylve = yylvals + p;
1314 yylvlim = yylvals + s;
1315 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1316 yylpp = yylpe = yylpsns + p;
1317 yylplim = yylpsns + s;
1319 yylexp = yylexemes + p;
1321 *yylexp = (short) YYLEX;
1324 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1331 /* normal operation, no conflict encountered */
1332 #endif /* YYBTYACC */
1336 #endif /* YYBTYACC */
1337 if (yychar < 0) yychar = YYEOF;
1341 if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN];
1342 fprintf(stderr, "%s[%d]: state %d, reading token %d (%s)\n",
1343 YYDEBUGSTR, yydepth, YYFINAL, yychar, yys);
1347 if (yychar == YYEOF) goto yyaccept;
1350 if (((yyn = yygindex[yym]) != 0) && (yyn += yystate) >= 0 &&
1351 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yystate)
1352 yystate = yytable[yyn];
1354 yystate = yydgoto[yym];
1358 fprintf(stderr, "%s[%d]: after reduction, ", YYDEBUGSTR, yydepth);
1359 #ifdef YYSTYPE_TOSTRING
1362 #endif /* YYBTYACC */
1363 fprintf(stderr, "result is <%s>, ", YYSTYPE_TOSTRING(yystos[yystate], yyval));
1365 fprintf(stderr, "shifting from state %d to state %d\n", *yystack.s_mark, yystate);
1368 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
1369 *++yystack.s_mark = (YYINT) yystate;
1370 *++yystack.l_mark = yyval;
1371 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1372 *++yystack.p_mark = yyloc;
1377 /* Reduction declares that this path is valid. Set yypath and do a full parse */
1379 if (yypath) YYABORT;
1382 YYParseState *save = yyps->save;
1383 yyps->save = save->save;
1384 save->save = yypath;
1389 fprintf(stderr, "%s[%d]: state %d, CONFLICT trial successful, backtracking to state %d, %d tokens\n",
1390 YYDEBUGSTR, yydepth, yystate, yypath->state, (int)(yylvp - yylvals - yypath->lexeme));
1394 yyFreeState(yyerrctx);
1397 yylvp = yylvals + yypath->lexeme;
1398 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1399 yylpp = yylpsns + yypath->lexeme;
1401 yylexp = yylexemes + yypath->lexeme;
1403 yystack.s_mark = yystack.s_base + (yypath->yystack.s_mark - yypath->yystack.s_base);
1404 memcpy (yystack.s_base, yypath->yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(YYINT));
1405 yystack.l_mark = yystack.l_base + (yypath->yystack.l_mark - yypath->yystack.l_base);
1406 memcpy (yystack.l_base, yypath->yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
1407 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1408 yystack.p_mark = yystack.p_base + (yypath->yystack.p_mark - yypath->yystack.p_base);
1409 memcpy (yystack.p_base, yypath->yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
1411 yystate = yypath->state;
1413 #endif /* YYBTYACC */
1416 YYERROR_CALL("yacc stack overflow");
1420 YYERROR_CALL("memory exhausted");
1422 #endif /* YYBTYACC */
1432 if (yyps->save) goto yyvalid;
1433 #endif /* YYBTYACC */
1437 #if defined(YYDESTRUCT_CALL)
1438 if (yychar != YYEOF && yychar != YYEMPTY)
1439 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1440 YYDESTRUCT_CALL("cleanup: discarding token", yychar, &yylval, &yylloc);
1442 YYDESTRUCT_CALL("cleanup: discarding token", yychar, &yylval);
1443 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
1447 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1450 for (pv = yystack.l_base, pp = yystack.p_base; pv <= yystack.l_mark; ++pv, ++pp)
1451 YYDESTRUCT_CALL("cleanup: discarding state",
1452 yystos[*(yystack.s_base + (pv - yystack.l_base))], pv, pp);
1454 for (pv = yystack.l_base; pv <= yystack.l_mark; ++pv)
1455 YYDESTRUCT_CALL("cleanup: discarding state",
1456 yystos[*(yystack.s_base + (pv - yystack.l_base))], pv);
1457 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
1459 #endif /* defined(YYDESTRUCT_CALL) */
1464 yyFreeState(yyerrctx);
1469 YYParseState *save = yyps;
1476 YYParseState *save = yypath;
1477 yypath = save->save;
1481 #endif /* YYBTYACC */
1482 yyfreestack(&yystack);