tools/llvm: Do not build with symbols
[minix3.git] / external / bsd / byacc / dist / test / pure_calc.tab.c
blob0d7b06d731452dc6cc0dee08f0b88e26b5f69c9a
1 /* $NetBSD: pure_calc.tab.c,v 1.1.1.4 2013/04/06 14:45:28 christos Exp $ */
3 #ifndef lint
4 static const char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93";
5 #endif
7 #define YYBYACC 1
8 #define YYMAJOR 1
9 #define YYMINOR 9
11 #define YYEMPTY (-1)
12 #define yyclearin (yychar = YYEMPTY)
13 #define yyerrok (yyerrflag = 0)
14 #define YYRECOVERING() (yyerrflag != 0)
17 #ifndef yyparse
18 #define yyparse calc_parse
19 #endif /* yyparse */
21 #ifndef yylex
22 #define yylex calc_lex
23 #endif /* yylex */
25 #ifndef yyerror
26 #define yyerror calc_error
27 #endif /* yyerror */
29 #ifndef yychar
30 #define yychar calc_char
31 #endif /* yychar */
33 #ifndef yyval
34 #define yyval calc_val
35 #endif /* yyval */
37 #ifndef yylval
38 #define yylval calc_lval
39 #endif /* yylval */
41 #ifndef yydebug
42 #define yydebug calc_debug
43 #endif /* yydebug */
45 #ifndef yynerrs
46 #define yynerrs calc_nerrs
47 #endif /* yynerrs */
49 #ifndef yyerrflag
50 #define yyerrflag calc_errflag
51 #endif /* yyerrflag */
53 #ifndef yylhs
54 #define yylhs calc_lhs
55 #endif /* yylhs */
57 #ifndef yylen
58 #define yylen calc_len
59 #endif /* yylen */
61 #ifndef yydefred
62 #define yydefred calc_defred
63 #endif /* yydefred */
65 #ifndef yydgoto
66 #define yydgoto calc_dgoto
67 #endif /* yydgoto */
69 #ifndef yysindex
70 #define yysindex calc_sindex
71 #endif /* yysindex */
73 #ifndef yyrindex
74 #define yyrindex calc_rindex
75 #endif /* yyrindex */
77 #ifndef yygindex
78 #define yygindex calc_gindex
79 #endif /* yygindex */
81 #ifndef yytable
82 #define yytable calc_table
83 #endif /* yytable */
85 #ifndef yycheck
86 #define yycheck calc_check
87 #endif /* yycheck */
89 #ifndef yyname
90 #define yyname calc_name
91 #endif /* yyname */
93 #ifndef yyrule
94 #define yyrule calc_rule
95 #endif /* yyrule */
96 #define YYPREFIX "calc_"
98 #define YYPURE 1
100 #line 2 "pure_calc.y"
101 # include <stdio.h>
102 # include <ctype.h>
104 int regs[26];
105 int base;
107 #ifdef YYBISON
108 #define YYSTYPE int
109 #define YYLEX_PARAM &yylval
110 #define YYLEX_DECL() yylex(YYSTYPE *yylval)
111 #define YYERROR_DECL() yyerror(const char *s)
112 int YYLEX_DECL();
113 static void YYERROR_DECL();
114 #endif
116 #line 115 "pure_calc.tab.c"
118 #ifndef YYSTYPE
119 typedef int YYSTYPE;
120 #endif
122 /* compatibility with bison */
123 #ifdef YYPARSE_PARAM
124 /* compatibility with FreeBSD */
125 # ifdef YYPARSE_PARAM_TYPE
126 # define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
127 # else
128 # define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
129 # endif
130 #else
131 # define YYPARSE_DECL() yyparse(void)
132 #endif
134 /* Parameters sent to lex. */
135 #ifdef YYLEX_PARAM
136 # ifdef YYLEX_PARAM_TYPE
137 # define YYLEX_DECL() yylex(YYSTYPE *yylval, YYLEX_PARAM_TYPE YYLEX_PARAM)
138 # else
139 # define YYLEX_DECL() yylex(YYSTYPE *yylval, void * YYLEX_PARAM)
140 # endif
141 # define YYLEX yylex(&yylval, YYLEX_PARAM)
142 #else
143 # define YYLEX_DECL() yylex(YYSTYPE *yylval)
144 # define YYLEX yylex(&yylval)
145 #endif
147 /* Parameters sent to yyerror. */
148 #ifndef YYERROR_DECL
149 #define YYERROR_DECL() yyerror(const char *s)
150 #endif
151 #ifndef YYERROR_CALL
152 #define YYERROR_CALL(msg) yyerror(msg)
153 #endif
155 extern int YYPARSE_DECL();
157 #define DIGIT 257
158 #define LETTER 258
159 #define UMINUS 259
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,
173 10, 11,
175 static const short calc_dgoto[] = { 1,
176 7, 8, 9,
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,
182 0, 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,
188 0, 0,
190 static const short calc_gindex[] = { 0,
191 0, 65, 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,
242 #define YYFINAL 1
243 #ifndef YYDEBUG
244 #define YYDEBUG 0
245 #endif
246 #define YYMAXTOKEN 259
247 #if YYDEBUG
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[] = {
260 "$accept : list",
261 "list :",
262 "list : list stat '\\n'",
263 "list : list error '\\n'",
264 "stat : expr",
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",
274 "expr : '-' expr",
275 "expr : LETTER",
276 "expr : number",
277 "number : DIGIT",
278 "number : number DIGIT",
281 #endif
283 int yydebug;
284 int yynerrs;
286 /* define the initial stack-sizes */
287 #ifdef YYSTACKSIZE
288 #undef YYMAXDEPTH
289 #define YYMAXDEPTH YYSTACKSIZE
290 #else
291 #ifdef YYMAXDEPTH
292 #define YYSTACKSIZE YYMAXDEPTH
293 #else
294 #define YYSTACKSIZE 500
295 #define YYMAXDEPTH 500
296 #endif
297 #endif
299 #define YYINITSTACKSIZE 500
301 typedef struct {
302 unsigned stacksize;
303 short *s_base;
304 short *s_mark;
305 short *s_last;
306 YYSTYPE *l_base;
307 YYSTYPE *l_mark;
308 } YYSTACKDATA;
309 #line 72 "pure_calc.y"
310 /* start of programs */
312 #ifdef YYBYACC
313 static int YYLEX_DECL();
314 #endif
317 main (void)
319 while(!feof(stdin)) {
320 yyparse();
322 return 0;
325 static void
326 YYERROR_DECL()
328 fprintf(stderr, "%s\n", s);
332 YYLEX_DECL()
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 */
339 int c;
341 while( (c=getchar()) == ' ' ) { /* skip blanks */ }
343 /* c is now nonblank */
345 if( islower( c )) {
346 *yylval = c - 'a';
347 return ( LETTER );
349 if( isdigit( c )) {
350 *yylval = c - '0';
351 return ( DIGIT );
353 return( c );
355 #line 354 "pure_calc.tab.c"
357 #if YYDEBUG
358 #include <stdio.h> /* needed for printf */
359 #endif
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)
367 int i;
368 unsigned newsize;
369 short *newss;
370 YYSTYPE *newvs;
372 if ((newsize = data->stacksize) == 0)
373 newsize = YYINITSTACKSIZE;
374 else if (newsize >= YYMAXDEPTH)
375 return -1;
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));
381 if (newss == 0)
382 return -1;
384 data->s_base = newss;
385 data->s_mark = newss + i;
387 newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));
388 if (newvs == 0)
389 return -1;
391 data->l_base = newvs;
392 data->l_mark = newvs + i;
394 data->stacksize = newsize;
395 data->s_last = data->s_base + newsize - 1;
396 return 0;
399 #if YYPURE || defined(YY_NO_LEAKS)
400 static void yyfreestack(YYSTACKDATA *data)
402 free(data->s_base);
403 free(data->l_base);
404 memset(data, 0, sizeof(*data));
406 #else
407 #define yyfreestack(data) /* nothing */
408 #endif
410 #define YYABORT goto yyabort
411 #define YYREJECT goto yyabort
412 #define YYACCEPT goto yyaccept
413 #define YYERROR goto yyerrlab
416 YYPARSE_DECL()
418 int yyerrflag;
419 int yychar;
420 YYSTYPE yyval;
421 YYSTYPE yylval;
423 /* variables for the parser stack */
424 YYSTACKDATA yystack;
425 int yym, yyn, yystate;
426 #if YYDEBUG
427 const char *yys;
429 if ((yys = getenv("YYDEBUG")) != 0)
431 yyn = *yys;
432 if (yyn >= '0' && yyn <= '9')
433 yydebug = yyn - '0';
435 #endif
437 yynerrs = 0;
438 yyerrflag = 0;
439 yychar = YYEMPTY;
440 yystate = 0;
442 #if YYPURE
443 memset(&yystack, 0, sizeof(yystack));
444 #endif
446 if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow;
447 yystack.s_mark = yystack.s_base;
448 yystack.l_mark = yystack.l_base;
449 yystate = 0;
450 *yystack.s_mark = 0;
452 yyloop:
453 if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
454 if (yychar < 0)
456 if ((yychar = YYLEX) < 0) yychar = 0;
457 #if YYDEBUG
458 if (yydebug)
460 yys = 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);
466 #endif
468 if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
469 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
471 #if YYDEBUG
472 if (yydebug)
473 printf("%sdebug: state %d, shifting to state %d\n",
474 YYPREFIX, yystate, yytable[yyn]);
475 #endif
476 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
478 goto yyoverflow;
480 yystate = yytable[yyn];
481 *++yystack.s_mark = yytable[yyn];
482 *++yystack.l_mark = yylval;
483 yychar = YYEMPTY;
484 if (yyerrflag > 0) --yyerrflag;
485 goto yyloop;
487 if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
488 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
490 yyn = yytable[yyn];
491 goto yyreduce;
493 if (yyerrflag) goto yyinrecovery;
495 yyerror("syntax error");
497 goto yyerrlab;
499 yyerrlab:
500 ++yynerrs;
502 yyinrecovery:
503 if (yyerrflag < 3)
505 yyerrflag = 3;
506 for (;;)
508 if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 &&
509 yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
511 #if YYDEBUG
512 if (yydebug)
513 printf("%sdebug: state %d, error recovery shifting\
514 to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]);
515 #endif
516 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
518 goto yyoverflow;
520 yystate = yytable[yyn];
521 *++yystack.s_mark = yytable[yyn];
522 *++yystack.l_mark = yylval;
523 goto yyloop;
525 else
527 #if YYDEBUG
528 if (yydebug)
529 printf("%sdebug: error recovery discarding state %d\n",
530 YYPREFIX, *yystack.s_mark);
531 #endif
532 if (yystack.s_mark <= yystack.s_base) goto yyabort;
533 --yystack.s_mark;
534 --yystack.l_mark;
538 else
540 if (yychar == 0) goto yyabort;
541 #if YYDEBUG
542 if (yydebug)
544 yys = 0;
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);
550 #endif
551 yychar = YYEMPTY;
552 goto yyloop;
555 yyreduce:
556 #if YYDEBUG
557 if (yydebug)
558 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
559 YYPREFIX, yystate, yyn, yyrule[yyn]);
560 #endif
561 yym = yylen[yyn];
562 if (yym)
563 yyval = yystack.l_mark[1-yym];
564 else
565 memset(&yyval, 0, sizeof yyval);
566 switch (yyn)
568 case 3:
569 #line 34 "pure_calc.y"
570 { yyerrok ; }
571 break;
572 case 4:
573 #line 38 "pure_calc.y"
574 { printf("%d\n",yystack.l_mark[0]);}
575 break;
576 case 5:
577 #line 40 "pure_calc.y"
578 { regs[yystack.l_mark[-2]] = yystack.l_mark[0]; }
579 break;
580 case 6:
581 #line 44 "pure_calc.y"
582 { yyval = yystack.l_mark[-1]; }
583 break;
584 case 7:
585 #line 46 "pure_calc.y"
586 { yyval = yystack.l_mark[-2] + yystack.l_mark[0]; }
587 break;
588 case 8:
589 #line 48 "pure_calc.y"
590 { yyval = yystack.l_mark[-2] - yystack.l_mark[0]; }
591 break;
592 case 9:
593 #line 50 "pure_calc.y"
594 { yyval = yystack.l_mark[-2] * yystack.l_mark[0]; }
595 break;
596 case 10:
597 #line 52 "pure_calc.y"
598 { yyval = yystack.l_mark[-2] / yystack.l_mark[0]; }
599 break;
600 case 11:
601 #line 54 "pure_calc.y"
602 { yyval = yystack.l_mark[-2] % yystack.l_mark[0]; }
603 break;
604 case 12:
605 #line 56 "pure_calc.y"
606 { yyval = yystack.l_mark[-2] & yystack.l_mark[0]; }
607 break;
608 case 13:
609 #line 58 "pure_calc.y"
610 { yyval = yystack.l_mark[-2] | yystack.l_mark[0]; }
611 break;
612 case 14:
613 #line 60 "pure_calc.y"
614 { yyval = - yystack.l_mark[0]; }
615 break;
616 case 15:
617 #line 62 "pure_calc.y"
618 { yyval = regs[yystack.l_mark[0]]; }
619 break;
620 case 17:
621 #line 67 "pure_calc.y"
622 { yyval = yystack.l_mark[0]; base = (yystack.l_mark[0]==0) ? 8 : 10; }
623 break;
624 case 18:
625 #line 69 "pure_calc.y"
626 { yyval = base * yystack.l_mark[-1] + yystack.l_mark[0]; }
627 break;
628 #line 627 "pure_calc.tab.c"
630 yystack.s_mark -= yym;
631 yystate = *yystack.s_mark;
632 yystack.l_mark -= yym;
633 yym = yylhs[yyn];
634 if (yystate == 0 && yym == 0)
636 #if YYDEBUG
637 if (yydebug)
638 printf("%sdebug: after reduction, shifting from state 0 to\
639 state %d\n", YYPREFIX, YYFINAL);
640 #endif
641 yystate = YYFINAL;
642 *++yystack.s_mark = YYFINAL;
643 *++yystack.l_mark = yyval;
644 if (yychar < 0)
646 if ((yychar = YYLEX) < 0) yychar = 0;
647 #if YYDEBUG
648 if (yydebug)
650 yys = 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);
656 #endif
658 if (yychar == 0) goto yyaccept;
659 goto yyloop;
661 if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
662 yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
663 yystate = yytable[yyn];
664 else
665 yystate = yydgoto[yym];
666 #if YYDEBUG
667 if (yydebug)
668 printf("%sdebug: after reduction, shifting from state %d \
669 to state %d\n", YYPREFIX, *yystack.s_mark, yystate);
670 #endif
671 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
673 goto yyoverflow;
675 *++yystack.s_mark = (short) yystate;
676 *++yystack.l_mark = yyval;
677 goto yyloop;
679 yyoverflow:
680 yyerror("yacc stack overflow");
682 yyabort:
683 yyfreestack(&yystack);
684 return (1);
686 yyaccept:
687 yyfreestack(&yystack);
688 return (0);