2 static const char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93";
10 #define yyclearin (yychar = YYEMPTY)
11 #define yyerrok (yyerrflag = 0)
12 #define YYRECOVERING() (yyerrflag != 0)
18 #line 2 "quote_calc4.y"
26 static void yyerror(const char *s);
28 #line 28 "/dev/stdout"
34 /* compatibility with bison */
36 /* compatibility with FreeBSD */
37 # ifdef YYPARSE_PARAM_TYPE
38 # define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
40 # define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
43 # define YYPARSE_DECL() yyparse(void)
46 /* Parameters sent to lex. */
48 # define YYLEX_DECL() yylex(void *YYLEX_PARAM)
49 # define YYLEX yylex(YYLEX_PARAM)
51 # define YYLEX_DECL() yylex(void)
52 # define YYLEX yylex()
55 /* Parameters sent to yyerror. */
57 #define YYERROR_DECL() yyerror(const char *s)
60 #define YYERROR_CALL(msg) yyerror(msg)
63 extern int YYPARSE_DECL();
75 static const short yylhs[] = { -1,
76 0, 0, 0, 1, 1, 2, 2, 2, 2, 2,
77 2, 2, 2, 2, 2, 2, 3, 3,
79 static const short yylen[] = { 2,
80 0, 3, 3, 1, 3, 3, 3, 3, 3, 3,
81 3, 3, 3, 2, 1, 1, 1, 2,
83 static const short yydefred[] = { 1,
84 0, 0, 0, 17, 0, 0, 0, 0, 0, 3,
85 15, 0, 0, 0, 2, 0, 0, 0, 0, 0,
86 0, 0, 18, 0, 6, 0, 0, 0, 0, 0,
89 static const short yydgoto[] = { 1,
92 static const short yysindex[] = { 0,
93 -38, 4, -36, 0, -51, -36, 6, -121, -249, 0,
94 0, -243, -36, -23, 0, -36, -36, -36, -36, -36,
95 -36, -36, 0, -121, 0, -121, -121, -121, -121, -121,
98 static const short yyrindex[] = { 0,
99 0, 0, 0, 0, -9, 0, 0, 12, -10, 0,
100 0, -5, 0, 0, 0, 0, 0, 0, 0, 0,
101 0, 0, 0, 14, 0, -3, -2, -1, 1, 2,
104 static const short yygindex[] = { 0,
107 #define YYTABLESIZE 259
108 static const short yytable[] = { 16,
109 15, 6, 22, 6, 14, 13, 7, 8, 9, 13,
110 10, 11, 12, 10, 16, 15, 17, 25, 18, 23,
111 19, 4, 20, 5, 21, 0, 0, 0, 0, 0,
112 16, 0, 0, 0, 0, 14, 13, 7, 8, 9,
113 0, 10, 11, 12, 12, 0, 0, 14, 0, 0,
114 0, 0, 0, 0, 24, 0, 0, 26, 27, 28,
115 29, 30, 31, 32, 0, 0, 0, 0, 0, 0,
116 0, 0, 0, 0, 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 22, 0, 0, 0, 0, 0, 0, 0, 0, 0,
120 0, 0, 0, 16, 15, 0, 0, 0, 14, 13,
121 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
122 0, 0, 0, 0, 0, 0, 16, 0, 17, 0,
123 18, 0, 19, 0, 20, 0, 21, 0, 0, 0,
124 0, 0, 0, 0, 0, 0, 0, 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, 2, 0, 0,
131 0, 3, 0, 3, 0, 0, 0, 0, 0, 0,
132 4, 5, 4, 11, 16, 0, 17, 0, 18, 0,
133 19, 0, 20, 0, 21, 0, 0, 16, 15, 16,
134 15, 16, 15, 16, 15, 16, 15, 16, 15,
136 static const short yycheck[] = { 10,
137 10, 40, 124, 40, 10, 10, 10, 10, 10, 61,
138 10, 10, 10, 10, 258, 10, 260, 41, 262, 269,
139 264, 10, 266, 10, 268, -1, -1, -1, -1, -1,
140 41, -1, -1, -1, -1, 41, 41, 41, 41, 41,
141 -1, 41, 41, 41, 3, -1, -1, 6, -1, -1,
142 -1, -1, -1, -1, 13, -1, -1, 16, 17, 18,
143 19, 20, 21, 22, -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 124, -1, -1, -1, -1, -1, -1, -1, -1, -1,
148 -1, -1, -1, 124, 124, -1, -1, -1, 124, 124,
149 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
150 -1, -1, -1, -1, -1, -1, 258, -1, 260, -1,
151 262, -1, 264, -1, 266, -1, 268, -1, -1, -1,
152 -1, -1, -1, -1, -1, -1, -1, -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, 256, -1, -1,
159 -1, 260, -1, 260, -1, -1, -1, -1, -1, -1,
160 269, 270, 269, 270, 258, -1, 260, -1, 262, -1,
161 264, -1, 266, -1, 268, -1, -1, 258, 258, 260,
162 260, 262, 262, 264, 264, 266, 266, 268, 268,
168 #define YYMAXTOKEN 271
170 static const char *yyname[] = {
172 "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,
173 0,0,0,0,0,0,"'%'","'&'",0,"'('","')'","'*'","'+'",0,"'-'",0,"'/'",0,0,0,0,0,0,0,
174 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,
175 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,
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,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,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,"OP_ADD","\"ADD-operator\"","OP_SUB","\"SUB-operator\"","OP_MUL",
180 "\"MUL-operator\"","OP_DIV","\"DIV-operator\"","OP_MOD","\"MOD-operator\"",
181 "OP_AND","\"AND-operator\"","DIGIT","LETTER","UMINUS",
183 static const char *yyrule[] = {
186 "list : list stat '\\n'",
187 "list : list error '\\n'",
189 "stat : LETTER '=' expr",
190 "expr : '(' expr ')'",
191 "expr : expr \"ADD-operator\" expr",
192 "expr : expr \"SUB-operator\" expr",
193 "expr : expr \"MUL-operator\" expr",
194 "expr : expr \"DIV-operator\" expr",
195 "expr : expr \"MOD-operator\" expr",
196 "expr : expr \"AND-operator\" expr",
197 "expr : expr '|' expr",
198 "expr : \"SUB-operator\" expr",
202 "number : number DIGIT",
215 /* define the initial stack-sizes */
218 #define YYMAXDEPTH YYSTACKSIZE
221 #define YYSTACKSIZE YYMAXDEPTH
223 #define YYSTACKSIZE 500
224 #define YYMAXDEPTH 500
228 #define YYINITSTACKSIZE 500
238 /* variables for the parser stack */
239 static YYSTACKDATA yystack;
240 #line 73 "quote_calc4.y"
241 /* start of programs */
246 while(!feof(stdin)) {
253 yyerror(const char *s)
255 fprintf(stderr, "%s\n", s);
260 /* lexical analysis routine */
261 /* returns LETTER for a lower case letter, yylval = 0 through 25 */
262 /* return DIGIT for a digit, yylval = 0 through 9 */
263 /* all other characters are returned immediately */
267 while( (c=getchar()) == ' ' ) { /* skip blanks */ }
269 /* c is now nonblank */
281 #line 281 "/dev/stdout"
284 #include <stdio.h> /* needed for printf */
287 #include <stdlib.h> /* needed for malloc, etc */
288 #include <string.h> /* needed for memset */
290 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
291 static int yygrowstack(YYSTACKDATA *data)
298 if ((newsize = data->stacksize) == 0)
299 newsize = YYINITSTACKSIZE;
300 else if (newsize >= YYMAXDEPTH)
302 else if ((newsize *= 2) > YYMAXDEPTH)
303 newsize = YYMAXDEPTH;
305 i = data->s_mark - data->s_base;
306 newss = (short *)realloc(data->s_base, newsize * sizeof(*newss));
310 data->s_base = newss;
311 data->s_mark = newss + i;
313 newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));
317 data->l_base = newvs;
318 data->l_mark = newvs + i;
320 data->stacksize = newsize;
321 data->s_last = data->s_base + newsize - 1;
325 #if YYPURE || defined(YY_NO_LEAKS)
326 static void yyfreestack(YYSTACKDATA *data)
330 memset(data, 0, sizeof(*data));
333 #define yyfreestack(data) /* nothing */
336 #define YYABORT goto yyabort
337 #define YYREJECT goto yyabort
338 #define YYACCEPT goto yyaccept
339 #define YYERROR goto yyerrlab
344 int yym, yyn, yystate;
348 if ((yys = getenv("YYDEBUG")) != 0)
351 if (yyn >= '0' && yyn <= '9')
362 memset(&yystack, 0, sizeof(yystack));
365 if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow;
366 yystack.s_mark = yystack.s_base;
367 yystack.l_mark = yystack.l_base;
372 if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
375 if ((yychar = YYLEX) < 0) yychar = 0;
380 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
381 if (!yys) yys = "illegal-symbol";
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;
464 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
465 if (!yys) yys = "illegal-symbol";
466 printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
467 YYPREFIX, yystate, yychar, yys);
477 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
478 YYPREFIX, yystate, yyn, yyrule[yyn]);
482 yyval = yystack.l_mark[1-yym];
484 memset(&yyval, 0, sizeof yyval);
488 #line 35 "quote_calc4.y"
492 #line 39 "quote_calc4.y"
493 { printf("%d\n",yystack.l_mark[0]);}
496 #line 41 "quote_calc4.y"
497 { regs[yystack.l_mark[-2]] = yystack.l_mark[0]; }
500 #line 45 "quote_calc4.y"
501 { yyval = yystack.l_mark[-1]; }
504 #line 47 "quote_calc4.y"
505 { yyval = yystack.l_mark[-2] + yystack.l_mark[0]; }
508 #line 49 "quote_calc4.y"
509 { yyval = yystack.l_mark[-2] - yystack.l_mark[0]; }
512 #line 51 "quote_calc4.y"
513 { yyval = yystack.l_mark[-2] * yystack.l_mark[0]; }
516 #line 53 "quote_calc4.y"
517 { yyval = yystack.l_mark[-2] / yystack.l_mark[0]; }
520 #line 55 "quote_calc4.y"
521 { yyval = yystack.l_mark[-2] % yystack.l_mark[0]; }
524 #line 57 "quote_calc4.y"
525 { yyval = yystack.l_mark[-2] & yystack.l_mark[0]; }
528 #line 59 "quote_calc4.y"
529 { yyval = yystack.l_mark[-2] | yystack.l_mark[0]; }
532 #line 61 "quote_calc4.y"
533 { yyval = - yystack.l_mark[0]; }
536 #line 63 "quote_calc4.y"
537 { yyval = regs[yystack.l_mark[0]]; }
540 #line 68 "quote_calc4.y"
541 { yyval = yystack.l_mark[0]; base = (yystack.l_mark[0]==0) ? 8 : 10; }
544 #line 70 "quote_calc4.y"
545 { yyval = base * yystack.l_mark[-1] + yystack.l_mark[0]; }
547 #line 547 "/dev/stdout"
549 yystack.s_mark -= yym;
550 yystate = *yystack.s_mark;
551 yystack.l_mark -= yym;
553 if (yystate == 0 && yym == 0)
557 printf("%sdebug: after reduction, shifting from state 0 to\
558 state %d\n", YYPREFIX, YYFINAL);
561 *++yystack.s_mark = YYFINAL;
562 *++yystack.l_mark = yyval;
565 if ((yychar = YYLEX) < 0) yychar = 0;
570 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
571 if (!yys) yys = "illegal-symbol";
572 printf("%sdebug: state %d, reading %d (%s)\n",
573 YYPREFIX, YYFINAL, yychar, yys);
577 if (yychar == 0) goto yyaccept;
580 if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
581 yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
582 yystate = yytable[yyn];
584 yystate = yydgoto[yym];
587 printf("%sdebug: after reduction, shifting from state %d \
588 to state %d\n", YYPREFIX, *yystack.s_mark, yystate);
590 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
594 *++yystack.s_mark = (short) yystate;
595 *++yystack.l_mark = yyval;
599 yyerror("yacc stack overflow");
602 yyfreestack(&yystack);
606 yyfreestack(&yystack);