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)
16 #define yyparse calc_parse
20 #define yylex calc_lex
24 #define yyerror calc_error
28 #define yychar calc_char
32 #define yyval calc_val
36 #define yylval calc_lval
40 #define yydebug calc_debug
44 #define yynerrs calc_nerrs
48 #define yyerrflag calc_errflag
49 #endif /* yyerrflag */
52 #define yylhs calc_lhs
56 #define yylen calc_len
60 #define yydefred calc_defred
64 #define yydgoto calc_dgoto
68 #define yysindex calc_sindex
72 #define yyrindex calc_rindex
76 #define yygindex calc_gindex
80 #define yytable calc_table
84 #define yycheck calc_check
88 #define yyname calc_name
92 #define yyrule calc_rule
94 #define YYPREFIX "calc_"
105 #line 106 "calc.tab.c"
111 /* compatibility with bison */
113 /* compatibility with FreeBSD */
114 # ifdef YYPARSE_PARAM_TYPE
115 # define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
117 # define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
120 # define YYPARSE_DECL() yyparse(void)
123 /* Parameters sent to lex. */
125 # define YYLEX_DECL() yylex(void *YYLEX_PARAM)
126 # define YYLEX yylex(YYLEX_PARAM)
128 # define YYLEX_DECL() yylex(void)
129 # define YYLEX yylex()
132 extern int YYPARSE_DECL();
133 extern int YYLEX_DECL();
138 #define YYERRCODE 256
139 static const short calc_lhs[] = { -1,
140 0, 0, 0, 1, 1, 2, 2, 2, 2, 2,
141 2, 2, 2, 2, 2, 2, 3, 3,
143 static const short calc_len[] = { 2,
144 0, 3, 3, 1, 3, 3, 3, 3, 3, 3,
145 3, 3, 3, 2, 1, 1, 1, 2,
147 static const short calc_defred[] = { 1,
148 0, 0, 17, 0, 0, 0, 0, 0, 0, 3,
149 0, 15, 14, 0, 2, 0, 0, 0, 0, 0,
150 0, 0, 18, 0, 6, 0, 0, 0, 0, 9,
153 static const short calc_dgoto[] = { 1,
156 static const short calc_sindex[] = { 0,
157 -40, -7, 0, -55, -38, -38, 1, -29, -247, 0,
158 -38, 0, 0, 22, 0, -38, -38, -38, -38, -38,
159 -38, -38, 0, -29, 0, 51, 60, -20, -20, 0,
162 static const short calc_rindex[] = { 0,
163 0, 0, 0, 2, 0, 0, 0, 9, -9, 0,
164 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
165 0, 0, 0, 10, 0, -6, 14, 5, 13, 0,
168 static const short calc_gindex[] = { 0,
171 #define YYTABLESIZE 220
172 static const short calc_table[] = { 6,
173 16, 6, 10, 13, 5, 11, 5, 22, 17, 23,
174 15, 15, 20, 18, 7, 19, 22, 21, 4, 5,
175 0, 20, 8, 12, 0, 0, 21, 16, 16, 0,
176 0, 16, 16, 16, 13, 16, 0, 16, 15, 15,
177 0, 0, 7, 15, 15, 7, 15, 7, 15, 7,
178 8, 12, 0, 8, 12, 8, 0, 8, 22, 17,
179 0, 0, 25, 20, 18, 0, 19, 0, 21, 13,
180 14, 0, 0, 0, 0, 24, 0, 0, 0, 0,
181 26, 27, 28, 29, 30, 31, 32, 22, 17, 0,
182 0, 0, 20, 18, 16, 19, 22, 21, 0, 0,
183 0, 20, 18, 0, 19, 0, 21, 0, 0, 0,
184 0, 0, 0, 0, 16, 0, 0, 13, 0, 0,
185 0, 0, 0, 0, 0, 15, 0, 0, 7, 0,
186 0, 0, 0, 0, 0, 0, 8, 12, 0, 0,
187 0, 0, 0, 0, 0, 16, 0, 0, 0, 0,
188 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
189 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
190 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
191 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
192 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
193 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
194 0, 0, 0, 0, 0, 2, 3, 4, 3, 12,
196 static const short calc_check[] = { 40,
197 10, 40, 10, 10, 45, 61, 45, 37, 38, 257,
198 10, 10, 42, 43, 10, 45, 37, 47, 10, 10,
199 -1, 42, 10, 10, -1, -1, 47, 37, 38, -1,
200 -1, 41, 42, 43, 41, 45, -1, 47, 37, 38,
201 -1, -1, 38, 42, 43, 41, 45, 43, 47, 45,
202 38, 38, -1, 41, 41, 43, -1, 45, 37, 38,
203 -1, -1, 41, 42, 43, -1, 45, -1, 47, 5,
204 6, -1, -1, -1, -1, 11, -1, -1, -1, -1,
205 16, 17, 18, 19, 20, 21, 22, 37, 38, -1,
206 -1, -1, 42, 43, 124, 45, 37, 47, -1, -1,
207 -1, 42, 43, -1, 45, -1, 47, -1, -1, -1,
208 -1, -1, -1, -1, 124, -1, -1, 124, -1, -1,
209 -1, -1, -1, -1, -1, 124, -1, -1, 124, -1,
210 -1, -1, -1, -1, -1, -1, 124, 124, -1, -1,
211 -1, -1, -1, -1, -1, 124, -1, -1, -1, -1,
212 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
213 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
214 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
215 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
216 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
217 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
218 -1, -1, -1, -1, -1, 256, 257, 258, 257, 258,
224 #define YYMAXTOKEN 259
226 static const char *yyname[] = {
228 "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,
229 0,0,0,0,0,0,"'%'","'&'",0,"'('","')'","'*'","'+'",0,"'-'",0,"'/'",0,0,0,0,0,0,0,
230 0,0,0,0,0,0,"'='",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
231 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"'|'",0,0,0,0,0,0,
232 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
233 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
234 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
235 0,0,0,0,0,0,"DIGIT","LETTER","UMINUS",
237 static const char *yyrule[] = {
240 "list : list stat '\\n'",
241 "list : list error '\\n'",
243 "stat : LETTER '=' expr",
244 "expr : '(' expr ')'",
245 "expr : expr '+' expr",
246 "expr : expr '-' expr",
247 "expr : expr '*' expr",
248 "expr : expr '/' expr",
249 "expr : expr '%' expr",
250 "expr : expr '&' expr",
251 "expr : expr '|' expr",
256 "number : number DIGIT",
260 /* define the initial stack-sizes */
263 #define YYMAXDEPTH YYSTACKSIZE
266 #define YYSTACKSIZE YYMAXDEPTH
268 #define YYSTACKSIZE 500
269 #define YYMAXDEPTH 500
273 #define YYINITSTACKSIZE 500
291 /* variables for the parser stack */
292 static YYSTACKDATA yystack;
294 /* start of programs */
299 while(!feof(stdin)) {
306 yyerror(const char *s)
308 fprintf(stderr, "%s\n", s);
314 /* lexical analysis routine */
315 /* returns LETTER for a lower case letter, yylval = 0 through 25 */
316 /* return DIGIT for a digit, yylval = 0 through 9 */
317 /* all other characters are returned immediately */
321 while( (c=getchar()) == ' ' ) { /* skip blanks */ }
323 /* c is now nonblank */
335 #line 336 "calc.tab.c"
338 #include <stdio.h> /* needed for printf */
341 #include <stdlib.h> /* needed for malloc, etc */
342 #include <string.h> /* needed for memset */
344 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
345 static int yygrowstack(YYSTACKDATA *data)
352 if ((newsize = data->stacksize) == 0)
353 newsize = YYINITSTACKSIZE;
354 else if (newsize >= YYMAXDEPTH)
356 else if ((newsize *= 2) > YYMAXDEPTH)
357 newsize = YYMAXDEPTH;
359 i = data->s_mark - data->s_base;
360 newss = (data->s_base != 0)
361 ? (short *)realloc(data->s_base, newsize * sizeof(*newss))
362 : (short *)malloc(newsize * sizeof(*newss));
366 data->s_base = newss;
367 data->s_mark = newss + i;
369 newvs = (data->l_base != 0)
370 ? (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs))
371 : (YYSTYPE *)malloc(newsize * sizeof(*newvs));
375 data->l_base = newvs;
376 data->l_mark = newvs + i;
378 data->stacksize = newsize;
379 data->s_last = data->s_base + newsize - 1;
383 #if YYPURE || defined(YY_NO_LEAKS)
384 static void yyfreestack(YYSTACKDATA *data)
388 memset(data, 0, sizeof(*data));
391 #define yyfreestack(data) /* nothing */
394 #define YYABORT goto yyabort
395 #define YYREJECT goto yyabort
396 #define YYACCEPT goto yyaccept
397 #define YYERROR goto yyerrlab
402 int yym, yyn, yystate;
406 if ((yys = getenv("YYDEBUG")) != 0)
409 if (yyn >= '0' && yyn <= '9')
420 memset(&yystack, 0, sizeof(yystack));
423 if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow;
424 yystack.s_mark = yystack.s_base;
425 yystack.l_mark = yystack.l_base;
430 if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
433 if ((yychar = YYLEX) < 0) yychar = 0;
438 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
439 if (!yys) yys = "illegal-symbol";
440 printf("%sdebug: state %d, reading %d (%s)\n",
441 YYPREFIX, yystate, yychar, yys);
445 if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
446 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
450 printf("%sdebug: state %d, shifting to state %d\n",
451 YYPREFIX, yystate, yytable[yyn]);
453 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
457 yystate = yytable[yyn];
458 *++yystack.s_mark = yytable[yyn];
459 *++yystack.l_mark = yylval;
461 if (yyerrflag > 0) --yyerrflag;
464 if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
465 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
470 if (yyerrflag) goto yyinrecovery;
472 yyerror("syntax error");
485 if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 &&
486 yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
490 printf("%sdebug: state %d, error recovery shifting\
491 to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]);
493 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
497 yystate = yytable[yyn];
498 *++yystack.s_mark = yytable[yyn];
499 *++yystack.l_mark = yylval;
506 printf("%sdebug: error recovery discarding state %d\n",
507 YYPREFIX, *yystack.s_mark);
509 if (yystack.s_mark <= yystack.s_base) goto yyabort;
517 if (yychar == 0) goto yyabort;
522 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
523 if (!yys) yys = "illegal-symbol";
524 printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
525 YYPREFIX, yystate, yychar, yys);
535 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
536 YYPREFIX, yystate, yyn, yyrule[yyn]);
540 yyval = yystack.l_mark[1-yym];
542 memset(&yyval, 0, sizeof yyval);
551 { printf("%d\n",yystack.l_mark[0]);}
555 { regs[yystack.l_mark[-2]] = yystack.l_mark[0]; }
559 { yyval = yystack.l_mark[-1]; }
563 { yyval = yystack.l_mark[-2] + yystack.l_mark[0]; }
567 { yyval = yystack.l_mark[-2] - yystack.l_mark[0]; }
571 { yyval = yystack.l_mark[-2] * yystack.l_mark[0]; }
575 { yyval = yystack.l_mark[-2] / yystack.l_mark[0]; }
579 { yyval = yystack.l_mark[-2] % yystack.l_mark[0]; }
583 { yyval = yystack.l_mark[-2] & yystack.l_mark[0]; }
587 { yyval = yystack.l_mark[-2] | yystack.l_mark[0]; }
591 { yyval = - yystack.l_mark[0]; }
595 { yyval = regs[yystack.l_mark[0]]; }
599 { yyval = yystack.l_mark[0]; base = (yystack.l_mark[0]==0) ? 8 : 10; }
603 { yyval = base * yystack.l_mark[-1] + yystack.l_mark[0]; }
605 #line 606 "calc.tab.c"
607 yystack.s_mark -= yym;
608 yystate = *yystack.s_mark;
609 yystack.l_mark -= yym;
611 if (yystate == 0 && yym == 0)
615 printf("%sdebug: after reduction, shifting from state 0 to\
616 state %d\n", YYPREFIX, YYFINAL);
619 *++yystack.s_mark = YYFINAL;
620 *++yystack.l_mark = yyval;
623 if ((yychar = YYLEX) < 0) yychar = 0;
628 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
629 if (!yys) yys = "illegal-symbol";
630 printf("%sdebug: state %d, reading %d (%s)\n",
631 YYPREFIX, YYFINAL, yychar, yys);
635 if (yychar == 0) goto yyaccept;
638 if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
639 yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
640 yystate = yytable[yyn];
642 yystate = yydgoto[yym];
645 printf("%sdebug: after reduction, shifting from state %d \
646 to state %d\n", YYPREFIX, *yystack.s_mark, yystate);
648 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
652 *++yystack.s_mark = (short) yystate;
653 *++yystack.l_mark = yyval;
657 yyerror("yacc stack overflow");
660 yyfreestack(&yystack);
664 yyfreestack(&yystack);