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)
27 static void yyerror(const char *s);
30 #line 30 "/dev/stdout"
36 /* compatibility with bison */
38 /* compatibility with FreeBSD */
39 # ifdef YYPARSE_PARAM_TYPE
40 # define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
42 # define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
45 # define YYPARSE_DECL() yyparse(void)
48 /* Parameters sent to lex. */
50 # define YYLEX_DECL() yylex(void *YYLEX_PARAM)
51 # define YYLEX yylex(YYLEX_PARAM)
53 # define YYLEX_DECL() yylex(void)
54 # define YYLEX yylex()
57 /* Parameters sent to yyerror. */
59 #define YYERROR_DECL() yyerror(const char *s)
62 #define YYERROR_CALL(msg) yyerror(msg)
65 extern int YYPARSE_DECL();
71 static const short yylhs[] = { -1,
72 0, 0, 0, 1, 1, 2, 2, 2, 2, 2,
73 2, 2, 2, 2, 2, 2, 3, 3,
75 static const short yylen[] = { 2,
76 0, 3, 3, 1, 3, 3, 3, 3, 3, 3,
77 3, 3, 3, 2, 1, 1, 1, 2,
79 static const short yydefred[] = { 1,
80 0, 0, 17, 0, 0, 0, 0, 0, 0, 3,
81 0, 15, 14, 0, 2, 0, 0, 0, 0, 0,
82 0, 0, 18, 0, 6, 0, 0, 0, 0, 9,
85 static const short yydgoto[] = { 1,
88 static const short yysindex[] = { 0,
89 -40, -7, 0, -55, -38, -38, 1, -29, -247, 0,
90 -38, 0, 0, 22, 0, -38, -38, -38, -38, -38,
91 -38, -38, 0, -29, 0, 51, 60, -20, -20, 0,
94 static const short yyrindex[] = { 0,
95 0, 0, 0, 2, 0, 0, 0, 9, -9, 0,
96 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
97 0, 0, 0, 10, 0, -6, 14, 5, 13, 0,
100 static const short yygindex[] = { 0,
103 #define YYTABLESIZE 220
104 static const short yytable[] = { 6,
105 16, 6, 10, 13, 5, 11, 5, 22, 17, 23,
106 15, 15, 20, 18, 7, 19, 22, 21, 4, 5,
107 0, 20, 8, 12, 0, 0, 21, 16, 16, 0,
108 0, 16, 16, 16, 13, 16, 0, 16, 15, 15,
109 0, 0, 7, 15, 15, 7, 15, 7, 15, 7,
110 8, 12, 0, 8, 12, 8, 0, 8, 22, 17,
111 0, 0, 25, 20, 18, 0, 19, 0, 21, 13,
112 14, 0, 0, 0, 0, 24, 0, 0, 0, 0,
113 26, 27, 28, 29, 30, 31, 32, 22, 17, 0,
114 0, 0, 20, 18, 16, 19, 22, 21, 0, 0,
115 0, 20, 18, 0, 19, 0, 21, 0, 0, 0,
116 0, 0, 0, 0, 16, 0, 0, 13, 0, 0,
117 0, 0, 0, 0, 0, 15, 0, 0, 7, 0,
118 0, 0, 0, 0, 0, 0, 8, 12, 0, 0,
119 0, 0, 0, 0, 0, 16, 0, 0, 0, 0,
120 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
121 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
122 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
123 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
124 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
125 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
126 0, 0, 0, 0, 0, 2, 3, 4, 3, 12,
128 static const short yycheck[] = { 40,
129 10, 40, 10, 10, 45, 61, 45, 37, 38, 257,
130 10, 10, 42, 43, 10, 45, 37, 47, 10, 10,
131 -1, 42, 10, 10, -1, -1, 47, 37, 38, -1,
132 -1, 41, 42, 43, 41, 45, -1, 47, 37, 38,
133 -1, -1, 38, 42, 43, 41, 45, 43, 47, 45,
134 38, 38, -1, 41, 41, 43, -1, 45, 37, 38,
135 -1, -1, 41, 42, 43, -1, 45, -1, 47, 5,
136 6, -1, -1, -1, -1, 11, -1, -1, -1, -1,
137 16, 17, 18, 19, 20, 21, 22, 37, 38, -1,
138 -1, -1, 42, 43, 124, 45, 37, 47, -1, -1,
139 -1, 42, 43, -1, 45, -1, 47, -1, -1, -1,
140 -1, -1, -1, -1, 124, -1, -1, 124, -1, -1,
141 -1, -1, -1, -1, -1, 124, -1, -1, 124, -1,
142 -1, -1, -1, -1, -1, -1, 124, 124, -1, -1,
143 -1, -1, -1, -1, -1, 124, -1, -1, -1, -1,
144 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
145 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
146 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
147 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
148 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
149 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
150 -1, -1, -1, -1, -1, 256, 257, 258, 257, 258,
156 #define YYMAXTOKEN 259
158 static const char *yyname[] = {
160 "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,
161 0,0,0,0,0,0,"'%'","'&'",0,"'('","')'","'*'","'+'",0,"'-'",0,"'/'",0,0,0,0,0,0,0,
162 0,0,0,0,0,0,"'='",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
163 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"'|'",0,0,0,0,0,0,
164 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
165 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
166 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
167 0,0,0,0,0,0,"DIGIT","LETTER","UMINUS",
169 static const char *yyrule[] = {
172 "list : list stat '\\n'",
173 "list : list error '\\n'",
175 "stat : LETTER '=' expr",
176 "expr : '(' expr ')'",
177 "expr : expr '+' expr",
178 "expr : expr '-' expr",
179 "expr : expr '*' expr",
180 "expr : expr '/' expr",
181 "expr : expr '%' expr",
182 "expr : expr '&' expr",
183 "expr : expr '|' expr",
188 "number : number DIGIT",
201 /* define the initial stack-sizes */
204 #define YYMAXDEPTH YYSTACKSIZE
207 #define YYSTACKSIZE YYMAXDEPTH
209 #define YYSTACKSIZE 500
210 #define YYMAXDEPTH 500
214 #define YYINITSTACKSIZE 500
224 /* variables for the parser stack */
225 static YYSTACKDATA yystack;
226 #line 68 "code_calc.y"
227 /* start of programs */
230 extern int YYLEX_DECL();
236 while(!feof(stdin)) {
243 yyerror(const char *s)
245 fprintf(stderr, "%s\n", s);
251 /* lexical analysis routine */
252 /* returns LETTER for a lower case letter, yylval = 0 through 25 */
253 /* return DIGIT for a digit, yylval = 0 through 9 */
254 /* all other characters are returned immediately */
258 while( (c=getchar()) == ' ' ) { /* skip blanks */ }
260 /* c is now nonblank */
272 #line 272 "/dev/stdout"
275 #include <stdio.h> /* needed for printf */
278 #include <stdlib.h> /* needed for malloc, etc */
279 #include <string.h> /* needed for memset */
281 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
282 static int yygrowstack(YYSTACKDATA *data)
289 if ((newsize = data->stacksize) == 0)
290 newsize = YYINITSTACKSIZE;
291 else if (newsize >= YYMAXDEPTH)
293 else if ((newsize *= 2) > YYMAXDEPTH)
294 newsize = YYMAXDEPTH;
296 i = data->s_mark - data->s_base;
297 newss = (short *)realloc(data->s_base, newsize * sizeof(*newss));
301 data->s_base = newss;
302 data->s_mark = newss + i;
304 newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));
308 data->l_base = newvs;
309 data->l_mark = newvs + i;
311 data->stacksize = newsize;
312 data->s_last = data->s_base + newsize - 1;
316 #if YYPURE || defined(YY_NO_LEAKS)
317 static void yyfreestack(YYSTACKDATA *data)
321 memset(data, 0, sizeof(*data));
324 #define yyfreestack(data) /* nothing */
327 #define YYABORT goto yyabort
328 #define YYREJECT goto yyabort
329 #define YYACCEPT goto yyaccept
330 #define YYERROR goto yyerrlab
335 int yym, yyn, yystate;
339 if ((yys = getenv("YYDEBUG")) != 0)
342 if (yyn >= '0' && yyn <= '9')
353 memset(&yystack, 0, sizeof(yystack));
356 if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow;
357 yystack.s_mark = yystack.s_base;
358 yystack.l_mark = yystack.l_base;
363 if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
366 if ((yychar = YYLEX) < 0) yychar = 0;
371 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
372 if (!yys) yys = "illegal-symbol";
373 printf("%sdebug: state %d, reading %d (%s)\n",
374 YYPREFIX, yystate, yychar, yys);
378 if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
379 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
383 printf("%sdebug: state %d, shifting to state %d\n",
384 YYPREFIX, yystate, yytable[yyn]);
386 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
390 yystate = yytable[yyn];
391 *++yystack.s_mark = yytable[yyn];
392 *++yystack.l_mark = yylval;
394 if (yyerrflag > 0) --yyerrflag;
397 if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
398 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
403 if (yyerrflag) goto yyinrecovery;
405 yyerror("syntax error");
418 if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 &&
419 yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
423 printf("%sdebug: state %d, error recovery shifting\
424 to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]);
426 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
430 yystate = yytable[yyn];
431 *++yystack.s_mark = yytable[yyn];
432 *++yystack.l_mark = yylval;
439 printf("%sdebug: error recovery discarding state %d\n",
440 YYPREFIX, *yystack.s_mark);
442 if (yystack.s_mark <= yystack.s_base) goto yyabort;
450 if (yychar == 0) goto yyabort;
455 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
456 if (!yys) yys = "illegal-symbol";
457 printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
458 YYPREFIX, yystate, yychar, yys);
468 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
469 YYPREFIX, yystate, yyn, yyrule[yyn]);
473 yyval = yystack.l_mark[1-yym];
475 memset(&yyval, 0, sizeof yyval);
479 #line 30 "code_calc.y"
483 #line 34 "code_calc.y"
484 { printf("%d\n",yystack.l_mark[0]);}
487 #line 36 "code_calc.y"
488 { regs[yystack.l_mark[-2]] = yystack.l_mark[0]; }
491 #line 40 "code_calc.y"
492 { yyval = yystack.l_mark[-1]; }
495 #line 42 "code_calc.y"
496 { yyval = yystack.l_mark[-2] + yystack.l_mark[0]; }
499 #line 44 "code_calc.y"
500 { yyval = yystack.l_mark[-2] - yystack.l_mark[0]; }
503 #line 46 "code_calc.y"
504 { yyval = yystack.l_mark[-2] * yystack.l_mark[0]; }
507 #line 48 "code_calc.y"
508 { yyval = yystack.l_mark[-2] / yystack.l_mark[0]; }
511 #line 50 "code_calc.y"
512 { yyval = yystack.l_mark[-2] % yystack.l_mark[0]; }
515 #line 52 "code_calc.y"
516 { yyval = yystack.l_mark[-2] & yystack.l_mark[0]; }
519 #line 54 "code_calc.y"
520 { yyval = yystack.l_mark[-2] | yystack.l_mark[0]; }
523 #line 56 "code_calc.y"
524 { yyval = - yystack.l_mark[0]; }
527 #line 58 "code_calc.y"
528 { yyval = regs[yystack.l_mark[0]]; }
531 #line 63 "code_calc.y"
532 { yyval = yystack.l_mark[0]; base = (yystack.l_mark[0]==0) ? 8 : 10; }
535 #line 65 "code_calc.y"
536 { yyval = base * yystack.l_mark[-1] + yystack.l_mark[0]; }
538 #line 538 "/dev/stdout"
540 yystack.s_mark -= yym;
541 yystate = *yystack.s_mark;
542 yystack.l_mark -= yym;
544 if (yystate == 0 && yym == 0)
548 printf("%sdebug: after reduction, shifting from state 0 to\
549 state %d\n", YYPREFIX, YYFINAL);
552 *++yystack.s_mark = YYFINAL;
553 *++yystack.l_mark = yyval;
556 if ((yychar = YYLEX) < 0) yychar = 0;
561 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
562 if (!yys) yys = "illegal-symbol";
563 printf("%sdebug: state %d, reading %d (%s)\n",
564 YYPREFIX, YYFINAL, yychar, yys);
568 if (yychar == 0) goto yyaccept;
571 if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
572 yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
573 yystate = yytable[yyn];
575 yystate = yydgoto[yym];
578 printf("%sdebug: after reduction, shifting from state %d \
579 to state %d\n", YYPREFIX, *yystack.s_mark, yystate);
581 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
585 *++yystack.s_mark = (short) yystate;
586 *++yystack.l_mark = yyval;
590 yyerror("yacc stack overflow");
593 yyfreestack(&yystack);
597 yyfreestack(&yystack);