2 static const char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93";
10 #define yyclearin (yychar = YYEMPTY)
11 #define yyerrok (yyerrflag = 0)
12 #define YYRECOVERING() (yyerrflag != 0)
26 static void yyerror(const char *s);
29 #line 30 "code_calc.code.c"
35 /* compatibility with bison */
37 /* compatibility with FreeBSD */
38 # ifdef YYPARSE_PARAM_TYPE
39 # define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
41 # define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
44 # define YYPARSE_DECL() yyparse(void)
47 /* Parameters sent to lex. */
49 # define YYLEX_DECL() yylex(void *YYLEX_PARAM)
50 # define YYLEX yylex(YYLEX_PARAM)
52 # define YYLEX_DECL() yylex(void)
53 # define YYLEX yylex()
56 /* Parameters sent to yyerror. */
58 #define YYERROR_DECL() yyerror(const char *s)
61 #define YYERROR_CALL(msg) yyerror(msg)
64 extern int YYPARSE_DECL();
70 #define YYTABLESIZE 220
75 #define YYMAXTOKEN 259
78 #define yyparse calc_parse
82 #define yylex calc_lex
86 #define yyerror calc_error
90 #define yychar calc_char
94 #define yyval calc_val
98 #define yylval calc_lval
102 #define yydebug calc_debug
106 #define yynerrs calc_nerrs
110 #define yyerrflag calc_errflag
111 #endif /* yyerrflag */
114 #define yylhs calc_lhs
118 #define yylen calc_len
122 #define yydefred calc_defred
123 #endif /* yydefred */
126 #define yydgoto calc_dgoto
130 #define yysindex calc_sindex
131 #endif /* yysindex */
134 #define yyrindex calc_rindex
135 #endif /* yyrindex */
138 #define yygindex calc_gindex
139 #endif /* yygindex */
142 #define yytable calc_table
146 #define yycheck calc_check
150 #define yyname calc_name
154 #define yyrule calc_rule
156 #define YYPREFIX "calc_"
158 extern int YYPARSE_DECL();
159 extern short yylhs[];
160 extern short yylen[];
161 extern short yydefred[];
162 extern short yydgoto[];
163 extern short yysindex[];
164 extern short yyrindex[];
165 extern short yygindex[];
166 extern short yytable[];
167 extern short yycheck[];
170 extern char *yyname[];
171 extern char *yyrule[];
182 /* define the initial stack-sizes */
185 #define YYMAXDEPTH YYSTACKSIZE
188 #define YYSTACKSIZE YYMAXDEPTH
190 #define YYSTACKSIZE 500
191 #define YYMAXDEPTH 500
195 #define YYINITSTACKSIZE 500
205 /* variables for the parser stack */
206 static YYSTACKDATA yystack;
207 #line 68 "code_calc.y"
208 /* start of programs */
211 extern int YYLEX_DECL();
217 while(!feof(stdin)) {
224 yyerror(const char *s)
226 fprintf(stderr, "%s\n", s);
232 /* lexical analysis routine */
233 /* returns LETTER for a lower case letter, yylval = 0 through 25 */
234 /* return DIGIT for a digit, yylval = 0 through 9 */
235 /* all other characters are returned immediately */
239 while( (c=getchar()) == ' ' ) { /* skip blanks */ }
241 /* c is now nonblank */
253 #line 254 "code_calc.code.c"
256 #include <stdio.h> /* needed for printf */
259 #include <stdlib.h> /* needed for malloc, etc */
260 #include <string.h> /* needed for memset */
262 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
263 static int yygrowstack(YYSTACKDATA *data)
270 if ((newsize = data->stacksize) == 0)
271 newsize = YYINITSTACKSIZE;
272 else if (newsize >= YYMAXDEPTH)
274 else if ((newsize *= 2) > YYMAXDEPTH)
275 newsize = YYMAXDEPTH;
277 i = (int) (data->s_mark - data->s_base);
278 newss = (short *)realloc(data->s_base, newsize * sizeof(*newss));
282 data->s_base = newss;
283 data->s_mark = newss + i;
285 newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));
289 data->l_base = newvs;
290 data->l_mark = newvs + i;
292 data->stacksize = newsize;
293 data->s_last = data->s_base + newsize - 1;
297 #if YYPURE || defined(YY_NO_LEAKS)
298 static void yyfreestack(YYSTACKDATA *data)
302 memset(data, 0, sizeof(*data));
305 #define yyfreestack(data) /* nothing */
308 #define YYABORT goto yyabort
309 #define YYREJECT goto yyabort
310 #define YYACCEPT goto yyaccept
311 #define YYERROR goto yyerrlab
316 int yym, yyn, yystate;
320 if ((yys = getenv("YYDEBUG")) != 0)
323 if (yyn >= '0' && yyn <= '9')
334 memset(&yystack, 0, sizeof(yystack));
337 if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow;
338 yystack.s_mark = yystack.s_base;
339 yystack.l_mark = yystack.l_base;
344 if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
347 if ((yychar = YYLEX) < 0) yychar = 0;
352 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
353 if (!yys) yys = "illegal-symbol";
354 printf("%sdebug: state %d, reading %d (%s)\n",
355 YYPREFIX, yystate, yychar, yys);
359 if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
360 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
364 printf("%sdebug: state %d, shifting to state %d\n",
365 YYPREFIX, yystate, yytable[yyn]);
367 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
371 yystate = yytable[yyn];
372 *++yystack.s_mark = yytable[yyn];
373 *++yystack.l_mark = yylval;
375 if (yyerrflag > 0) --yyerrflag;
378 if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
379 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
384 if (yyerrflag) goto yyinrecovery;
386 yyerror("syntax error");
399 if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 &&
400 yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
404 printf("%sdebug: state %d, error recovery shifting\
405 to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]);
407 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
411 yystate = yytable[yyn];
412 *++yystack.s_mark = yytable[yyn];
413 *++yystack.l_mark = yylval;
420 printf("%sdebug: error recovery discarding state %d\n",
421 YYPREFIX, *yystack.s_mark);
423 if (yystack.s_mark <= yystack.s_base) goto yyabort;
431 if (yychar == 0) goto yyabort;
436 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
437 if (!yys) yys = "illegal-symbol";
438 printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
439 YYPREFIX, yystate, yychar, yys);
449 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
450 YYPREFIX, yystate, yyn, yyrule[yyn]);
454 yyval = yystack.l_mark[1-yym];
456 memset(&yyval, 0, sizeof yyval);
460 #line 30 "code_calc.y"
464 #line 34 "code_calc.y"
465 { printf("%d\n",yystack.l_mark[0]);}
468 #line 36 "code_calc.y"
469 { regs[yystack.l_mark[-2]] = yystack.l_mark[0]; }
472 #line 40 "code_calc.y"
473 { yyval = yystack.l_mark[-1]; }
476 #line 42 "code_calc.y"
477 { yyval = yystack.l_mark[-2] + yystack.l_mark[0]; }
480 #line 44 "code_calc.y"
481 { yyval = yystack.l_mark[-2] - yystack.l_mark[0]; }
484 #line 46 "code_calc.y"
485 { yyval = yystack.l_mark[-2] * yystack.l_mark[0]; }
488 #line 48 "code_calc.y"
489 { yyval = yystack.l_mark[-2] / yystack.l_mark[0]; }
492 #line 50 "code_calc.y"
493 { yyval = yystack.l_mark[-2] % yystack.l_mark[0]; }
496 #line 52 "code_calc.y"
497 { yyval = yystack.l_mark[-2] & yystack.l_mark[0]; }
500 #line 54 "code_calc.y"
501 { yyval = yystack.l_mark[-2] | yystack.l_mark[0]; }
504 #line 56 "code_calc.y"
505 { yyval = - yystack.l_mark[0]; }
508 #line 58 "code_calc.y"
509 { yyval = regs[yystack.l_mark[0]]; }
512 #line 63 "code_calc.y"
513 { yyval = yystack.l_mark[0]; base = (yystack.l_mark[0]==0) ? 8 : 10; }
516 #line 65 "code_calc.y"
517 { yyval = base * yystack.l_mark[-1] + yystack.l_mark[0]; }
519 #line 520 "code_calc.code.c"
521 yystack.s_mark -= yym;
522 yystate = *yystack.s_mark;
523 yystack.l_mark -= yym;
525 if (yystate == 0 && yym == 0)
529 printf("%sdebug: after reduction, shifting from state 0 to\
530 state %d\n", YYPREFIX, YYFINAL);
533 *++yystack.s_mark = YYFINAL;
534 *++yystack.l_mark = yyval;
537 if ((yychar = YYLEX) < 0) yychar = 0;
542 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
543 if (!yys) yys = "illegal-symbol";
544 printf("%sdebug: state %d, reading %d (%s)\n",
545 YYPREFIX, YYFINAL, yychar, yys);
549 if (yychar == 0) goto yyaccept;
552 if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
553 yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
554 yystate = yytable[yyn];
556 yystate = yydgoto[yym];
559 printf("%sdebug: after reduction, shifting from state %d \
560 to state %d\n", YYPREFIX, *yystack.s_mark, yystate);
562 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
566 *++yystack.s_mark = (short) yystate;
567 *++yystack.l_mark = yyval;
571 yyerror("yacc stack overflow");
574 yyfreestack(&yystack);
578 yyfreestack(&yystack);