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_calc.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();
81 static const short yylhs[] = { -1,
82 0, 0, 0, 1, 1, 2, 2, 2, 2, 2,
83 2, 2, 2, 2, 2, 2, 3, 3,
85 static const short yylen[] = { 2,
86 0, 3, 3, 1, 3, 3, 3, 3, 3, 3,
87 3, 3, 3, 2, 1, 1, 1, 2,
89 static const short yydefred[] = { 1,
90 0, 0, 0, 17, 0, 0, 0, 0, 0, 3,
91 15, 0, 0, 0, 2, 0, 0, 0, 0, 0,
92 0, 0, 18, 0, 6, 0, 0, 0, 0, 0,
95 static const short yydgoto[] = { 1,
98 static const short yysindex[] = { 0,
99 -38, 5, -36, 0, -51, -36, 7, -121, -248, 0,
100 0, -243, -36, -22, 0, -36, -36, -36, -36, -36,
101 -36, -36, 0, -121, 0, -121, -121, -121, -121, -121,
104 static const short yyrindex[] = { 0,
105 0, 0, 0, 0, -9, 0, 0, 13, -10, 0,
106 0, -5, 0, 0, 0, 0, 0, 0, 0, 0,
107 0, 0, 0, 15, 0, -3, -2, -1, 1, 2,
110 static const short yygindex[] = { 0,
113 #define YYTABLESIZE 258
114 static const short yytable[] = { 16,
115 15, 6, 22, 6, 14, 13, 7, 8, 9, 13,
116 10, 11, 12, 16, 10, 17, 15, 18, 25, 19,
117 23, 20, 4, 21, 5, 0, 0, 0, 0, 0,
118 16, 0, 0, 0, 0, 14, 13, 7, 8, 9,
119 0, 10, 11, 12, 12, 0, 0, 14, 0, 0,
120 0, 0, 0, 0, 24, 0, 0, 26, 27, 28,
121 29, 30, 31, 32, 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, 0, 0, 0, 0, 0,
125 0, 22, 0, 0, 0, 0, 0, 0, 0, 0,
126 0, 0, 0, 16, 15, 0, 0, 0, 14, 13,
127 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
128 0, 0, 0, 0, 0, 16, 0, 17, 0, 18,
129 0, 19, 0, 20, 0, 21, 0, 0, 0, 0,
130 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
131 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
132 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
133 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
134 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
135 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
136 0, 0, 0, 0, 0, 0, 0, 2, 0, 0,
137 3, 0, 3, 0, 0, 0, 0, 0, 0, 0,
138 4, 5, 4, 11, 16, 0, 17, 0, 18, 0,
139 19, 0, 20, 0, 21, 0, 16, 15, 16, 15,
140 16, 15, 16, 15, 16, 15, 16, 15,
142 static const short yycheck[] = { 10,
143 10, 40, 124, 40, 10, 10, 10, 10, 10, 61,
144 10, 10, 10, 257, 10, 259, 10, 261, 41, 263,
145 269, 265, 10, 267, 10, -1, -1, -1, -1, -1,
146 41, -1, -1, -1, -1, 41, 41, 41, 41, 41,
147 -1, 41, 41, 41, 3, -1, -1, 6, -1, -1,
148 -1, -1, -1, -1, 13, -1, -1, 16, 17, 18,
149 19, 20, 21, 22, -1, -1, -1, -1, -1, -1,
150 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
151 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
152 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
153 -1, 124, -1, -1, -1, -1, -1, -1, -1, -1,
154 -1, -1, -1, 124, 124, -1, -1, -1, 124, 124,
155 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
156 -1, -1, -1, -1, -1, 257, -1, 259, -1, 261,
157 -1, 263, -1, 265, -1, 267, -1, -1, -1, -1,
158 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
159 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
160 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
161 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
162 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
163 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
164 -1, -1, -1, -1, -1, -1, -1, 256, -1, -1,
165 259, -1, 259, -1, -1, -1, -1, -1, -1, -1,
166 269, 270, 269, 270, 257, -1, 259, -1, 261, -1,
167 263, -1, 265, -1, 267, -1, 257, 257, 259, 259,
168 261, 261, 263, 263, 265, 265, 267, 267,
174 #define YYMAXTOKEN 271
176 static const char *yyname[] = {
178 "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,
179 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,
181 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,
182 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,
183 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,
184 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,
185 0,0,0,0,0,0,"OP_ADD","\"ADD\"","OP_SUB","\"SUB\"","OP_MUL","\"MUL\"","OP_DIV",
186 "\"DIV\"","OP_MOD","\"MOD\"","OP_AND","\"AND\"","DIGIT","LETTER","UMINUS",
188 static const char *yyrule[] = {
191 "list : list stat '\\n'",
192 "list : list error '\\n'",
194 "stat : LETTER '=' expr",
195 "expr : '(' expr ')'",
196 "expr : expr OP_ADD expr",
197 "expr : expr OP_SUB expr",
198 "expr : expr OP_MUL expr",
199 "expr : expr OP_DIV expr",
200 "expr : expr OP_MOD expr",
201 "expr : expr OP_AND expr",
202 "expr : expr '|' expr",
203 "expr : OP_SUB expr",
207 "number : number DIGIT",
220 /* define the initial stack-sizes */
223 #define YYMAXDEPTH YYSTACKSIZE
226 #define YYSTACKSIZE YYMAXDEPTH
228 #define YYSTACKSIZE 500
229 #define YYMAXDEPTH 500
233 #define YYINITSTACKSIZE 500
243 /* variables for the parser stack */
244 static YYSTACKDATA yystack;
245 #line 73 "quote_calc.y"
246 /* start of programs */
251 while(!feof(stdin)) {
258 yyerror(const char *s)
260 fprintf(stderr, "%s\n", s);
265 /* lexical analysis routine */
266 /* returns LETTER for a lower case letter, yylval = 0 through 25 */
267 /* return DIGIT for a digit, yylval = 0 through 9 */
268 /* all other characters are returned immediately */
272 while( (c=getchar()) == ' ' ) { /* skip blanks */ }
274 /* c is now nonblank */
286 #line 286 "/dev/stdout"
289 #include <stdio.h> /* needed for printf */
292 #include <stdlib.h> /* needed for malloc, etc */
293 #include <string.h> /* needed for memset */
295 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
296 static int yygrowstack(YYSTACKDATA *data)
303 if ((newsize = data->stacksize) == 0)
304 newsize = YYINITSTACKSIZE;
305 else if (newsize >= YYMAXDEPTH)
307 else if ((newsize *= 2) > YYMAXDEPTH)
308 newsize = YYMAXDEPTH;
310 i = data->s_mark - data->s_base;
311 newss = (short *)realloc(data->s_base, newsize * sizeof(*newss));
315 data->s_base = newss;
316 data->s_mark = newss + i;
318 newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));
322 data->l_base = newvs;
323 data->l_mark = newvs + i;
325 data->stacksize = newsize;
326 data->s_last = data->s_base + newsize - 1;
330 #if YYPURE || defined(YY_NO_LEAKS)
331 static void yyfreestack(YYSTACKDATA *data)
335 memset(data, 0, sizeof(*data));
338 #define yyfreestack(data) /* nothing */
341 #define YYABORT goto yyabort
342 #define YYREJECT goto yyabort
343 #define YYACCEPT goto yyaccept
344 #define YYERROR goto yyerrlab
349 int yym, yyn, yystate;
353 if ((yys = getenv("YYDEBUG")) != 0)
356 if (yyn >= '0' && yyn <= '9')
367 memset(&yystack, 0, sizeof(yystack));
370 if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow;
371 yystack.s_mark = yystack.s_base;
372 yystack.l_mark = yystack.l_base;
377 if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
380 if ((yychar = YYLEX) < 0) yychar = 0;
385 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
386 if (!yys) yys = "illegal-symbol";
387 printf("%sdebug: state %d, reading %d (%s)\n",
388 YYPREFIX, yystate, yychar, yys);
392 if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
393 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
397 printf("%sdebug: state %d, shifting to state %d\n",
398 YYPREFIX, yystate, yytable[yyn]);
400 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
404 yystate = yytable[yyn];
405 *++yystack.s_mark = yytable[yyn];
406 *++yystack.l_mark = yylval;
408 if (yyerrflag > 0) --yyerrflag;
411 if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
412 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
417 if (yyerrflag) goto yyinrecovery;
419 yyerror("syntax error");
432 if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 &&
433 yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
437 printf("%sdebug: state %d, error recovery shifting\
438 to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]);
440 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
444 yystate = yytable[yyn];
445 *++yystack.s_mark = yytable[yyn];
446 *++yystack.l_mark = yylval;
453 printf("%sdebug: error recovery discarding state %d\n",
454 YYPREFIX, *yystack.s_mark);
456 if (yystack.s_mark <= yystack.s_base) goto yyabort;
464 if (yychar == 0) goto yyabort;
469 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
470 if (!yys) yys = "illegal-symbol";
471 printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
472 YYPREFIX, yystate, yychar, yys);
482 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
483 YYPREFIX, yystate, yyn, yyrule[yyn]);
487 yyval = yystack.l_mark[1-yym];
489 memset(&yyval, 0, sizeof yyval);
493 #line 35 "quote_calc.y"
497 #line 39 "quote_calc.y"
498 { printf("%d\n",yystack.l_mark[0]);}
501 #line 41 "quote_calc.y"
502 { regs[yystack.l_mark[-2]] = yystack.l_mark[0]; }
505 #line 45 "quote_calc.y"
506 { yyval = yystack.l_mark[-1]; }
509 #line 47 "quote_calc.y"
510 { yyval = yystack.l_mark[-2] + yystack.l_mark[0]; }
513 #line 49 "quote_calc.y"
514 { yyval = yystack.l_mark[-2] - yystack.l_mark[0]; }
517 #line 51 "quote_calc.y"
518 { yyval = yystack.l_mark[-2] * yystack.l_mark[0]; }
521 #line 53 "quote_calc.y"
522 { yyval = yystack.l_mark[-2] / yystack.l_mark[0]; }
525 #line 55 "quote_calc.y"
526 { yyval = yystack.l_mark[-2] % yystack.l_mark[0]; }
529 #line 57 "quote_calc.y"
530 { yyval = yystack.l_mark[-2] & yystack.l_mark[0]; }
533 #line 59 "quote_calc.y"
534 { yyval = yystack.l_mark[-2] | yystack.l_mark[0]; }
537 #line 61 "quote_calc.y"
538 { yyval = - yystack.l_mark[0]; }
541 #line 63 "quote_calc.y"
542 { yyval = regs[yystack.l_mark[0]]; }
545 #line 68 "quote_calc.y"
546 { yyval = yystack.l_mark[0]; base = (yystack.l_mark[0]==0) ? 8 : 10; }
549 #line 70 "quote_calc.y"
550 { yyval = base * yystack.l_mark[-1] + yystack.l_mark[0]; }
552 #line 552 "/dev/stdout"
554 yystack.s_mark -= yym;
555 yystate = *yystack.s_mark;
556 yystack.l_mark -= yym;
558 if (yystate == 0 && yym == 0)
562 printf("%sdebug: after reduction, shifting from state 0 to\
563 state %d\n", YYPREFIX, YYFINAL);
566 *++yystack.s_mark = YYFINAL;
567 *++yystack.l_mark = yyval;
570 if ((yychar = YYLEX) < 0) yychar = 0;
575 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
576 if (!yys) yys = "illegal-symbol";
577 printf("%sdebug: state %d, reading %d (%s)\n",
578 YYPREFIX, YYFINAL, yychar, yys);
582 if (yychar == 0) goto yyaccept;
585 if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
586 yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
587 yystate = yytable[yyn];
589 yystate = yydgoto[yym];
592 printf("%sdebug: after reduction, shifting from state %d \
593 to state %d\n", YYPREFIX, *yystack.s_mark, yystate);
595 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
599 *++yystack.s_mark = (short) yystate;
600 *++yystack.l_mark = yyval;
604 yyerror("yacc stack overflow");
607 yyfreestack(&yystack);
611 yyfreestack(&yystack);