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 calc3_parse
20 #define yylex calc3_lex
24 #define yyerror calc3_error
28 #define yychar calc3_char
32 #define yyval calc3_val
36 #define yylval calc3_lval
40 #define yydebug calc3_debug
44 #define yynerrs calc3_nerrs
48 #define yyerrflag calc3_errflag
49 #endif /* yyerrflag */
52 #define yylhs calc3_lhs
56 #define yylen calc3_len
60 #define yydefred calc3_defred
64 #define yydgoto calc3_dgoto
68 #define yysindex calc3_sindex
72 #define yyrindex calc3_rindex
76 #define yygindex calc3_gindex
80 #define yytable calc3_table
84 #define yycheck calc3_check
88 #define yyname calc3_name
92 #define yyrule calc3_rule
94 #define YYPREFIX "calc3_"
102 #line 103 "calc3.tab.c"
108 /* compatibility with bison */
110 /* compatibility with FreeBSD */
111 # ifdef YYPARSE_PARAM_TYPE
112 # define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
114 # define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
117 # define YYPARSE_DECL() yyparse(int regs[26], int * base)
120 /* Parameters sent to lex. */
122 # define YYLEX_DECL() yylex(YYSTYPE *yylval, void *YYLEX_PARAM)
123 # define YYLEX yylex(&yylval, YYLEX_PARAM)
125 # define YYLEX_DECL() yylex(YYSTYPE *yylval, int * base)
126 # define YYLEX yylex(&yylval, base)
129 /* Parameters sent to yyerror. */
130 #define YYERROR_DECL() yyerror(YYSTYPE *v, const char *s)
131 #define YYERROR_CALL(msg) yyerror(regs, base, msg)
133 extern int YYPARSE_DECL();
134 extern int YYLEX_DECL();
139 #define YYERRCODE 256
140 static const short calc3_lhs[] = { -1,
141 0, 0, 0, 1, 1, 2, 2, 2, 2, 2,
142 2, 2, 2, 2, 2, 2, 3, 3,
144 static const short calc3_len[] = { 2,
145 0, 3, 3, 1, 3, 3, 3, 3, 3, 3,
146 3, 3, 3, 2, 1, 1, 1, 2,
148 static const short calc3_defred[] = { 1,
149 0, 0, 17, 0, 0, 0, 0, 0, 0, 3,
150 0, 15, 14, 0, 2, 0, 0, 0, 0, 0,
151 0, 0, 18, 0, 6, 0, 0, 0, 0, 9,
154 static const short calc3_dgoto[] = { 1,
157 static const short calc3_sindex[] = { 0,
158 -40, -7, 0, -55, -38, -38, 1, -29, -247, 0,
159 -38, 0, 0, 22, 0, -38, -38, -38, -38, -38,
160 -38, -38, 0, -29, 0, 51, 60, -20, -20, 0,
163 static const short calc3_rindex[] = { 0,
164 0, 0, 0, 2, 0, 0, 0, 9, -9, 0,
165 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
166 0, 0, 0, 10, 0, -6, 14, 5, 13, 0,
169 static const short calc3_gindex[] = { 0,
172 #define YYTABLESIZE 220
173 static const short calc3_table[] = { 6,
174 16, 6, 10, 13, 5, 11, 5, 22, 17, 23,
175 15, 15, 20, 18, 7, 19, 22, 21, 4, 5,
176 0, 20, 8, 12, 0, 0, 21, 16, 16, 0,
177 0, 16, 16, 16, 13, 16, 0, 16, 15, 15,
178 0, 0, 7, 15, 15, 7, 15, 7, 15, 7,
179 8, 12, 0, 8, 12, 8, 0, 8, 22, 17,
180 0, 0, 25, 20, 18, 0, 19, 0, 21, 13,
181 14, 0, 0, 0, 0, 24, 0, 0, 0, 0,
182 26, 27, 28, 29, 30, 31, 32, 22, 17, 0,
183 0, 0, 20, 18, 16, 19, 22, 21, 0, 0,
184 0, 20, 18, 0, 19, 0, 21, 0, 0, 0,
185 0, 0, 0, 0, 16, 0, 0, 13, 0, 0,
186 0, 0, 0, 0, 0, 15, 0, 0, 7, 0,
187 0, 0, 0, 0, 0, 0, 8, 12, 0, 0,
188 0, 0, 0, 0, 0, 16, 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, 0, 0, 0, 0, 0,
195 0, 0, 0, 0, 0, 2, 3, 4, 3, 12,
197 static const short calc3_check[] = { 40,
198 10, 40, 10, 10, 45, 61, 45, 37, 38, 257,
199 10, 10, 42, 43, 10, 45, 37, 47, 10, 10,
200 -1, 42, 10, 10, -1, -1, 47, 37, 38, -1,
201 -1, 41, 42, 43, 41, 45, -1, 47, 37, 38,
202 -1, -1, 38, 42, 43, 41, 45, 43, 47, 45,
203 38, 38, -1, 41, 41, 43, -1, 45, 37, 38,
204 -1, -1, 41, 42, 43, -1, 45, -1, 47, 5,
205 6, -1, -1, -1, -1, 11, -1, -1, -1, -1,
206 16, 17, 18, 19, 20, 21, 22, 37, 38, -1,
207 -1, -1, 42, 43, 124, 45, 37, 47, -1, -1,
208 -1, 42, 43, -1, 45, -1, 47, -1, -1, -1,
209 -1, -1, -1, -1, 124, -1, -1, 124, -1, -1,
210 -1, -1, -1, -1, -1, 124, -1, -1, 124, -1,
211 -1, -1, -1, -1, -1, -1, 124, 124, -1, -1,
212 -1, -1, -1, -1, -1, 124, -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, -1, -1, -1, -1, -1,
219 -1, -1, -1, -1, -1, 256, 257, 258, 257, 258,
225 #define YYMAXTOKEN 259
227 static const char *yyname[] = {
229 "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,
230 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,
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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
236 0,0,0,0,0,0,"DIGIT","LETTER","UMINUS",
238 static const char *yyrule[] = {
241 "list : list stat '\\n'",
242 "list : list error '\\n'",
244 "stat : LETTER '=' expr",
245 "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",
252 "expr : expr '|' expr",
257 "number : number DIGIT",
261 /* define the initial stack-sizes */
264 #define YYMAXDEPTH YYSTACKSIZE
267 #define YYSTACKSIZE YYMAXDEPTH
269 #define YYSTACKSIZE 500
270 #define YYMAXDEPTH 500
274 #define YYINITSTACKSIZE 500
288 /* start of programs */
296 while(!feof(stdin)) {
297 yyparse(regs, &base);
305 fprintf(stderr, "%s\n", s);
311 /* lexical analysis routine */
312 /* returns LETTER for a lower case letter, yylval = 0 through 25 */
313 /* return DIGIT for a digit, yylval = 0 through 9 */
314 /* all other characters are returned immediately */
318 while( (c=getchar()) == ' ' ) { /* skip blanks */ }
320 /* c is now nonblank */
327 *yylval = (c - '0') % (*base);
332 #line 333 "calc3.tab.c"
335 #include <stdio.h> /* needed for printf */
338 #include <stdlib.h> /* needed for malloc, etc */
339 #include <string.h> /* needed for memset */
341 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
342 static int yygrowstack(YYSTACKDATA *data)
349 if ((newsize = data->stacksize) == 0)
350 newsize = YYINITSTACKSIZE;
351 else if (newsize >= YYMAXDEPTH)
353 else if ((newsize *= 2) > YYMAXDEPTH)
354 newsize = YYMAXDEPTH;
356 i = data->s_mark - data->s_base;
357 newss = (data->s_base != 0)
358 ? (short *)realloc(data->s_base, newsize * sizeof(*newss))
359 : (short *)malloc(newsize * sizeof(*newss));
363 data->s_base = newss;
364 data->s_mark = newss + i;
366 newvs = (data->l_base != 0)
367 ? (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs))
368 : (YYSTYPE *)malloc(newsize * sizeof(*newvs));
372 data->l_base = newvs;
373 data->l_mark = newvs + i;
375 data->stacksize = newsize;
376 data->s_last = data->s_base + newsize - 1;
380 #if YYPURE || defined(YY_NO_LEAKS)
381 static void yyfreestack(YYSTACKDATA *data)
385 memset(data, 0, sizeof(*data));
388 #define yyfreestack(data) /* nothing */
391 #define YYABORT goto yyabort
392 #define YYREJECT goto yyabort
393 #define YYACCEPT goto yyaccept
394 #define YYERROR goto yyerrlab
404 /* variables for the parser stack */
406 int yym, yyn, yystate;
410 if ((yys = getenv("YYDEBUG")) != 0)
413 if (yyn >= '0' && yyn <= '9')
424 memset(&yystack, 0, sizeof(yystack));
427 if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow;
428 yystack.s_mark = yystack.s_base;
429 yystack.l_mark = yystack.l_base;
434 if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
437 if ((yychar = YYLEX) < 0) yychar = 0;
442 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
443 if (!yys) yys = "illegal-symbol";
444 printf("%sdebug: state %d, reading %d (%s)\n",
445 YYPREFIX, yystate, yychar, yys);
449 if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
450 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
454 printf("%sdebug: state %d, shifting to state %d\n",
455 YYPREFIX, yystate, yytable[yyn]);
457 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
461 yystate = yytable[yyn];
462 *++yystack.s_mark = yytable[yyn];
463 *++yystack.l_mark = yylval;
465 if (yyerrflag > 0) --yyerrflag;
468 if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
469 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
474 if (yyerrflag) goto yyinrecovery;
476 yyerror(regs, base, "syntax error");
489 if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 &&
490 yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
494 printf("%sdebug: state %d, error recovery shifting\
495 to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]);
497 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
501 yystate = yytable[yyn];
502 *++yystack.s_mark = yytable[yyn];
503 *++yystack.l_mark = yylval;
510 printf("%sdebug: error recovery discarding state %d\n",
511 YYPREFIX, *yystack.s_mark);
513 if (yystack.s_mark <= yystack.s_base) goto yyabort;
521 if (yychar == 0) goto yyabort;
526 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
527 if (!yys) yys = "illegal-symbol";
528 printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
529 YYPREFIX, yystate, yychar, yys);
539 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
540 YYPREFIX, yystate, yyn, yyrule[yyn]);
544 yyval = yystack.l_mark[1-yym];
546 memset(&yyval, 0, sizeof yyval);
555 { printf("%d\n",yystack.l_mark[0]);}
559 { regs[yystack.l_mark[-2]] = yystack.l_mark[0]; }
563 { yyval = yystack.l_mark[-1]; }
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[-2] | yystack.l_mark[0]; }
595 { yyval = - yystack.l_mark[0]; }
599 { yyval = regs[yystack.l_mark[0]]; }
603 { yyval = yystack.l_mark[0]; (*base) = (yystack.l_mark[0]==0) ? 8 : 10; }
607 { yyval = (*base) * yystack.l_mark[-1] + yystack.l_mark[0]; }
609 #line 610 "calc3.tab.c"
611 yystack.s_mark -= yym;
612 yystate = *yystack.s_mark;
613 yystack.l_mark -= yym;
615 if (yystate == 0 && yym == 0)
619 printf("%sdebug: after reduction, shifting from state 0 to\
620 state %d\n", YYPREFIX, YYFINAL);
623 *++yystack.s_mark = YYFINAL;
624 *++yystack.l_mark = yyval;
627 if ((yychar = YYLEX) < 0) yychar = 0;
632 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
633 if (!yys) yys = "illegal-symbol";
634 printf("%sdebug: state %d, reading %d (%s)\n",
635 YYPREFIX, YYFINAL, yychar, yys);
639 if (yychar == 0) goto yyaccept;
642 if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
643 yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
644 yystate = yytable[yyn];
646 yystate = yydgoto[yym];
649 printf("%sdebug: after reduction, shifting from state %d \
650 to state %d\n", YYPREFIX, *yystack.s_mark, yystate);
652 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
656 *++yystack.s_mark = (short) yystate;
657 *++yystack.l_mark = yyval;
661 yyerror(regs, base, "yacc stack overflow");
664 yyfreestack(&yystack);
668 yyfreestack(&yystack);