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