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)
16 #define yyparse quote_calc2_parse
20 #define yylex quote_calc2_lex
24 #define yyerror quote_calc2_error
28 #define yychar quote_calc2_char
32 #define yyval quote_calc2_val
36 #define yylval quote_calc2_lval
40 #define yydebug quote_calc2_debug
44 #define yynerrs quote_calc2_nerrs
48 #define yyerrflag quote_calc2_errflag
49 #endif /* yyerrflag */
52 #define yylhs quote_calc2_lhs
56 #define yylen quote_calc2_len
60 #define yydefred quote_calc2_defred
64 #define yydgoto quote_calc2_dgoto
68 #define yysindex quote_calc2_sindex
72 #define yyrindex quote_calc2_rindex
76 #define yygindex quote_calc2_gindex
80 #define yytable quote_calc2_table
84 #define yycheck quote_calc2_check
88 #define yyname quote_calc2_name
92 #define yyrule quote_calc2_rule
94 #define YYPREFIX "quote_calc2_"
98 #line 2 "quote_calc2.y"
106 static void yyerror(const char *s);
108 #line 109 "quote_calc2-s.tab.c"
114 /* compatibility with bison */
116 /* compatibility with FreeBSD */
117 # ifdef YYPARSE_PARAM_TYPE
118 # define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
120 # define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
123 # define YYPARSE_DECL() yyparse(void)
126 /* Parameters sent to lex. */
128 # define YYLEX_DECL() yylex(void *YYLEX_PARAM)
129 # define YYLEX yylex(YYLEX_PARAM)
131 # define YYLEX_DECL() yylex(void)
132 # define YYLEX yylex()
135 /* Parameters sent to yyerror. */
137 #define YYERROR_DECL() yyerror(const char *s)
140 #define YYERROR_CALL(msg) yyerror(msg)
143 extern int YYPARSE_DECL();
154 #define YYERRCODE 256
155 static const short quote_calc2_lhs[] = { -1,
156 0, 0, 0, 1, 1, 2, 2, 2, 2, 2,
157 2, 2, 2, 2, 2, 2, 3, 3,
159 static const short quote_calc2_len[] = { 2,
160 0, 3, 3, 1, 3, 3, 3, 3, 3, 3,
161 3, 3, 3, 2, 1, 1, 1, 2,
163 static const short quote_calc2_defred[] = { 1,
164 0, 0, 0, 17, 0, 0, 0, 0, 0, 3,
165 15, 0, 0, 0, 2, 0, 0, 0, 0, 0,
166 0, 0, 18, 0, 6, 0, 0, 0, 0, 0,
169 static const short quote_calc2_dgoto[] = { 1,
172 static const short quote_calc2_sindex[] = { 0,
173 -38, 4, -36, 0, -51, -36, 6, -121, -249, 0,
174 0, -243, -36, -23, 0, -36, -36, -36, -36, -36,
175 -36, -36, 0, -121, 0, -121, -121, -121, -121, -121,
178 static const short quote_calc2_rindex[] = { 0,
179 0, 0, 0, 0, -9, 0, 0, 12, -10, 0,
180 0, -5, 0, 0, 0, 0, 0, 0, 0, 0,
181 0, 0, 0, 14, 0, -3, -2, -1, 1, 2,
184 static const short quote_calc2_gindex[] = { 0,
187 #define YYTABLESIZE 259
188 static const short quote_calc2_table[] = { 16,
189 15, 6, 22, 6, 14, 13, 7, 8, 9, 13,
190 10, 11, 12, 10, 16, 15, 17, 25, 18, 23,
191 19, 4, 20, 5, 21, 0, 0, 0, 0, 0,
192 16, 0, 0, 0, 0, 14, 13, 7, 8, 9,
193 0, 10, 11, 12, 12, 0, 0, 14, 0, 0,
194 0, 0, 0, 0, 24, 0, 0, 26, 27, 28,
195 29, 30, 31, 32, 0, 0, 0, 0, 0, 0,
196 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
197 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
198 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
199 22, 0, 0, 0, 0, 0, 0, 0, 0, 0,
200 0, 0, 0, 16, 15, 0, 0, 0, 14, 13,
201 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
202 0, 0, 0, 0, 0, 0, 16, 0, 17, 0,
203 18, 0, 19, 0, 20, 0, 21, 0, 0, 0,
204 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
205 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
206 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
207 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
208 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
209 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
210 0, 0, 0, 0, 0, 0, 0, 2, 0, 0,
211 0, 3, 0, 3, 0, 0, 0, 0, 0, 0,
212 4, 5, 4, 11, 16, 0, 17, 0, 18, 0,
213 19, 0, 20, 0, 21, 0, 0, 16, 15, 16,
214 15, 16, 15, 16, 15, 16, 15, 16, 15,
216 static const short quote_calc2_check[] = { 10,
217 10, 40, 124, 40, 10, 10, 10, 10, 10, 61,
218 10, 10, 10, 10, 258, 10, 260, 41, 262, 269,
219 264, 10, 266, 10, 268, -1, -1, -1, -1, -1,
220 41, -1, -1, -1, -1, 41, 41, 41, 41, 41,
221 -1, 41, 41, 41, 3, -1, -1, 6, -1, -1,
222 -1, -1, -1, -1, 13, -1, -1, 16, 17, 18,
223 19, 20, 21, 22, -1, -1, -1, -1, -1, -1,
224 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
225 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
226 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
227 124, -1, -1, -1, -1, -1, -1, -1, -1, -1,
228 -1, -1, -1, 124, 124, -1, -1, -1, 124, 124,
229 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
230 -1, -1, -1, -1, -1, -1, 258, -1, 260, -1,
231 262, -1, 264, -1, 266, -1, 268, -1, -1, -1,
232 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
233 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
234 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
235 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
236 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
237 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
238 -1, -1, -1, -1, -1, -1, -1, 256, -1, -1,
239 -1, 260, -1, 260, -1, -1, -1, -1, -1, -1,
240 269, 270, 269, 270, 258, -1, 260, -1, 262, -1,
241 264, -1, 266, -1, 268, -1, -1, 258, 258, 260,
242 260, 262, 262, 264, 264, 266, 266, 268, 268,
248 #define YYMAXTOKEN 271
250 static const char *yyname[] = {
252 "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,
253 0,0,0,0,0,0,"'%'","'&'",0,"'('","')'","'*'","'+'",0,"'-'",0,"'/'",0,0,0,0,0,0,0,
254 0,0,0,0,0,0,"'='",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
255 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"'|'",0,0,0,0,0,0,
256 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
257 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
258 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
259 0,0,0,0,0,0,"OP_ADD","\"ADD\"","OP_SUB","\"SUB\"","OP_MUL","\"MUL\"","OP_DIV",
260 "\"DIV\"","OP_MOD","\"MOD\"","OP_AND","\"AND\"","DIGIT","LETTER","UMINUS",
262 static const char *yyrule[] = {
265 "list : list stat '\\n'",
266 "list : list error '\\n'",
268 "stat : LETTER '=' expr",
269 "expr : '(' expr ')'",
270 "expr : expr \"ADD\" expr",
271 "expr : expr \"SUB\" expr",
272 "expr : expr \"MUL\" expr",
273 "expr : expr \"DIV\" expr",
274 "expr : expr \"MOD\" expr",
275 "expr : expr \"AND\" expr",
276 "expr : expr '|' expr",
277 "expr : \"SUB\" expr",
281 "number : number DIGIT",
294 /* define the initial stack-sizes */
297 #define YYMAXDEPTH YYSTACKSIZE
300 #define YYSTACKSIZE YYMAXDEPTH
302 #define YYSTACKSIZE 500
303 #define YYMAXDEPTH 500
307 #define YYINITSTACKSIZE 500
317 /* variables for the parser stack */
318 static YYSTACKDATA yystack;
319 #line 73 "quote_calc2.y"
320 /* start of programs */
325 while(!feof(stdin)) {
332 yyerror(const char *s)
334 fprintf(stderr, "%s\n", s);
339 /* lexical analysis routine */
340 /* returns LETTER for a lower case letter, yylval = 0 through 25 */
341 /* return DIGIT for a digit, yylval = 0 through 9 */
342 /* all other characters are returned immediately */
346 while( (c=getchar()) == ' ' ) { /* skip blanks */ }
348 /* c is now nonblank */
360 #line 361 "quote_calc2-s.tab.c"
363 #include <stdio.h> /* needed for printf */
366 #include <stdlib.h> /* needed for malloc, etc */
367 #include <string.h> /* needed for memset */
369 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
370 static int yygrowstack(YYSTACKDATA *data)
377 if ((newsize = data->stacksize) == 0)
378 newsize = YYINITSTACKSIZE;
379 else if (newsize >= YYMAXDEPTH)
381 else if ((newsize *= 2) > YYMAXDEPTH)
382 newsize = YYMAXDEPTH;
384 i = (int) (data->s_mark - data->s_base);
385 newss = (short *)realloc(data->s_base, newsize * sizeof(*newss));
389 data->s_base = newss;
390 data->s_mark = newss + i;
392 newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));
396 data->l_base = newvs;
397 data->l_mark = newvs + i;
399 data->stacksize = newsize;
400 data->s_last = data->s_base + newsize - 1;
404 #if YYPURE || defined(YY_NO_LEAKS)
405 static void yyfreestack(YYSTACKDATA *data)
409 memset(data, 0, sizeof(*data));
412 #define yyfreestack(data) /* nothing */
415 #define YYABORT goto yyabort
416 #define YYREJECT goto yyabort
417 #define YYACCEPT goto yyaccept
418 #define YYERROR goto yyerrlab
423 int yym, yyn, yystate;
427 if ((yys = getenv("YYDEBUG")) != 0)
430 if (yyn >= '0' && yyn <= '9')
441 memset(&yystack, 0, sizeof(yystack));
444 if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow;
445 yystack.s_mark = yystack.s_base;
446 yystack.l_mark = yystack.l_base;
451 if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
454 if ((yychar = YYLEX) < 0) yychar = 0;
459 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
460 if (!yys) yys = "illegal-symbol";
461 printf("%sdebug: state %d, reading %d (%s)\n",
462 YYPREFIX, yystate, yychar, yys);
466 if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
467 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
471 printf("%sdebug: state %d, shifting to state %d\n",
472 YYPREFIX, yystate, yytable[yyn]);
474 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
478 yystate = yytable[yyn];
479 *++yystack.s_mark = yytable[yyn];
480 *++yystack.l_mark = yylval;
482 if (yyerrflag > 0) --yyerrflag;
485 if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
486 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
491 if (yyerrflag) goto yyinrecovery;
493 yyerror("syntax error");
506 if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 &&
507 yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
511 printf("%sdebug: state %d, error recovery shifting\
512 to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]);
514 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
518 yystate = yytable[yyn];
519 *++yystack.s_mark = yytable[yyn];
520 *++yystack.l_mark = yylval;
527 printf("%sdebug: error recovery discarding state %d\n",
528 YYPREFIX, *yystack.s_mark);
530 if (yystack.s_mark <= yystack.s_base) goto yyabort;
538 if (yychar == 0) goto yyabort;
543 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
544 if (!yys) yys = "illegal-symbol";
545 printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
546 YYPREFIX, yystate, yychar, yys);
556 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
557 YYPREFIX, yystate, yyn, yyrule[yyn]);
561 yyval = yystack.l_mark[1-yym];
563 memset(&yyval, 0, sizeof yyval);
567 #line 35 "quote_calc2.y"
571 #line 39 "quote_calc2.y"
572 { printf("%d\n",yystack.l_mark[0]);}
575 #line 41 "quote_calc2.y"
576 { regs[yystack.l_mark[-2]] = yystack.l_mark[0]; }
579 #line 45 "quote_calc2.y"
580 { yyval = yystack.l_mark[-1]; }
583 #line 47 "quote_calc2.y"
584 { yyval = yystack.l_mark[-2] + yystack.l_mark[0]; }
587 #line 49 "quote_calc2.y"
588 { yyval = yystack.l_mark[-2] - yystack.l_mark[0]; }
591 #line 51 "quote_calc2.y"
592 { yyval = yystack.l_mark[-2] * yystack.l_mark[0]; }
595 #line 53 "quote_calc2.y"
596 { yyval = yystack.l_mark[-2] / yystack.l_mark[0]; }
599 #line 55 "quote_calc2.y"
600 { yyval = yystack.l_mark[-2] % yystack.l_mark[0]; }
603 #line 57 "quote_calc2.y"
604 { yyval = yystack.l_mark[-2] & yystack.l_mark[0]; }
607 #line 59 "quote_calc2.y"
608 { yyval = yystack.l_mark[-2] | yystack.l_mark[0]; }
611 #line 61 "quote_calc2.y"
612 { yyval = - yystack.l_mark[0]; }
615 #line 63 "quote_calc2.y"
616 { yyval = regs[yystack.l_mark[0]]; }
619 #line 68 "quote_calc2.y"
620 { yyval = yystack.l_mark[0]; base = (yystack.l_mark[0]==0) ? 8 : 10; }
623 #line 70 "quote_calc2.y"
624 { yyval = base * yystack.l_mark[-1] + yystack.l_mark[0]; }
626 #line 627 "quote_calc2-s.tab.c"
628 yystack.s_mark -= yym;
629 yystate = *yystack.s_mark;
630 yystack.l_mark -= yym;
632 if (yystate == 0 && yym == 0)
636 printf("%sdebug: after reduction, shifting from state 0 to\
637 state %d\n", YYPREFIX, YYFINAL);
640 *++yystack.s_mark = YYFINAL;
641 *++yystack.l_mark = yyval;
644 if ((yychar = YYLEX) < 0) yychar = 0;
649 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
650 if (!yys) yys = "illegal-symbol";
651 printf("%sdebug: state %d, reading %d (%s)\n",
652 YYPREFIX, YYFINAL, yychar, yys);
656 if (yychar == 0) goto yyaccept;
659 if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
660 yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
661 yystate = yytable[yyn];
663 yystate = yydgoto[yym];
666 printf("%sdebug: after reduction, shifting from state %d \
667 to state %d\n", YYPREFIX, *yystack.s_mark, yystate);
669 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
673 *++yystack.s_mark = (short) yystate;
674 *++yystack.l_mark = yyval;
678 yyerror("yacc stack overflow");
681 yyfreestack(&yystack);
685 yyfreestack(&yystack);