tools/llvm: Do not build with symbols
[minix3.git] / external / bsd / byacc / dist / test / code_calc.code.c
blobc8820a5fb44cae79cf10603fca07dd2198adc366
1 /* $NetBSD: code_calc.code.c,v 1.1.1.4 2013/04/06 14:45:29 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 #define YYPURE 0
19 #line 2 "code_calc.y"
20 # include <stdio.h>
21 # include <ctype.h>
23 int regs[26];
24 int base;
26 #ifdef YYBISON
27 int yylex(void);
28 static void yyerror(const char *s);
29 #endif
31 #line 30 "code_calc.code.c"
33 #ifndef YYSTYPE
34 typedef int YYSTYPE;
35 #endif
37 /* compatibility with bison */
38 #ifdef YYPARSE_PARAM
39 /* compatibility with FreeBSD */
40 # ifdef YYPARSE_PARAM_TYPE
41 # define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
42 # else
43 # define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
44 # endif
45 #else
46 # define YYPARSE_DECL() yyparse(void)
47 #endif
49 /* Parameters sent to lex. */
50 #ifdef YYLEX_PARAM
51 # define YYLEX_DECL() yylex(void *YYLEX_PARAM)
52 # define YYLEX yylex(YYLEX_PARAM)
53 #else
54 # define YYLEX_DECL() yylex(void)
55 # define YYLEX yylex()
56 #endif
58 /* Parameters sent to yyerror. */
59 #ifndef YYERROR_DECL
60 #define YYERROR_DECL() yyerror(const char *s)
61 #endif
62 #ifndef YYERROR_CALL
63 #define YYERROR_CALL(msg) yyerror(msg)
64 #endif
66 extern int YYPARSE_DECL();
68 #define DIGIT 257
69 #define LETTER 258
70 #define UMINUS 259
71 #define YYERRCODE 256
72 #define YYTABLESIZE 220
73 #define YYFINAL 1
74 #ifndef YYDEBUG
75 #define YYDEBUG 0
76 #endif
77 #define YYMAXTOKEN 259
79 #ifndef yyparse
80 #define yyparse calc_parse
81 #endif /* yyparse */
83 #ifndef yylex
84 #define yylex calc_lex
85 #endif /* yylex */
87 #ifndef yyerror
88 #define yyerror calc_error
89 #endif /* yyerror */
91 #ifndef yychar
92 #define yychar calc_char
93 #endif /* yychar */
95 #ifndef yyval
96 #define yyval calc_val
97 #endif /* yyval */
99 #ifndef yylval
100 #define yylval calc_lval
101 #endif /* yylval */
103 #ifndef yydebug
104 #define yydebug calc_debug
105 #endif /* yydebug */
107 #ifndef yynerrs
108 #define yynerrs calc_nerrs
109 #endif /* yynerrs */
111 #ifndef yyerrflag
112 #define yyerrflag calc_errflag
113 #endif /* yyerrflag */
115 #ifndef yylhs
116 #define yylhs calc_lhs
117 #endif /* yylhs */
119 #ifndef yylen
120 #define yylen calc_len
121 #endif /* yylen */
123 #ifndef yydefred
124 #define yydefred calc_defred
125 #endif /* yydefred */
127 #ifndef yydgoto
128 #define yydgoto calc_dgoto
129 #endif /* yydgoto */
131 #ifndef yysindex
132 #define yysindex calc_sindex
133 #endif /* yysindex */
135 #ifndef yyrindex
136 #define yyrindex calc_rindex
137 #endif /* yyrindex */
139 #ifndef yygindex
140 #define yygindex calc_gindex
141 #endif /* yygindex */
143 #ifndef yytable
144 #define yytable calc_table
145 #endif /* yytable */
147 #ifndef yycheck
148 #define yycheck calc_check
149 #endif /* yycheck */
151 #ifndef yyname
152 #define yyname calc_name
153 #endif /* yyname */
155 #ifndef yyrule
156 #define yyrule calc_rule
157 #endif /* yyrule */
158 #define YYPREFIX "calc_"
160 extern int YYPARSE_DECL();
161 extern short yylhs[];
162 extern short yylen[];
163 extern short yydefred[];
164 extern short yydgoto[];
165 extern short yysindex[];
166 extern short yyrindex[];
167 extern short yygindex[];
168 extern short yytable[];
169 extern short yycheck[];
171 #if YYDEBUG
172 extern char *yyname[];
173 extern char *yyrule[];
174 #endif
176 int yydebug;
177 int yynerrs;
179 int yyerrflag;
180 int yychar;
181 YYSTYPE yyval;
182 YYSTYPE yylval;
184 /* define the initial stack-sizes */
185 #ifdef YYSTACKSIZE
186 #undef YYMAXDEPTH
187 #define YYMAXDEPTH YYSTACKSIZE
188 #else
189 #ifdef YYMAXDEPTH
190 #define YYSTACKSIZE YYMAXDEPTH
191 #else
192 #define YYSTACKSIZE 500
193 #define YYMAXDEPTH 500
194 #endif
195 #endif
197 #define YYINITSTACKSIZE 500
199 typedef struct {
200 unsigned stacksize;
201 short *s_base;
202 short *s_mark;
203 short *s_last;
204 YYSTYPE *l_base;
205 YYSTYPE *l_mark;
206 } YYSTACKDATA;
207 /* variables for the parser stack */
208 static YYSTACKDATA yystack;
209 #line 68 "code_calc.y"
210 /* start of programs */
212 #ifdef YYBYACC
213 extern int YYLEX_DECL();
214 #endif
217 main (void)
219 while(!feof(stdin)) {
220 yyparse();
222 return 0;
225 static void
226 yyerror(const char *s)
228 fprintf(stderr, "%s\n", s);
232 yylex(void)
234 /* lexical analysis routine */
235 /* returns LETTER for a lower case letter, yylval = 0 through 25 */
236 /* return DIGIT for a digit, yylval = 0 through 9 */
237 /* all other characters are returned immediately */
239 int c;
241 while( (c=getchar()) == ' ' ) { /* skip blanks */ }
243 /* c is now nonblank */
245 if( islower( c )) {
246 yylval = c - 'a';
247 return ( LETTER );
249 if( isdigit( c )) {
250 yylval = c - '0';
251 return ( DIGIT );
253 return( c );
255 #line 254 "code_calc.code.c"
257 #if YYDEBUG
258 #include <stdio.h> /* needed for printf */
259 #endif
261 #include <stdlib.h> /* needed for malloc, etc */
262 #include <string.h> /* needed for memset */
264 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
265 static int yygrowstack(YYSTACKDATA *data)
267 int i;
268 unsigned newsize;
269 short *newss;
270 YYSTYPE *newvs;
272 if ((newsize = data->stacksize) == 0)
273 newsize = YYINITSTACKSIZE;
274 else if (newsize >= YYMAXDEPTH)
275 return -1;
276 else if ((newsize *= 2) > YYMAXDEPTH)
277 newsize = YYMAXDEPTH;
279 i = (int) (data->s_mark - data->s_base);
280 newss = (short *)realloc(data->s_base, newsize * sizeof(*newss));
281 if (newss == 0)
282 return -1;
284 data->s_base = newss;
285 data->s_mark = newss + i;
287 newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));
288 if (newvs == 0)
289 return -1;
291 data->l_base = newvs;
292 data->l_mark = newvs + i;
294 data->stacksize = newsize;
295 data->s_last = data->s_base + newsize - 1;
296 return 0;
299 #if YYPURE || defined(YY_NO_LEAKS)
300 static void yyfreestack(YYSTACKDATA *data)
302 free(data->s_base);
303 free(data->l_base);
304 memset(data, 0, sizeof(*data));
306 #else
307 #define yyfreestack(data) /* nothing */
308 #endif
310 #define YYABORT goto yyabort
311 #define YYREJECT goto yyabort
312 #define YYACCEPT goto yyaccept
313 #define YYERROR goto yyerrlab
316 YYPARSE_DECL()
318 int yym, yyn, yystate;
319 #if YYDEBUG
320 const char *yys;
322 if ((yys = getenv("YYDEBUG")) != 0)
324 yyn = *yys;
325 if (yyn >= '0' && yyn <= '9')
326 yydebug = yyn - '0';
328 #endif
330 yynerrs = 0;
331 yyerrflag = 0;
332 yychar = YYEMPTY;
333 yystate = 0;
335 #if YYPURE
336 memset(&yystack, 0, sizeof(yystack));
337 #endif
339 if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow;
340 yystack.s_mark = yystack.s_base;
341 yystack.l_mark = yystack.l_base;
342 yystate = 0;
343 *yystack.s_mark = 0;
345 yyloop:
346 if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
347 if (yychar < 0)
349 if ((yychar = YYLEX) < 0) yychar = 0;
350 #if YYDEBUG
351 if (yydebug)
353 yys = 0;
354 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
355 if (!yys) yys = "illegal-symbol";
356 printf("%sdebug: state %d, reading %d (%s)\n",
357 YYPREFIX, yystate, yychar, yys);
359 #endif
361 if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
362 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
364 #if YYDEBUG
365 if (yydebug)
366 printf("%sdebug: state %d, shifting to state %d\n",
367 YYPREFIX, yystate, yytable[yyn]);
368 #endif
369 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
371 goto yyoverflow;
373 yystate = yytable[yyn];
374 *++yystack.s_mark = yytable[yyn];
375 *++yystack.l_mark = yylval;
376 yychar = YYEMPTY;
377 if (yyerrflag > 0) --yyerrflag;
378 goto yyloop;
380 if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
381 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
383 yyn = yytable[yyn];
384 goto yyreduce;
386 if (yyerrflag) goto yyinrecovery;
388 yyerror("syntax error");
390 goto yyerrlab;
392 yyerrlab:
393 ++yynerrs;
395 yyinrecovery:
396 if (yyerrflag < 3)
398 yyerrflag = 3;
399 for (;;)
401 if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 &&
402 yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
404 #if YYDEBUG
405 if (yydebug)
406 printf("%sdebug: state %d, error recovery shifting\
407 to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]);
408 #endif
409 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
411 goto yyoverflow;
413 yystate = yytable[yyn];
414 *++yystack.s_mark = yytable[yyn];
415 *++yystack.l_mark = yylval;
416 goto yyloop;
418 else
420 #if YYDEBUG
421 if (yydebug)
422 printf("%sdebug: error recovery discarding state %d\n",
423 YYPREFIX, *yystack.s_mark);
424 #endif
425 if (yystack.s_mark <= yystack.s_base) goto yyabort;
426 --yystack.s_mark;
427 --yystack.l_mark;
431 else
433 if (yychar == 0) goto yyabort;
434 #if YYDEBUG
435 if (yydebug)
437 yys = 0;
438 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
439 if (!yys) yys = "illegal-symbol";
440 printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
441 YYPREFIX, yystate, yychar, yys);
443 #endif
444 yychar = YYEMPTY;
445 goto yyloop;
448 yyreduce:
449 #if YYDEBUG
450 if (yydebug)
451 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
452 YYPREFIX, yystate, yyn, yyrule[yyn]);
453 #endif
454 yym = yylen[yyn];
455 if (yym)
456 yyval = yystack.l_mark[1-yym];
457 else
458 memset(&yyval, 0, sizeof yyval);
459 switch (yyn)
461 case 3:
462 #line 30 "code_calc.y"
463 { yyerrok ; }
464 break;
465 case 4:
466 #line 34 "code_calc.y"
467 { printf("%d\n",yystack.l_mark[0]);}
468 break;
469 case 5:
470 #line 36 "code_calc.y"
471 { regs[yystack.l_mark[-2]] = yystack.l_mark[0]; }
472 break;
473 case 6:
474 #line 40 "code_calc.y"
475 { yyval = yystack.l_mark[-1]; }
476 break;
477 case 7:
478 #line 42 "code_calc.y"
479 { yyval = yystack.l_mark[-2] + yystack.l_mark[0]; }
480 break;
481 case 8:
482 #line 44 "code_calc.y"
483 { yyval = yystack.l_mark[-2] - yystack.l_mark[0]; }
484 break;
485 case 9:
486 #line 46 "code_calc.y"
487 { yyval = yystack.l_mark[-2] * yystack.l_mark[0]; }
488 break;
489 case 10:
490 #line 48 "code_calc.y"
491 { yyval = yystack.l_mark[-2] / yystack.l_mark[0]; }
492 break;
493 case 11:
494 #line 50 "code_calc.y"
495 { yyval = yystack.l_mark[-2] % yystack.l_mark[0]; }
496 break;
497 case 12:
498 #line 52 "code_calc.y"
499 { yyval = yystack.l_mark[-2] & yystack.l_mark[0]; }
500 break;
501 case 13:
502 #line 54 "code_calc.y"
503 { yyval = yystack.l_mark[-2] | yystack.l_mark[0]; }
504 break;
505 case 14:
506 #line 56 "code_calc.y"
507 { yyval = - yystack.l_mark[0]; }
508 break;
509 case 15:
510 #line 58 "code_calc.y"
511 { yyval = regs[yystack.l_mark[0]]; }
512 break;
513 case 17:
514 #line 63 "code_calc.y"
515 { yyval = yystack.l_mark[0]; base = (yystack.l_mark[0]==0) ? 8 : 10; }
516 break;
517 case 18:
518 #line 65 "code_calc.y"
519 { yyval = base * yystack.l_mark[-1] + yystack.l_mark[0]; }
520 break;
521 #line 520 "code_calc.code.c"
523 yystack.s_mark -= yym;
524 yystate = *yystack.s_mark;
525 yystack.l_mark -= yym;
526 yym = yylhs[yyn];
527 if (yystate == 0 && yym == 0)
529 #if YYDEBUG
530 if (yydebug)
531 printf("%sdebug: after reduction, shifting from state 0 to\
532 state %d\n", YYPREFIX, YYFINAL);
533 #endif
534 yystate = YYFINAL;
535 *++yystack.s_mark = YYFINAL;
536 *++yystack.l_mark = yyval;
537 if (yychar < 0)
539 if ((yychar = YYLEX) < 0) yychar = 0;
540 #if YYDEBUG
541 if (yydebug)
543 yys = 0;
544 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
545 if (!yys) yys = "illegal-symbol";
546 printf("%sdebug: state %d, reading %d (%s)\n",
547 YYPREFIX, YYFINAL, yychar, yys);
549 #endif
551 if (yychar == 0) goto yyaccept;
552 goto yyloop;
554 if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
555 yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
556 yystate = yytable[yyn];
557 else
558 yystate = yydgoto[yym];
559 #if YYDEBUG
560 if (yydebug)
561 printf("%sdebug: after reduction, shifting from state %d \
562 to state %d\n", YYPREFIX, *yystack.s_mark, yystate);
563 #endif
564 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
566 goto yyoverflow;
568 *++yystack.s_mark = (short) yystate;
569 *++yystack.l_mark = yyval;
570 goto yyloop;
572 yyoverflow:
573 yyerror("yacc stack overflow");
575 yyabort:
576 yyfreestack(&yystack);
577 return (1);
579 yyaccept:
580 yyfreestack(&yystack);
581 return (0);