tools/llvm: Do not build with symbols
[minix3.git] / external / bsd / byacc / dist / test / calc.tab.c
blobe166639778ecc0a3a6f6a14d5c45180da9eff698
1 /* $NetBSD: calc.tab.c,v 1.1.1.5 2013/04/06 14:45:27 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 0
100 #line 2 "calc.y"
101 # include <stdio.h>
102 # include <ctype.h>
104 int regs[26];
105 int base;
107 extern int yylex(void);
108 static void yyerror(const char *s);
110 #line 109 "calc.tab.c"
112 #ifndef YYSTYPE
113 typedef int YYSTYPE;
114 #endif
116 /* compatibility with bison */
117 #ifdef YYPARSE_PARAM
118 /* compatibility with FreeBSD */
119 # ifdef YYPARSE_PARAM_TYPE
120 # define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
121 # else
122 # define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
123 # endif
124 #else
125 # define YYPARSE_DECL() yyparse(void)
126 #endif
128 /* Parameters sent to lex. */
129 #ifdef YYLEX_PARAM
130 # define YYLEX_DECL() yylex(void *YYLEX_PARAM)
131 # define YYLEX yylex(YYLEX_PARAM)
132 #else
133 # define YYLEX_DECL() yylex(void)
134 # define YYLEX yylex()
135 #endif
137 /* Parameters sent to yyerror. */
138 #ifndef YYERROR_DECL
139 #define YYERROR_DECL() yyerror(const char *s)
140 #endif
141 #ifndef YYERROR_CALL
142 #define YYERROR_CALL(msg) yyerror(msg)
143 #endif
145 extern int YYPARSE_DECL();
147 #define DIGIT 257
148 #define LETTER 258
149 #define UMINUS 259
150 #define YYERRCODE 256
151 static const short calc_lhs[] = { -1,
152 0, 0, 0, 1, 1, 2, 2, 2, 2, 2,
153 2, 2, 2, 2, 2, 2, 3, 3,
155 static const short calc_len[] = { 2,
156 0, 3, 3, 1, 3, 3, 3, 3, 3, 3,
157 3, 3, 3, 2, 1, 1, 1, 2,
159 static const short calc_defred[] = { 1,
160 0, 0, 17, 0, 0, 0, 0, 0, 0, 3,
161 0, 15, 14, 0, 2, 0, 0, 0, 0, 0,
162 0, 0, 18, 0, 6, 0, 0, 0, 0, 9,
163 10, 11,
165 static const short calc_dgoto[] = { 1,
166 7, 8, 9,
168 static const short calc_sindex[] = { 0,
169 -40, -7, 0, -55, -38, -38, 1, -29, -247, 0,
170 -38, 0, 0, 22, 0, -38, -38, -38, -38, -38,
171 -38, -38, 0, -29, 0, 51, 60, -20, -20, 0,
172 0, 0,
174 static const short calc_rindex[] = { 0,
175 0, 0, 0, 2, 0, 0, 0, 9, -9, 0,
176 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
177 0, 0, 0, 10, 0, -6, 14, 5, 13, 0,
178 0, 0,
180 static const short calc_gindex[] = { 0,
181 0, 65, 0,
183 #define YYTABLESIZE 220
184 static const short calc_table[] = { 6,
185 16, 6, 10, 13, 5, 11, 5, 22, 17, 23,
186 15, 15, 20, 18, 7, 19, 22, 21, 4, 5,
187 0, 20, 8, 12, 0, 0, 21, 16, 16, 0,
188 0, 16, 16, 16, 13, 16, 0, 16, 15, 15,
189 0, 0, 7, 15, 15, 7, 15, 7, 15, 7,
190 8, 12, 0, 8, 12, 8, 0, 8, 22, 17,
191 0, 0, 25, 20, 18, 0, 19, 0, 21, 13,
192 14, 0, 0, 0, 0, 24, 0, 0, 0, 0,
193 26, 27, 28, 29, 30, 31, 32, 22, 17, 0,
194 0, 0, 20, 18, 16, 19, 22, 21, 0, 0,
195 0, 20, 18, 0, 19, 0, 21, 0, 0, 0,
196 0, 0, 0, 0, 16, 0, 0, 13, 0, 0,
197 0, 0, 0, 0, 0, 15, 0, 0, 7, 0,
198 0, 0, 0, 0, 0, 0, 8, 12, 0, 0,
199 0, 0, 0, 0, 0, 16, 0, 0, 0, 0,
200 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
201 0, 0, 0, 0, 0, 0, 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, 2, 3, 4, 3, 12,
208 static const short calc_check[] = { 40,
209 10, 40, 10, 10, 45, 61, 45, 37, 38, 257,
210 10, 10, 42, 43, 10, 45, 37, 47, 10, 10,
211 -1, 42, 10, 10, -1, -1, 47, 37, 38, -1,
212 -1, 41, 42, 43, 41, 45, -1, 47, 37, 38,
213 -1, -1, 38, 42, 43, 41, 45, 43, 47, 45,
214 38, 38, -1, 41, 41, 43, -1, 45, 37, 38,
215 -1, -1, 41, 42, 43, -1, 45, -1, 47, 5,
216 6, -1, -1, -1, -1, 11, -1, -1, -1, -1,
217 16, 17, 18, 19, 20, 21, 22, 37, 38, -1,
218 -1, -1, 42, 43, 124, 45, 37, 47, -1, -1,
219 -1, 42, 43, -1, 45, -1, 47, -1, -1, -1,
220 -1, -1, -1, -1, 124, -1, -1, 124, -1, -1,
221 -1, -1, -1, -1, -1, 124, -1, -1, 124, -1,
222 -1, -1, -1, -1, -1, -1, 124, 124, -1, -1,
223 -1, -1, -1, -1, -1, 124, -1, -1, -1, -1,
224 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
225 -1, -1, -1, -1, -1, -1, -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, 256, 257, 258, 257, 258,
232 #define YYFINAL 1
233 #ifndef YYDEBUG
234 #define YYDEBUG 0
235 #endif
236 #define YYMAXTOKEN 259
237 #if YYDEBUG
238 static const char *yyname[] = {
240 "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,
241 0,0,0,0,0,0,"'%'","'&'",0,"'('","')'","'*'","'+'",0,"'-'",0,"'/'",0,0,0,0,0,0,0,
242 0,0,0,0,0,0,"'='",0,0,0,0,0,0,0,0,0,0,0,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,0,0,0,0,0,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,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,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,"DIGIT","LETTER","UMINUS",
249 static const char *yyrule[] = {
250 "$accept : list",
251 "list :",
252 "list : list stat '\\n'",
253 "list : list error '\\n'",
254 "stat : expr",
255 "stat : LETTER '=' expr",
256 "expr : '(' expr ')'",
257 "expr : expr '+' expr",
258 "expr : 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",
265 "expr : LETTER",
266 "expr : number",
267 "number : DIGIT",
268 "number : number DIGIT",
271 #endif
273 int yydebug;
274 int yynerrs;
276 int yyerrflag;
277 int yychar;
278 YYSTYPE yyval;
279 YYSTYPE yylval;
281 /* define the initial stack-sizes */
282 #ifdef YYSTACKSIZE
283 #undef YYMAXDEPTH
284 #define YYMAXDEPTH YYSTACKSIZE
285 #else
286 #ifdef YYMAXDEPTH
287 #define YYSTACKSIZE YYMAXDEPTH
288 #else
289 #define YYSTACKSIZE 500
290 #define YYMAXDEPTH 500
291 #endif
292 #endif
294 #define YYINITSTACKSIZE 500
296 typedef struct {
297 unsigned stacksize;
298 short *s_base;
299 short *s_mark;
300 short *s_last;
301 YYSTYPE *l_base;
302 YYSTYPE *l_mark;
303 } YYSTACKDATA;
304 /* variables for the parser stack */
305 static YYSTACKDATA yystack;
306 #line 66 "calc.y"
307 /* start of programs */
310 main (void)
312 while(!feof(stdin)) {
313 yyparse();
315 return 0;
318 static void
319 yyerror(const char *s)
321 fprintf(stderr, "%s\n", s);
325 yylex(void)
327 /* lexical analysis routine */
328 /* returns LETTER for a lower case letter, yylval = 0 through 25 */
329 /* return DIGIT for a digit, yylval = 0 through 9 */
330 /* all other characters are returned immediately */
332 int c;
334 while( (c=getchar()) == ' ' ) { /* skip blanks */ }
336 /* c is now nonblank */
338 if( islower( c )) {
339 yylval = c - 'a';
340 return ( LETTER );
342 if( isdigit( c )) {
343 yylval = c - '0';
344 return ( DIGIT );
346 return( c );
348 #line 347 "calc.tab.c"
350 #if YYDEBUG
351 #include <stdio.h> /* needed for printf */
352 #endif
354 #include <stdlib.h> /* needed for malloc, etc */
355 #include <string.h> /* needed for memset */
357 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
358 static int yygrowstack(YYSTACKDATA *data)
360 int i;
361 unsigned newsize;
362 short *newss;
363 YYSTYPE *newvs;
365 if ((newsize = data->stacksize) == 0)
366 newsize = YYINITSTACKSIZE;
367 else if (newsize >= YYMAXDEPTH)
368 return -1;
369 else if ((newsize *= 2) > YYMAXDEPTH)
370 newsize = YYMAXDEPTH;
372 i = (int) (data->s_mark - data->s_base);
373 newss = (short *)realloc(data->s_base, newsize * sizeof(*newss));
374 if (newss == 0)
375 return -1;
377 data->s_base = newss;
378 data->s_mark = newss + i;
380 newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));
381 if (newvs == 0)
382 return -1;
384 data->l_base = newvs;
385 data->l_mark = newvs + i;
387 data->stacksize = newsize;
388 data->s_last = data->s_base + newsize - 1;
389 return 0;
392 #if YYPURE || defined(YY_NO_LEAKS)
393 static void yyfreestack(YYSTACKDATA *data)
395 free(data->s_base);
396 free(data->l_base);
397 memset(data, 0, sizeof(*data));
399 #else
400 #define yyfreestack(data) /* nothing */
401 #endif
403 #define YYABORT goto yyabort
404 #define YYREJECT goto yyabort
405 #define YYACCEPT goto yyaccept
406 #define YYERROR goto yyerrlab
409 YYPARSE_DECL()
411 int yym, yyn, yystate;
412 #if YYDEBUG
413 const char *yys;
415 if ((yys = getenv("YYDEBUG")) != 0)
417 yyn = *yys;
418 if (yyn >= '0' && yyn <= '9')
419 yydebug = yyn - '0';
421 #endif
423 yynerrs = 0;
424 yyerrflag = 0;
425 yychar = YYEMPTY;
426 yystate = 0;
428 #if YYPURE
429 memset(&yystack, 0, sizeof(yystack));
430 #endif
432 if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow;
433 yystack.s_mark = yystack.s_base;
434 yystack.l_mark = yystack.l_base;
435 yystate = 0;
436 *yystack.s_mark = 0;
438 yyloop:
439 if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
440 if (yychar < 0)
442 if ((yychar = YYLEX) < 0) yychar = 0;
443 #if YYDEBUG
444 if (yydebug)
446 yys = 0;
447 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
448 if (!yys) yys = "illegal-symbol";
449 printf("%sdebug: state %d, reading %d (%s)\n",
450 YYPREFIX, yystate, yychar, yys);
452 #endif
454 if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
455 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
457 #if YYDEBUG
458 if (yydebug)
459 printf("%sdebug: state %d, shifting to state %d\n",
460 YYPREFIX, yystate, yytable[yyn]);
461 #endif
462 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
464 goto yyoverflow;
466 yystate = yytable[yyn];
467 *++yystack.s_mark = yytable[yyn];
468 *++yystack.l_mark = yylval;
469 yychar = YYEMPTY;
470 if (yyerrflag > 0) --yyerrflag;
471 goto yyloop;
473 if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
474 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
476 yyn = yytable[yyn];
477 goto yyreduce;
479 if (yyerrflag) goto yyinrecovery;
481 yyerror("syntax error");
483 goto yyerrlab;
485 yyerrlab:
486 ++yynerrs;
488 yyinrecovery:
489 if (yyerrflag < 3)
491 yyerrflag = 3;
492 for (;;)
494 if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 &&
495 yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
497 #if YYDEBUG
498 if (yydebug)
499 printf("%sdebug: state %d, error recovery shifting\
500 to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]);
501 #endif
502 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
504 goto yyoverflow;
506 yystate = yytable[yyn];
507 *++yystack.s_mark = yytable[yyn];
508 *++yystack.l_mark = yylval;
509 goto yyloop;
511 else
513 #if YYDEBUG
514 if (yydebug)
515 printf("%sdebug: error recovery discarding state %d\n",
516 YYPREFIX, *yystack.s_mark);
517 #endif
518 if (yystack.s_mark <= yystack.s_base) goto yyabort;
519 --yystack.s_mark;
520 --yystack.l_mark;
524 else
526 if (yychar == 0) goto yyabort;
527 #if YYDEBUG
528 if (yydebug)
530 yys = 0;
531 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
532 if (!yys) yys = "illegal-symbol";
533 printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
534 YYPREFIX, yystate, yychar, yys);
536 #endif
537 yychar = YYEMPTY;
538 goto yyloop;
541 yyreduce:
542 #if YYDEBUG
543 if (yydebug)
544 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
545 YYPREFIX, yystate, yyn, yyrule[yyn]);
546 #endif
547 yym = yylen[yyn];
548 if (yym)
549 yyval = yystack.l_mark[1-yym];
550 else
551 memset(&yyval, 0, sizeof yyval);
552 switch (yyn)
554 case 3:
555 #line 28 "calc.y"
556 { yyerrok ; }
557 break;
558 case 4:
559 #line 32 "calc.y"
560 { printf("%d\n",yystack.l_mark[0]);}
561 break;
562 case 5:
563 #line 34 "calc.y"
564 { regs[yystack.l_mark[-2]] = yystack.l_mark[0]; }
565 break;
566 case 6:
567 #line 38 "calc.y"
568 { yyval = yystack.l_mark[-1]; }
569 break;
570 case 7:
571 #line 40 "calc.y"
572 { yyval = yystack.l_mark[-2] + yystack.l_mark[0]; }
573 break;
574 case 8:
575 #line 42 "calc.y"
576 { yyval = yystack.l_mark[-2] - yystack.l_mark[0]; }
577 break;
578 case 9:
579 #line 44 "calc.y"
580 { yyval = yystack.l_mark[-2] * yystack.l_mark[0]; }
581 break;
582 case 10:
583 #line 46 "calc.y"
584 { yyval = yystack.l_mark[-2] / yystack.l_mark[0]; }
585 break;
586 case 11:
587 #line 48 "calc.y"
588 { yyval = yystack.l_mark[-2] % yystack.l_mark[0]; }
589 break;
590 case 12:
591 #line 50 "calc.y"
592 { yyval = yystack.l_mark[-2] & yystack.l_mark[0]; }
593 break;
594 case 13:
595 #line 52 "calc.y"
596 { yyval = yystack.l_mark[-2] | yystack.l_mark[0]; }
597 break;
598 case 14:
599 #line 54 "calc.y"
600 { yyval = - yystack.l_mark[0]; }
601 break;
602 case 15:
603 #line 56 "calc.y"
604 { yyval = regs[yystack.l_mark[0]]; }
605 break;
606 case 17:
607 #line 61 "calc.y"
608 { yyval = yystack.l_mark[0]; base = (yystack.l_mark[0]==0) ? 8 : 10; }
609 break;
610 case 18:
611 #line 63 "calc.y"
612 { yyval = base * yystack.l_mark[-1] + yystack.l_mark[0]; }
613 break;
614 #line 613 "calc.tab.c"
616 yystack.s_mark -= yym;
617 yystate = *yystack.s_mark;
618 yystack.l_mark -= yym;
619 yym = yylhs[yyn];
620 if (yystate == 0 && yym == 0)
622 #if YYDEBUG
623 if (yydebug)
624 printf("%sdebug: after reduction, shifting from state 0 to\
625 state %d\n", YYPREFIX, YYFINAL);
626 #endif
627 yystate = YYFINAL;
628 *++yystack.s_mark = YYFINAL;
629 *++yystack.l_mark = yyval;
630 if (yychar < 0)
632 if ((yychar = YYLEX) < 0) yychar = 0;
633 #if YYDEBUG
634 if (yydebug)
636 yys = 0;
637 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
638 if (!yys) yys = "illegal-symbol";
639 printf("%sdebug: state %d, reading %d (%s)\n",
640 YYPREFIX, YYFINAL, yychar, yys);
642 #endif
644 if (yychar == 0) goto yyaccept;
645 goto yyloop;
647 if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
648 yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
649 yystate = yytable[yyn];
650 else
651 yystate = yydgoto[yym];
652 #if YYDEBUG
653 if (yydebug)
654 printf("%sdebug: after reduction, shifting from state %d \
655 to state %d\n", YYPREFIX, *yystack.s_mark, yystate);
656 #endif
657 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
659 goto yyoverflow;
661 *++yystack.s_mark = (short) yystate;
662 *++yystack.l_mark = yyval;
663 goto yyloop;
665 yyoverflow:
666 yyerror("yacc stack overflow");
668 yyabort:
669 yyfreestack(&yystack);
670 return (1);
672 yyaccept:
673 yyfreestack(&yystack);
674 return (0);