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 "pure_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(YYSTYPE *yylval, void *YYLEX_PARAM)
126 # define YYLEX yylex(&yylval, YYLEX_PARAM)
128 # define YYLEX_DECL() yylex(YYSTYPE *yylval)
129 # define YYLEX yylex(&yylval)
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
286 #line 63 "pure_calc.y"
287 /* start of programs */
292 while(!feof(stdin)) {
299 yyerror(const char *s)
301 fprintf(stderr, "%s\n", s);
305 yylex(YYSTYPE *value)
307 /* lexical analysis routine */
308 /* returns LETTER for a lower case letter, yylval = 0 through 25 */
309 /* return DIGIT for a digit, yylval = 0 through 9 */
310 /* all other characters are returned immediately */
314 while( (c=getchar()) == ' ' ) { /* skip blanks */ }
316 /* c is now nonblank */
328 #line 329 "pure_calc.tab.c"
331 #include <stdio.h> /* needed for printf */
334 #include <stdlib.h> /* needed for malloc, etc */
335 #include <string.h> /* needed for memset */
337 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
338 static int yygrowstack(YYSTACKDATA *data)
345 if ((newsize = data->stacksize) == 0)
346 newsize = YYINITSTACKSIZE;
347 else if (newsize >= YYMAXDEPTH)
349 else if ((newsize *= 2) > YYMAXDEPTH)
350 newsize = YYMAXDEPTH;
352 i = data->s_mark - data->s_base;
353 newss = (data->s_base != 0)
354 ? (short *)realloc(data->s_base, newsize * sizeof(*newss))
355 : (short *)malloc(newsize * sizeof(*newss));
359 data->s_base = newss;
360 data->s_mark = newss + i;
362 newvs = (data->l_base != 0)
363 ? (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs))
364 : (YYSTYPE *)malloc(newsize * sizeof(*newvs));
368 data->l_base = newvs;
369 data->l_mark = newvs + i;
371 data->stacksize = newsize;
372 data->s_last = data->s_base + newsize - 1;
376 #if YYPURE || defined(YY_NO_LEAKS)
377 static void yyfreestack(YYSTACKDATA *data)
381 memset(data, 0, sizeof(*data));
384 #define yyfreestack(data) /* nothing */
387 #define YYABORT goto yyabort
388 #define YYREJECT goto yyabort
389 #define YYACCEPT goto yyaccept
390 #define YYERROR goto yyerrlab
400 /* variables for the parser stack */
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);
546 #line 25 "pure_calc.y"
550 #line 29 "pure_calc.y"
551 { printf("%d\n",yystack.l_mark[0]);}
554 #line 31 "pure_calc.y"
555 { regs[yystack.l_mark[-2]] = yystack.l_mark[0]; }
558 #line 35 "pure_calc.y"
559 { yyval = yystack.l_mark[-1]; }
562 #line 37 "pure_calc.y"
563 { yyval = yystack.l_mark[-2] + yystack.l_mark[0]; }
566 #line 39 "pure_calc.y"
567 { yyval = yystack.l_mark[-2] - yystack.l_mark[0]; }
570 #line 41 "pure_calc.y"
571 { yyval = yystack.l_mark[-2] * yystack.l_mark[0]; }
574 #line 43 "pure_calc.y"
575 { yyval = yystack.l_mark[-2] / yystack.l_mark[0]; }
578 #line 45 "pure_calc.y"
579 { yyval = yystack.l_mark[-2] % yystack.l_mark[0]; }
582 #line 47 "pure_calc.y"
583 { yyval = yystack.l_mark[-2] & yystack.l_mark[0]; }
586 #line 49 "pure_calc.y"
587 { yyval = yystack.l_mark[-2] | yystack.l_mark[0]; }
590 #line 51 "pure_calc.y"
591 { yyval = - yystack.l_mark[0]; }
594 #line 53 "pure_calc.y"
595 { yyval = regs[yystack.l_mark[0]]; }
598 #line 58 "pure_calc.y"
599 { yyval = yystack.l_mark[0]; base = (yystack.l_mark[0]==0) ? 8 : 10; }
602 #line 60 "pure_calc.y"
603 { yyval = base * yystack.l_mark[-1] + yystack.l_mark[0]; }
605 #line 606 "pure_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);