1 /* $NetBSD: pure_calc.tab.c,v 1.1.1.4 2013/04/06 14:45:28 christos Exp $ */
4 static const char yysccsid
[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93";
12 #define yyclearin (yychar = YYEMPTY)
13 #define yyerrok (yyerrflag = 0)
14 #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_"
100 #line 2 "pure_calc.y"
109 #define YYLEX_PARAM &yylval
110 #define YYLEX_DECL() yylex(YYSTYPE *yylval)
111 #define YYERROR_DECL() yyerror(const char *s)
113 static void YYERROR_DECL();
116 #line 115 "pure_calc.tab.c"
122 /* compatibility with bison */
124 /* compatibility with FreeBSD */
125 # ifdef YYPARSE_PARAM_TYPE
126 # define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
128 # define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
131 # define YYPARSE_DECL() yyparse(void)
134 /* Parameters sent to lex. */
136 # ifdef YYLEX_PARAM_TYPE
137 # define YYLEX_DECL() yylex(YYSTYPE *yylval, YYLEX_PARAM_TYPE YYLEX_PARAM)
139 # define YYLEX_DECL() yylex(YYSTYPE *yylval, void * YYLEX_PARAM)
141 # define YYLEX yylex(&yylval, YYLEX_PARAM)
143 # define YYLEX_DECL() yylex(YYSTYPE *yylval)
144 # define YYLEX yylex(&yylval)
147 /* Parameters sent to yyerror. */
149 #define YYERROR_DECL() yyerror(const char *s)
152 #define YYERROR_CALL(msg) yyerror(msg)
155 extern int YYPARSE_DECL();
160 #define YYERRCODE 256
161 static const short calc_lhs
[] = { -1,
162 0, 0, 0, 1, 1, 2, 2, 2, 2, 2,
163 2, 2, 2, 2, 2, 2, 3, 3,
165 static const short calc_len
[] = { 2,
166 0, 3, 3, 1, 3, 3, 3, 3, 3, 3,
167 3, 3, 3, 2, 1, 1, 1, 2,
169 static const short calc_defred
[] = { 1,
170 0, 0, 17, 0, 0, 0, 0, 0, 0, 3,
171 0, 15, 14, 0, 2, 0, 0, 0, 0, 0,
172 0, 0, 18, 0, 6, 0, 0, 0, 0, 9,
175 static const short calc_dgoto
[] = { 1,
178 static const short calc_sindex
[] = { 0,
179 -40, -7, 0, -55, -38, -38, 1, -29, -247, 0,
180 -38, 0, 0, 22, 0, -38, -38, -38, -38, -38,
181 -38, -38, 0, -29, 0, 51, 60, -20, -20, 0,
184 static const short calc_rindex
[] = { 0,
185 0, 0, 0, 2, 0, 0, 0, 9, -9, 0,
186 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
187 0, 0, 0, 10, 0, -6, 14, 5, 13, 0,
190 static const short calc_gindex
[] = { 0,
193 #define YYTABLESIZE 220
194 static const short calc_table
[] = { 6,
195 16, 6, 10, 13, 5, 11, 5, 22, 17, 23,
196 15, 15, 20, 18, 7, 19, 22, 21, 4, 5,
197 0, 20, 8, 12, 0, 0, 21, 16, 16, 0,
198 0, 16, 16, 16, 13, 16, 0, 16, 15, 15,
199 0, 0, 7, 15, 15, 7, 15, 7, 15, 7,
200 8, 12, 0, 8, 12, 8, 0, 8, 22, 17,
201 0, 0, 25, 20, 18, 0, 19, 0, 21, 13,
202 14, 0, 0, 0, 0, 24, 0, 0, 0, 0,
203 26, 27, 28, 29, 30, 31, 32, 22, 17, 0,
204 0, 0, 20, 18, 16, 19, 22, 21, 0, 0,
205 0, 20, 18, 0, 19, 0, 21, 0, 0, 0,
206 0, 0, 0, 0, 16, 0, 0, 13, 0, 0,
207 0, 0, 0, 0, 0, 15, 0, 0, 7, 0,
208 0, 0, 0, 0, 0, 0, 8, 12, 0, 0,
209 0, 0, 0, 0, 0, 16, 0, 0, 0, 0,
210 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
211 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
212 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
213 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
214 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
215 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
216 0, 0, 0, 0, 0, 2, 3, 4, 3, 12,
218 static const short calc_check
[] = { 40,
219 10, 40, 10, 10, 45, 61, 45, 37, 38, 257,
220 10, 10, 42, 43, 10, 45, 37, 47, 10, 10,
221 -1, 42, 10, 10, -1, -1, 47, 37, 38, -1,
222 -1, 41, 42, 43, 41, 45, -1, 47, 37, 38,
223 -1, -1, 38, 42, 43, 41, 45, 43, 47, 45,
224 38, 38, -1, 41, 41, 43, -1, 45, 37, 38,
225 -1, -1, 41, 42, 43, -1, 45, -1, 47, 5,
226 6, -1, -1, -1, -1, 11, -1, -1, -1, -1,
227 16, 17, 18, 19, 20, 21, 22, 37, 38, -1,
228 -1, -1, 42, 43, 124, 45, 37, 47, -1, -1,
229 -1, 42, 43, -1, 45, -1, 47, -1, -1, -1,
230 -1, -1, -1, -1, 124, -1, -1, 124, -1, -1,
231 -1, -1, -1, -1, -1, 124, -1, -1, 124, -1,
232 -1, -1, -1, -1, -1, -1, 124, 124, -1, -1,
233 -1, -1, -1, -1, -1, 124, -1, -1, -1, -1,
234 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
235 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
236 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
237 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
238 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
239 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
240 -1, -1, -1, -1, -1, 256, 257, 258, 257, 258,
246 #define YYMAXTOKEN 259
248 static const char *yyname
[] = {
250 "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,
251 0,0,0,0,0,0,"'%'","'&'",0,"'('","')'","'*'","'+'",0,"'-'",0,"'/'",0,0,0,0,0,0,0,
252 0,0,0,0,0,0,"'='",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
253 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"'|'",0,0,0,0,0,0,
254 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
255 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
256 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
257 0,0,0,0,0,0,"DIGIT","LETTER","UMINUS",
259 static const char *yyrule
[] = {
262 "list : list stat '\\n'",
263 "list : list error '\\n'",
265 "stat : LETTER '=' expr",
266 "expr : '(' expr ')'",
267 "expr : expr '+' expr",
268 "expr : expr '-' expr",
269 "expr : expr '*' expr",
270 "expr : expr '/' expr",
271 "expr : expr '%' expr",
272 "expr : expr '&' expr",
273 "expr : expr '|' expr",
278 "number : number DIGIT",
286 /* define the initial stack-sizes */
289 #define YYMAXDEPTH YYSTACKSIZE
292 #define YYSTACKSIZE YYMAXDEPTH
294 #define YYSTACKSIZE 500
295 #define YYMAXDEPTH 500
299 #define YYINITSTACKSIZE 500
309 #line 72 "pure_calc.y"
310 /* start of programs */
313 static int YYLEX_DECL();
319 while(!feof(stdin
)) {
328 fprintf(stderr
, "%s\n", s
);
334 /* lexical analysis routine */
335 /* returns LETTER for a lower case letter, yylval = 0 through 25 */
336 /* return DIGIT for a digit, yylval = 0 through 9 */
337 /* all other characters are returned immediately */
341 while( (c
=getchar()) == ' ' ) { /* skip blanks */ }
343 /* c is now nonblank */
355 #line 354 "pure_calc.tab.c"
358 #include <stdio.h> /* needed for printf */
361 #include <stdlib.h> /* needed for malloc, etc */
362 #include <string.h> /* needed for memset */
364 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
365 static int yygrowstack(YYSTACKDATA
*data
)
372 if ((newsize
= data
->stacksize
) == 0)
373 newsize
= YYINITSTACKSIZE
;
374 else if (newsize
>= YYMAXDEPTH
)
376 else if ((newsize
*= 2) > YYMAXDEPTH
)
377 newsize
= YYMAXDEPTH
;
379 i
= (int) (data
->s_mark
- data
->s_base
);
380 newss
= (short *)realloc(data
->s_base
, newsize
* sizeof(*newss
));
384 data
->s_base
= newss
;
385 data
->s_mark
= newss
+ i
;
387 newvs
= (YYSTYPE
*)realloc(data
->l_base
, newsize
* sizeof(*newvs
));
391 data
->l_base
= newvs
;
392 data
->l_mark
= newvs
+ i
;
394 data
->stacksize
= newsize
;
395 data
->s_last
= data
->s_base
+ newsize
- 1;
399 #if YYPURE || defined(YY_NO_LEAKS)
400 static void yyfreestack(YYSTACKDATA
*data
)
404 memset(data
, 0, sizeof(*data
));
407 #define yyfreestack(data) /* nothing */
410 #define YYABORT goto yyabort
411 #define YYREJECT goto yyabort
412 #define YYACCEPT goto yyaccept
413 #define YYERROR goto yyerrlab
423 /* variables for the parser stack */
425 int yym
, yyn
, yystate
;
429 if ((yys
= getenv("YYDEBUG")) != 0)
432 if (yyn
>= '0' && yyn
<= '9')
443 memset(&yystack
, 0, sizeof(yystack
));
446 if (yystack
.s_base
== NULL
&& yygrowstack(&yystack
)) goto yyoverflow
;
447 yystack
.s_mark
= yystack
.s_base
;
448 yystack
.l_mark
= yystack
.l_base
;
453 if ((yyn
= yydefred
[yystate
]) != 0) goto yyreduce
;
456 if ((yychar
= YYLEX
) < 0) yychar
= 0;
461 if (yychar
<= YYMAXTOKEN
) yys
= yyname
[yychar
];
462 if (!yys
) yys
= "illegal-symbol";
463 printf("%sdebug: state %d, reading %d (%s)\n",
464 YYPREFIX
, yystate
, yychar
, yys
);
468 if ((yyn
= yysindex
[yystate
]) && (yyn
+= yychar
) >= 0 &&
469 yyn
<= YYTABLESIZE
&& yycheck
[yyn
] == yychar
)
473 printf("%sdebug: state %d, shifting to state %d\n",
474 YYPREFIX
, yystate
, yytable
[yyn
]);
476 if (yystack
.s_mark
>= yystack
.s_last
&& yygrowstack(&yystack
))
480 yystate
= yytable
[yyn
];
481 *++yystack
.s_mark
= yytable
[yyn
];
482 *++yystack
.l_mark
= yylval
;
484 if (yyerrflag
> 0) --yyerrflag
;
487 if ((yyn
= yyrindex
[yystate
]) && (yyn
+= yychar
) >= 0 &&
488 yyn
<= YYTABLESIZE
&& yycheck
[yyn
] == yychar
)
493 if (yyerrflag
) goto yyinrecovery
;
495 yyerror("syntax error");
508 if ((yyn
= yysindex
[*yystack
.s_mark
]) && (yyn
+= YYERRCODE
) >= 0 &&
509 yyn
<= YYTABLESIZE
&& yycheck
[yyn
] == YYERRCODE
)
513 printf("%sdebug: state %d, error recovery shifting\
514 to state %d\n", YYPREFIX
, *yystack
.s_mark
, yytable
[yyn
]);
516 if (yystack
.s_mark
>= yystack
.s_last
&& yygrowstack(&yystack
))
520 yystate
= yytable
[yyn
];
521 *++yystack
.s_mark
= yytable
[yyn
];
522 *++yystack
.l_mark
= yylval
;
529 printf("%sdebug: error recovery discarding state %d\n",
530 YYPREFIX
, *yystack
.s_mark
);
532 if (yystack
.s_mark
<= yystack
.s_base
) goto yyabort
;
540 if (yychar
== 0) goto yyabort
;
545 if (yychar
<= YYMAXTOKEN
) yys
= yyname
[yychar
];
546 if (!yys
) yys
= "illegal-symbol";
547 printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
548 YYPREFIX
, yystate
, yychar
, yys
);
558 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
559 YYPREFIX
, yystate
, yyn
, yyrule
[yyn
]);
563 yyval
= yystack
.l_mark
[1-yym
];
565 memset(&yyval
, 0, sizeof yyval
);
569 #line 34 "pure_calc.y"
573 #line 38 "pure_calc.y"
574 { printf("%d\n",yystack
.l_mark
[0]);}
577 #line 40 "pure_calc.y"
578 { regs
[yystack
.l_mark
[-2]] = yystack
.l_mark
[0]; }
581 #line 44 "pure_calc.y"
582 { yyval
= yystack
.l_mark
[-1]; }
585 #line 46 "pure_calc.y"
586 { yyval
= yystack
.l_mark
[-2] + yystack
.l_mark
[0]; }
589 #line 48 "pure_calc.y"
590 { yyval
= yystack
.l_mark
[-2] - yystack
.l_mark
[0]; }
593 #line 50 "pure_calc.y"
594 { yyval
= yystack
.l_mark
[-2] * yystack
.l_mark
[0]; }
597 #line 52 "pure_calc.y"
598 { yyval
= yystack
.l_mark
[-2] / yystack
.l_mark
[0]; }
601 #line 54 "pure_calc.y"
602 { yyval
= yystack
.l_mark
[-2] % yystack
.l_mark
[0]; }
605 #line 56 "pure_calc.y"
606 { yyval
= yystack
.l_mark
[-2] & yystack
.l_mark
[0]; }
609 #line 58 "pure_calc.y"
610 { yyval
= yystack
.l_mark
[-2] | yystack
.l_mark
[0]; }
613 #line 60 "pure_calc.y"
614 { yyval
= - yystack
.l_mark
[0]; }
617 #line 62 "pure_calc.y"
618 { yyval
= regs
[yystack
.l_mark
[0]]; }
621 #line 67 "pure_calc.y"
622 { yyval
= yystack
.l_mark
[0]; base
= (yystack
.l_mark
[0]==0) ? 8 : 10; }
625 #line 69 "pure_calc.y"
626 { yyval
= base
* yystack
.l_mark
[-1] + yystack
.l_mark
[0]; }
628 #line 627 "pure_calc.tab.c"
630 yystack
.s_mark
-= yym
;
631 yystate
= *yystack
.s_mark
;
632 yystack
.l_mark
-= yym
;
634 if (yystate
== 0 && yym
== 0)
638 printf("%sdebug: after reduction, shifting from state 0 to\
639 state %d\n", YYPREFIX
, YYFINAL
);
642 *++yystack
.s_mark
= YYFINAL
;
643 *++yystack
.l_mark
= yyval
;
646 if ((yychar
= YYLEX
) < 0) yychar
= 0;
651 if (yychar
<= YYMAXTOKEN
) yys
= yyname
[yychar
];
652 if (!yys
) yys
= "illegal-symbol";
653 printf("%sdebug: state %d, reading %d (%s)\n",
654 YYPREFIX
, YYFINAL
, yychar
, yys
);
658 if (yychar
== 0) goto yyaccept
;
661 if ((yyn
= yygindex
[yym
]) && (yyn
+= yystate
) >= 0 &&
662 yyn
<= YYTABLESIZE
&& yycheck
[yyn
] == yystate
)
663 yystate
= yytable
[yyn
];
665 yystate
= yydgoto
[yym
];
668 printf("%sdebug: after reduction, shifting from state %d \
669 to state %d\n", YYPREFIX
, *yystack
.s_mark
, yystate
);
671 if (yystack
.s_mark
>= yystack
.s_last
&& yygrowstack(&yystack
))
675 *++yystack
.s_mark
= (short) yystate
;
676 *++yystack
.l_mark
= yyval
;
680 yyerror("yacc stack overflow");
683 yyfreestack(&yystack
);
687 yyfreestack(&yystack
);