2 static const char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93";
13 #define yyclearin (yychar = YYEMPTY)
14 #define yyerrok (yyerrflag = 0)
15 #define YYRECOVERING() (yyerrflag != 0)
17 /* compatibility with bison */
19 /* compatibility with FreeBSD */
20 #ifdef YYPARSE_PARAM_TYPE
21 #define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
23 #define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
26 #define YYPARSE_DECL() yyparse(void)
27 #endif /* YYPARSE_PARAM */
29 extern int YYPARSE_DECL();
31 static int yygrowstack(void);
32 #define yyparse calc_parse
33 #define yylex calc_lex
34 #define yyerror calc_error
35 #define yychar calc_char
36 #define yyval calc_val
37 #define yylval calc_lval
38 #define yydebug calc_debug
39 #define yynerrs calc_nerrs
40 #define yyerrflag calc_errflag
42 #define yyssp calc_ssp
44 #define yyvsp calc_vsp
45 #define yylhs calc_lhs
46 #define yylen calc_len
47 #define yydefred calc_defred
48 #define yydgoto calc_dgoto
49 #define yysindex calc_sindex
50 #define yyrindex calc_rindex
51 #define yygindex calc_gindex
52 #define yytable calc_table
53 #define yycheck calc_check
54 #define yyname calc_name
55 #define yyrule calc_rule
56 #define YYPREFIX "calc_"
69 static const short calc_lhs[] = { -1,
70 0, 0, 0, 1, 1, 2, 2, 2, 2, 2,
71 2, 2, 2, 2, 2, 2, 3, 3,
73 static const short calc_len[] = { 2,
74 0, 3, 3, 1, 3, 3, 3, 3, 3, 3,
75 3, 3, 3, 2, 1, 1, 1, 2,
77 static const short calc_defred[] = { 1,
78 0, 0, 17, 0, 0, 0, 0, 0, 0, 3,
79 0, 15, 14, 0, 2, 0, 0, 0, 0, 0,
80 0, 0, 18, 0, 6, 0, 0, 0, 0, 9,
83 static const short calc_dgoto[] = { 1,
86 static const short calc_sindex[] = { 0,
87 -40, -7, 0, -55, -38, -38, 1, -29, -247, 0,
88 -38, 0, 0, 22, 0, -38, -38, -38, -38, -38,
89 -38, -38, 0, -29, 0, 51, 60, -20, -20, 0,
92 static const short calc_rindex[] = { 0,
93 0, 0, 0, 2, 0, 0, 0, 9, -9, 0,
94 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
95 0, 0, 0, 10, 0, -6, 14, 5, 13, 0,
98 static const short calc_gindex[] = { 0,
101 #define YYTABLESIZE 220
102 static const short calc_table[] = { 6,
103 16, 6, 10, 13, 5, 11, 5, 22, 17, 23,
104 15, 15, 20, 18, 7, 19, 22, 21, 4, 5,
105 0, 20, 8, 12, 0, 0, 21, 16, 16, 0,
106 0, 16, 16, 16, 13, 16, 0, 16, 15, 15,
107 0, 0, 7, 15, 15, 7, 15, 7, 15, 7,
108 8, 12, 0, 8, 12, 8, 0, 8, 22, 17,
109 0, 0, 25, 20, 18, 0, 19, 0, 21, 13,
110 14, 0, 0, 0, 0, 24, 0, 0, 0, 0,
111 26, 27, 28, 29, 30, 31, 32, 22, 17, 0,
112 0, 0, 20, 18, 16, 19, 22, 21, 0, 0,
113 0, 20, 18, 0, 19, 0, 21, 0, 0, 0,
114 0, 0, 0, 0, 16, 0, 0, 13, 0, 0,
115 0, 0, 0, 0, 0, 15, 0, 0, 7, 0,
116 0, 0, 0, 0, 0, 0, 8, 12, 0, 0,
117 0, 0, 0, 0, 0, 16, 0, 0, 0, 0,
118 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
119 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
120 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
121 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
122 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
123 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
124 0, 0, 0, 0, 0, 2, 3, 4, 3, 12,
126 static const short calc_check[] = { 40,
127 10, 40, 10, 10, 45, 61, 45, 37, 38, 257,
128 10, 10, 42, 43, 10, 45, 37, 47, 10, 10,
129 -1, 42, 10, 10, -1, -1, 47, 37, 38, -1,
130 -1, 41, 42, 43, 41, 45, -1, 47, 37, 38,
131 -1, -1, 38, 42, 43, 41, 45, 43, 47, 45,
132 38, 38, -1, 41, 41, 43, -1, 45, 37, 38,
133 -1, -1, 41, 42, 43, -1, 45, -1, 47, 5,
134 6, -1, -1, -1, -1, 11, -1, -1, -1, -1,
135 16, 17, 18, 19, 20, 21, 22, 37, 38, -1,
136 -1, -1, 42, 43, 124, 45, 37, 47, -1, -1,
137 -1, 42, 43, -1, 45, -1, 47, -1, -1, -1,
138 -1, -1, -1, -1, 124, -1, -1, 124, -1, -1,
139 -1, -1, -1, -1, -1, 124, -1, -1, 124, -1,
140 -1, -1, -1, -1, -1, -1, 124, 124, -1, -1,
141 -1, -1, -1, -1, -1, 124, -1, -1, -1, -1,
142 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
143 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
144 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
145 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
146 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
147 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
148 -1, -1, -1, -1, -1, 256, 257, 258, 257, 258,
154 #define YYMAXTOKEN 259
156 static const char *calc_name[] = {
158 "end-of-file",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,
159 0,0,0,0,0,0,"'%'","'&'",0,"'('","')'","'*'","'+'",0,"'-'",0,"'/'",0,0,0,0,0,0,0,
160 0,0,0,0,0,0,"'='",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
161 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"'|'",0,0,0,0,0,0,
162 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
163 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
164 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
165 0,0,0,0,0,0,"DIGIT","LETTER","UMINUS",
167 static const char *calc_rule[] = {
170 "list : list stat '\\n'",
171 "list : list error '\\n'",
173 "stat : LETTER '=' expr",
174 "expr : '(' expr ')'",
175 "expr : expr '+' expr",
176 "expr : expr '-' expr",
177 "expr : expr '*' expr",
178 "expr : expr '/' expr",
179 "expr : expr '%' expr",
180 "expr : expr '&' expr",
181 "expr : expr '|' expr",
186 "number : number DIGIT",
197 /* define the initial stack-sizes */
200 #define YYMAXDEPTH YYSTACKSIZE
203 #define YYSTACKSIZE YYMAXDEPTH
205 #define YYSTACKSIZE 500
206 #define YYMAXDEPTH 500
210 #define YYINITSTACKSIZE 500
221 /* variables for the parser stack */
223 static short *yysslim;
224 static YYSTYPE *yyvs;
225 static unsigned yystacksize;
227 /* start of programs */
232 while(!feof(stdin)) {
239 fprintf(stderr, "%s\n", s);
243 yylex() { /* lexical analysis routine */
244 /* returns LETTER for a lower case letter, yylval = 0 through 25 */
245 /* return DIGIT for a digit, yylval = 0 through 9 */
246 /* all other characters are returned immediately */
250 while( (c=getchar()) == ' ' ) { /* skip blanks */ }
252 /* c is now nonblank */
264 #line 265 "calc.tab.c"
265 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
266 static int yygrowstack(void)
273 if ((newsize = yystacksize) == 0)
274 newsize = YYINITSTACKSIZE;
275 else if (newsize >= YYMAXDEPTH)
277 else if ((newsize *= 2) > YYMAXDEPTH)
278 newsize = YYMAXDEPTH;
282 ? (short *)realloc(yyss, newsize * sizeof(*newss))
283 : (short *)malloc(newsize * sizeof(*newss));
290 ? (YYSTYPE *)realloc(yyvs, newsize * sizeof(*newvs))
291 : (YYSTYPE *)malloc(newsize * sizeof(*newvs));
297 yystacksize = newsize;
298 yysslim = yyss + newsize - 1;
302 #define YYABORT goto yyabort
303 #define YYREJECT goto yyabort
304 #define YYACCEPT goto yyaccept
305 #define YYERROR goto yyerrlab
310 int yym, yyn, yystate;
314 if ((yys = getenv("YYDEBUG")) != 0)
317 if (yyn >= '0' && yyn <= '9')
327 if (yyss == NULL && yygrowstack()) goto yyoverflow;
334 if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
337 if ((yychar = yylex()) < 0) yychar = 0;
342 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
343 if (!yys) yys = "illegal-symbol";
344 printf("%sdebug: state %d, reading %d (%s)\n",
345 YYPREFIX, yystate, yychar, yys);
349 if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
350 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
354 printf("%sdebug: state %d, shifting to state %d\n",
355 YYPREFIX, yystate, yytable[yyn]);
357 if (yyssp >= yysslim && yygrowstack())
361 yystate = yytable[yyn];
362 *++yyssp = yytable[yyn];
365 if (yyerrflag > 0) --yyerrflag;
368 if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
369 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
374 if (yyerrflag) goto yyinrecovery;
376 yyerror("syntax error");
389 if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&
390 yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
394 printf("%sdebug: state %d, error recovery shifting\
395 to state %d\n", YYPREFIX, *yyssp, yytable[yyn]);
397 if (yyssp >= yysslim && yygrowstack())
401 yystate = yytable[yyn];
402 *++yyssp = yytable[yyn];
410 printf("%sdebug: error recovery discarding state %d\n",
413 if (yyssp <= yyss) goto yyabort;
421 if (yychar == 0) goto yyabort;
426 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
427 if (!yys) yys = "illegal-symbol";
428 printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
429 YYPREFIX, yystate, yychar, yys);
439 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
440 YYPREFIX, yystate, yyn, yyrule[yyn]);
444 yyval = yyvsp[1-yym];
446 memset(&yyval, 0, sizeof yyval);
455 { printf("%d\n",yyvsp[0]);}
459 { regs[yyvsp[-2]] = yyvsp[0]; }
463 { yyval = yyvsp[-1]; }
467 { yyval = yyvsp[-2] + yyvsp[0]; }
471 { yyval = yyvsp[-2] - yyvsp[0]; }
475 { yyval = yyvsp[-2] * yyvsp[0]; }
479 { yyval = yyvsp[-2] / yyvsp[0]; }
483 { yyval = yyvsp[-2] % yyvsp[0]; }
487 { yyval = yyvsp[-2] & yyvsp[0]; }
491 { yyval = yyvsp[-2] | yyvsp[0]; }
495 { yyval = - yyvsp[0]; }
499 { yyval = regs[yyvsp[0]]; }
503 { yyval = yyvsp[0]; base = (yyvsp[0]==0) ? 8 : 10; }
507 { yyval = base * yyvsp[-1] + yyvsp[0]; }
509 #line 510 "calc.tab.c"
515 if (yystate == 0 && yym == 0)
519 printf("%sdebug: after reduction, shifting from state 0 to\
520 state %d\n", YYPREFIX, YYFINAL);
527 if ((yychar = yylex()) < 0) yychar = 0;
532 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
533 if (!yys) yys = "illegal-symbol";
534 printf("%sdebug: state %d, reading %d (%s)\n",
535 YYPREFIX, YYFINAL, yychar, yys);
539 if (yychar == 0) goto yyaccept;
542 if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
543 yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
544 yystate = yytable[yyn];
546 yystate = yydgoto[yym];
549 printf("%sdebug: after reduction, shifting from state %d \
550 to state %d\n", YYPREFIX, *yyssp, yystate);
552 if (yyssp >= yysslim && yygrowstack())
556 *++yyssp = (short) yystate;
561 yyerror("yacc stack overflow");