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)
25 extern int yylex(void);
26 static void yyerror(const char *s);
28 #line 28 "/dev/stdout"
34 /* compatibility with bison */
36 /* compatibility with FreeBSD */
37 # ifdef YYPARSE_PARAM_TYPE
38 # define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
40 # define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
43 # define YYPARSE_DECL() yyparse(void)
46 /* Parameters sent to lex. */
48 # define YYLEX_DECL() yylex(void *YYLEX_PARAM)
49 # define YYLEX yylex(YYLEX_PARAM)
51 # define YYLEX_DECL() yylex(void)
52 # define YYLEX yylex()
55 /* Parameters sent to yyerror. */
57 #define YYERROR_DECL() yyerror(const char *s)
60 #define YYERROR_CALL(msg) yyerror(msg)
63 extern int YYPARSE_DECL();
69 static const short yylhs[] = { -1,
70 0, 0, 0, 1, 1, 2, 2, 2, 2, 2,
71 2, 2, 2, 2, 2, 2, 3, 3,
73 static const short yylen[] = { 2,
74 0, 3, 3, 1, 3, 3, 3, 3, 3, 3,
75 3, 3, 3, 2, 1, 1, 1, 2,
77 static const short yydefred[] = { 1,
78 0, 0, 17, 0, 0, 0, 0, 0, 0, 3,
79 0, 15, 14, 0, 2, 0, 0, 0, 0, 0,
80 0, 0, 18, 0, 6, 0, 0, 0, 0, 9,
83 static const short yydgoto[] = { 1,
86 static const short yysindex[] = { 0,
87 -40, -7, 0, -55, -38, -38, 1, -29, -247, 0,
88 -38, 0, 0, 22, 0, -38, -38, -38, -38, -38,
89 -38, -38, 0, -29, 0, 51, 60, -20, -20, 0,
92 static const short yyrindex[] = { 0,
93 0, 0, 0, 2, 0, 0, 0, 9, -9, 0,
94 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
95 0, 0, 0, 10, 0, -6, 14, 5, 13, 0,
98 static const short yygindex[] = { 0,
101 #define YYTABLESIZE 220
102 static const short yytable[] = { 6,
103 16, 6, 10, 13, 5, 11, 5, 22, 17, 23,
104 15, 15, 20, 18, 7, 19, 22, 21, 4, 5,
105 0, 20, 8, 12, 0, 0, 21, 16, 16, 0,
106 0, 16, 16, 16, 13, 16, 0, 16, 15, 15,
107 0, 0, 7, 15, 15, 7, 15, 7, 15, 7,
108 8, 12, 0, 8, 12, 8, 0, 8, 22, 17,
109 0, 0, 25, 20, 18, 0, 19, 0, 21, 13,
110 14, 0, 0, 0, 0, 24, 0, 0, 0, 0,
111 26, 27, 28, 29, 30, 31, 32, 22, 17, 0,
112 0, 0, 20, 18, 16, 19, 22, 21, 0, 0,
113 0, 20, 18, 0, 19, 0, 21, 0, 0, 0,
114 0, 0, 0, 0, 16, 0, 0, 13, 0, 0,
115 0, 0, 0, 0, 0, 15, 0, 0, 7, 0,
116 0, 0, 0, 0, 0, 0, 8, 12, 0, 0,
117 0, 0, 0, 0, 0, 16, 0, 0, 0, 0,
118 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
119 0, 0, 0, 0, 0, 0, 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, 2, 3, 4, 3, 12,
126 static const short yycheck[] = { 40,
127 10, 40, 10, 10, 45, 61, 45, 37, 38, 257,
128 10, 10, 42, 43, 10, 45, 37, 47, 10, 10,
129 -1, 42, 10, 10, -1, -1, 47, 37, 38, -1,
130 -1, 41, 42, 43, 41, 45, -1, 47, 37, 38,
131 -1, -1, 38, 42, 43, 41, 45, 43, 47, 45,
132 38, 38, -1, 41, 41, 43, -1, 45, 37, 38,
133 -1, -1, 41, 42, 43, -1, 45, -1, 47, 5,
134 6, -1, -1, -1, -1, 11, -1, -1, -1, -1,
135 16, 17, 18, 19, 20, 21, 22, 37, 38, -1,
136 -1, -1, 42, 43, 124, 45, 37, 47, -1, -1,
137 -1, 42, 43, -1, 45, -1, 47, -1, -1, -1,
138 -1, -1, -1, -1, 124, -1, -1, 124, -1, -1,
139 -1, -1, -1, -1, -1, 124, -1, -1, 124, -1,
140 -1, -1, -1, -1, -1, -1, 124, 124, -1, -1,
141 -1, -1, -1, -1, -1, 124, -1, -1, -1, -1,
142 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
143 -1, -1, -1, -1, -1, -1, -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, 256, 257, 258, 257, 258,
154 #define YYMAXTOKEN 259
156 static const char *yyname[] = {
158 "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,
159 0,0,0,0,0,0,"'%'","'&'",0,"'('","')'","'*'","'+'",0,"'-'",0,"'/'",0,0,0,0,0,0,0,
160 0,0,0,0,0,0,"'='",0,0,0,0,0,0,0,0,0,0,0,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,0,0,0,0,0,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,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,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,"DIGIT","LETTER","UMINUS",
167 static const char *yyrule[] = {
170 "list : list stat '\\n'",
171 "list : list error '\\n'",
173 "stat : LETTER '=' expr",
174 "expr : '(' expr ')'",
175 "expr : expr '+' expr",
176 "expr : expr '-' expr",
177 "expr : expr '*' expr",
178 "expr : expr '/' expr",
179 "expr : expr '%' expr",
180 "expr : expr '&' expr",
181 "expr : expr '|' expr",
186 "number : number DIGIT",
199 /* define the initial stack-sizes */
202 #define YYMAXDEPTH YYSTACKSIZE
205 #define YYSTACKSIZE YYMAXDEPTH
207 #define YYSTACKSIZE 500
208 #define YYMAXDEPTH 500
212 #define YYINITSTACKSIZE 500
222 /* variables for the parser stack */
223 static YYSTACKDATA yystack;
225 /* start of programs */
230 while(!feof(stdin)) {
237 yyerror(const char *s)
239 fprintf(stderr, "%s\n", s);
245 /* lexical analysis routine */
246 /* returns LETTER for a lower case letter, yylval = 0 through 25 */
247 /* return DIGIT for a digit, yylval = 0 through 9 */
248 /* all other characters are returned immediately */
252 while( (c=getchar()) == ' ' ) { /* skip blanks */ }
254 /* c is now nonblank */
266 #line 266 "/dev/stdout"
269 #include <stdio.h> /* needed for printf */
272 #include <stdlib.h> /* needed for malloc, etc */
273 #include <string.h> /* needed for memset */
275 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
276 static int yygrowstack(YYSTACKDATA *data)
283 if ((newsize = data->stacksize) == 0)
284 newsize = YYINITSTACKSIZE;
285 else if (newsize >= YYMAXDEPTH)
287 else if ((newsize *= 2) > YYMAXDEPTH)
288 newsize = YYMAXDEPTH;
290 i = data->s_mark - data->s_base;
291 newss = (short *)realloc(data->s_base, newsize * sizeof(*newss));
295 data->s_base = newss;
296 data->s_mark = newss + i;
298 newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));
302 data->l_base = newvs;
303 data->l_mark = newvs + i;
305 data->stacksize = newsize;
306 data->s_last = data->s_base + newsize - 1;
310 #if YYPURE || defined(YY_NO_LEAKS)
311 static void yyfreestack(YYSTACKDATA *data)
315 memset(data, 0, sizeof(*data));
318 #define yyfreestack(data) /* nothing */
321 #define YYABORT goto yyabort
322 #define YYREJECT goto yyabort
323 #define YYACCEPT goto yyaccept
324 #define YYERROR goto yyerrlab
329 int yym, yyn, yystate;
333 if ((yys = getenv("YYDEBUG")) != 0)
336 if (yyn >= '0' && yyn <= '9')
347 memset(&yystack, 0, sizeof(yystack));
350 if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow;
351 yystack.s_mark = yystack.s_base;
352 yystack.l_mark = yystack.l_base;
357 if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
360 if ((yychar = YYLEX) < 0) yychar = 0;
365 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
366 if (!yys) yys = "illegal-symbol";
367 printf("%sdebug: state %d, reading %d (%s)\n",
368 YYPREFIX, yystate, yychar, yys);
372 if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
373 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
377 printf("%sdebug: state %d, shifting to state %d\n",
378 YYPREFIX, yystate, yytable[yyn]);
380 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
384 yystate = yytable[yyn];
385 *++yystack.s_mark = yytable[yyn];
386 *++yystack.l_mark = yylval;
388 if (yyerrflag > 0) --yyerrflag;
391 if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
392 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
397 if (yyerrflag) goto yyinrecovery;
399 yyerror("syntax error");
412 if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 &&
413 yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
417 printf("%sdebug: state %d, error recovery shifting\
418 to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]);
420 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
424 yystate = yytable[yyn];
425 *++yystack.s_mark = yytable[yyn];
426 *++yystack.l_mark = yylval;
433 printf("%sdebug: error recovery discarding state %d\n",
434 YYPREFIX, *yystack.s_mark);
436 if (yystack.s_mark <= yystack.s_base) goto yyabort;
444 if (yychar == 0) goto yyabort;
449 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
450 if (!yys) yys = "illegal-symbol";
451 printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
452 YYPREFIX, yystate, yychar, yys);
462 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
463 YYPREFIX, yystate, yyn, yyrule[yyn]);
467 yyval = yystack.l_mark[1-yym];
469 memset(&yyval, 0, sizeof yyval);
478 { printf("%d\n",yystack.l_mark[0]);}
482 { regs[yystack.l_mark[-2]] = yystack.l_mark[0]; }
486 { yyval = yystack.l_mark[-1]; }
490 { yyval = yystack.l_mark[-2] + yystack.l_mark[0]; }
494 { yyval = yystack.l_mark[-2] - yystack.l_mark[0]; }
498 { yyval = yystack.l_mark[-2] * yystack.l_mark[0]; }
502 { yyval = yystack.l_mark[-2] / yystack.l_mark[0]; }
506 { yyval = yystack.l_mark[-2] % yystack.l_mark[0]; }
510 { yyval = yystack.l_mark[-2] & yystack.l_mark[0]; }
514 { yyval = yystack.l_mark[-2] | yystack.l_mark[0]; }
518 { yyval = - yystack.l_mark[0]; }
522 { yyval = regs[yystack.l_mark[0]]; }
526 { yyval = yystack.l_mark[0]; base = (yystack.l_mark[0]==0) ? 8 : 10; }
530 { yyval = base * yystack.l_mark[-1] + yystack.l_mark[0]; }
532 #line 532 "/dev/stdout"
534 yystack.s_mark -= yym;
535 yystate = *yystack.s_mark;
536 yystack.l_mark -= yym;
538 if (yystate == 0 && yym == 0)
542 printf("%sdebug: after reduction, shifting from state 0 to\
543 state %d\n", YYPREFIX, YYFINAL);
546 *++yystack.s_mark = YYFINAL;
547 *++yystack.l_mark = yyval;
550 if ((yychar = YYLEX) < 0) yychar = 0;
555 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
556 if (!yys) yys = "illegal-symbol";
557 printf("%sdebug: state %d, reading %d (%s)\n",
558 YYPREFIX, YYFINAL, yychar, yys);
562 if (yychar == 0) goto yyaccept;
565 if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
566 yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
567 yystate = yytable[yyn];
569 yystate = yydgoto[yym];
572 printf("%sdebug: after reduction, shifting from state %d \
573 to state %d\n", YYPREFIX, *yystack.s_mark, yystate);
575 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
579 *++yystack.s_mark = (short) yystate;
580 *++yystack.l_mark = yyval;
584 yyerror("yacc stack overflow");
587 yyfreestack(&yystack);
591 yyfreestack(&yystack);