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_calc_parse
20 #define yylex quote_calc_lex
24 #define yyerror quote_calc_error
28 #define yychar quote_calc_char
32 #define yyval quote_calc_val
36 #define yylval quote_calc_lval
40 #define yydebug quote_calc_debug
44 #define yynerrs quote_calc_nerrs
48 #define yyerrflag quote_calc_errflag
49 #endif /* yyerrflag */
52 #define yylhs quote_calc_lhs
56 #define yylen quote_calc_len
60 #define yydefred quote_calc_defred
64 #define yydgoto quote_calc_dgoto
68 #define yysindex quote_calc_sindex
72 #define yyrindex quote_calc_rindex
76 #define yygindex quote_calc_gindex
80 #define yytable quote_calc_table
84 #define yycheck quote_calc_check
88 #define yyname quote_calc_name
92 #define yyrule quote_calc_rule
94 #define YYPREFIX "quote_calc_"
98 #line 2 "quote_calc.y"
106 static void yyerror(const char *s);
108 #line 109 "quote_calc.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();
160 #define YYERRCODE 256
161 static const short quote_calc_lhs[] = { -1,
162 0, 0, 0, 1, 1, 2, 2, 2, 2, 2,
163 2, 2, 2, 2, 2, 2, 3, 3,
165 static const short quote_calc_len[] = { 2,
166 0, 3, 3, 1, 3, 3, 3, 3, 3, 3,
167 3, 3, 3, 2, 1, 1, 1, 2,
169 static const short quote_calc_defred[] = { 1,
170 0, 0, 0, 17, 0, 0, 0, 0, 0, 3,
171 15, 0, 0, 0, 2, 0, 0, 0, 0, 0,
172 0, 0, 18, 0, 6, 0, 0, 0, 0, 0,
175 static const short quote_calc_dgoto[] = { 1,
178 static const short quote_calc_sindex[] = { 0,
179 -38, 5, -36, 0, -51, -36, 7, -121, -248, 0,
180 0, -243, -36, -22, 0, -36, -36, -36, -36, -36,
181 -36, -36, 0, -121, 0, -121, -121, -121, -121, -121,
184 static const short quote_calc_rindex[] = { 0,
185 0, 0, 0, 0, -9, 0, 0, 13, -10, 0,
186 0, -5, 0, 0, 0, 0, 0, 0, 0, 0,
187 0, 0, 0, 15, 0, -3, -2, -1, 1, 2,
190 static const short quote_calc_gindex[] = { 0,
193 #define YYTABLESIZE 258
194 static const short quote_calc_table[] = { 16,
195 15, 6, 22, 6, 14, 13, 7, 8, 9, 13,
196 10, 11, 12, 16, 10, 17, 15, 18, 25, 19,
197 23, 20, 4, 21, 5, 0, 0, 0, 0, 0,
198 16, 0, 0, 0, 0, 14, 13, 7, 8, 9,
199 0, 10, 11, 12, 12, 0, 0, 14, 0, 0,
200 0, 0, 0, 0, 24, 0, 0, 26, 27, 28,
201 29, 30, 31, 32, 0, 0, 0, 0, 0, 0,
202 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
203 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
204 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
205 0, 22, 0, 0, 0, 0, 0, 0, 0, 0,
206 0, 0, 0, 16, 15, 0, 0, 0, 14, 13,
207 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
208 0, 0, 0, 0, 0, 16, 0, 17, 0, 18,
209 0, 19, 0, 20, 0, 21, 0, 0, 0, 0,
210 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
211 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
212 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
213 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
214 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
215 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
216 0, 0, 0, 0, 0, 0, 0, 2, 0, 0,
217 3, 0, 3, 0, 0, 0, 0, 0, 0, 0,
218 4, 5, 4, 11, 16, 0, 17, 0, 18, 0,
219 19, 0, 20, 0, 21, 0, 16, 15, 16, 15,
220 16, 15, 16, 15, 16, 15, 16, 15,
222 static const short quote_calc_check[] = { 10,
223 10, 40, 124, 40, 10, 10, 10, 10, 10, 61,
224 10, 10, 10, 257, 10, 259, 10, 261, 41, 263,
225 269, 265, 10, 267, 10, -1, -1, -1, -1, -1,
226 41, -1, -1, -1, -1, 41, 41, 41, 41, 41,
227 -1, 41, 41, 41, 3, -1, -1, 6, -1, -1,
228 -1, -1, -1, -1, 13, -1, -1, 16, 17, 18,
229 19, 20, 21, 22, -1, -1, -1, -1, -1, -1,
230 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
231 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
232 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
233 -1, 124, -1, -1, -1, -1, -1, -1, -1, -1,
234 -1, -1, -1, 124, 124, -1, -1, -1, 124, 124,
235 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
236 -1, -1, -1, -1, -1, 257, -1, 259, -1, 261,
237 -1, 263, -1, 265, -1, 267, -1, -1, -1, -1,
238 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
239 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
240 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
241 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
242 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
243 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
244 -1, -1, -1, -1, -1, -1, -1, 256, -1, -1,
245 259, -1, 259, -1, -1, -1, -1, -1, -1, -1,
246 269, 270, 269, 270, 257, -1, 259, -1, 261, -1,
247 263, -1, 265, -1, 267, -1, 257, 257, 259, 259,
248 261, 261, 263, 263, 265, 265, 267, 267,
254 #define YYMAXTOKEN 271
256 static const char *yyname[] = {
258 "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,
259 0,0,0,0,0,0,"'%'","'&'",0,"'('","')'","'*'","'+'",0,"'-'",0,"'/'",0,0,0,0,0,0,0,
260 0,0,0,0,0,0,"'='",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
261 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"'|'",0,0,0,0,0,0,
262 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
263 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
264 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
265 0,0,0,0,0,0,"OP_ADD","\"ADD\"","OP_SUB","\"SUB\"","OP_MUL","\"MUL\"","OP_DIV",
266 "\"DIV\"","OP_MOD","\"MOD\"","OP_AND","\"AND\"","DIGIT","LETTER","UMINUS",
268 static const char *yyrule[] = {
271 "list : list stat '\\n'",
272 "list : list error '\\n'",
274 "stat : LETTER '=' expr",
275 "expr : '(' expr ')'",
276 "expr : expr OP_ADD expr",
277 "expr : expr OP_SUB expr",
278 "expr : expr OP_MUL expr",
279 "expr : expr OP_DIV expr",
280 "expr : expr OP_MOD expr",
281 "expr : expr OP_AND expr",
282 "expr : expr '|' expr",
283 "expr : OP_SUB expr",
287 "number : number DIGIT",
300 /* define the initial stack-sizes */
303 #define YYMAXDEPTH YYSTACKSIZE
306 #define YYSTACKSIZE YYMAXDEPTH
308 #define YYSTACKSIZE 500
309 #define YYMAXDEPTH 500
313 #define YYINITSTACKSIZE 500
323 /* variables for the parser stack */
324 static YYSTACKDATA yystack;
325 #line 73 "quote_calc.y"
326 /* start of programs */
331 while(!feof(stdin)) {
338 yyerror(const char *s)
340 fprintf(stderr, "%s\n", s);
345 /* lexical analysis routine */
346 /* returns LETTER for a lower case letter, yylval = 0 through 25 */
347 /* return DIGIT for a digit, yylval = 0 through 9 */
348 /* all other characters are returned immediately */
352 while( (c=getchar()) == ' ' ) { /* skip blanks */ }
354 /* c is now nonblank */
366 #line 367 "quote_calc.tab.c"
369 #include <stdio.h> /* needed for printf */
372 #include <stdlib.h> /* needed for malloc, etc */
373 #include <string.h> /* needed for memset */
375 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
376 static int yygrowstack(YYSTACKDATA *data)
383 if ((newsize = data->stacksize) == 0)
384 newsize = YYINITSTACKSIZE;
385 else if (newsize >= YYMAXDEPTH)
387 else if ((newsize *= 2) > YYMAXDEPTH)
388 newsize = YYMAXDEPTH;
390 i = (int) (data->s_mark - data->s_base);
391 newss = (short *)realloc(data->s_base, newsize * sizeof(*newss));
395 data->s_base = newss;
396 data->s_mark = newss + i;
398 newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));
402 data->l_base = newvs;
403 data->l_mark = newvs + i;
405 data->stacksize = newsize;
406 data->s_last = data->s_base + newsize - 1;
410 #if YYPURE || defined(YY_NO_LEAKS)
411 static void yyfreestack(YYSTACKDATA *data)
415 memset(data, 0, sizeof(*data));
418 #define yyfreestack(data) /* nothing */
421 #define YYABORT goto yyabort
422 #define YYREJECT goto yyabort
423 #define YYACCEPT goto yyaccept
424 #define YYERROR goto yyerrlab
429 int yym, yyn, yystate;
433 if ((yys = getenv("YYDEBUG")) != 0)
436 if (yyn >= '0' && yyn <= '9')
447 memset(&yystack, 0, sizeof(yystack));
450 if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow;
451 yystack.s_mark = yystack.s_base;
452 yystack.l_mark = yystack.l_base;
457 if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
460 if ((yychar = YYLEX) < 0) yychar = 0;
465 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
466 if (!yys) yys = "illegal-symbol";
467 printf("%sdebug: state %d, reading %d (%s)\n",
468 YYPREFIX, yystate, yychar, yys);
472 if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
473 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
477 printf("%sdebug: state %d, shifting to state %d\n",
478 YYPREFIX, yystate, yytable[yyn]);
480 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
484 yystate = yytable[yyn];
485 *++yystack.s_mark = yytable[yyn];
486 *++yystack.l_mark = yylval;
488 if (yyerrflag > 0) --yyerrflag;
491 if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
492 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
497 if (yyerrflag) goto yyinrecovery;
499 yyerror("syntax error");
512 if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 &&
513 yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
517 printf("%sdebug: state %d, error recovery shifting\
518 to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]);
520 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
524 yystate = yytable[yyn];
525 *++yystack.s_mark = yytable[yyn];
526 *++yystack.l_mark = yylval;
533 printf("%sdebug: error recovery discarding state %d\n",
534 YYPREFIX, *yystack.s_mark);
536 if (yystack.s_mark <= yystack.s_base) goto yyabort;
544 if (yychar == 0) goto yyabort;
549 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
550 if (!yys) yys = "illegal-symbol";
551 printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
552 YYPREFIX, yystate, yychar, yys);
562 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
563 YYPREFIX, yystate, yyn, yyrule[yyn]);
567 yyval = yystack.l_mark[1-yym];
569 memset(&yyval, 0, sizeof yyval);
573 #line 35 "quote_calc.y"
577 #line 39 "quote_calc.y"
578 { printf("%d\n",yystack.l_mark[0]);}
581 #line 41 "quote_calc.y"
582 { regs[yystack.l_mark[-2]] = yystack.l_mark[0]; }
585 #line 45 "quote_calc.y"
586 { yyval = yystack.l_mark[-1]; }
589 #line 47 "quote_calc.y"
590 { yyval = yystack.l_mark[-2] + yystack.l_mark[0]; }
593 #line 49 "quote_calc.y"
594 { yyval = yystack.l_mark[-2] - yystack.l_mark[0]; }
597 #line 51 "quote_calc.y"
598 { yyval = yystack.l_mark[-2] * yystack.l_mark[0]; }
601 #line 53 "quote_calc.y"
602 { yyval = yystack.l_mark[-2] / yystack.l_mark[0]; }
605 #line 55 "quote_calc.y"
606 { yyval = yystack.l_mark[-2] % yystack.l_mark[0]; }
609 #line 57 "quote_calc.y"
610 { yyval = yystack.l_mark[-2] & yystack.l_mark[0]; }
613 #line 59 "quote_calc.y"
614 { yyval = yystack.l_mark[-2] | yystack.l_mark[0]; }
617 #line 61 "quote_calc.y"
618 { yyval = - yystack.l_mark[0]; }
621 #line 63 "quote_calc.y"
622 { yyval = regs[yystack.l_mark[0]]; }
625 #line 68 "quote_calc.y"
626 { yyval = yystack.l_mark[0]; base = (yystack.l_mark[0]==0) ? 8 : 10; }
629 #line 70 "quote_calc.y"
630 { yyval = base * yystack.l_mark[-1] + yystack.l_mark[0]; }
632 #line 633 "quote_calc.tab.c"
634 yystack.s_mark -= yym;
635 yystate = *yystack.s_mark;
636 yystack.l_mark -= yym;
638 if (yystate == 0 && yym == 0)
642 printf("%sdebug: after reduction, shifting from state 0 to\
643 state %d\n", YYPREFIX, YYFINAL);
646 *++yystack.s_mark = YYFINAL;
647 *++yystack.l_mark = yyval;
650 if ((yychar = YYLEX) < 0) yychar = 0;
655 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
656 if (!yys) yys = "illegal-symbol";
657 printf("%sdebug: state %d, reading %d (%s)\n",
658 YYPREFIX, YYFINAL, yychar, yys);
662 if (yychar == 0) goto yyaccept;
665 if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
666 yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
667 yystate = yytable[yyn];
669 yystate = yydgoto[yym];
672 printf("%sdebug: after reduction, shifting from state %d \
673 to state %d\n", YYPREFIX, *yystack.s_mark, yystate);
675 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
679 *++yystack.s_mark = (short) yystate;
680 *++yystack.l_mark = yyval;
684 yyerror("yacc stack overflow");
687 yyfreestack(&yystack);
691 yyfreestack(&yystack);