tools/llvm: Do not build with symbols
[minix3.git] / external / bsd / byacc / dist / test / calc2.tab.c
blob21c2984c0e013cba98e3a5eb93ee68bf24a418b9
1 /* $NetBSD: calc2.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 calc2_parse
19 #endif /* yyparse */
21 #ifndef yylex
22 #define yylex calc2_lex
23 #endif /* yylex */
25 #ifndef yyerror
26 #define yyerror calc2_error
27 #endif /* yyerror */
29 #ifndef yychar
30 #define yychar calc2_char
31 #endif /* yychar */
33 #ifndef yyval
34 #define yyval calc2_val
35 #endif /* yyval */
37 #ifndef yylval
38 #define yylval calc2_lval
39 #endif /* yylval */
41 #ifndef yydebug
42 #define yydebug calc2_debug
43 #endif /* yydebug */
45 #ifndef yynerrs
46 #define yynerrs calc2_nerrs
47 #endif /* yynerrs */
49 #ifndef yyerrflag
50 #define yyerrflag calc2_errflag
51 #endif /* yyerrflag */
53 #ifndef yylhs
54 #define yylhs calc2_lhs
55 #endif /* yylhs */
57 #ifndef yylen
58 #define yylen calc2_len
59 #endif /* yylen */
61 #ifndef yydefred
62 #define yydefred calc2_defred
63 #endif /* yydefred */
65 #ifndef yydgoto
66 #define yydgoto calc2_dgoto
67 #endif /* yydgoto */
69 #ifndef yysindex
70 #define yysindex calc2_sindex
71 #endif /* yysindex */
73 #ifndef yyrindex
74 #define yyrindex calc2_rindex
75 #endif /* yyrindex */
77 #ifndef yygindex
78 #define yygindex calc2_gindex
79 #endif /* yygindex */
81 #ifndef yytable
82 #define yytable calc2_table
83 #endif /* yytable */
85 #ifndef yycheck
86 #define yycheck calc2_check
87 #endif /* yycheck */
89 #ifndef yyname
90 #define yyname calc2_name
91 #endif /* yyname */
93 #ifndef yyrule
94 #define yyrule calc2_rule
95 #endif /* yyrule */
96 #define YYPREFIX "calc2_"
98 #define YYPURE 0
100 #line 7 "calc2.y"
101 # include <stdio.h>
102 # include <ctype.h>
104 #ifdef YYBISON
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)
108 int YYLEX_DECL();
109 static void YYERROR_DECL();
110 #endif
112 #line 111 "calc2.tab.c"
114 #ifndef YYSTYPE
115 typedef int YYSTYPE;
116 #endif
118 /* compatibility with bison */
119 #ifdef YYPARSE_PARAM
120 /* compatibility with FreeBSD */
121 # ifdef YYPARSE_PARAM_TYPE
122 # define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
123 # else
124 # define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
125 # endif
126 #else
127 # define YYPARSE_DECL() yyparse(int regs[26], int * base)
128 #endif
130 /* Parameters sent to lex. */
131 #ifdef YYLEX_PARAM
132 # define YYLEX_DECL() yylex(void *YYLEX_PARAM)
133 # define YYLEX yylex(YYLEX_PARAM)
134 #else
135 # define YYLEX_DECL() yylex(int * base)
136 # define YYLEX yylex(base)
137 #endif
139 /* Parameters sent to yyerror. */
140 #ifndef YYERROR_DECL
141 #define YYERROR_DECL() yyerror(int regs[26], int * base, const char *s)
142 #endif
143 #ifndef YYERROR_CALL
144 #define YYERROR_CALL(msg) yyerror(regs, base, msg)
145 #endif
147 extern int YYPARSE_DECL();
149 #define DIGIT 257
150 #define LETTER 258
151 #define UMINUS 259
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,
165 10, 11,
167 static const short calc2_dgoto[] = { 1,
168 7, 8, 9,
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,
174 0, 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,
180 0, 0,
182 static const short calc2_gindex[] = { 0,
183 0, 65, 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,
234 #define YYFINAL 1
235 #ifndef YYDEBUG
236 #define YYDEBUG 0
237 #endif
238 #define YYMAXTOKEN 259
239 #if YYDEBUG
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[] = {
252 "$accept : list",
253 "list :",
254 "list : list stat '\\n'",
255 "list : list error '\\n'",
256 "stat : expr",
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",
266 "expr : '-' expr",
267 "expr : LETTER",
268 "expr : number",
269 "number : DIGIT",
270 "number : number DIGIT",
273 #endif
275 int yydebug;
276 int yynerrs;
278 int yyerrflag;
279 int yychar;
280 YYSTYPE yyval;
281 YYSTYPE yylval;
283 /* define the initial stack-sizes */
284 #ifdef YYSTACKSIZE
285 #undef YYMAXDEPTH
286 #define YYMAXDEPTH YYSTACKSIZE
287 #else
288 #ifdef YYMAXDEPTH
289 #define YYSTACKSIZE YYMAXDEPTH
290 #else
291 #define YYSTACKSIZE 500
292 #define YYMAXDEPTH 500
293 #endif
294 #endif
296 #define YYINITSTACKSIZE 500
298 typedef struct {
299 unsigned stacksize;
300 short *s_base;
301 short *s_mark;
302 short *s_last;
303 YYSTYPE *l_base;
304 YYSTYPE *l_mark;
305 } YYSTACKDATA;
306 /* variables for the parser stack */
307 static YYSTACKDATA yystack;
308 #line 73 "calc2.y"
309 /* start of programs */
311 #ifdef YYBYACC
312 extern int YYLEX_DECL();
313 #endif
316 main (void)
318 int regs[26];
319 int base = 10;
321 while(!feof(stdin)) {
322 yyparse(regs, &base);
324 return 0;
327 static void
328 YYERROR_DECL()
330 fprintf(stderr, "%s\n", s);
334 YYLEX_DECL()
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 */
341 int c;
343 while( (c=getchar()) == ' ' ) { /* skip blanks */ }
345 /* c is now nonblank */
347 if( islower( c )) {
348 yylval = c - 'a';
349 return ( LETTER );
351 if( isdigit( c )) {
352 yylval = (c - '0') % (*base);
353 return ( DIGIT );
355 return( c );
357 #line 356 "calc2.tab.c"
359 #if YYDEBUG
360 #include <stdio.h> /* needed for printf */
361 #endif
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)
369 int i;
370 unsigned newsize;
371 short *newss;
372 YYSTYPE *newvs;
374 if ((newsize = data->stacksize) == 0)
375 newsize = YYINITSTACKSIZE;
376 else if (newsize >= YYMAXDEPTH)
377 return -1;
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));
383 if (newss == 0)
384 return -1;
386 data->s_base = newss;
387 data->s_mark = newss + i;
389 newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));
390 if (newvs == 0)
391 return -1;
393 data->l_base = newvs;
394 data->l_mark = newvs + i;
396 data->stacksize = newsize;
397 data->s_last = data->s_base + newsize - 1;
398 return 0;
401 #if YYPURE || defined(YY_NO_LEAKS)
402 static void yyfreestack(YYSTACKDATA *data)
404 free(data->s_base);
405 free(data->l_base);
406 memset(data, 0, sizeof(*data));
408 #else
409 #define yyfreestack(data) /* nothing */
410 #endif
412 #define YYABORT goto yyabort
413 #define YYREJECT goto yyabort
414 #define YYACCEPT goto yyaccept
415 #define YYERROR goto yyerrlab
418 YYPARSE_DECL()
420 int yym, yyn, yystate;
421 #if YYDEBUG
422 const char *yys;
424 if ((yys = getenv("YYDEBUG")) != 0)
426 yyn = *yys;
427 if (yyn >= '0' && yyn <= '9')
428 yydebug = yyn - '0';
430 #endif
432 yynerrs = 0;
433 yyerrflag = 0;
434 yychar = YYEMPTY;
435 yystate = 0;
437 #if YYPURE
438 memset(&yystack, 0, sizeof(yystack));
439 #endif
441 if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow;
442 yystack.s_mark = yystack.s_base;
443 yystack.l_mark = yystack.l_base;
444 yystate = 0;
445 *yystack.s_mark = 0;
447 yyloop:
448 if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
449 if (yychar < 0)
451 if ((yychar = YYLEX) < 0) yychar = 0;
452 #if YYDEBUG
453 if (yydebug)
455 yys = 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);
461 #endif
463 if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
464 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
466 #if YYDEBUG
467 if (yydebug)
468 printf("%sdebug: state %d, shifting to state %d\n",
469 YYPREFIX, yystate, yytable[yyn]);
470 #endif
471 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
473 goto yyoverflow;
475 yystate = yytable[yyn];
476 *++yystack.s_mark = yytable[yyn];
477 *++yystack.l_mark = yylval;
478 yychar = YYEMPTY;
479 if (yyerrflag > 0) --yyerrflag;
480 goto yyloop;
482 if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
483 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
485 yyn = yytable[yyn];
486 goto yyreduce;
488 if (yyerrflag) goto yyinrecovery;
490 yyerror(regs, base, "syntax error");
492 goto yyerrlab;
494 yyerrlab:
495 ++yynerrs;
497 yyinrecovery:
498 if (yyerrflag < 3)
500 yyerrflag = 3;
501 for (;;)
503 if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 &&
504 yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
506 #if YYDEBUG
507 if (yydebug)
508 printf("%sdebug: state %d, error recovery shifting\
509 to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]);
510 #endif
511 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
513 goto yyoverflow;
515 yystate = yytable[yyn];
516 *++yystack.s_mark = yytable[yyn];
517 *++yystack.l_mark = yylval;
518 goto yyloop;
520 else
522 #if YYDEBUG
523 if (yydebug)
524 printf("%sdebug: error recovery discarding state %d\n",
525 YYPREFIX, *yystack.s_mark);
526 #endif
527 if (yystack.s_mark <= yystack.s_base) goto yyabort;
528 --yystack.s_mark;
529 --yystack.l_mark;
533 else
535 if (yychar == 0) goto yyabort;
536 #if YYDEBUG
537 if (yydebug)
539 yys = 0;
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);
545 #endif
546 yychar = YYEMPTY;
547 goto yyloop;
550 yyreduce:
551 #if YYDEBUG
552 if (yydebug)
553 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
554 YYPREFIX, yystate, yyn, yyrule[yyn]);
555 #endif
556 yym = yylen[yyn];
557 if (yym)
558 yyval = yystack.l_mark[1-yym];
559 else
560 memset(&yyval, 0, sizeof yyval);
561 switch (yyn)
563 case 3:
564 #line 35 "calc2.y"
565 { yyerrok ; }
566 break;
567 case 4:
568 #line 39 "calc2.y"
569 { printf("%d\n",yystack.l_mark[0]);}
570 break;
571 case 5:
572 #line 41 "calc2.y"
573 { regs[yystack.l_mark[-2]] = yystack.l_mark[0]; }
574 break;
575 case 6:
576 #line 45 "calc2.y"
577 { yyval = yystack.l_mark[-1]; }
578 break;
579 case 7:
580 #line 47 "calc2.y"
581 { yyval = yystack.l_mark[-2] + yystack.l_mark[0]; }
582 break;
583 case 8:
584 #line 49 "calc2.y"
585 { yyval = yystack.l_mark[-2] - yystack.l_mark[0]; }
586 break;
587 case 9:
588 #line 51 "calc2.y"
589 { yyval = yystack.l_mark[-2] * yystack.l_mark[0]; }
590 break;
591 case 10:
592 #line 53 "calc2.y"
593 { yyval = yystack.l_mark[-2] / yystack.l_mark[0]; }
594 break;
595 case 11:
596 #line 55 "calc2.y"
597 { yyval = yystack.l_mark[-2] % yystack.l_mark[0]; }
598 break;
599 case 12:
600 #line 57 "calc2.y"
601 { yyval = yystack.l_mark[-2] & yystack.l_mark[0]; }
602 break;
603 case 13:
604 #line 59 "calc2.y"
605 { yyval = yystack.l_mark[-2] | yystack.l_mark[0]; }
606 break;
607 case 14:
608 #line 61 "calc2.y"
609 { yyval = - yystack.l_mark[0]; }
610 break;
611 case 15:
612 #line 63 "calc2.y"
613 { yyval = regs[yystack.l_mark[0]]; }
614 break;
615 case 17:
616 #line 68 "calc2.y"
617 { yyval = yystack.l_mark[0]; (*base) = (yystack.l_mark[0]==0) ? 8 : 10; }
618 break;
619 case 18:
620 #line 70 "calc2.y"
621 { yyval = (*base) * yystack.l_mark[-1] + yystack.l_mark[0]; }
622 break;
623 #line 622 "calc2.tab.c"
625 yystack.s_mark -= yym;
626 yystate = *yystack.s_mark;
627 yystack.l_mark -= yym;
628 yym = yylhs[yyn];
629 if (yystate == 0 && yym == 0)
631 #if YYDEBUG
632 if (yydebug)
633 printf("%sdebug: after reduction, shifting from state 0 to\
634 state %d\n", YYPREFIX, YYFINAL);
635 #endif
636 yystate = YYFINAL;
637 *++yystack.s_mark = YYFINAL;
638 *++yystack.l_mark = yyval;
639 if (yychar < 0)
641 if ((yychar = YYLEX) < 0) yychar = 0;
642 #if YYDEBUG
643 if (yydebug)
645 yys = 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);
651 #endif
653 if (yychar == 0) goto yyaccept;
654 goto yyloop;
656 if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
657 yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
658 yystate = yytable[yyn];
659 else
660 yystate = yydgoto[yym];
661 #if YYDEBUG
662 if (yydebug)
663 printf("%sdebug: after reduction, shifting from state %d \
664 to state %d\n", YYPREFIX, *yystack.s_mark, yystate);
665 #endif
666 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
668 goto yyoverflow;
670 *++yystack.s_mark = (short) yystate;
671 *++yystack.l_mark = yyval;
672 goto yyloop;
674 yyoverflow:
675 yyerror(regs, base, "yacc stack overflow");
677 yyabort:
678 yyfreestack(&yystack);
679 return (1);
681 yyaccept:
682 yyfreestack(&yystack);
683 return (0);