1 /* $NetBSD: code_calc.code.c,v 1.1.1.4 2013/04/06 14:45:29 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)
28 static void yyerror(const char *s
);
31 #line 30 "code_calc.code.c"
37 /* compatibility with bison */
39 /* compatibility with FreeBSD */
40 # ifdef YYPARSE_PARAM_TYPE
41 # define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
43 # define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
46 # define YYPARSE_DECL() yyparse(void)
49 /* Parameters sent to lex. */
51 # define YYLEX_DECL() yylex(void *YYLEX_PARAM)
52 # define YYLEX yylex(YYLEX_PARAM)
54 # define YYLEX_DECL() yylex(void)
55 # define YYLEX yylex()
58 /* Parameters sent to yyerror. */
60 #define YYERROR_DECL() yyerror(const char *s)
63 #define YYERROR_CALL(msg) yyerror(msg)
66 extern int YYPARSE_DECL();
72 #define YYTABLESIZE 220
77 #define YYMAXTOKEN 259
80 #define yyparse calc_parse
84 #define yylex calc_lex
88 #define yyerror calc_error
92 #define yychar calc_char
96 #define yyval calc_val
100 #define yylval calc_lval
104 #define yydebug calc_debug
108 #define yynerrs calc_nerrs
112 #define yyerrflag calc_errflag
113 #endif /* yyerrflag */
116 #define yylhs calc_lhs
120 #define yylen calc_len
124 #define yydefred calc_defred
125 #endif /* yydefred */
128 #define yydgoto calc_dgoto
132 #define yysindex calc_sindex
133 #endif /* yysindex */
136 #define yyrindex calc_rindex
137 #endif /* yyrindex */
140 #define yygindex calc_gindex
141 #endif /* yygindex */
144 #define yytable calc_table
148 #define yycheck calc_check
152 #define yyname calc_name
156 #define yyrule calc_rule
158 #define YYPREFIX "calc_"
160 extern int YYPARSE_DECL();
161 extern short yylhs
[];
162 extern short yylen
[];
163 extern short yydefred
[];
164 extern short yydgoto
[];
165 extern short yysindex
[];
166 extern short yyrindex
[];
167 extern short yygindex
[];
168 extern short yytable
[];
169 extern short yycheck
[];
172 extern char *yyname
[];
173 extern char *yyrule
[];
184 /* define the initial stack-sizes */
187 #define YYMAXDEPTH YYSTACKSIZE
190 #define YYSTACKSIZE YYMAXDEPTH
192 #define YYSTACKSIZE 500
193 #define YYMAXDEPTH 500
197 #define YYINITSTACKSIZE 500
207 /* variables for the parser stack */
208 static YYSTACKDATA yystack
;
209 #line 68 "code_calc.y"
210 /* start of programs */
213 extern int YYLEX_DECL();
219 while(!feof(stdin
)) {
226 yyerror(const char *s
)
228 fprintf(stderr
, "%s\n", s
);
234 /* lexical analysis routine */
235 /* returns LETTER for a lower case letter, yylval = 0 through 25 */
236 /* return DIGIT for a digit, yylval = 0 through 9 */
237 /* all other characters are returned immediately */
241 while( (c
=getchar()) == ' ' ) { /* skip blanks */ }
243 /* c is now nonblank */
255 #line 254 "code_calc.code.c"
258 #include <stdio.h> /* needed for printf */
261 #include <stdlib.h> /* needed for malloc, etc */
262 #include <string.h> /* needed for memset */
264 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
265 static int yygrowstack(YYSTACKDATA
*data
)
272 if ((newsize
= data
->stacksize
) == 0)
273 newsize
= YYINITSTACKSIZE
;
274 else if (newsize
>= YYMAXDEPTH
)
276 else if ((newsize
*= 2) > YYMAXDEPTH
)
277 newsize
= YYMAXDEPTH
;
279 i
= (int) (data
->s_mark
- data
->s_base
);
280 newss
= (short *)realloc(data
->s_base
, newsize
* sizeof(*newss
));
284 data
->s_base
= newss
;
285 data
->s_mark
= newss
+ i
;
287 newvs
= (YYSTYPE
*)realloc(data
->l_base
, newsize
* sizeof(*newvs
));
291 data
->l_base
= newvs
;
292 data
->l_mark
= newvs
+ i
;
294 data
->stacksize
= newsize
;
295 data
->s_last
= data
->s_base
+ newsize
- 1;
299 #if YYPURE || defined(YY_NO_LEAKS)
300 static void yyfreestack(YYSTACKDATA
*data
)
304 memset(data
, 0, sizeof(*data
));
307 #define yyfreestack(data) /* nothing */
310 #define YYABORT goto yyabort
311 #define YYREJECT goto yyabort
312 #define YYACCEPT goto yyaccept
313 #define YYERROR goto yyerrlab
318 int yym
, yyn
, yystate
;
322 if ((yys
= getenv("YYDEBUG")) != 0)
325 if (yyn
>= '0' && yyn
<= '9')
336 memset(&yystack
, 0, sizeof(yystack
));
339 if (yystack
.s_base
== NULL
&& yygrowstack(&yystack
)) goto yyoverflow
;
340 yystack
.s_mark
= yystack
.s_base
;
341 yystack
.l_mark
= yystack
.l_base
;
346 if ((yyn
= yydefred
[yystate
]) != 0) goto yyreduce
;
349 if ((yychar
= YYLEX
) < 0) yychar
= 0;
354 if (yychar
<= YYMAXTOKEN
) yys
= yyname
[yychar
];
355 if (!yys
) yys
= "illegal-symbol";
356 printf("%sdebug: state %d, reading %d (%s)\n",
357 YYPREFIX
, yystate
, yychar
, yys
);
361 if ((yyn
= yysindex
[yystate
]) && (yyn
+= yychar
) >= 0 &&
362 yyn
<= YYTABLESIZE
&& yycheck
[yyn
] == yychar
)
366 printf("%sdebug: state %d, shifting to state %d\n",
367 YYPREFIX
, yystate
, yytable
[yyn
]);
369 if (yystack
.s_mark
>= yystack
.s_last
&& yygrowstack(&yystack
))
373 yystate
= yytable
[yyn
];
374 *++yystack
.s_mark
= yytable
[yyn
];
375 *++yystack
.l_mark
= yylval
;
377 if (yyerrflag
> 0) --yyerrflag
;
380 if ((yyn
= yyrindex
[yystate
]) && (yyn
+= yychar
) >= 0 &&
381 yyn
<= YYTABLESIZE
&& yycheck
[yyn
] == yychar
)
386 if (yyerrflag
) goto yyinrecovery
;
388 yyerror("syntax error");
401 if ((yyn
= yysindex
[*yystack
.s_mark
]) && (yyn
+= YYERRCODE
) >= 0 &&
402 yyn
<= YYTABLESIZE
&& yycheck
[yyn
] == YYERRCODE
)
406 printf("%sdebug: state %d, error recovery shifting\
407 to state %d\n", YYPREFIX
, *yystack
.s_mark
, yytable
[yyn
]);
409 if (yystack
.s_mark
>= yystack
.s_last
&& yygrowstack(&yystack
))
413 yystate
= yytable
[yyn
];
414 *++yystack
.s_mark
= yytable
[yyn
];
415 *++yystack
.l_mark
= yylval
;
422 printf("%sdebug: error recovery discarding state %d\n",
423 YYPREFIX
, *yystack
.s_mark
);
425 if (yystack
.s_mark
<= yystack
.s_base
) goto yyabort
;
433 if (yychar
== 0) goto yyabort
;
438 if (yychar
<= YYMAXTOKEN
) yys
= yyname
[yychar
];
439 if (!yys
) yys
= "illegal-symbol";
440 printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
441 YYPREFIX
, yystate
, yychar
, yys
);
451 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
452 YYPREFIX
, yystate
, yyn
, yyrule
[yyn
]);
456 yyval
= yystack
.l_mark
[1-yym
];
458 memset(&yyval
, 0, sizeof yyval
);
462 #line 30 "code_calc.y"
466 #line 34 "code_calc.y"
467 { printf("%d\n",yystack
.l_mark
[0]);}
470 #line 36 "code_calc.y"
471 { regs
[yystack
.l_mark
[-2]] = yystack
.l_mark
[0]; }
474 #line 40 "code_calc.y"
475 { yyval
= yystack
.l_mark
[-1]; }
478 #line 42 "code_calc.y"
479 { yyval
= yystack
.l_mark
[-2] + yystack
.l_mark
[0]; }
482 #line 44 "code_calc.y"
483 { yyval
= yystack
.l_mark
[-2] - yystack
.l_mark
[0]; }
486 #line 46 "code_calc.y"
487 { yyval
= yystack
.l_mark
[-2] * yystack
.l_mark
[0]; }
490 #line 48 "code_calc.y"
491 { yyval
= yystack
.l_mark
[-2] / yystack
.l_mark
[0]; }
494 #line 50 "code_calc.y"
495 { yyval
= yystack
.l_mark
[-2] % yystack
.l_mark
[0]; }
498 #line 52 "code_calc.y"
499 { yyval
= yystack
.l_mark
[-2] & yystack
.l_mark
[0]; }
502 #line 54 "code_calc.y"
503 { yyval
= yystack
.l_mark
[-2] | yystack
.l_mark
[0]; }
506 #line 56 "code_calc.y"
507 { yyval
= - yystack
.l_mark
[0]; }
510 #line 58 "code_calc.y"
511 { yyval
= regs
[yystack
.l_mark
[0]]; }
514 #line 63 "code_calc.y"
515 { yyval
= yystack
.l_mark
[0]; base
= (yystack
.l_mark
[0]==0) ? 8 : 10; }
518 #line 65 "code_calc.y"
519 { yyval
= base
* yystack
.l_mark
[-1] + yystack
.l_mark
[0]; }
521 #line 520 "code_calc.code.c"
523 yystack
.s_mark
-= yym
;
524 yystate
= *yystack
.s_mark
;
525 yystack
.l_mark
-= yym
;
527 if (yystate
== 0 && yym
== 0)
531 printf("%sdebug: after reduction, shifting from state 0 to\
532 state %d\n", YYPREFIX
, YYFINAL
);
535 *++yystack
.s_mark
= YYFINAL
;
536 *++yystack
.l_mark
= yyval
;
539 if ((yychar
= YYLEX
) < 0) yychar
= 0;
544 if (yychar
<= YYMAXTOKEN
) yys
= yyname
[yychar
];
545 if (!yys
) yys
= "illegal-symbol";
546 printf("%sdebug: state %d, reading %d (%s)\n",
547 YYPREFIX
, YYFINAL
, yychar
, yys
);
551 if (yychar
== 0) goto yyaccept
;
554 if ((yyn
= yygindex
[yym
]) && (yyn
+= yystate
) >= 0 &&
555 yyn
<= YYTABLESIZE
&& yycheck
[yyn
] == yystate
)
556 yystate
= yytable
[yyn
];
558 yystate
= yydgoto
[yym
];
561 printf("%sdebug: after reduction, shifting from state %d \
562 to state %d\n", YYPREFIX
, *yystack
.s_mark
, yystate
);
564 if (yystack
.s_mark
>= yystack
.s_last
&& yygrowstack(&yystack
))
568 *++yystack
.s_mark
= (short) yystate
;
569 *++yystack
.l_mark
= yyval
;
573 yyerror("yacc stack overflow");
576 yyfreestack(&yystack
);
580 yyfreestack(&yystack
);