1 /* $NetBSD: calc2.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 calc2_parse
22 #define yylex calc2_lex
26 #define yyerror calc2_error
30 #define yychar calc2_char
34 #define yyval calc2_val
38 #define yylval calc2_lval
42 #define yydebug calc2_debug
46 #define yynerrs calc2_nerrs
50 #define yyerrflag calc2_errflag
51 #endif /* yyerrflag */
54 #define yylhs calc2_lhs
58 #define yylen calc2_len
62 #define yydefred calc2_defred
66 #define yydgoto calc2_dgoto
70 #define yysindex calc2_sindex
74 #define yyrindex calc2_rindex
78 #define yygindex calc2_gindex
82 #define yytable calc2_table
86 #define yycheck calc2_check
90 #define yyname calc2_name
94 #define yyrule calc2_rule
96 #define YYPREFIX "calc2_"
105 #define YYLEX_PARAM base
106 #define YYLEX_DECL() yylex(int *YYLEX_PARAM)
107 #define YYERROR_DECL() yyerror(int regs[26], int *base, const char *s)
109 static void YYERROR_DECL();
112 #line 111 "calc2.tab.c"
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(int regs[26], int * base)
130 /* Parameters sent to lex. */
132 # define YYLEX_DECL() yylex(void *YYLEX_PARAM)
133 # define YYLEX yylex(YYLEX_PARAM)
135 # define YYLEX_DECL() yylex(int * base)
136 # define YYLEX yylex(base)
139 /* Parameters sent to yyerror. */
141 #define YYERROR_DECL() yyerror(int regs[26], int * base, const char *s)
144 #define YYERROR_CALL(msg) yyerror(regs, base, msg)
147 extern int YYPARSE_DECL();
152 #define YYERRCODE 256
153 static const short calc2_lhs
[] = { -1,
154 0, 0, 0, 1, 1, 2, 2, 2, 2, 2,
155 2, 2, 2, 2, 2, 2, 3, 3,
157 static const short calc2_len
[] = { 2,
158 0, 3, 3, 1, 3, 3, 3, 3, 3, 3,
159 3, 3, 3, 2, 1, 1, 1, 2,
161 static const short calc2_defred
[] = { 1,
162 0, 0, 17, 0, 0, 0, 0, 0, 0, 3,
163 0, 15, 14, 0, 2, 0, 0, 0, 0, 0,
164 0, 0, 18, 0, 6, 0, 0, 0, 0, 9,
167 static const short calc2_dgoto
[] = { 1,
170 static const short calc2_sindex
[] = { 0,
171 -40, -7, 0, -55, -38, -38, 1, -29, -247, 0,
172 -38, 0, 0, 22, 0, -38, -38, -38, -38, -38,
173 -38, -38, 0, -29, 0, 51, 60, -20, -20, 0,
176 static const short calc2_rindex
[] = { 0,
177 0, 0, 0, 2, 0, 0, 0, 9, -9, 0,
178 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
179 0, 0, 0, 10, 0, -6, 14, 5, 13, 0,
182 static const short calc2_gindex
[] = { 0,
185 #define YYTABLESIZE 220
186 static const short calc2_table
[] = { 6,
187 16, 6, 10, 13, 5, 11, 5, 22, 17, 23,
188 15, 15, 20, 18, 7, 19, 22, 21, 4, 5,
189 0, 20, 8, 12, 0, 0, 21, 16, 16, 0,
190 0, 16, 16, 16, 13, 16, 0, 16, 15, 15,
191 0, 0, 7, 15, 15, 7, 15, 7, 15, 7,
192 8, 12, 0, 8, 12, 8, 0, 8, 22, 17,
193 0, 0, 25, 20, 18, 0, 19, 0, 21, 13,
194 14, 0, 0, 0, 0, 24, 0, 0, 0, 0,
195 26, 27, 28, 29, 30, 31, 32, 22, 17, 0,
196 0, 0, 20, 18, 16, 19, 22, 21, 0, 0,
197 0, 20, 18, 0, 19, 0, 21, 0, 0, 0,
198 0, 0, 0, 0, 16, 0, 0, 13, 0, 0,
199 0, 0, 0, 0, 0, 15, 0, 0, 7, 0,
200 0, 0, 0, 0, 0, 0, 8, 12, 0, 0,
201 0, 0, 0, 0, 0, 16, 0, 0, 0, 0,
202 0, 0, 0, 0, 0, 0, 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, 2, 3, 4, 3, 12,
210 static const short calc2_check
[] = { 40,
211 10, 40, 10, 10, 45, 61, 45, 37, 38, 257,
212 10, 10, 42, 43, 10, 45, 37, 47, 10, 10,
213 -1, 42, 10, 10, -1, -1, 47, 37, 38, -1,
214 -1, 41, 42, 43, 41, 45, -1, 47, 37, 38,
215 -1, -1, 38, 42, 43, 41, 45, 43, 47, 45,
216 38, 38, -1, 41, 41, 43, -1, 45, 37, 38,
217 -1, -1, 41, 42, 43, -1, 45, -1, 47, 5,
218 6, -1, -1, -1, -1, 11, -1, -1, -1, -1,
219 16, 17, 18, 19, 20, 21, 22, 37, 38, -1,
220 -1, -1, 42, 43, 124, 45, 37, 47, -1, -1,
221 -1, 42, 43, -1, 45, -1, 47, -1, -1, -1,
222 -1, -1, -1, -1, 124, -1, -1, 124, -1, -1,
223 -1, -1, -1, -1, -1, 124, -1, -1, 124, -1,
224 -1, -1, -1, -1, -1, -1, 124, 124, -1, -1,
225 -1, -1, -1, -1, -1, 124, -1, -1, -1, -1,
226 -1, -1, -1, -1, -1, -1, -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, 256, 257, 258, 257, 258,
238 #define YYMAXTOKEN 259
240 static const char *yyname
[] = {
242 "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,
243 0,0,0,0,0,0,"'%'","'&'",0,"'('","')'","'*'","'+'",0,"'-'",0,"'/'",0,0,0,0,0,0,0,
244 0,0,0,0,0,0,"'='",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
245 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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,0,0,0,0,0,0,0,0,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,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,0,0,0,
249 0,0,0,0,0,0,"DIGIT","LETTER","UMINUS",
251 static const char *yyrule
[] = {
254 "list : list stat '\\n'",
255 "list : list error '\\n'",
257 "stat : LETTER '=' expr",
258 "expr : '(' expr ')'",
259 "expr : expr '+' expr",
260 "expr : expr '-' expr",
261 "expr : expr '*' expr",
262 "expr : expr '/' expr",
263 "expr : expr '%' expr",
264 "expr : expr '&' expr",
265 "expr : expr '|' expr",
270 "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
306 /* variables for the parser stack */
307 static YYSTACKDATA yystack
;
309 /* start of programs */
312 extern int YYLEX_DECL();
321 while(!feof(stdin
)) {
322 yyparse(regs
, &base
);
330 fprintf(stderr
, "%s\n", s
);
336 /* lexical analysis routine */
337 /* returns LETTER for a lower case letter, yylval = 0 through 25 */
338 /* return DIGIT for a digit, yylval = 0 through 9 */
339 /* all other characters are returned immediately */
343 while( (c
=getchar()) == ' ' ) { /* skip blanks */ }
345 /* c is now nonblank */
352 yylval
= (c
- '0') % (*base
);
357 #line 356 "calc2.tab.c"
360 #include <stdio.h> /* needed for printf */
363 #include <stdlib.h> /* needed for malloc, etc */
364 #include <string.h> /* needed for memset */
366 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
367 static int yygrowstack(YYSTACKDATA
*data
)
374 if ((newsize
= data
->stacksize
) == 0)
375 newsize
= YYINITSTACKSIZE
;
376 else if (newsize
>= YYMAXDEPTH
)
378 else if ((newsize
*= 2) > YYMAXDEPTH
)
379 newsize
= YYMAXDEPTH
;
381 i
= (int) (data
->s_mark
- data
->s_base
);
382 newss
= (short *)realloc(data
->s_base
, newsize
* sizeof(*newss
));
386 data
->s_base
= newss
;
387 data
->s_mark
= newss
+ i
;
389 newvs
= (YYSTYPE
*)realloc(data
->l_base
, newsize
* sizeof(*newvs
));
393 data
->l_base
= newvs
;
394 data
->l_mark
= newvs
+ i
;
396 data
->stacksize
= newsize
;
397 data
->s_last
= data
->s_base
+ newsize
- 1;
401 #if YYPURE || defined(YY_NO_LEAKS)
402 static void yyfreestack(YYSTACKDATA
*data
)
406 memset(data
, 0, sizeof(*data
));
409 #define yyfreestack(data) /* nothing */
412 #define YYABORT goto yyabort
413 #define YYREJECT goto yyabort
414 #define YYACCEPT goto yyaccept
415 #define YYERROR goto yyerrlab
420 int yym
, yyn
, yystate
;
424 if ((yys
= getenv("YYDEBUG")) != 0)
427 if (yyn
>= '0' && yyn
<= '9')
438 memset(&yystack
, 0, sizeof(yystack
));
441 if (yystack
.s_base
== NULL
&& yygrowstack(&yystack
)) goto yyoverflow
;
442 yystack
.s_mark
= yystack
.s_base
;
443 yystack
.l_mark
= yystack
.l_base
;
448 if ((yyn
= yydefred
[yystate
]) != 0) goto yyreduce
;
451 if ((yychar
= YYLEX
) < 0) yychar
= 0;
456 if (yychar
<= YYMAXTOKEN
) yys
= yyname
[yychar
];
457 if (!yys
) yys
= "illegal-symbol";
458 printf("%sdebug: state %d, reading %d (%s)\n",
459 YYPREFIX
, yystate
, yychar
, yys
);
463 if ((yyn
= yysindex
[yystate
]) && (yyn
+= yychar
) >= 0 &&
464 yyn
<= YYTABLESIZE
&& yycheck
[yyn
] == yychar
)
468 printf("%sdebug: state %d, shifting to state %d\n",
469 YYPREFIX
, yystate
, yytable
[yyn
]);
471 if (yystack
.s_mark
>= yystack
.s_last
&& yygrowstack(&yystack
))
475 yystate
= yytable
[yyn
];
476 *++yystack
.s_mark
= yytable
[yyn
];
477 *++yystack
.l_mark
= yylval
;
479 if (yyerrflag
> 0) --yyerrflag
;
482 if ((yyn
= yyrindex
[yystate
]) && (yyn
+= yychar
) >= 0 &&
483 yyn
<= YYTABLESIZE
&& yycheck
[yyn
] == yychar
)
488 if (yyerrflag
) goto yyinrecovery
;
490 yyerror(regs
, base
, "syntax error");
503 if ((yyn
= yysindex
[*yystack
.s_mark
]) && (yyn
+= YYERRCODE
) >= 0 &&
504 yyn
<= YYTABLESIZE
&& yycheck
[yyn
] == YYERRCODE
)
508 printf("%sdebug: state %d, error recovery shifting\
509 to state %d\n", YYPREFIX
, *yystack
.s_mark
, yytable
[yyn
]);
511 if (yystack
.s_mark
>= yystack
.s_last
&& yygrowstack(&yystack
))
515 yystate
= yytable
[yyn
];
516 *++yystack
.s_mark
= yytable
[yyn
];
517 *++yystack
.l_mark
= yylval
;
524 printf("%sdebug: error recovery discarding state %d\n",
525 YYPREFIX
, *yystack
.s_mark
);
527 if (yystack
.s_mark
<= yystack
.s_base
) goto yyabort
;
535 if (yychar
== 0) goto yyabort
;
540 if (yychar
<= YYMAXTOKEN
) yys
= yyname
[yychar
];
541 if (!yys
) yys
= "illegal-symbol";
542 printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
543 YYPREFIX
, yystate
, yychar
, yys
);
553 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
554 YYPREFIX
, yystate
, yyn
, yyrule
[yyn
]);
558 yyval
= yystack
.l_mark
[1-yym
];
560 memset(&yyval
, 0, sizeof yyval
);
569 { printf("%d\n",yystack
.l_mark
[0]);}
573 { regs
[yystack
.l_mark
[-2]] = yystack
.l_mark
[0]; }
577 { yyval
= yystack
.l_mark
[-1]; }
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
[-2] & yystack
.l_mark
[0]; }
605 { yyval
= yystack
.l_mark
[-2] | yystack
.l_mark
[0]; }
609 { yyval
= - yystack
.l_mark
[0]; }
613 { yyval
= regs
[yystack
.l_mark
[0]]; }
617 { yyval
= yystack
.l_mark
[0]; (*base
) = (yystack
.l_mark
[0]==0) ? 8 : 10; }
621 { yyval
= (*base
) * yystack
.l_mark
[-1] + yystack
.l_mark
[0]; }
623 #line 622 "calc2.tab.c"
625 yystack
.s_mark
-= yym
;
626 yystate
= *yystack
.s_mark
;
627 yystack
.l_mark
-= yym
;
629 if (yystate
== 0 && yym
== 0)
633 printf("%sdebug: after reduction, shifting from state 0 to\
634 state %d\n", YYPREFIX
, YYFINAL
);
637 *++yystack
.s_mark
= YYFINAL
;
638 *++yystack
.l_mark
= yyval
;
641 if ((yychar
= YYLEX
) < 0) yychar
= 0;
646 if (yychar
<= YYMAXTOKEN
) yys
= yyname
[yychar
];
647 if (!yys
) yys
= "illegal-symbol";
648 printf("%sdebug: state %d, reading %d (%s)\n",
649 YYPREFIX
, YYFINAL
, yychar
, yys
);
653 if (yychar
== 0) goto yyaccept
;
656 if ((yyn
= yygindex
[yym
]) && (yyn
+= yystate
) >= 0 &&
657 yyn
<= YYTABLESIZE
&& yycheck
[yyn
] == yystate
)
658 yystate
= yytable
[yyn
];
660 yystate
= yydgoto
[yym
];
663 printf("%sdebug: after reduction, shifting from state %d \
664 to state %d\n", YYPREFIX
, *yystack
.s_mark
, yystate
);
666 if (yystack
.s_mark
>= yystack
.s_last
&& yygrowstack(&yystack
))
670 *++yystack
.s_mark
= (short) yystate
;
671 *++yystack
.l_mark
= yyval
;
675 yyerror(regs
, base
, "yacc stack overflow");
678 yyfreestack(&yystack
);
682 yyfreestack(&yystack
);