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