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_"
104 #define YYLEX_PARAM base
105 #define YYLEX_DECL() yylex(YYSTYPE *yylval, int *YYLEX_PARAM)
106 #define YYERROR_DECL() yyerror(int regs[26], int *base, const char *s)
108 static void YYERROR_DECL();
111 #line 112 "calc3.tab.c"
117 /* compatibility with bison */
119 /* compatibility with FreeBSD */
120 # ifdef YYPARSE_PARAM_TYPE
121 # define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
123 # define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
126 # define YYPARSE_DECL() yyparse(int regs[26], int * base)
129 /* Parameters sent to lex. */
131 # ifdef YYLEX_PARAM_TYPE
132 # define YYLEX_DECL() yylex(YYSTYPE *yylval, YYLEX_PARAM_TYPE YYLEX_PARAM)
134 # define YYLEX_DECL() yylex(YYSTYPE *yylval, void * YYLEX_PARAM)
136 # define YYLEX yylex(&yylval, YYLEX_PARAM)
138 # define YYLEX_DECL() yylex(YYSTYPE *yylval, int * base)
139 # define YYLEX yylex(&yylval, base)
142 /* Parameters sent to yyerror. */
144 #define YYERROR_DECL() yyerror(int regs[26], int * base, const char *s)
147 #define YYERROR_CALL(msg) yyerror(regs, base, msg)
150 extern int YYPARSE_DECL();
155 #define YYERRCODE 256
156 static const short calc3_lhs[] = { -1,
157 0, 0, 0, 1, 1, 2, 2, 2, 2, 2,
158 2, 2, 2, 2, 2, 2, 3, 3,
160 static const short calc3_len[] = { 2,
161 0, 3, 3, 1, 3, 3, 3, 3, 3, 3,
162 3, 3, 3, 2, 1, 1, 1, 2,
164 static const short calc3_defred[] = { 1,
165 0, 0, 17, 0, 0, 0, 0, 0, 0, 3,
166 0, 15, 14, 0, 2, 0, 0, 0, 0, 0,
167 0, 0, 18, 0, 6, 0, 0, 0, 0, 9,
170 static const short calc3_dgoto[] = { 1,
173 static const short calc3_sindex[] = { 0,
174 -40, -7, 0, -55, -38, -38, 1, -29, -247, 0,
175 -38, 0, 0, 22, 0, -38, -38, -38, -38, -38,
176 -38, -38, 0, -29, 0, 51, 60, -20, -20, 0,
179 static const short calc3_rindex[] = { 0,
180 0, 0, 0, 2, 0, 0, 0, 9, -9, 0,
181 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
182 0, 0, 0, 10, 0, -6, 14, 5, 13, 0,
185 static const short calc3_gindex[] = { 0,
188 #define YYTABLESIZE 220
189 static const short calc3_table[] = { 6,
190 16, 6, 10, 13, 5, 11, 5, 22, 17, 23,
191 15, 15, 20, 18, 7, 19, 22, 21, 4, 5,
192 0, 20, 8, 12, 0, 0, 21, 16, 16, 0,
193 0, 16, 16, 16, 13, 16, 0, 16, 15, 15,
194 0, 0, 7, 15, 15, 7, 15, 7, 15, 7,
195 8, 12, 0, 8, 12, 8, 0, 8, 22, 17,
196 0, 0, 25, 20, 18, 0, 19, 0, 21, 13,
197 14, 0, 0, 0, 0, 24, 0, 0, 0, 0,
198 26, 27, 28, 29, 30, 31, 32, 22, 17, 0,
199 0, 0, 20, 18, 16, 19, 22, 21, 0, 0,
200 0, 20, 18, 0, 19, 0, 21, 0, 0, 0,
201 0, 0, 0, 0, 16, 0, 0, 13, 0, 0,
202 0, 0, 0, 0, 0, 15, 0, 0, 7, 0,
203 0, 0, 0, 0, 0, 0, 8, 12, 0, 0,
204 0, 0, 0, 0, 0, 16, 0, 0, 0, 0,
205 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
206 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
207 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
208 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
209 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
210 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
211 0, 0, 0, 0, 0, 2, 3, 4, 3, 12,
213 static const short calc3_check[] = { 40,
214 10, 40, 10, 10, 45, 61, 45, 37, 38, 257,
215 10, 10, 42, 43, 10, 45, 37, 47, 10, 10,
216 -1, 42, 10, 10, -1, -1, 47, 37, 38, -1,
217 -1, 41, 42, 43, 41, 45, -1, 47, 37, 38,
218 -1, -1, 38, 42, 43, 41, 45, 43, 47, 45,
219 38, 38, -1, 41, 41, 43, -1, 45, 37, 38,
220 -1, -1, 41, 42, 43, -1, 45, -1, 47, 5,
221 6, -1, -1, -1, -1, 11, -1, -1, -1, -1,
222 16, 17, 18, 19, 20, 21, 22, 37, 38, -1,
223 -1, -1, 42, 43, 124, 45, 37, 47, -1, -1,
224 -1, 42, 43, -1, 45, -1, 47, -1, -1, -1,
225 -1, -1, -1, -1, 124, -1, -1, 124, -1, -1,
226 -1, -1, -1, -1, -1, 124, -1, -1, 124, -1,
227 -1, -1, -1, -1, -1, -1, 124, 124, -1, -1,
228 -1, -1, -1, -1, -1, 124, -1, -1, -1, -1,
229 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
230 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
231 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
232 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
233 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
234 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
235 -1, -1, -1, -1, -1, 256, 257, 258, 257, 258,
241 #define YYMAXTOKEN 259
243 static const char *yyname[] = {
245 "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,
246 0,0,0,0,0,0,"'%'","'&'",0,"'('","')'","'*'","'+'",0,"'-'",0,"'/'",0,0,0,0,0,0,0,
247 0,0,0,0,0,0,"'='",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
248 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"'|'",0,0,0,0,0,0,
249 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
250 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
251 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
252 0,0,0,0,0,0,"DIGIT","LETTER","UMINUS",
254 static const char *yyrule[] = {
257 "list : list stat '\\n'",
258 "list : list error '\\n'",
260 "stat : LETTER '=' expr",
261 "expr : '(' expr ')'",
262 "expr : expr '+' expr",
263 "expr : expr '-' expr",
264 "expr : expr '*' expr",
265 "expr : expr '/' expr",
266 "expr : expr '%' expr",
267 "expr : expr '&' expr",
268 "expr : expr '|' expr",
273 "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
305 /* start of programs */
308 extern int YYLEX_DECL();
317 while(!feof(stdin)) {
318 yyparse(regs, &base);
326 fprintf(stderr, "%s\n", s);
332 /* lexical analysis routine */
333 /* returns LETTER for a lower case letter, yylval = 0 through 25 */
334 /* return DIGIT for a digit, yylval = 0 through 9 */
335 /* all other characters are returned immediately */
339 while( (c=getchar()) == ' ' ) { /* skip blanks */ }
341 /* c is now nonblank */
348 *yylval = (c - '0') % (*base);
353 #line 354 "calc3.tab.c"
356 #include <stdio.h> /* needed for printf */
359 #include <stdlib.h> /* needed for malloc, etc */
360 #include <string.h> /* needed for memset */
362 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
363 static int yygrowstack(YYSTACKDATA *data)
370 if ((newsize = data->stacksize) == 0)
371 newsize = YYINITSTACKSIZE;
372 else if (newsize >= YYMAXDEPTH)
374 else if ((newsize *= 2) > YYMAXDEPTH)
375 newsize = YYMAXDEPTH;
377 i = data->s_mark - data->s_base;
378 newss = (short *)realloc(data->s_base, newsize * sizeof(*newss));
382 data->s_base = newss;
383 data->s_mark = newss + i;
385 newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));
389 data->l_base = newvs;
390 data->l_mark = newvs + i;
392 data->stacksize = newsize;
393 data->s_last = data->s_base + newsize - 1;
397 #if YYPURE || defined(YY_NO_LEAKS)
398 static void yyfreestack(YYSTACKDATA *data)
402 memset(data, 0, sizeof(*data));
405 #define yyfreestack(data) /* nothing */
408 #define YYABORT goto yyabort
409 #define YYREJECT goto yyabort
410 #define YYACCEPT goto yyaccept
411 #define YYERROR goto yyerrlab
421 /* variables for the parser stack */
423 int yym, yyn, yystate;
427 if ((yys = getenv("YYDEBUG")) != 0)
430 if (yyn >= '0' && yyn <= '9')
441 memset(&yystack, 0, sizeof(yystack));
444 if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow;
445 yystack.s_mark = yystack.s_base;
446 yystack.l_mark = yystack.l_base;
451 if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
454 if ((yychar = YYLEX) < 0) yychar = 0;
459 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
460 if (!yys) yys = "illegal-symbol";
461 printf("%sdebug: state %d, reading %d (%s)\n",
462 YYPREFIX, yystate, yychar, yys);
466 if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
467 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
471 printf("%sdebug: state %d, shifting to state %d\n",
472 YYPREFIX, yystate, yytable[yyn]);
474 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
478 yystate = yytable[yyn];
479 *++yystack.s_mark = yytable[yyn];
480 *++yystack.l_mark = yylval;
482 if (yyerrflag > 0) --yyerrflag;
485 if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
486 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
491 if (yyerrflag) goto yyinrecovery;
493 yyerror(regs, base, "syntax error");
506 if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 &&
507 yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
511 printf("%sdebug: state %d, error recovery shifting\
512 to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]);
514 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
518 yystate = yytable[yyn];
519 *++yystack.s_mark = yytable[yyn];
520 *++yystack.l_mark = yylval;
527 printf("%sdebug: error recovery discarding state %d\n",
528 YYPREFIX, *yystack.s_mark);
530 if (yystack.s_mark <= yystack.s_base) goto yyabort;
538 if (yychar == 0) goto yyabort;
543 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
544 if (!yys) yys = "illegal-symbol";
545 printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
546 YYPREFIX, yystate, yychar, yys);
556 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
557 YYPREFIX, yystate, yyn, yyrule[yyn]);
561 yyval = yystack.l_mark[1-yym];
563 memset(&yyval, 0, sizeof yyval);
572 { printf("%d\n",yystack.l_mark[0]);}
576 { regs[yystack.l_mark[-2]] = yystack.l_mark[0]; }
580 { yyval = yystack.l_mark[-1]; }
584 { yyval = yystack.l_mark[-2] + yystack.l_mark[0]; }
588 { yyval = yystack.l_mark[-2] - yystack.l_mark[0]; }
592 { yyval = yystack.l_mark[-2] * yystack.l_mark[0]; }
596 { yyval = yystack.l_mark[-2] / yystack.l_mark[0]; }
600 { yyval = yystack.l_mark[-2] % yystack.l_mark[0]; }
604 { yyval = yystack.l_mark[-2] & yystack.l_mark[0]; }
608 { yyval = yystack.l_mark[-2] | yystack.l_mark[0]; }
612 { yyval = - yystack.l_mark[0]; }
616 { yyval = regs[yystack.l_mark[0]]; }
620 { yyval = yystack.l_mark[0]; (*base) = (yystack.l_mark[0]==0) ? 8 : 10; }
624 { yyval = (*base) * yystack.l_mark[-1] + yystack.l_mark[0]; }
626 #line 627 "calc3.tab.c"
628 yystack.s_mark -= yym;
629 yystate = *yystack.s_mark;
630 yystack.l_mark -= yym;
632 if (yystate == 0 && yym == 0)
636 printf("%sdebug: after reduction, shifting from state 0 to\
637 state %d\n", YYPREFIX, YYFINAL);
640 *++yystack.s_mark = YYFINAL;
641 *++yystack.l_mark = yyval;
644 if ((yychar = YYLEX) < 0) yychar = 0;
649 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
650 if (!yys) yys = "illegal-symbol";
651 printf("%sdebug: state %d, reading %d (%s)\n",
652 YYPREFIX, YYFINAL, yychar, yys);
656 if (yychar == 0) goto yyaccept;
659 if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
660 yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
661 yystate = yytable[yyn];
663 yystate = yydgoto[yym];
666 printf("%sdebug: after reduction, shifting from state %d \
667 to state %d\n", YYPREFIX, *yystack.s_mark, yystate);
669 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
673 *++yystack.s_mark = (short) yystate;
674 *++yystack.l_mark = yyval;
678 yyerror(regs, base, "yacc stack overflow");
681 yyfreestack(&yystack);
685 yyfreestack(&yystack);