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)
17 /* %code "top" block start */
18 #line 1 "calc_code_top.y"
20 #line 2 "calc_code_top.y"
22 /* %code "top" block end */
23 #line 24 "calc_code_top.tab.c"
26 #define YYDEBUGSTR YYPREFIX "debug"
29 #define yyparse calc_code_top_parse
33 #define yylex calc_code_top_lex
37 #define yyerror calc_code_top_error
41 #define yychar calc_code_top_char
45 #define yyval calc_code_top_val
49 #define yylval calc_code_top_lval
53 #define yydebug calc_code_top_debug
57 #define yynerrs calc_code_top_nerrs
61 #define yyerrflag calc_code_top_errflag
62 #endif /* yyerrflag */
65 #define yylhs calc_code_top_lhs
69 #define yylen calc_code_top_len
73 #define yydefred calc_code_top_defred
77 #define yystos calc_code_top_stos
81 #define yydgoto calc_code_top_dgoto
85 #define yysindex calc_code_top_sindex
89 #define yyrindex calc_code_top_rindex
93 #define yygindex calc_code_top_gindex
97 #define yytable calc_code_top_table
101 #define yycheck calc_code_top_check
105 #define yyname calc_code_top_name
109 #define yyrule calc_code_top_rule
115 #define yycindex calc_code_top_cindex
116 #endif /* yycindex */
119 #define yyctable calc_code_top_ctable
120 #endif /* yyctable */
122 #endif /* YYBTYACC */
124 #define YYPREFIX "calc_code_top_"
128 #line 5 "calc_code_top.y"
135 extern int yylex(void);
136 static void yyerror(const char *s);
138 #line 139 "calc_code_top.tab.c"
140 #if ! defined(YYSTYPE) && ! defined(YYSTYPE_IS_DECLARED)
141 /* Default: YYSTYPE is the semantic value type. */
143 # define YYSTYPE_IS_DECLARED 1
146 /* compatibility with bison */
148 /* compatibility with FreeBSD */
149 # ifdef YYPARSE_PARAM_TYPE
150 # define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
152 # define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
155 # define YYPARSE_DECL() yyparse(void)
158 /* Parameters sent to lex. */
160 # define YYLEX_DECL() yylex(void *YYLEX_PARAM)
161 # define YYLEX yylex(YYLEX_PARAM)
163 # define YYLEX_DECL() yylex(void)
164 # define YYLEX yylex()
167 /* Parameters sent to yyerror. */
169 #define YYERROR_DECL() yyerror(const char *s)
172 #define YYERROR_CALL(msg) yyerror(msg)
175 extern int YYPARSE_DECL();
180 #define YYERRCODE 256
182 static const YYINT calc_code_top_lhs[] = { -1,
183 0, 0, 0, 1, 1, 2, 2, 2, 2, 2,
184 2, 2, 2, 2, 2, 2, 3, 3,
186 static const YYINT calc_code_top_len[] = { 2,
187 0, 3, 3, 1, 3, 3, 3, 3, 3, 3,
188 3, 3, 3, 2, 1, 1, 1, 2,
190 static const YYINT calc_code_top_defred[] = { 1,
191 0, 0, 17, 0, 0, 0, 0, 0, 0, 3,
192 0, 15, 14, 0, 2, 0, 0, 0, 0, 0,
193 0, 0, 18, 0, 6, 0, 0, 0, 0, 9,
196 #if defined(YYDESTRUCT_CALL) || defined(YYSTYPE_TOSTRING)
197 static const YYINT calc_code_top_stos[] = { 0,
198 261, 256, 257, 258, 45, 40, 262, 263, 264, 10,
199 61, 258, 263, 263, 10, 124, 38, 43, 45, 42,
200 47, 37, 257, 263, 41, 263, 263, 263, 263, 263,
203 #endif /* YYDESTRUCT_CALL || YYSTYPE_TOSTRING */
204 static const YYINT calc_code_top_dgoto[] = { 1,
207 static const YYINT calc_code_top_sindex[] = { 0,
208 -40, -7, 0, -55, -38, -38, 1, -29, -247, 0,
209 -38, 0, 0, 22, 0, -38, -38, -38, -38, -38,
210 -38, -38, 0, -29, 0, 51, 60, -20, -20, 0,
213 static const YYINT calc_code_top_rindex[] = { 0,
214 0, 0, 0, 2, 0, 0, 0, 9, -9, 0,
215 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
216 0, 0, 0, 10, 0, -6, 14, 5, 13, 0,
220 static const YYINT calc_code_top_cindex[] = { 0,
221 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
222 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
223 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
227 static const YYINT calc_code_top_gindex[] = { 0,
230 #define YYTABLESIZE 220
231 static const YYINT calc_code_top_table[] = { 6,
232 16, 6, 10, 13, 5, 11, 5, 22, 17, 23,
233 15, 15, 20, 18, 7, 19, 22, 21, 4, 5,
234 0, 20, 8, 12, 0, 0, 21, 16, 16, 0,
235 0, 16, 16, 16, 13, 16, 0, 16, 15, 15,
236 0, 0, 7, 15, 15, 7, 15, 7, 15, 7,
237 8, 12, 0, 8, 12, 8, 0, 8, 22, 17,
238 0, 0, 25, 20, 18, 0, 19, 0, 21, 13,
239 14, 0, 0, 0, 0, 24, 0, 0, 0, 0,
240 26, 27, 28, 29, 30, 31, 32, 22, 17, 0,
241 0, 0, 20, 18, 16, 19, 22, 21, 0, 0,
242 0, 20, 18, 0, 19, 0, 21, 0, 0, 0,
243 0, 0, 0, 0, 16, 0, 0, 13, 0, 0,
244 0, 0, 0, 0, 0, 15, 0, 0, 7, 0,
245 0, 0, 0, 0, 0, 0, 8, 12, 0, 0,
246 0, 0, 0, 0, 0, 16, 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, 0, 0, 0, 0, 0,
251 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
252 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
253 0, 0, 0, 0, 0, 2, 3, 4, 3, 12,
255 static const YYINT calc_code_top_check[] = { 40,
256 10, 40, 10, 10, 45, 61, 45, 37, 38, 257,
257 10, 10, 42, 43, 10, 45, 37, 47, 10, 10,
258 -1, 42, 10, 10, -1, -1, 47, 37, 38, -1,
259 -1, 41, 42, 43, 41, 45, -1, 47, 37, 38,
260 -1, -1, 38, 42, 43, 41, 45, 43, 47, 45,
261 38, 38, -1, 41, 41, 43, -1, 45, 37, 38,
262 -1, -1, 41, 42, 43, -1, 45, -1, 47, 5,
263 6, -1, -1, -1, -1, 11, -1, -1, -1, -1,
264 16, 17, 18, 19, 20, 21, 22, 37, 38, -1,
265 -1, -1, 42, 43, 124, 45, 37, 47, -1, -1,
266 -1, 42, 43, -1, 45, -1, 47, -1, -1, -1,
267 -1, -1, -1, -1, 124, -1, -1, 124, -1, -1,
268 -1, -1, -1, -1, -1, 124, -1, -1, 124, -1,
269 -1, -1, -1, -1, -1, -1, 124, 124, -1, -1,
270 -1, -1, -1, -1, -1, 124, -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, -1, -1, -1, -1, -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, 256, 257, 258, 257, 258,
280 static const YYINT calc_code_top_ctable[] = { -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, -1,
300 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
301 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
302 -1, -1, -1, -1, -1, -1, -1, -1, -1,
309 #define YYMAXTOKEN 259
310 #define YYUNDFTOKEN 265
311 #define YYTRANSLATE(a) ((a) > YYMAXTOKEN ? YYUNDFTOKEN : (a))
313 static const char *const calc_code_top_name[] = {
315 "$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,
316 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,
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,
319 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,
320 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,
321 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,
322 0,0,"error","DIGIT","LETTER","UMINUS","$accept","list","stat","expr","number",
325 static const char *const calc_code_top_rule[] = {
328 "list : list stat '\\n'",
329 "list : list error '\\n'",
331 "stat : LETTER '=' expr",
332 "expr : '(' expr ')'",
333 "expr : expr '+' expr",
334 "expr : expr '-' expr",
335 "expr : expr '*' expr",
336 "expr : expr '/' expr",
337 "expr : expr '%' expr",
338 "expr : expr '&' expr",
339 "expr : expr '|' expr",
344 "number : number DIGIT",
359 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
360 YYLTYPE yyloc; /* position returned by actions */
361 YYLTYPE yylloc; /* position from the lexer */
364 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
365 #ifndef YYLLOC_DEFAULT
366 #define YYLLOC_DEFAULT(loc, rhs, n) \
371 (loc).first_line = YYRHSLOC(rhs, 0).last_line; \
372 (loc).first_column = YYRHSLOC(rhs, 0).last_column; \
373 (loc).last_line = YYRHSLOC(rhs, 0).last_line; \
374 (loc).last_column = YYRHSLOC(rhs, 0).last_column; \
378 (loc).first_line = YYRHSLOC(rhs, 1).first_line; \
379 (loc).first_column = YYRHSLOC(rhs, 1).first_column; \
380 (loc).last_line = YYRHSLOC(rhs, n).last_line; \
381 (loc).last_column = YYRHSLOC(rhs, n).last_column; \
384 #endif /* YYLLOC_DEFAULT */
385 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
388 #ifndef YYLVQUEUEGROWTH
389 #define YYLVQUEUEGROWTH 32
391 #endif /* YYBTYACC */
393 /* define the initial stack-sizes */
396 #define YYMAXDEPTH YYSTACKSIZE
399 #define YYSTACKSIZE YYMAXDEPTH
401 #define YYSTACKSIZE 10000
402 #define YYMAXDEPTH 10000
406 #ifndef YYINITSTACKSIZE
407 #define YYINITSTACKSIZE 200
417 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
424 struct YYParseState_s
426 struct YYParseState_s *save; /* Previously saved parser state */
427 YYSTACKDATA yystack; /* saved parser stack */
428 int state; /* saved parser state */
429 int errflag; /* saved error recovery status */
430 int lexeme; /* saved index of the conflict lexeme in the lexical queue */
431 YYINT ctry; /* saved index in yyctable[] for this conflict */
433 typedef struct YYParseState_s YYParseState;
434 #endif /* YYBTYACC */
435 /* variables for the parser stack */
436 static YYSTACKDATA yystack;
439 /* Current parser state */
440 static YYParseState *yyps = 0;
442 /* yypath != NULL: do the full parse, starting at *yypath parser state. */
443 static YYParseState *yypath = 0;
445 /* Base of the lexical value queue */
446 static YYSTYPE *yylvals = 0;
448 /* Current position at lexical value queue */
449 static YYSTYPE *yylvp = 0;
451 /* End position of lexical value queue */
452 static YYSTYPE *yylve = 0;
454 /* The last allocated position at the lexical value queue */
455 static YYSTYPE *yylvlim = 0;
457 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
458 /* Base of the lexical position queue */
459 static YYLTYPE *yylpsns = 0;
461 /* Current position at lexical position queue */
462 static YYLTYPE *yylpp = 0;
464 /* End position of lexical position queue */
465 static YYLTYPE *yylpe = 0;
467 /* The last allocated position at the lexical position queue */
468 static YYLTYPE *yylplim = 0;
471 /* Current position at lexical token queue */
472 static YYINT *yylexp = 0;
474 static YYINT *yylexemes = 0;
475 #endif /* YYBTYACC */
476 #line 69 "calc_code_top.y"
477 /* start of programs */
482 while(!feof(stdin)) {
489 yyerror(const char *s)
491 fprintf(stderr, "%s\n", s);
497 /* lexical analysis routine */
498 /* returns LETTER for a lower case letter, yylval = 0 through 25 */
499 /* return DIGIT for a digit, yylval = 0 through 9 */
500 /* all other characters are returned immediately */
504 while( (c=getchar()) == ' ' ) { /* skip blanks */ }
506 /* c is now nonblank */
518 #line 519 "calc_code_top.tab.c"
520 /* For use in generated program */
521 #define yydepth (int)(yystack.s_mark - yystack.s_base)
523 #define yytrial (yyps->save)
524 #endif /* YYBTYACC */
527 #include <stdio.h> /* needed for printf */
530 #include <stdlib.h> /* needed for malloc, etc */
531 #include <string.h> /* needed for memset */
533 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
534 static int yygrowstack(YYSTACKDATA *data)
540 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
544 if ((newsize = data->stacksize) == 0)
545 newsize = YYINITSTACKSIZE;
546 else if (newsize >= YYMAXDEPTH)
548 else if ((newsize *= 2) > YYMAXDEPTH)
549 newsize = YYMAXDEPTH;
551 i = (int) (data->s_mark - data->s_base);
552 newss = (YYINT *)realloc(data->s_base, newsize * sizeof(*newss));
556 data->s_base = newss;
557 data->s_mark = newss + i;
559 newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));
563 data->l_base = newvs;
564 data->l_mark = newvs + i;
566 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
567 newps = (YYLTYPE *)realloc(data->p_base, newsize * sizeof(*newps));
571 data->p_base = newps;
572 data->p_mark = newps + i;
575 data->stacksize = newsize;
576 data->s_last = data->s_base + newsize - 1;
580 fprintf(stderr, "%sdebug: stack size increased to %d\n", YYPREFIX, newsize);
585 #if YYPURE || defined(YY_NO_LEAKS)
586 static void yyfreestack(YYSTACKDATA *data)
590 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
593 memset(data, 0, sizeof(*data));
596 #define yyfreestack(data) /* nothing */
597 #endif /* YYPURE || defined(YY_NO_LEAKS) */
600 static YYParseState *
601 yyNewState(unsigned size)
603 YYParseState *p = (YYParseState *) malloc(sizeof(YYParseState));
604 if (p == NULL) return NULL;
606 p->yystack.stacksize = size;
609 p->yystack.s_base = NULL;
610 p->yystack.l_base = NULL;
611 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
612 p->yystack.p_base = NULL;
616 p->yystack.s_base = (YYINT *) malloc(size * sizeof(YYINT));
617 if (p->yystack.s_base == NULL) return NULL;
618 p->yystack.l_base = (YYSTYPE *) malloc(size * sizeof(YYSTYPE));
619 if (p->yystack.l_base == NULL) return NULL;
620 memset(p->yystack.l_base, 0, size * sizeof(YYSTYPE));
621 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
622 p->yystack.p_base = (YYLTYPE *) malloc(size * sizeof(YYLTYPE));
623 if (p->yystack.p_base == NULL) return NULL;
624 memset(p->yystack.p_base, 0, size * sizeof(YYLTYPE));
631 yyFreeState(YYParseState *p)
633 yyfreestack(&p->yystack);
636 #endif /* YYBTYACC */
638 #define YYABORT goto yyabort
639 #define YYREJECT goto yyabort
640 #define YYACCEPT goto yyaccept
641 #define YYERROR goto yyerrlab
643 #define YYVALID do { if (yyps->save) goto yyvalid; } while(0)
644 #define YYVALID_NESTED do { if (yyps->save && \
645 yyps->save->save == 0) goto yyvalid; } while(0)
646 #endif /* YYBTYACC */
651 int yym, yyn, yystate, yyresult;
654 YYParseState *yyerrctx = NULL;
655 #endif /* YYBTYACC */
656 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
657 YYLTYPE yyerror_loc_range[3]; /* position of error start/end (0 unused) */
662 if ((yys = getenv("YYDEBUG")) != 0)
665 if (yyn >= '0' && yyn <= '9')
669 fprintf(stderr, "%sdebug[<# of symbols on state stack>]\n", YYPREFIX);
671 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
672 memset(yyerror_loc_range, 0, sizeof(yyerror_loc_range));
676 yyps = yyNewState(0); if (yyps == 0) goto yyenomem;
678 #endif /* YYBTYACC */
687 memset(&yystack, 0, sizeof(yystack));
690 if (yystack.s_base == NULL && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
691 yystack.s_mark = yystack.s_base;
692 yystack.l_mark = yystack.l_base;
693 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
694 yystack.p_mark = yystack.p_base;
700 if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
707 /* we're currently re-reading tokens */
709 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
717 /* in trial mode; save scanner results for future parse attempts */
718 if (yylvp == yylvlim)
719 { /* Enlarge lexical value queue */
720 size_t p = (size_t) (yylvp - yylvals);
721 size_t s = (size_t) (yylvlim - yylvals);
723 s += YYLVQUEUEGROWTH;
724 if ((yylexemes = (YYINT *)realloc(yylexemes, s * sizeof(YYINT))) == NULL) goto yyenomem;
725 if ((yylvals = (YYSTYPE *)realloc(yylvals, s * sizeof(YYSTYPE))) == NULL) goto yyenomem;
726 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
727 if ((yylpsns = (YYLTYPE *)realloc(yylpsns, s * sizeof(YYLTYPE))) == NULL) goto yyenomem;
729 yylvp = yylve = yylvals + p;
730 yylvlim = yylvals + s;
731 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
732 yylpp = yylpe = yylpsns + p;
733 yylplim = yylpsns + s;
735 yylexp = yylexemes + p;
737 *yylexp = (YYINT) YYLEX;
740 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
747 /* normal operation, no conflict encountered */
748 #endif /* YYBTYACC */
752 #endif /* YYBTYACC */
753 if (yychar < 0) yychar = YYEOF;
757 if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN];
758 fprintf(stderr, "%s[%d]: state %d, reading token %d (%s)",
759 YYDEBUGSTR, yydepth, yystate, yychar, yys);
760 #ifdef YYSTYPE_TOSTRING
763 #endif /* YYBTYACC */
764 fprintf(stderr, " <%s>", YYSTYPE_TOSTRING(yychar, yylval));
772 /* Do we have a conflict? */
773 if (((yyn = yycindex[yystate]) != 0) && (yyn += yychar) >= 0 &&
774 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar)
783 fprintf(stderr, "%s[%d]: CONFLICT in state %d: following successful trial parse\n",
784 YYDEBUGSTR, yydepth, yystate);
786 /* Switch to the next conflict context */
791 if (save->state != yystate) YYABORT;
798 /* Unresolved conflict - start/continue trial parse */
803 fprintf(stderr, "%s[%d]: CONFLICT in state %d. ", YYDEBUGSTR, yydepth, yystate);
805 fputs("ALREADY in conflict, continuing trial parse.\n", stderr);
807 fputs("Starting trial parse.\n", stderr);
810 save = yyNewState((unsigned)(yystack.s_mark - yystack.s_base + 1));
811 if (save == NULL) goto yyenomem;
812 save->save = yyps->save;
813 save->state = yystate;
814 save->errflag = yyerrflag;
815 save->yystack.s_mark = save->yystack.s_base + (yystack.s_mark - yystack.s_base);
816 memcpy (save->yystack.s_base, yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(YYINT));
817 save->yystack.l_mark = save->yystack.l_base + (yystack.l_mark - yystack.l_base);
818 memcpy (save->yystack.l_base, yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
819 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
820 save->yystack.p_mark = save->yystack.p_base + (yystack.p_mark - yystack.p_base);
821 memcpy (save->yystack.p_base, yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
824 if (yyctable[ctry] == -1)
827 if (yydebug && yychar >= YYEOF)
828 fprintf(stderr, "%s[%d]: backtracking 1 token\n", YYDEBUGSTR, yydepth);
833 if (yyps->save == NULL)
835 /* If this is a first conflict in the stack, start saving lexemes */
838 yylexemes = (YYINT *) malloc((YYLVQUEUEGROWTH) * sizeof(YYINT));
839 if (yylexemes == NULL) goto yyenomem;
840 yylvals = (YYSTYPE *) malloc((YYLVQUEUEGROWTH) * sizeof(YYSTYPE));
841 if (yylvals == NULL) goto yyenomem;
842 yylvlim = yylvals + YYLVQUEUEGROWTH;
843 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
844 yylpsns = (YYLTYPE *) malloc((YYLVQUEUEGROWTH) * sizeof(YYLTYPE));
845 if (yylpsns == NULL) goto yyenomem;
846 yylplim = yylpsns + YYLVQUEUEGROWTH;
851 yylvp = yylve = yylvals;
852 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
853 yylpp = yylpe = yylpsns;
859 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
862 *yylexp = (YYINT) yychar;
870 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
876 save->lexeme = (int) (yylvp - yylvals);
879 if (yytable[yyn] == ctry)
883 fprintf(stderr, "%s[%d]: state %d, shifting to state %d\n",
884 YYDEBUGSTR, yydepth, yystate, yyctable[ctry]);
889 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
894 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM)
896 yystate = yyctable[ctry];
897 *++yystack.s_mark = (YYINT) yystate;
898 *++yystack.l_mark = yylval;
899 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
900 *++yystack.p_mark = yylloc;
903 if (yyerrflag > 0) --yyerrflag;
908 yyn = yyctable[ctry];
911 } /* End of code dealing with conflicts */
912 #endif /* YYBTYACC */
913 if (((yyn = yysindex[yystate]) != 0) && (yyn += yychar) >= 0 &&
914 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar)
918 fprintf(stderr, "%s[%d]: state %d, shifting to state %d\n",
919 YYDEBUGSTR, yydepth, yystate, yytable[yyn]);
921 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
922 yystate = yytable[yyn];
923 *++yystack.s_mark = yytable[yyn];
924 *++yystack.l_mark = yylval;
925 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
926 *++yystack.p_mark = yylloc;
929 if (yyerrflag > 0) --yyerrflag;
932 if (((yyn = yyrindex[yystate]) != 0) && (yyn += yychar) >= 0 &&
933 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar)
938 if (yyerrflag != 0) goto yyinrecovery;
943 goto yyerrlab; /* redundant goto avoids 'unused label' warning */
946 /* explicit YYERROR from an action -- pop the rhs of the rule reduced
947 * before looking for error recovery */
948 yystack.s_mark -= yym;
949 yystate = *yystack.s_mark;
950 yystack.l_mark -= yym;
951 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
952 yystack.p_mark -= yym;
960 YYParseState *save = yyps->save;
963 fprintf(stderr, "%s[%d]: ERROR in state %d, CONFLICT BACKTRACKING to state %d, %d tokens\n",
964 YYDEBUGSTR, yydepth, yystate, yyps->save->state,
965 (int)(yylvp - yylvals - yyps->save->lexeme));
967 /* Memorize most forward-looking error state in case it's really an error. */
968 if (yyerrctx == NULL || yyerrctx->lexeme < yylvp - yylvals)
970 /* Free old saved error context state */
971 if (yyerrctx) yyFreeState(yyerrctx);
972 /* Create and fill out new saved error context state */
973 yyerrctx = yyNewState((unsigned)(yystack.s_mark - yystack.s_base + 1));
974 if (yyerrctx == NULL) goto yyenomem;
975 yyerrctx->save = yyps->save;
976 yyerrctx->state = yystate;
977 yyerrctx->errflag = yyerrflag;
978 yyerrctx->yystack.s_mark = yyerrctx->yystack.s_base + (yystack.s_mark - yystack.s_base);
979 memcpy (yyerrctx->yystack.s_base, yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(YYINT));
980 yyerrctx->yystack.l_mark = yyerrctx->yystack.l_base + (yystack.l_mark - yystack.l_base);
981 memcpy (yyerrctx->yystack.l_base, yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
982 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
983 yyerrctx->yystack.p_mark = yyerrctx->yystack.p_base + (yystack.p_mark - yystack.p_base);
984 memcpy (yyerrctx->yystack.p_base, yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
986 yyerrctx->lexeme = (int) (yylvp - yylvals);
988 yylvp = yylvals + save->lexeme;
989 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
990 yylpp = yylpsns + save->lexeme;
992 yylexp = yylexemes + save->lexeme;
994 yystack.s_mark = yystack.s_base + (save->yystack.s_mark - save->yystack.s_base);
995 memcpy (yystack.s_base, save->yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(YYINT));
996 yystack.l_mark = yystack.l_base + (save->yystack.l_mark - save->yystack.l_base);
997 memcpy (yystack.l_base, save->yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
998 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
999 yystack.p_mark = yystack.p_base + (save->yystack.p_mark - save->yystack.p_base);
1000 memcpy (yystack.p_base, save->yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
1002 ctry = ++save->ctry;
1003 yystate = save->state;
1004 /* We tried shift, try reduce now */
1005 if ((yyn = yyctable[ctry]) >= 0) goto yyreduce;
1006 yyps->save = save->save;
1010 /* Nothing left on the stack -- error */
1015 fprintf(stderr, "%sdebug[%d,trial]: trial parse FAILED, entering ERROR mode\n",
1018 /* Restore state as it was in the most forward-advanced error */
1019 yylvp = yylvals + yyerrctx->lexeme;
1020 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1021 yylpp = yylpsns + yyerrctx->lexeme;
1023 yylexp = yylexemes + yyerrctx->lexeme;
1024 yychar = yylexp[-1];
1026 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1029 yystack.s_mark = yystack.s_base + (yyerrctx->yystack.s_mark - yyerrctx->yystack.s_base);
1030 memcpy (yystack.s_base, yyerrctx->yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(YYINT));
1031 yystack.l_mark = yystack.l_base + (yyerrctx->yystack.l_mark - yyerrctx->yystack.l_base);
1032 memcpy (yystack.l_base, yyerrctx->yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
1033 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1034 yystack.p_mark = yystack.p_base + (yyerrctx->yystack.p_mark - yyerrctx->yystack.p_base);
1035 memcpy (yystack.p_base, yyerrctx->yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
1037 yystate = yyerrctx->state;
1038 yyFreeState(yyerrctx);
1043 if (yynewerrflag == 0) goto yyinrecovery;
1044 #endif /* YYBTYACC */
1046 YYERROR_CALL("syntax error");
1047 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1048 yyerror_loc_range[1] = yylloc; /* lookahead position is error start position */
1052 goto yyerrlab; /* redundant goto avoids 'unused label' warning */
1063 if (((yyn = yysindex[*yystack.s_mark]) != 0) && (yyn += YYERRCODE) >= 0 &&
1064 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) YYERRCODE)
1068 fprintf(stderr, "%s[%d]: state %d, error recovery shifting to state %d\n",
1069 YYDEBUGSTR, yydepth, *yystack.s_mark, yytable[yyn]);
1071 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
1072 yystate = yytable[yyn];
1073 *++yystack.s_mark = yytable[yyn];
1074 *++yystack.l_mark = yylval;
1075 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1076 /* lookahead position is error end position */
1077 yyerror_loc_range[2] = yylloc;
1078 YYLLOC_DEFAULT(yyloc, yyerror_loc_range, 2); /* position of error span */
1079 *++yystack.p_mark = yyloc;
1087 fprintf(stderr, "%s[%d]: error recovery discarding state %d\n",
1088 YYDEBUGSTR, yydepth, *yystack.s_mark);
1090 if (yystack.s_mark <= yystack.s_base) goto yyabort;
1091 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1092 /* the current TOS position is the error start position */
1093 yyerror_loc_range[1] = *yystack.p_mark;
1095 #if defined(YYDESTRUCT_CALL)
1098 #endif /* YYBTYACC */
1099 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1100 YYDESTRUCT_CALL("error: discarding state",
1101 yystos[*yystack.s_mark], yystack.l_mark, yystack.p_mark);
1103 YYDESTRUCT_CALL("error: discarding state",
1104 yystos[*yystack.s_mark], yystack.l_mark);
1105 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
1106 #endif /* defined(YYDESTRUCT_CALL) */
1109 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1117 if (yychar == YYEOF) goto yyabort;
1121 if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN];
1122 fprintf(stderr, "%s[%d]: state %d, error recovery discarding token %d (%s)\n",
1123 YYDEBUGSTR, yydepth, yystate, yychar, yys);
1126 #if defined(YYDESTRUCT_CALL)
1129 #endif /* YYBTYACC */
1130 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1131 YYDESTRUCT_CALL("error: discarding token", yychar, &yylval, &yylloc);
1133 YYDESTRUCT_CALL("error: discarding token", yychar, &yylval);
1134 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
1135 #endif /* defined(YYDESTRUCT_CALL) */
1145 fprintf(stderr, "%s[%d]: state %d, reducing by rule %d (%s)",
1146 YYDEBUGSTR, yydepth, yystate, yyn, yyrule[yyn]);
1147 #ifdef YYSTYPE_TOSTRING
1150 #endif /* YYBTYACC */
1155 for (i = yym; i > 0; i--)
1157 if (i != yym) fputs(", ", stderr);
1158 fputs(YYSTYPE_TOSTRING(yystos[yystack.s_mark[1-i]],
1159 yystack.l_mark[1-i]), stderr);
1164 fputc('\n', stderr);
1168 yyval = yystack.l_mark[1-yym];
1170 memset(&yyval, 0, sizeof yyval);
1171 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1173 /* Perform position reduction */
1174 memset(&yyloc, 0, sizeof(yyloc));
1177 #endif /* YYBTYACC */
1179 YYLLOC_DEFAULT(yyloc, &yystack.p_mark[-yym], yym);
1180 /* just in case YYERROR is invoked within the action, save
1181 the start of the rhs as the error start position */
1182 yyerror_loc_range[1] = yystack.p_mark[1-yym];
1189 #line 31 "calc_code_top.y"
1193 #line 35 "calc_code_top.y"
1194 { printf("%d\n",yystack.l_mark[0]);}
1197 #line 37 "calc_code_top.y"
1198 { regs[yystack.l_mark[-2]] = yystack.l_mark[0]; }
1201 #line 41 "calc_code_top.y"
1202 { yyval = yystack.l_mark[-1]; }
1205 #line 43 "calc_code_top.y"
1206 { yyval = yystack.l_mark[-2] + yystack.l_mark[0]; }
1209 #line 45 "calc_code_top.y"
1210 { yyval = yystack.l_mark[-2] - yystack.l_mark[0]; }
1213 #line 47 "calc_code_top.y"
1214 { yyval = yystack.l_mark[-2] * yystack.l_mark[0]; }
1217 #line 49 "calc_code_top.y"
1218 { yyval = yystack.l_mark[-2] / yystack.l_mark[0]; }
1221 #line 51 "calc_code_top.y"
1222 { yyval = yystack.l_mark[-2] % yystack.l_mark[0]; }
1225 #line 53 "calc_code_top.y"
1226 { yyval = yystack.l_mark[-2] & yystack.l_mark[0]; }
1229 #line 55 "calc_code_top.y"
1230 { yyval = yystack.l_mark[-2] | yystack.l_mark[0]; }
1233 #line 57 "calc_code_top.y"
1234 { yyval = - yystack.l_mark[0]; }
1237 #line 59 "calc_code_top.y"
1238 { yyval = regs[yystack.l_mark[0]]; }
1241 #line 64 "calc_code_top.y"
1242 { yyval = yystack.l_mark[0]; base = (yystack.l_mark[0]==0) ? 8 : 10; }
1245 #line 66 "calc_code_top.y"
1246 { yyval = base * yystack.l_mark[-1] + yystack.l_mark[0]; }
1248 #line 1249 "calc_code_top.tab.c"
1252 yystack.s_mark -= yym;
1253 yystate = *yystack.s_mark;
1254 yystack.l_mark -= yym;
1255 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1256 yystack.p_mark -= yym;
1259 if (yystate == 0 && yym == 0)
1264 fprintf(stderr, "%s[%d]: after reduction, ", YYDEBUGSTR, yydepth);
1265 #ifdef YYSTYPE_TOSTRING
1268 #endif /* YYBTYACC */
1269 fprintf(stderr, "result is <%s>, ", YYSTYPE_TOSTRING(yystos[YYFINAL], yyval));
1271 fprintf(stderr, "shifting from state 0 to final state %d\n", YYFINAL);
1275 *++yystack.s_mark = YYFINAL;
1276 *++yystack.l_mark = yyval;
1277 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1278 *++yystack.p_mark = yyloc;
1286 /* we're currently re-reading tokens */
1288 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1296 /* in trial mode; save scanner results for future parse attempts */
1297 if (yylvp == yylvlim)
1298 { /* Enlarge lexical value queue */
1299 size_t p = (size_t) (yylvp - yylvals);
1300 size_t s = (size_t) (yylvlim - yylvals);
1302 s += YYLVQUEUEGROWTH;
1303 if ((yylexemes = (YYINT *)realloc(yylexemes, s * sizeof(YYINT))) == NULL)
1305 if ((yylvals = (YYSTYPE *)realloc(yylvals, s * sizeof(YYSTYPE))) == NULL)
1307 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1308 if ((yylpsns = (YYLTYPE *)realloc(yylpsns, s * sizeof(YYLTYPE))) == NULL)
1311 yylvp = yylve = yylvals + p;
1312 yylvlim = yylvals + s;
1313 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1314 yylpp = yylpe = yylpsns + p;
1315 yylplim = yylpsns + s;
1317 yylexp = yylexemes + p;
1319 *yylexp = (YYINT) YYLEX;
1322 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1329 /* normal operation, no conflict encountered */
1330 #endif /* YYBTYACC */
1334 #endif /* YYBTYACC */
1335 if (yychar < 0) yychar = YYEOF;
1339 if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN];
1340 fprintf(stderr, "%s[%d]: state %d, reading token %d (%s)\n",
1341 YYDEBUGSTR, yydepth, YYFINAL, yychar, yys);
1345 if (yychar == YYEOF) goto yyaccept;
1348 if (((yyn = yygindex[yym]) != 0) && (yyn += yystate) >= 0 &&
1349 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yystate)
1350 yystate = yytable[yyn];
1352 yystate = yydgoto[yym];
1356 fprintf(stderr, "%s[%d]: after reduction, ", YYDEBUGSTR, yydepth);
1357 #ifdef YYSTYPE_TOSTRING
1360 #endif /* YYBTYACC */
1361 fprintf(stderr, "result is <%s>, ", YYSTYPE_TOSTRING(yystos[yystate], yyval));
1363 fprintf(stderr, "shifting from state %d to state %d\n", *yystack.s_mark, yystate);
1366 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
1367 *++yystack.s_mark = (YYINT) yystate;
1368 *++yystack.l_mark = yyval;
1369 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1370 *++yystack.p_mark = yyloc;
1375 /* Reduction declares that this path is valid. Set yypath and do a full parse */
1377 if (yypath) YYABORT;
1380 YYParseState *save = yyps->save;
1381 yyps->save = save->save;
1382 save->save = yypath;
1387 fprintf(stderr, "%s[%d]: state %d, CONFLICT trial successful, backtracking to state %d, %d tokens\n",
1388 YYDEBUGSTR, yydepth, yystate, yypath->state, (int)(yylvp - yylvals - yypath->lexeme));
1392 yyFreeState(yyerrctx);
1395 yylvp = yylvals + yypath->lexeme;
1396 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1397 yylpp = yylpsns + yypath->lexeme;
1399 yylexp = yylexemes + yypath->lexeme;
1401 yystack.s_mark = yystack.s_base + (yypath->yystack.s_mark - yypath->yystack.s_base);
1402 memcpy (yystack.s_base, yypath->yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(YYINT));
1403 yystack.l_mark = yystack.l_base + (yypath->yystack.l_mark - yypath->yystack.l_base);
1404 memcpy (yystack.l_base, yypath->yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
1405 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1406 yystack.p_mark = yystack.p_base + (yypath->yystack.p_mark - yypath->yystack.p_base);
1407 memcpy (yystack.p_base, yypath->yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
1409 yystate = yypath->state;
1411 #endif /* YYBTYACC */
1414 YYERROR_CALL("yacc stack overflow");
1418 YYERROR_CALL("memory exhausted");
1420 #endif /* YYBTYACC */
1430 if (yyps->save) goto yyvalid;
1431 #endif /* YYBTYACC */
1435 #if defined(YYDESTRUCT_CALL)
1436 if (yychar != YYEOF && yychar != YYEMPTY)
1437 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1438 YYDESTRUCT_CALL("cleanup: discarding token", yychar, &yylval, &yylloc);
1440 YYDESTRUCT_CALL("cleanup: discarding token", yychar, &yylval);
1441 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
1445 #if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1448 for (pv = yystack.l_base, pp = yystack.p_base; pv <= yystack.l_mark; ++pv, ++pp)
1449 YYDESTRUCT_CALL("cleanup: discarding state",
1450 yystos[*(yystack.s_base + (pv - yystack.l_base))], pv, pp);
1452 for (pv = yystack.l_base; pv <= yystack.l_mark; ++pv)
1453 YYDESTRUCT_CALL("cleanup: discarding state",
1454 yystos[*(yystack.s_base + (pv - yystack.l_base))], pv);
1455 #endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
1457 #endif /* defined(YYDESTRUCT_CALL) */
1462 yyFreeState(yyerrctx);
1467 YYParseState *save = yyps;
1474 YYParseState *save = yypath;
1475 yypath = save->save;
1479 #endif /* YYBTYACC */
1480 yyfreestack(&yystack);