2 static const char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93";
8 #define YYPATCH 20140101
11 #define yyclearin (yychar = YYEMPTY)
12 #define yyerrok (yyerrflag = 0)
13 #define YYRECOVERING() (yyerrflag != 0)
19 #line 2 "quote_calc4.y"
27 static void yyerror(const char *s);
29 #line 29 "/dev/stdout"
35 /* compatibility with bison */
37 /* compatibility with FreeBSD */
38 # ifdef YYPARSE_PARAM_TYPE
39 # define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
41 # define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
44 # define YYPARSE_DECL() yyparse(void)
47 /* Parameters sent to lex. */
49 # define YYLEX_DECL() yylex(void *YYLEX_PARAM)
50 # define YYLEX yylex(YYLEX_PARAM)
52 # define YYLEX_DECL() yylex(void)
53 # define YYLEX yylex()
56 /* Parameters sent to yyerror. */
58 #define YYERROR_DECL() yyerror(const char *s)
61 #define YYERROR_CALL(msg) yyerror(msg)
64 extern int YYPARSE_DECL();
76 static const short yylhs[] = { -1,
77 0, 0, 0, 1, 1, 2, 2, 2, 2, 2,
78 2, 2, 2, 2, 2, 2, 3, 3,
80 static const short yylen[] = { 2,
81 0, 3, 3, 1, 3, 3, 3, 3, 3, 3,
82 3, 3, 3, 2, 1, 1, 1, 2,
84 static const short yydefred[] = { 1,
85 0, 0, 0, 17, 0, 0, 0, 0, 0, 3,
86 15, 0, 0, 0, 2, 0, 0, 0, 0, 0,
87 0, 0, 18, 0, 6, 0, 0, 0, 0, 0,
90 static const short yydgoto[] = { 1,
93 static const short yysindex[] = { 0,
94 -38, 4, -36, 0, -51, -36, 6, -121, -249, 0,
95 0, -243, -36, -23, 0, -36, -36, -36, -36, -36,
96 -36, -36, 0, -121, 0, -121, -121, -121, -121, -121,
99 static const short yyrindex[] = { 0,
100 0, 0, 0, 0, -9, 0, 0, 12, -10, 0,
101 0, -5, 0, 0, 0, 0, 0, 0, 0, 0,
102 0, 0, 0, 14, 0, -3, -2, -1, 1, 2,
105 static const short yygindex[] = { 0,
108 #define YYTABLESIZE 259
109 static const short yytable[] = { 16,
110 15, 6, 22, 6, 14, 13, 7, 8, 9, 13,
111 10, 11, 12, 10, 16, 15, 17, 25, 18, 23,
112 19, 4, 20, 5, 21, 0, 0, 0, 0, 0,
113 16, 0, 0, 0, 0, 14, 13, 7, 8, 9,
114 0, 10, 11, 12, 12, 0, 0, 14, 0, 0,
115 0, 0, 0, 0, 24, 0, 0, 26, 27, 28,
116 29, 30, 31, 32, 0, 0, 0, 0, 0, 0,
117 0, 0, 0, 0, 0, 0, 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 22, 0, 0, 0, 0, 0, 0, 0, 0, 0,
121 0, 0, 0, 16, 15, 0, 0, 0, 14, 13,
122 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
123 0, 0, 0, 0, 0, 0, 16, 0, 17, 0,
124 18, 0, 19, 0, 20, 0, 21, 0, 0, 0,
125 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
126 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
127 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
128 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
129 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
130 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
131 0, 0, 0, 0, 0, 0, 0, 2, 0, 0,
132 0, 3, 0, 3, 0, 0, 0, 0, 0, 0,
133 4, 5, 4, 11, 16, 0, 17, 0, 18, 0,
134 19, 0, 20, 0, 21, 0, 0, 16, 15, 16,
135 15, 16, 15, 16, 15, 16, 15, 16, 15,
137 static const short yycheck[] = { 10,
138 10, 40, 124, 40, 10, 10, 10, 10, 10, 61,
139 10, 10, 10, 10, 258, 10, 260, 41, 262, 269,
140 264, 10, 266, 10, 268, -1, -1, -1, -1, -1,
141 41, -1, -1, -1, -1, 41, 41, 41, 41, 41,
142 -1, 41, 41, 41, 3, -1, -1, 6, -1, -1,
143 -1, -1, -1, -1, 13, -1, -1, 16, 17, 18,
144 19, 20, 21, 22, -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 124, -1, -1, -1, -1, -1, -1, -1, -1, -1,
149 -1, -1, -1, 124, 124, -1, -1, -1, 124, 124,
150 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
151 -1, -1, -1, -1, -1, -1, 258, -1, 260, -1,
152 262, -1, 264, -1, 266, -1, 268, -1, -1, -1,
153 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
154 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
155 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
156 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
157 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
158 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
159 -1, -1, -1, -1, -1, -1, -1, 256, -1, -1,
160 -1, 260, -1, 260, -1, -1, -1, -1, -1, -1,
161 269, 270, 269, 270, 258, -1, 260, -1, 262, -1,
162 264, -1, 266, -1, 268, -1, -1, 258, 258, 260,
163 260, 262, 262, 264, 264, 266, 266, 268, 268,
169 #define YYMAXTOKEN 271
170 #define YYTRANSLATE(a) ((a) > YYMAXTOKEN ? (YYMAXTOKEN + 1) : (a))
172 static const char *yyname[] = {
174 "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,
175 0,0,0,0,0,0,"'%'","'&'",0,"'('","')'","'*'","'+'",0,"'-'",0,"'/'",0,0,0,0,0,0,0,
176 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,
177 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,
178 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,
179 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,
180 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,
181 0,0,0,0,0,0,"OP_ADD","\"ADD-operator\"","OP_SUB","\"SUB-operator\"","OP_MUL",
182 "\"MUL-operator\"","OP_DIV","\"DIV-operator\"","OP_MOD","\"MOD-operator\"",
183 "OP_AND","\"AND-operator\"","DIGIT","LETTER","UMINUS","illegal-symbol",
185 static const char *yyrule[] = {
188 "list : list stat '\\n'",
189 "list : list error '\\n'",
191 "stat : LETTER '=' expr",
192 "expr : '(' expr ')'",
193 "expr : expr \"ADD-operator\" expr",
194 "expr : expr \"SUB-operator\" expr",
195 "expr : expr \"MUL-operator\" expr",
196 "expr : expr \"DIV-operator\" expr",
197 "expr : expr \"MOD-operator\" expr",
198 "expr : expr \"AND-operator\" expr",
199 "expr : expr '|' expr",
200 "expr : \"SUB-operator\" expr",
204 "number : number DIGIT",
217 /* define the initial stack-sizes */
220 #define YYMAXDEPTH YYSTACKSIZE
223 #define YYSTACKSIZE YYMAXDEPTH
225 #define YYSTACKSIZE 10000
226 #define YYMAXDEPTH 10000
230 #define YYINITSTACKSIZE 200
240 /* variables for the parser stack */
241 static YYSTACKDATA yystack;
242 #line 73 "quote_calc4.y"
243 /* start of programs */
248 while(!feof(stdin)) {
255 yyerror(const char *s)
257 fprintf(stderr, "%s\n", s);
262 /* lexical analysis routine */
263 /* returns LETTER for a lower case letter, yylval = 0 through 25 */
264 /* return DIGIT for a digit, yylval = 0 through 9 */
265 /* all other characters are returned immediately */
269 while( (c=getchar()) == ' ' ) { /* skip blanks */ }
271 /* c is now nonblank */
283 #line 282 "/dev/stdout"
286 #include <stdio.h> /* needed for printf */
289 #include <stdlib.h> /* needed for malloc, etc */
290 #include <string.h> /* needed for memset */
292 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
293 static int yygrowstack(YYSTACKDATA *data)
300 if ((newsize = data->stacksize) == 0)
301 newsize = YYINITSTACKSIZE;
302 else if (newsize >= YYMAXDEPTH)
304 else if ((newsize *= 2) > YYMAXDEPTH)
305 newsize = YYMAXDEPTH;
307 i = (int) (data->s_mark - data->s_base);
308 newss = (short *)realloc(data->s_base, newsize * sizeof(*newss));
312 data->s_base = newss;
313 data->s_mark = newss + i;
315 newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));
319 data->l_base = newvs;
320 data->l_mark = newvs + i;
322 data->stacksize = newsize;
323 data->s_last = data->s_base + newsize - 1;
327 #if YYPURE || defined(YY_NO_LEAKS)
328 static void yyfreestack(YYSTACKDATA *data)
332 memset(data, 0, sizeof(*data));
335 #define yyfreestack(data) /* nothing */
338 #define YYABORT goto yyabort
339 #define YYREJECT goto yyabort
340 #define YYACCEPT goto yyaccept
341 #define YYERROR goto yyerrlab
346 int yym, yyn, yystate;
350 if ((yys = getenv("YYDEBUG")) != 0)
353 if (yyn >= '0' && yyn <= '9')
364 memset(&yystack, 0, sizeof(yystack));
367 if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow;
368 yystack.s_mark = yystack.s_base;
369 yystack.l_mark = yystack.l_base;
374 if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
377 if ((yychar = YYLEX) < 0) yychar = 0;
381 yys = yyname[YYTRANSLATE(yychar)];
382 printf("%sdebug: state %d, reading %d (%s)\n",
383 YYPREFIX, yystate, yychar, yys);
387 if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
388 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
392 printf("%sdebug: state %d, shifting to state %d\n",
393 YYPREFIX, yystate, yytable[yyn]);
395 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
399 yystate = yytable[yyn];
400 *++yystack.s_mark = yytable[yyn];
401 *++yystack.l_mark = yylval;
403 if (yyerrflag > 0) --yyerrflag;
406 if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
407 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
412 if (yyerrflag) goto yyinrecovery;
414 yyerror("syntax error");
427 if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 &&
428 yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
432 printf("%sdebug: state %d, error recovery shifting\
433 to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]);
435 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
439 yystate = yytable[yyn];
440 *++yystack.s_mark = yytable[yyn];
441 *++yystack.l_mark = yylval;
448 printf("%sdebug: error recovery discarding state %d\n",
449 YYPREFIX, *yystack.s_mark);
451 if (yystack.s_mark <= yystack.s_base) goto yyabort;
459 if (yychar == 0) goto yyabort;
463 yys = yyname[YYTRANSLATE(yychar)];
464 printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
465 YYPREFIX, yystate, yychar, yys);
475 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
476 YYPREFIX, yystate, yyn, yyrule[yyn]);
480 yyval = yystack.l_mark[1-yym];
482 memset(&yyval, 0, sizeof yyval);
486 #line 35 "quote_calc4.y"
490 #line 39 "quote_calc4.y"
491 { printf("%d\n",yystack.l_mark[0]);}
494 #line 41 "quote_calc4.y"
495 { regs[yystack.l_mark[-2]] = yystack.l_mark[0]; }
498 #line 45 "quote_calc4.y"
499 { yyval = yystack.l_mark[-1]; }
502 #line 47 "quote_calc4.y"
503 { yyval = yystack.l_mark[-2] + yystack.l_mark[0]; }
506 #line 49 "quote_calc4.y"
507 { yyval = yystack.l_mark[-2] - yystack.l_mark[0]; }
510 #line 51 "quote_calc4.y"
511 { yyval = yystack.l_mark[-2] * yystack.l_mark[0]; }
514 #line 53 "quote_calc4.y"
515 { yyval = yystack.l_mark[-2] / yystack.l_mark[0]; }
518 #line 55 "quote_calc4.y"
519 { yyval = yystack.l_mark[-2] % yystack.l_mark[0]; }
522 #line 57 "quote_calc4.y"
523 { yyval = yystack.l_mark[-2] & yystack.l_mark[0]; }
526 #line 59 "quote_calc4.y"
527 { yyval = yystack.l_mark[-2] | yystack.l_mark[0]; }
530 #line 61 "quote_calc4.y"
531 { yyval = - yystack.l_mark[0]; }
534 #line 63 "quote_calc4.y"
535 { yyval = regs[yystack.l_mark[0]]; }
538 #line 68 "quote_calc4.y"
539 { yyval = yystack.l_mark[0]; base = (yystack.l_mark[0]==0) ? 8 : 10; }
542 #line 70 "quote_calc4.y"
543 { yyval = base * yystack.l_mark[-1] + yystack.l_mark[0]; }
545 #line 544 "/dev/stdout"
547 yystack.s_mark -= yym;
548 yystate = *yystack.s_mark;
549 yystack.l_mark -= yym;
551 if (yystate == 0 && yym == 0)
555 printf("%sdebug: after reduction, shifting from state 0 to\
556 state %d\n", YYPREFIX, YYFINAL);
559 *++yystack.s_mark = YYFINAL;
560 *++yystack.l_mark = yyval;
563 if ((yychar = YYLEX) < 0) yychar = 0;
567 yys = yyname[YYTRANSLATE(yychar)];
568 printf("%sdebug: state %d, reading %d (%s)\n",
569 YYPREFIX, YYFINAL, yychar, yys);
573 if (yychar == 0) goto yyaccept;
576 if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
577 yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
578 yystate = yytable[yyn];
580 yystate = yydgoto[yym];
583 printf("%sdebug: after reduction, shifting from state %d \
584 to state %d\n", YYPREFIX, *yystack.s_mark, yystate);
586 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
590 *++yystack.s_mark = (short) yystate;
591 *++yystack.l_mark = yyval;
595 yyerror("yacc stack overflow");
598 yyfreestack(&yystack);
602 yyfreestack(&yystack);