1 /* $NetBSD: calc3.tab.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)
18 #define yyparse calc3_parse
22 #define yylex calc3_lex
26 #define yyerror calc3_error
30 #define yychar calc3_char
34 #define yyval calc3_val
38 #define yylval calc3_lval
42 #define yydebug calc3_debug
46 #define yynerrs calc3_nerrs
50 #define yyerrflag calc3_errflag
51 #endif /* yyerrflag */
54 #define yylhs calc3_lhs
58 #define yylen calc3_len
62 #define yydefred calc3_defred
66 #define yydgoto calc3_dgoto
70 #define yysindex calc3_sindex
74 #define yyrindex calc3_rindex
78 #define yygindex calc3_gindex
82 #define yytable calc3_table
86 #define yycheck calc3_check
90 #define yyname calc3_name
94 #define yyrule calc3_rule
96 #define YYPREFIX "calc3_"
106 #define YYLEX_PARAM base
107 #define YYLEX_DECL() yylex(YYSTYPE *yylval, int *YYLEX_PARAM)
108 #define YYERROR_DECL() yyerror(int regs[26], int *base, const char *s)
110 static void YYERROR_DECL();
113 #line 112 "calc3.tab.c"
119 /* compatibility with bison */
121 /* compatibility with FreeBSD */
122 # ifdef YYPARSE_PARAM_TYPE
123 # define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
125 # define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
128 # define YYPARSE_DECL() yyparse(int regs[26], int * base)
131 /* Parameters sent to lex. */
133 # ifdef YYLEX_PARAM_TYPE
134 # define YYLEX_DECL() yylex(YYSTYPE *yylval, YYLEX_PARAM_TYPE YYLEX_PARAM)
136 # define YYLEX_DECL() yylex(YYSTYPE *yylval, void * YYLEX_PARAM)
138 # define YYLEX yylex(&yylval, YYLEX_PARAM)
140 # define YYLEX_DECL() yylex(YYSTYPE *yylval, int * base)
141 # define YYLEX yylex(&yylval, base)
144 /* Parameters sent to yyerror. */
146 #define YYERROR_DECL() yyerror(int regs[26], int * base, const char *s)
149 #define YYERROR_CALL(msg) yyerror(regs, base, msg)
152 extern int YYPARSE_DECL();
157 #define YYERRCODE 256
158 static const short calc3_lhs
[] = { -1,
159 0, 0, 0, 1, 1, 2, 2, 2, 2, 2,
160 2, 2, 2, 2, 2, 2, 3, 3,
162 static const short calc3_len
[] = { 2,
163 0, 3, 3, 1, 3, 3, 3, 3, 3, 3,
164 3, 3, 3, 2, 1, 1, 1, 2,
166 static const short calc3_defred
[] = { 1,
167 0, 0, 17, 0, 0, 0, 0, 0, 0, 3,
168 0, 15, 14, 0, 2, 0, 0, 0, 0, 0,
169 0, 0, 18, 0, 6, 0, 0, 0, 0, 9,
172 static const short calc3_dgoto
[] = { 1,
175 static const short calc3_sindex
[] = { 0,
176 -40, -7, 0, -55, -38, -38, 1, -29, -247, 0,
177 -38, 0, 0, 22, 0, -38, -38, -38, -38, -38,
178 -38, -38, 0, -29, 0, 51, 60, -20, -20, 0,
181 static const short calc3_rindex
[] = { 0,
182 0, 0, 0, 2, 0, 0, 0, 9, -9, 0,
183 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
184 0, 0, 0, 10, 0, -6, 14, 5, 13, 0,
187 static const short calc3_gindex
[] = { 0,
190 #define YYTABLESIZE 220
191 static const short calc3_table
[] = { 6,
192 16, 6, 10, 13, 5, 11, 5, 22, 17, 23,
193 15, 15, 20, 18, 7, 19, 22, 21, 4, 5,
194 0, 20, 8, 12, 0, 0, 21, 16, 16, 0,
195 0, 16, 16, 16, 13, 16, 0, 16, 15, 15,
196 0, 0, 7, 15, 15, 7, 15, 7, 15, 7,
197 8, 12, 0, 8, 12, 8, 0, 8, 22, 17,
198 0, 0, 25, 20, 18, 0, 19, 0, 21, 13,
199 14, 0, 0, 0, 0, 24, 0, 0, 0, 0,
200 26, 27, 28, 29, 30, 31, 32, 22, 17, 0,
201 0, 0, 20, 18, 16, 19, 22, 21, 0, 0,
202 0, 20, 18, 0, 19, 0, 21, 0, 0, 0,
203 0, 0, 0, 0, 16, 0, 0, 13, 0, 0,
204 0, 0, 0, 0, 0, 15, 0, 0, 7, 0,
205 0, 0, 0, 0, 0, 0, 8, 12, 0, 0,
206 0, 0, 0, 0, 0, 16, 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, 0, 0, 0, 0, 0,
212 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
213 0, 0, 0, 0, 0, 2, 3, 4, 3, 12,
215 static const short calc3_check
[] = { 40,
216 10, 40, 10, 10, 45, 61, 45, 37, 38, 257,
217 10, 10, 42, 43, 10, 45, 37, 47, 10, 10,
218 -1, 42, 10, 10, -1, -1, 47, 37, 38, -1,
219 -1, 41, 42, 43, 41, 45, -1, 47, 37, 38,
220 -1, -1, 38, 42, 43, 41, 45, 43, 47, 45,
221 38, 38, -1, 41, 41, 43, -1, 45, 37, 38,
222 -1, -1, 41, 42, 43, -1, 45, -1, 47, 5,
223 6, -1, -1, -1, -1, 11, -1, -1, -1, -1,
224 16, 17, 18, 19, 20, 21, 22, 37, 38, -1,
225 -1, -1, 42, 43, 124, 45, 37, 47, -1, -1,
226 -1, 42, 43, -1, 45, -1, 47, -1, -1, -1,
227 -1, -1, -1, -1, 124, -1, -1, 124, -1, -1,
228 -1, -1, -1, -1, -1, 124, -1, -1, 124, -1,
229 -1, -1, -1, -1, -1, -1, 124, 124, -1, -1,
230 -1, -1, -1, -1, -1, 124, -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, -1, -1, -1, -1, -1,
236 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
237 -1, -1, -1, -1, -1, 256, 257, 258, 257, 258,
243 #define YYMAXTOKEN 259
245 static const char *yyname
[] = {
247 "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,
248 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,
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,
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,0,0,0,0,0,0,0,0,0,0,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,0,0,0,
254 0,0,0,0,0,0,"DIGIT","LETTER","UMINUS",
256 static const char *yyrule
[] = {
259 "list : list stat '\\n'",
260 "list : list error '\\n'",
262 "stat : LETTER '=' expr",
263 "expr : '(' expr ')'",
264 "expr : expr '+' expr",
265 "expr : expr '-' expr",
266 "expr : expr '*' expr",
267 "expr : expr '/' expr",
268 "expr : expr '%' expr",
269 "expr : expr '&' expr",
270 "expr : expr '|' expr",
275 "number : number DIGIT",
283 /* define the initial stack-sizes */
286 #define YYMAXDEPTH YYSTACKSIZE
289 #define YYSTACKSIZE YYMAXDEPTH
291 #define YYSTACKSIZE 500
292 #define YYMAXDEPTH 500
296 #define YYINITSTACKSIZE 500
307 /* start of programs */
310 extern int YYLEX_DECL();
319 while(!feof(stdin
)) {
320 yyparse(regs
, &base
);
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 */
350 *yylval
= (c
- '0') % (*base
);
355 #line 354 "calc3.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(regs
, base
, "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
);
574 { printf("%d\n",yystack
.l_mark
[0]);}
578 { regs
[yystack
.l_mark
[-2]] = yystack
.l_mark
[0]; }
582 { yyval
= yystack
.l_mark
[-1]; }
586 { yyval
= yystack
.l_mark
[-2] + yystack
.l_mark
[0]; }
590 { yyval
= yystack
.l_mark
[-2] - yystack
.l_mark
[0]; }
594 { yyval
= yystack
.l_mark
[-2] * yystack
.l_mark
[0]; }
598 { yyval
= yystack
.l_mark
[-2] / yystack
.l_mark
[0]; }
602 { yyval
= yystack
.l_mark
[-2] % yystack
.l_mark
[0]; }
606 { yyval
= yystack
.l_mark
[-2] & yystack
.l_mark
[0]; }
610 { yyval
= yystack
.l_mark
[-2] | yystack
.l_mark
[0]; }
614 { yyval
= - yystack
.l_mark
[0]; }
618 { yyval
= regs
[yystack
.l_mark
[0]]; }
622 { yyval
= yystack
.l_mark
[0]; (*base
) = (yystack
.l_mark
[0]==0) ? 8 : 10; }
626 { yyval
= (*base
) * yystack
.l_mark
[-1] + yystack
.l_mark
[0]; }
628 #line 627 "calc3.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(regs
, base
, "yacc stack overflow");
683 yyfreestack(&yystack
);
687 yyfreestack(&yystack
);