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 calc2_parse
20 #define yylex calc2_lex
24 #define yyerror calc2_error
28 #define yychar calc2_char
32 #define yyval calc2_val
36 #define yylval calc2_lval
40 #define yydebug calc2_debug
44 #define yynerrs calc2_nerrs
48 #define yyerrflag calc2_errflag
49 #endif /* yyerrflag */
52 #define yylhs calc2_lhs
56 #define yylen calc2_len
60 #define yydefred calc2_defred
64 #define yydgoto calc2_dgoto
68 #define yysindex calc2_sindex
72 #define yyrindex calc2_rindex
76 #define yygindex calc2_gindex
80 #define yytable calc2_table
84 #define yycheck calc2_check
88 #define yyname calc2_name
92 #define yyrule calc2_rule
94 #define YYPREFIX "calc2_"
103 #define YYLEX_PARAM base
104 #define YYLEX_DECL() yylex(int *YYLEX_PARAM)
105 #define YYERROR_DECL() yyerror(int regs[26], int *base, const char *s)
107 static void YYERROR_DECL();
110 #line 111 "calc2.tab.c"
116 /* compatibility with bison */
118 /* compatibility with FreeBSD */
119 # ifdef YYPARSE_PARAM_TYPE
120 # define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
122 # define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
125 # define YYPARSE_DECL() yyparse(int regs[26], int * base)
128 /* Parameters sent to lex. */
130 # define YYLEX_DECL() yylex(void *YYLEX_PARAM)
131 # define YYLEX yylex(YYLEX_PARAM)
133 # define YYLEX_DECL() yylex(int * base)
134 # define YYLEX yylex(base)
137 /* Parameters sent to yyerror. */
139 #define YYERROR_DECL() yyerror(int regs[26], int * base, const char *s)
142 #define YYERROR_CALL(msg) yyerror(regs, base, msg)
145 extern int YYPARSE_DECL();
150 #define YYERRCODE 256
151 static const short calc2_lhs[] = { -1,
152 0, 0, 0, 1, 1, 2, 2, 2, 2, 2,
153 2, 2, 2, 2, 2, 2, 3, 3,
155 static const short calc2_len[] = { 2,
156 0, 3, 3, 1, 3, 3, 3, 3, 3, 3,
157 3, 3, 3, 2, 1, 1, 1, 2,
159 static const short calc2_defred[] = { 1,
160 0, 0, 17, 0, 0, 0, 0, 0, 0, 3,
161 0, 15, 14, 0, 2, 0, 0, 0, 0, 0,
162 0, 0, 18, 0, 6, 0, 0, 0, 0, 9,
165 static const short calc2_dgoto[] = { 1,
168 static const short calc2_sindex[] = { 0,
169 -40, -7, 0, -55, -38, -38, 1, -29, -247, 0,
170 -38, 0, 0, 22, 0, -38, -38, -38, -38, -38,
171 -38, -38, 0, -29, 0, 51, 60, -20, -20, 0,
174 static const short calc2_rindex[] = { 0,
175 0, 0, 0, 2, 0, 0, 0, 9, -9, 0,
176 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
177 0, 0, 0, 10, 0, -6, 14, 5, 13, 0,
180 static const short calc2_gindex[] = { 0,
183 #define YYTABLESIZE 220
184 static const short calc2_table[] = { 6,
185 16, 6, 10, 13, 5, 11, 5, 22, 17, 23,
186 15, 15, 20, 18, 7, 19, 22, 21, 4, 5,
187 0, 20, 8, 12, 0, 0, 21, 16, 16, 0,
188 0, 16, 16, 16, 13, 16, 0, 16, 15, 15,
189 0, 0, 7, 15, 15, 7, 15, 7, 15, 7,
190 8, 12, 0, 8, 12, 8, 0, 8, 22, 17,
191 0, 0, 25, 20, 18, 0, 19, 0, 21, 13,
192 14, 0, 0, 0, 0, 24, 0, 0, 0, 0,
193 26, 27, 28, 29, 30, 31, 32, 22, 17, 0,
194 0, 0, 20, 18, 16, 19, 22, 21, 0, 0,
195 0, 20, 18, 0, 19, 0, 21, 0, 0, 0,
196 0, 0, 0, 0, 16, 0, 0, 13, 0, 0,
197 0, 0, 0, 0, 0, 15, 0, 0, 7, 0,
198 0, 0, 0, 0, 0, 0, 8, 12, 0, 0,
199 0, 0, 0, 0, 0, 16, 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, 0, 0, 0, 0, 0,
205 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
206 0, 0, 0, 0, 0, 2, 3, 4, 3, 12,
208 static const short calc2_check[] = { 40,
209 10, 40, 10, 10, 45, 61, 45, 37, 38, 257,
210 10, 10, 42, 43, 10, 45, 37, 47, 10, 10,
211 -1, 42, 10, 10, -1, -1, 47, 37, 38, -1,
212 -1, 41, 42, 43, 41, 45, -1, 47, 37, 38,
213 -1, -1, 38, 42, 43, 41, 45, 43, 47, 45,
214 38, 38, -1, 41, 41, 43, -1, 45, 37, 38,
215 -1, -1, 41, 42, 43, -1, 45, -1, 47, 5,
216 6, -1, -1, -1, -1, 11, -1, -1, -1, -1,
217 16, 17, 18, 19, 20, 21, 22, 37, 38, -1,
218 -1, -1, 42, 43, 124, 45, 37, 47, -1, -1,
219 -1, 42, 43, -1, 45, -1, 47, -1, -1, -1,
220 -1, -1, -1, -1, 124, -1, -1, 124, -1, -1,
221 -1, -1, -1, -1, -1, 124, -1, -1, 124, -1,
222 -1, -1, -1, -1, -1, -1, 124, 124, -1, -1,
223 -1, -1, -1, -1, -1, 124, -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, -1, -1, -1, -1, -1,
229 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
230 -1, -1, -1, -1, -1, 256, 257, 258, 257, 258,
236 #define YYMAXTOKEN 259
238 static const char *yyname[] = {
240 "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,
241 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,
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,
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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
246 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
247 0,0,0,0,0,0,"DIGIT","LETTER","UMINUS",
249 static const char *yyrule[] = {
252 "list : list stat '\\n'",
253 "list : list error '\\n'",
255 "stat : LETTER '=' expr",
256 "expr : '(' expr ')'",
257 "expr : expr '+' expr",
258 "expr : expr '-' expr",
259 "expr : expr '*' expr",
260 "expr : expr '/' expr",
261 "expr : expr '%' expr",
262 "expr : expr '&' expr",
263 "expr : expr '|' expr",
268 "number : number DIGIT",
281 /* define the initial stack-sizes */
284 #define YYMAXDEPTH YYSTACKSIZE
287 #define YYSTACKSIZE YYMAXDEPTH
289 #define YYSTACKSIZE 500
290 #define YYMAXDEPTH 500
294 #define YYINITSTACKSIZE 500
304 /* variables for the parser stack */
305 static YYSTACKDATA yystack;
307 /* start of programs */
310 extern int YYLEX_DECL();
319 while(!feof(stdin)) {
320 yyparse(regs, &base);
328 fprintf(stderr, "%s\n", s);
334 /* lexical analysis routine */
335 /* returns LETTER for a lower case letter, yylval = 0 through 25 */
336 /* return DIGIT for a digit, yylval = 0 through 9 */
337 /* all other characters are returned immediately */
341 while( (c=getchar()) == ' ' ) { /* skip blanks */ }
343 /* c is now nonblank */
350 yylval = (c - '0') % (*base);
355 #line 356 "calc2.tab.c"
358 #include <stdio.h> /* needed for printf */
361 #include <stdlib.h> /* needed for malloc, etc */
362 #include <string.h> /* needed for memset */
364 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
365 static int yygrowstack(YYSTACKDATA *data)
372 if ((newsize = data->stacksize) == 0)
373 newsize = YYINITSTACKSIZE;
374 else if (newsize >= YYMAXDEPTH)
376 else if ((newsize *= 2) > YYMAXDEPTH)
377 newsize = YYMAXDEPTH;
379 i = (int) (data->s_mark - data->s_base);
380 newss = (short *)realloc(data->s_base, newsize * sizeof(*newss));
384 data->s_base = newss;
385 data->s_mark = newss + i;
387 newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));
391 data->l_base = newvs;
392 data->l_mark = newvs + i;
394 data->stacksize = newsize;
395 data->s_last = data->s_base + newsize - 1;
399 #if YYPURE || defined(YY_NO_LEAKS)
400 static void yyfreestack(YYSTACKDATA *data)
404 memset(data, 0, sizeof(*data));
407 #define yyfreestack(data) /* nothing */
410 #define YYABORT goto yyabort
411 #define YYREJECT goto yyabort
412 #define YYACCEPT goto yyaccept
413 #define YYERROR goto yyerrlab
418 int yym, yyn, yystate;
422 if ((yys = getenv("YYDEBUG")) != 0)
425 if (yyn >= '0' && yyn <= '9')
436 memset(&yystack, 0, sizeof(yystack));
439 if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow;
440 yystack.s_mark = yystack.s_base;
441 yystack.l_mark = yystack.l_base;
446 if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
449 if ((yychar = YYLEX) < 0) yychar = 0;
454 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
455 if (!yys) yys = "illegal-symbol";
456 printf("%sdebug: state %d, reading %d (%s)\n",
457 YYPREFIX, yystate, yychar, yys);
461 if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
462 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
466 printf("%sdebug: state %d, shifting to state %d\n",
467 YYPREFIX, yystate, yytable[yyn]);
469 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
473 yystate = yytable[yyn];
474 *++yystack.s_mark = yytable[yyn];
475 *++yystack.l_mark = yylval;
477 if (yyerrflag > 0) --yyerrflag;
480 if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
481 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
486 if (yyerrflag) goto yyinrecovery;
488 yyerror(regs, base, "syntax error");
501 if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 &&
502 yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
506 printf("%sdebug: state %d, error recovery shifting\
507 to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]);
509 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
513 yystate = yytable[yyn];
514 *++yystack.s_mark = yytable[yyn];
515 *++yystack.l_mark = yylval;
522 printf("%sdebug: error recovery discarding state %d\n",
523 YYPREFIX, *yystack.s_mark);
525 if (yystack.s_mark <= yystack.s_base) goto yyabort;
533 if (yychar == 0) goto yyabort;
538 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
539 if (!yys) yys = "illegal-symbol";
540 printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
541 YYPREFIX, yystate, yychar, yys);
551 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
552 YYPREFIX, yystate, yyn, yyrule[yyn]);
556 yyval = yystack.l_mark[1-yym];
558 memset(&yyval, 0, sizeof yyval);
567 { printf("%d\n",yystack.l_mark[0]);}
571 { regs[yystack.l_mark[-2]] = yystack.l_mark[0]; }
575 { yyval = yystack.l_mark[-1]; }
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[-2] % yystack.l_mark[0]; }
599 { yyval = yystack.l_mark[-2] & yystack.l_mark[0]; }
603 { yyval = yystack.l_mark[-2] | yystack.l_mark[0]; }
607 { yyval = - yystack.l_mark[0]; }
611 { yyval = regs[yystack.l_mark[0]]; }
615 { yyval = yystack.l_mark[0]; (*base) = (yystack.l_mark[0]==0) ? 8 : 10; }
619 { yyval = (*base) * yystack.l_mark[-1] + yystack.l_mark[0]; }
621 #line 622 "calc2.tab.c"
623 yystack.s_mark -= yym;
624 yystate = *yystack.s_mark;
625 yystack.l_mark -= yym;
627 if (yystate == 0 && yym == 0)
631 printf("%sdebug: after reduction, shifting from state 0 to\
632 state %d\n", YYPREFIX, YYFINAL);
635 *++yystack.s_mark = YYFINAL;
636 *++yystack.l_mark = yyval;
639 if ((yychar = YYLEX) < 0) yychar = 0;
644 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
645 if (!yys) yys = "illegal-symbol";
646 printf("%sdebug: state %d, reading %d (%s)\n",
647 YYPREFIX, YYFINAL, yychar, yys);
651 if (yychar == 0) goto yyaccept;
654 if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
655 yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
656 yystate = yytable[yyn];
658 yystate = yydgoto[yym];
661 printf("%sdebug: after reduction, shifting from state %d \
662 to state %d\n", YYPREFIX, *yystack.s_mark, yystate);
664 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
668 *++yystack.s_mark = (short) yystate;
669 *++yystack.l_mark = yyval;
673 yyerror(regs, base, "yacc stack overflow");
676 yyfreestack(&yystack);
680 yyfreestack(&yystack);