1 /* original parser id follows */
2 /* yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93" */
3 /* (use YYMAJOR/YYMINOR for ifdefs dependent on parser version) */
8 #define YYCHECK "yyyymmdd"
11 #define yyclearin (yychar = YYEMPTY)
12 #define yyerrok (yyerrflag = 0)
13 #define YYRECOVERING() (yyerrflag != 0)
18 #define yyparse calc_parse
22 #define yylex calc_lex
26 #define yyerror calc_error
30 #define yychar calc_char
34 #define yyval calc_val
38 #define yylval calc_lval
42 #define yydebug calc_debug
46 #define yynerrs calc_nerrs
50 #define yyerrflag calc_errflag
51 #endif /* yyerrflag */
54 #define yylhs calc_lhs
58 #define yylen calc_len
62 #define yydefred calc_defred
66 #define yydgoto calc_dgoto
70 #define yysindex calc_sindex
74 #define yyrindex calc_rindex
78 #define yygindex calc_gindex
82 #define yytable calc_table
86 #define yycheck calc_check
90 #define yyname calc_name
94 #define yyrule calc_rule
96 #define YYPREFIX "calc_"
107 extern int yylex(void);
108 static void yyerror(const char *s);
110 #line 111 "calc.tab.c"
112 #if ! defined(YYSTYPE) && ! defined(YYSTYPE_IS_DECLARED)
113 /* Default: YYSTYPE is the semantic value type. */
115 # define YYSTYPE_IS_DECLARED 1
118 /* compatibility with bison */
120 /* compatibility with FreeBSD */
121 # ifdef YYPARSE_PARAM_TYPE
122 # define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
124 # define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
127 # define YYPARSE_DECL() yyparse(void)
130 /* Parameters sent to lex. */
132 # define YYLEX_DECL() yylex(void *YYLEX_PARAM)
133 # define YYLEX yylex(YYLEX_PARAM)
135 # define YYLEX_DECL() yylex(void)
136 # define YYLEX yylex()
139 /* Parameters sent to yyerror. */
141 #define YYERROR_DECL() yyerror(const char *s)
144 #define YYERROR_CALL(msg) yyerror(msg)
147 extern int YYPARSE_DECL();
152 #define YYERRCODE 256
154 static const YYINT calc_lhs[] = { -1,
155 0, 0, 0, 1, 1, 2, 2, 2, 2, 2,
156 2, 2, 2, 2, 2, 2, 3, 3,
158 static const YYINT calc_len[] = { 2,
159 0, 3, 3, 1, 3, 3, 3, 3, 3, 3,
160 3, 3, 3, 2, 1, 1, 1, 2,
162 static const YYINT calc_defred[] = { 1,
163 0, 0, 17, 0, 0, 0, 0, 0, 0, 3,
164 0, 15, 14, 0, 2, 0, 0, 0, 0, 0,
165 0, 0, 18, 0, 6, 0, 0, 0, 0, 9,
168 static const YYINT calc_dgoto[] = { 1,
171 static const YYINT calc_sindex[] = { 0,
172 -40, -7, 0, -55, -38, -38, 1, -29, -247, 0,
173 -38, 0, 0, 22, 0, -38, -38, -38, -38, -38,
174 -38, -38, 0, -29, 0, 51, 60, -20, -20, 0,
177 static const YYINT calc_rindex[] = { 0,
178 0, 0, 0, 2, 0, 0, 0, 9, -9, 0,
179 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
180 0, 0, 0, 10, 0, -6, 14, 5, 13, 0,
183 static const YYINT calc_gindex[] = { 0,
186 #define YYTABLESIZE 220
187 static const YYINT calc_table[] = { 6,
188 16, 6, 10, 13, 5, 11, 5, 22, 17, 23,
189 15, 15, 20, 18, 7, 19, 22, 21, 4, 5,
190 0, 20, 8, 12, 0, 0, 21, 16, 16, 0,
191 0, 16, 16, 16, 13, 16, 0, 16, 15, 15,
192 0, 0, 7, 15, 15, 7, 15, 7, 15, 7,
193 8, 12, 0, 8, 12, 8, 0, 8, 22, 17,
194 0, 0, 25, 20, 18, 0, 19, 0, 21, 13,
195 14, 0, 0, 0, 0, 24, 0, 0, 0, 0,
196 26, 27, 28, 29, 30, 31, 32, 22, 17, 0,
197 0, 0, 20, 18, 16, 19, 22, 21, 0, 0,
198 0, 20, 18, 0, 19, 0, 21, 0, 0, 0,
199 0, 0, 0, 0, 16, 0, 0, 13, 0, 0,
200 0, 0, 0, 0, 0, 15, 0, 0, 7, 0,
201 0, 0, 0, 0, 0, 0, 8, 12, 0, 0,
202 0, 0, 0, 0, 0, 16, 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, 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, 2, 3, 4, 3, 12,
211 static const YYINT calc_check[] = { 40,
212 10, 40, 10, 10, 45, 61, 45, 37, 38, 257,
213 10, 10, 42, 43, 10, 45, 37, 47, 10, 10,
214 -1, 42, 10, 10, -1, -1, 47, 37, 38, -1,
215 -1, 41, 42, 43, 41, 45, -1, 47, 37, 38,
216 -1, -1, 38, 42, 43, 41, 45, 43, 47, 45,
217 38, 38, -1, 41, 41, 43, -1, 45, 37, 38,
218 -1, -1, 41, 42, 43, -1, 45, -1, 47, 5,
219 6, -1, -1, -1, -1, 11, -1, -1, -1, -1,
220 16, 17, 18, 19, 20, 21, 22, 37, 38, -1,
221 -1, -1, 42, 43, 124, 45, 37, 47, -1, -1,
222 -1, 42, 43, -1, 45, -1, 47, -1, -1, -1,
223 -1, -1, -1, -1, 124, -1, -1, 124, -1, -1,
224 -1, -1, -1, -1, -1, 124, -1, -1, 124, -1,
225 -1, -1, -1, -1, -1, -1, 124, 124, -1, -1,
226 -1, -1, -1, -1, -1, 124, -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, -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, 256, 257, 258, 257, 258,
239 #define YYMAXTOKEN 259
240 #define YYUNDFTOKEN 265
241 #define YYTRANSLATE(a) ((a) > YYMAXTOKEN ? YYUNDFTOKEN : (a))
243 static const char *const calc_name[] = {
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",0,0,0,0,0,"illegal-symbol",
254 static const char *const calc_rule[] = {
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",
286 /* define the initial stack-sizes */
289 #define YYMAXDEPTH YYSTACKSIZE
292 #define YYSTACKSIZE YYMAXDEPTH
294 #define YYSTACKSIZE 10000
295 #define YYMAXDEPTH 10000
299 #define YYINITSTACKSIZE 200
309 /* variables for the parser stack */
310 static YYSTACKDATA yystack;
312 /* start of programs */
317 while(!feof(stdin)) {
324 yyerror(const char *s)
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 */
353 #line 354 "calc.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 = (int) (data->s_mark - data->s_base);
378 newss = (YYINT *)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
416 int yym, yyn, yystate;
420 if ((yys = getenv("YYDEBUG")) != 0)
423 if (yyn >= '0' && yyn <= '9')
434 memset(&yystack, 0, sizeof(yystack));
437 if (yystack.s_base == NULL && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
438 yystack.s_mark = yystack.s_base;
439 yystack.l_mark = yystack.l_base;
444 if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
447 if ((yychar = YYLEX) < 0) yychar = YYEOF;
451 yys = yyname[YYTRANSLATE(yychar)];
452 printf("%sdebug: state %d, reading %d (%s)\n",
453 YYPREFIX, yystate, yychar, yys);
457 if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
458 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
462 printf("%sdebug: state %d, shifting to state %d\n",
463 YYPREFIX, yystate, yytable[yyn]);
465 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM)
469 yystate = yytable[yyn];
470 *++yystack.s_mark = yytable[yyn];
471 *++yystack.l_mark = yylval;
473 if (yyerrflag > 0) --yyerrflag;
476 if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
477 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
482 if (yyerrflag) goto yyinrecovery;
484 YYERROR_CALL("syntax error");
497 if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 &&
498 yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
502 printf("%sdebug: state %d, error recovery shifting\
503 to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]);
505 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM)
509 yystate = yytable[yyn];
510 *++yystack.s_mark = yytable[yyn];
511 *++yystack.l_mark = yylval;
518 printf("%sdebug: error recovery discarding state %d\n",
519 YYPREFIX, *yystack.s_mark);
521 if (yystack.s_mark <= yystack.s_base) goto yyabort;
529 if (yychar == YYEOF) goto yyabort;
533 yys = yyname[YYTRANSLATE(yychar)];
534 printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
535 YYPREFIX, yystate, yychar, yys);
545 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
546 YYPREFIX, yystate, yyn, yyrule[yyn]);
550 yyval = yystack.l_mark[1-yym];
552 memset(&yyval, 0, sizeof yyval);
561 { printf("%d\n",yystack.l_mark[0]);}
565 { regs[yystack.l_mark[-2]] = yystack.l_mark[0]; }
569 { yyval = yystack.l_mark[-1]; }
573 { yyval = yystack.l_mark[-2] + yystack.l_mark[0]; }
577 { yyval = yystack.l_mark[-2] - yystack.l_mark[0]; }
581 { yyval = yystack.l_mark[-2] * yystack.l_mark[0]; }
585 { yyval = yystack.l_mark[-2] / yystack.l_mark[0]; }
589 { yyval = yystack.l_mark[-2] % yystack.l_mark[0]; }
593 { yyval = yystack.l_mark[-2] & yystack.l_mark[0]; }
597 { yyval = yystack.l_mark[-2] | yystack.l_mark[0]; }
601 { yyval = - yystack.l_mark[0]; }
605 { yyval = regs[yystack.l_mark[0]]; }
609 { yyval = yystack.l_mark[0]; base = (yystack.l_mark[0]==0) ? 8 : 10; }
613 { yyval = base * yystack.l_mark[-1] + yystack.l_mark[0]; }
615 #line 616 "calc.tab.c"
617 yystack.s_mark -= yym;
618 yystate = *yystack.s_mark;
619 yystack.l_mark -= yym;
621 if (yystate == 0 && yym == 0)
625 printf("%sdebug: after reduction, shifting from state 0 to\
626 state %d\n", YYPREFIX, YYFINAL);
629 *++yystack.s_mark = YYFINAL;
630 *++yystack.l_mark = yyval;
633 if ((yychar = YYLEX) < 0) yychar = YYEOF;
637 yys = yyname[YYTRANSLATE(yychar)];
638 printf("%sdebug: state %d, reading %d (%s)\n",
639 YYPREFIX, YYFINAL, yychar, yys);
643 if (yychar == YYEOF) goto yyaccept;
646 if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
647 yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
648 yystate = yytable[yyn];
650 yystate = yydgoto[yym];
653 printf("%sdebug: after reduction, shifting from state %d \
654 to state %d\n", YYPREFIX, *yystack.s_mark, yystate);
656 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM)
660 *++yystack.s_mark = (YYINT) yystate;
661 *++yystack.l_mark = yyval;
665 YYERROR_CALL("yacc stack overflow");
668 yyfreestack(&yystack);
672 yyfreestack(&yystack);