4 static const char yysccsid
[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93";
15 #define yyclearin (yychar = YYEMPTY)
16 #define yyerrok (yyerrflag = 0)
17 #define YYRECOVERING() (yyerrflag != 0)
19 /* compatibility with bison */
21 /* compatibility with FreeBSD */
22 #ifdef YYPARSE_PARAM_TYPE
23 #define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
25 #define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
28 #define YYPARSE_DECL() yyparse(void)
29 #endif /* YYPARSE_PARAM */
31 extern int YYPARSE_DECL();
33 static int yygrowstack(void);
34 #define yyparse calc_parse
35 #define yylex calc_lex
36 #define yyerror calc_error
37 #define yychar calc_char
38 #define yyval calc_val
39 #define yylval calc_lval
40 #define yydebug calc_debug
41 #define yynerrs calc_nerrs
42 #define yyerrflag calc_errflag
44 #define yyssp calc_ssp
46 #define yyvsp calc_vsp
47 #define yylhs calc_lhs
48 #define yylen calc_len
49 #define yydefred calc_defred
50 #define yydgoto calc_dgoto
51 #define yysindex calc_sindex
52 #define yyrindex calc_rindex
53 #define yygindex calc_gindex
54 #define yytable calc_table
55 #define yycheck calc_check
56 #define yyname calc_name
57 #define yyrule calc_rule
58 #define YYPREFIX "calc_"
71 static const short calc_lhs
[] = { -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 calc_len
[] = { 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 calc_defred
[] = { 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 calc_dgoto
[] = { 1,
88 static const short calc_sindex
[] = { 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 calc_rindex
[] = { 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 calc_gindex
[] = { 0,
103 #define YYTABLESIZE 220
104 static const short calc_table
[] = { 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 calc_check
[] = { 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 *calc_name
[] = {
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 *calc_rule
[] = {
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",
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
223 /* variables for the parser stack */
225 static short *yysslim
;
226 static YYSTYPE
*yyvs
;
227 static unsigned yystacksize
;
229 /* start of programs */
234 while(!feof(stdin
)) {
241 fprintf(stderr
, "%s\n", s
);
245 yylex() { /* 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 265 "calc.tab.c"
267 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
268 static int yygrowstack(void)
275 if ((newsize
= yystacksize
) == 0)
276 newsize
= YYINITSTACKSIZE
;
277 else if (newsize
>= YYMAXDEPTH
)
279 else if ((newsize
*= 2) > YYMAXDEPTH
)
280 newsize
= YYMAXDEPTH
;
284 ? (short *)realloc(yyss
, newsize
* sizeof(*newss
))
285 : (short *)malloc(newsize
* sizeof(*newss
));
292 ? (YYSTYPE
*)realloc(yyvs
, newsize
* sizeof(*newvs
))
293 : (YYSTYPE
*)malloc(newsize
* sizeof(*newvs
));
299 yystacksize
= newsize
;
300 yysslim
= yyss
+ newsize
- 1;
304 #define YYABORT goto yyabort
305 #define YYREJECT goto yyabort
306 #define YYACCEPT goto yyaccept
307 #define YYERROR goto yyerrlab
312 int yym
, yyn
, yystate
;
316 if ((yys
= getenv("YYDEBUG")) != 0)
319 if (yyn
>= '0' && yyn
<= '9')
329 if (yyss
== NULL
&& yygrowstack()) goto yyoverflow
;
336 if ((yyn
= yydefred
[yystate
]) != 0) goto yyreduce
;
339 if ((yychar
= yylex()) < 0) yychar
= 0;
344 if (yychar
<= YYMAXTOKEN
) yys
= yyname
[yychar
];
345 if (!yys
) yys
= "illegal-symbol";
346 printf("%sdebug: state %d, reading %d (%s)\n",
347 YYPREFIX
, yystate
, yychar
, yys
);
351 if ((yyn
= yysindex
[yystate
]) && (yyn
+= yychar
) >= 0 &&
352 yyn
<= YYTABLESIZE
&& yycheck
[yyn
] == yychar
)
356 printf("%sdebug: state %d, shifting to state %d\n",
357 YYPREFIX
, yystate
, yytable
[yyn
]);
359 if (yyssp
>= yysslim
&& yygrowstack())
363 yystate
= yytable
[yyn
];
364 *++yyssp
= yytable
[yyn
];
367 if (yyerrflag
> 0) --yyerrflag
;
370 if ((yyn
= yyrindex
[yystate
]) && (yyn
+= yychar
) >= 0 &&
371 yyn
<= YYTABLESIZE
&& yycheck
[yyn
] == yychar
)
376 if (yyerrflag
) goto yyinrecovery
;
378 yyerror("syntax error");
391 if ((yyn
= yysindex
[*yyssp
]) && (yyn
+= YYERRCODE
) >= 0 &&
392 yyn
<= YYTABLESIZE
&& yycheck
[yyn
] == YYERRCODE
)
396 printf("%sdebug: state %d, error recovery shifting\
397 to state %d\n", YYPREFIX
, *yyssp
, yytable
[yyn
]);
399 if (yyssp
>= yysslim
&& yygrowstack())
403 yystate
= yytable
[yyn
];
404 *++yyssp
= yytable
[yyn
];
412 printf("%sdebug: error recovery discarding state %d\n",
415 if (yyssp
<= yyss
) goto yyabort
;
423 if (yychar
== 0) goto yyabort
;
428 if (yychar
<= YYMAXTOKEN
) yys
= yyname
[yychar
];
429 if (!yys
) yys
= "illegal-symbol";
430 printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
431 YYPREFIX
, yystate
, yychar
, yys
);
441 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
442 YYPREFIX
, yystate
, yyn
, yyrule
[yyn
]);
446 yyval
= yyvsp
[1-yym
];
448 memset(&yyval
, 0, sizeof yyval
);
457 { printf("%d\n",yyvsp
[0]);}
461 { regs
[yyvsp
[-2]] = yyvsp
[0]; }
465 { yyval
= yyvsp
[-1]; }
469 { yyval
= yyvsp
[-2] + yyvsp
[0]; }
473 { yyval
= yyvsp
[-2] - yyvsp
[0]; }
477 { yyval
= yyvsp
[-2] * yyvsp
[0]; }
481 { yyval
= yyvsp
[-2] / yyvsp
[0]; }
485 { yyval
= yyvsp
[-2] % yyvsp
[0]; }
489 { yyval
= yyvsp
[-2] & yyvsp
[0]; }
493 { yyval
= yyvsp
[-2] | yyvsp
[0]; }
497 { yyval
= - yyvsp
[0]; }
501 { yyval
= regs
[yyvsp
[0]]; }
505 { yyval
= yyvsp
[0]; base
= (yyvsp
[0]==0) ? 8 : 10; }
509 { yyval
= base
* yyvsp
[-1] + yyvsp
[0]; }
511 #line 510 "calc.tab.c"
517 if (yystate
== 0 && yym
== 0)
521 printf("%sdebug: after reduction, shifting from state 0 to\
522 state %d\n", YYPREFIX
, YYFINAL
);
529 if ((yychar
= yylex()) < 0) yychar
= 0;
534 if (yychar
<= YYMAXTOKEN
) yys
= yyname
[yychar
];
535 if (!yys
) yys
= "illegal-symbol";
536 printf("%sdebug: state %d, reading %d (%s)\n",
537 YYPREFIX
, YYFINAL
, yychar
, yys
);
541 if (yychar
== 0) goto yyaccept
;
544 if ((yyn
= yygindex
[yym
]) && (yyn
+= yystate
) >= 0 &&
545 yyn
<= YYTABLESIZE
&& yycheck
[yyn
] == yystate
)
546 yystate
= yytable
[yyn
];
548 yystate
= yydgoto
[yym
];
551 printf("%sdebug: after reduction, shifting from state %d \
552 to state %d\n", YYPREFIX
, *yyssp
, yystate
);
554 if (yyssp
>= yysslim
&& yygrowstack())
558 *++yyssp
= (short) yystate
;
563 yyerror("yacc stack overflow");