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 extern int yylex(void);
106 static void yyerror(const char *s);
108 #line 109 "calc.tab.c"
114 /* compatibility with bison */
116 /* compatibility with FreeBSD */
117 # ifdef YYPARSE_PARAM_TYPE
118 # define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
120 # define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
123 # define YYPARSE_DECL() yyparse(void)
126 /* Parameters sent to lex. */
128 # define YYLEX_DECL() yylex(void *YYLEX_PARAM)
129 # define YYLEX yylex(YYLEX_PARAM)
131 # define YYLEX_DECL() yylex(void)
132 # define YYLEX yylex()
135 /* Parameters sent to yyerror. */
137 #define YYERROR_DECL() yyerror(const char *s)
140 #define YYERROR_CALL(msg) yyerror(msg)
143 extern int YYPARSE_DECL();
148 #define YYERRCODE 256
149 static const short calc_lhs[] = { -1,
150 0, 0, 0, 1, 1, 2, 2, 2, 2, 2,
151 2, 2, 2, 2, 2, 2, 3, 3,
153 static const short calc_len[] = { 2,
154 0, 3, 3, 1, 3, 3, 3, 3, 3, 3,
155 3, 3, 3, 2, 1, 1, 1, 2,
157 static const short calc_defred[] = { 1,
158 0, 0, 17, 0, 0, 0, 0, 0, 0, 3,
159 0, 15, 14, 0, 2, 0, 0, 0, 0, 0,
160 0, 0, 18, 0, 6, 0, 0, 0, 0, 9,
163 static const short calc_dgoto[] = { 1,
166 static const short calc_sindex[] = { 0,
167 -40, -7, 0, -55, -38, -38, 1, -29, -247, 0,
168 -38, 0, 0, 22, 0, -38, -38, -38, -38, -38,
169 -38, -38, 0, -29, 0, 51, 60, -20, -20, 0,
172 static const short calc_rindex[] = { 0,
173 0, 0, 0, 2, 0, 0, 0, 9, -9, 0,
174 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
175 0, 0, 0, 10, 0, -6, 14, 5, 13, 0,
178 static const short calc_gindex[] = { 0,
181 #define YYTABLESIZE 220
182 static const short calc_table[] = { 6,
183 16, 6, 10, 13, 5, 11, 5, 22, 17, 23,
184 15, 15, 20, 18, 7, 19, 22, 21, 4, 5,
185 0, 20, 8, 12, 0, 0, 21, 16, 16, 0,
186 0, 16, 16, 16, 13, 16, 0, 16, 15, 15,
187 0, 0, 7, 15, 15, 7, 15, 7, 15, 7,
188 8, 12, 0, 8, 12, 8, 0, 8, 22, 17,
189 0, 0, 25, 20, 18, 0, 19, 0, 21, 13,
190 14, 0, 0, 0, 0, 24, 0, 0, 0, 0,
191 26, 27, 28, 29, 30, 31, 32, 22, 17, 0,
192 0, 0, 20, 18, 16, 19, 22, 21, 0, 0,
193 0, 20, 18, 0, 19, 0, 21, 0, 0, 0,
194 0, 0, 0, 0, 16, 0, 0, 13, 0, 0,
195 0, 0, 0, 0, 0, 15, 0, 0, 7, 0,
196 0, 0, 0, 0, 0, 0, 8, 12, 0, 0,
197 0, 0, 0, 0, 0, 16, 0, 0, 0, 0,
198 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
199 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
200 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
201 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
202 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
203 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
204 0, 0, 0, 0, 0, 2, 3, 4, 3, 12,
206 static const short calc_check[] = { 40,
207 10, 40, 10, 10, 45, 61, 45, 37, 38, 257,
208 10, 10, 42, 43, 10, 45, 37, 47, 10, 10,
209 -1, 42, 10, 10, -1, -1, 47, 37, 38, -1,
210 -1, 41, 42, 43, 41, 45, -1, 47, 37, 38,
211 -1, -1, 38, 42, 43, 41, 45, 43, 47, 45,
212 38, 38, -1, 41, 41, 43, -1, 45, 37, 38,
213 -1, -1, 41, 42, 43, -1, 45, -1, 47, 5,
214 6, -1, -1, -1, -1, 11, -1, -1, -1, -1,
215 16, 17, 18, 19, 20, 21, 22, 37, 38, -1,
216 -1, -1, 42, 43, 124, 45, 37, 47, -1, -1,
217 -1, 42, 43, -1, 45, -1, 47, -1, -1, -1,
218 -1, -1, -1, -1, 124, -1, -1, 124, -1, -1,
219 -1, -1, -1, -1, -1, 124, -1, -1, 124, -1,
220 -1, -1, -1, -1, -1, -1, 124, 124, -1, -1,
221 -1, -1, -1, -1, -1, 124, -1, -1, -1, -1,
222 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
223 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
224 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
225 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
226 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
227 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
228 -1, -1, -1, -1, -1, 256, 257, 258, 257, 258,
234 #define YYMAXTOKEN 259
236 static const char *yyname[] = {
238 "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,
239 0,0,0,0,0,0,"'%'","'&'",0,"'('","')'","'*'","'+'",0,"'-'",0,"'/'",0,0,0,0,0,0,0,
240 0,0,0,0,0,0,"'='",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
241 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"'|'",0,0,0,0,0,0,
242 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
243 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
244 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
245 0,0,0,0,0,0,"DIGIT","LETTER","UMINUS",
247 static const char *yyrule[] = {
250 "list : list stat '\\n'",
251 "list : list error '\\n'",
253 "stat : LETTER '=' expr",
254 "expr : '(' expr ')'",
255 "expr : expr '+' expr",
256 "expr : expr '-' expr",
257 "expr : expr '*' expr",
258 "expr : expr '/' expr",
259 "expr : expr '%' expr",
260 "expr : expr '&' expr",
261 "expr : expr '|' expr",
266 "number : number DIGIT",
279 /* define the initial stack-sizes */
282 #define YYMAXDEPTH YYSTACKSIZE
285 #define YYSTACKSIZE YYMAXDEPTH
287 #define YYSTACKSIZE 500
288 #define YYMAXDEPTH 500
292 #define YYINITSTACKSIZE 500
302 /* variables for the parser stack */
303 static YYSTACKDATA yystack;
305 /* start of programs */
310 while(!feof(stdin)) {
317 yyerror(const char *s)
319 fprintf(stderr, "%s\n", s);
325 /* lexical analysis routine */
326 /* returns LETTER for a lower case letter, yylval = 0 through 25 */
327 /* return DIGIT for a digit, yylval = 0 through 9 */
328 /* all other characters are returned immediately */
332 while( (c=getchar()) == ' ' ) { /* skip blanks */ }
334 /* c is now nonblank */
346 #line 347 "calc.tab.c"
349 #include <stdio.h> /* needed for printf */
352 #include <stdlib.h> /* needed for malloc, etc */
353 #include <string.h> /* needed for memset */
355 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
356 static int yygrowstack(YYSTACKDATA *data)
363 if ((newsize = data->stacksize) == 0)
364 newsize = YYINITSTACKSIZE;
365 else if (newsize >= YYMAXDEPTH)
367 else if ((newsize *= 2) > YYMAXDEPTH)
368 newsize = YYMAXDEPTH;
370 i = (int) (data->s_mark - data->s_base);
371 newss = (short *)realloc(data->s_base, newsize * sizeof(*newss));
375 data->s_base = newss;
376 data->s_mark = newss + i;
378 newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));
382 data->l_base = newvs;
383 data->l_mark = newvs + i;
385 data->stacksize = newsize;
386 data->s_last = data->s_base + newsize - 1;
390 #if YYPURE || defined(YY_NO_LEAKS)
391 static void yyfreestack(YYSTACKDATA *data)
395 memset(data, 0, sizeof(*data));
398 #define yyfreestack(data) /* nothing */
401 #define YYABORT goto yyabort
402 #define YYREJECT goto yyabort
403 #define YYACCEPT goto yyaccept
404 #define YYERROR goto yyerrlab
409 int yym, yyn, yystate;
413 if ((yys = getenv("YYDEBUG")) != 0)
416 if (yyn >= '0' && yyn <= '9')
427 memset(&yystack, 0, sizeof(yystack));
430 if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow;
431 yystack.s_mark = yystack.s_base;
432 yystack.l_mark = yystack.l_base;
437 if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
440 if ((yychar = YYLEX) < 0) yychar = 0;
445 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
446 if (!yys) yys = "illegal-symbol";
447 printf("%sdebug: state %d, reading %d (%s)\n",
448 YYPREFIX, yystate, yychar, yys);
452 if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
453 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
457 printf("%sdebug: state %d, shifting to state %d\n",
458 YYPREFIX, yystate, yytable[yyn]);
460 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
464 yystate = yytable[yyn];
465 *++yystack.s_mark = yytable[yyn];
466 *++yystack.l_mark = yylval;
468 if (yyerrflag > 0) --yyerrflag;
471 if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
472 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
477 if (yyerrflag) goto yyinrecovery;
479 yyerror("syntax error");
492 if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 &&
493 yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
497 printf("%sdebug: state %d, error recovery shifting\
498 to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]);
500 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
504 yystate = yytable[yyn];
505 *++yystack.s_mark = yytable[yyn];
506 *++yystack.l_mark = yylval;
513 printf("%sdebug: error recovery discarding state %d\n",
514 YYPREFIX, *yystack.s_mark);
516 if (yystack.s_mark <= yystack.s_base) goto yyabort;
524 if (yychar == 0) goto yyabort;
529 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
530 if (!yys) yys = "illegal-symbol";
531 printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
532 YYPREFIX, yystate, yychar, yys);
542 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
543 YYPREFIX, yystate, yyn, yyrule[yyn]);
547 yyval = yystack.l_mark[1-yym];
549 memset(&yyval, 0, sizeof yyval);
558 { printf("%d\n",yystack.l_mark[0]);}
562 { regs[yystack.l_mark[-2]] = yystack.l_mark[0]; }
566 { yyval = yystack.l_mark[-1]; }
570 { yyval = yystack.l_mark[-2] + yystack.l_mark[0]; }
574 { yyval = yystack.l_mark[-2] - yystack.l_mark[0]; }
578 { yyval = yystack.l_mark[-2] * yystack.l_mark[0]; }
582 { yyval = yystack.l_mark[-2] / yystack.l_mark[0]; }
586 { yyval = yystack.l_mark[-2] % yystack.l_mark[0]; }
590 { yyval = yystack.l_mark[-2] & yystack.l_mark[0]; }
594 { yyval = yystack.l_mark[-2] | yystack.l_mark[0]; }
598 { yyval = - yystack.l_mark[0]; }
602 { yyval = regs[yystack.l_mark[0]]; }
606 { yyval = yystack.l_mark[0]; base = (yystack.l_mark[0]==0) ? 8 : 10; }
610 { yyval = base * yystack.l_mark[-1] + yystack.l_mark[0]; }
612 #line 613 "calc.tab.c"
614 yystack.s_mark -= yym;
615 yystate = *yystack.s_mark;
616 yystack.l_mark -= yym;
618 if (yystate == 0 && yym == 0)
622 printf("%sdebug: after reduction, shifting from state 0 to\
623 state %d\n", YYPREFIX, YYFINAL);
626 *++yystack.s_mark = YYFINAL;
627 *++yystack.l_mark = yyval;
630 if ((yychar = YYLEX) < 0) yychar = 0;
635 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
636 if (!yys) yys = "illegal-symbol";
637 printf("%sdebug: state %d, reading %d (%s)\n",
638 YYPREFIX, YYFINAL, yychar, yys);
642 if (yychar == 0) goto yyaccept;
645 if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
646 yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
647 yystate = yytable[yyn];
649 yystate = yydgoto[yym];
652 printf("%sdebug: after reduction, shifting from state %d \
653 to state %d\n", YYPREFIX, *yystack.s_mark, yystate);
655 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
659 *++yystack.s_mark = (short) yystate;
660 *++yystack.l_mark = yyval;
664 yyerror("yacc stack overflow");
667 yyfreestack(&yystack);
671 yyfreestack(&yystack);