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_calc3_parse
20 #define yylex quote_calc3_lex
24 #define yyerror quote_calc3_error
28 #define yychar quote_calc3_char
32 #define yyval quote_calc3_val
36 #define yylval quote_calc3_lval
40 #define yydebug quote_calc3_debug
44 #define yynerrs quote_calc3_nerrs
48 #define yyerrflag quote_calc3_errflag
49 #endif /* yyerrflag */
52 #define yylhs quote_calc3_lhs
56 #define yylen quote_calc3_len
60 #define yydefred quote_calc3_defred
64 #define yydgoto quote_calc3_dgoto
68 #define yysindex quote_calc3_sindex
72 #define yyrindex quote_calc3_rindex
76 #define yygindex quote_calc3_gindex
80 #define yytable quote_calc3_table
84 #define yycheck quote_calc3_check
88 #define yyname quote_calc3_name
92 #define yyrule quote_calc3_rule
94 #define YYPREFIX "quote_calc3_"
98 #line 2 "quote_calc3.y"
106 static void yyerror(const char *s);
108 #line 109 "quote_calc3-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_calc3_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_calc3_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_calc3_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_calc3_dgoto[] = { 1,
172 static const short quote_calc3_sindex[] = { 0,
173 -38, 5, -36, 0, -51, -36, 7, -121, -248, 0,
174 0, -243, -36, -22, 0, -36, -36, -36, -36, -36,
175 -36, -36, 0, -121, 0, -121, -121, -121, -121, -121,
178 static const short quote_calc3_rindex[] = { 0,
179 0, 0, 0, 0, -9, 0, 0, 13, -10, 0,
180 0, -5, 0, 0, 0, 0, 0, 0, 0, 0,
181 0, 0, 0, 15, 0, -3, -2, -1, 1, 2,
184 static const short quote_calc3_gindex[] = { 0,
187 #define YYTABLESIZE 258
188 static const short quote_calc3_table[] = { 16,
189 15, 6, 22, 6, 14, 13, 7, 8, 9, 13,
190 10, 11, 12, 16, 10, 17, 15, 18, 25, 19,
191 23, 20, 4, 21, 5, 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 0, 22, 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, 16, 0, 17, 0, 18,
203 0, 19, 0, 20, 0, 21, 0, 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 3, 0, 3, 0, 0, 0, 0, 0, 0, 0,
212 4, 5, 4, 11, 16, 0, 17, 0, 18, 0,
213 19, 0, 20, 0, 21, 0, 16, 15, 16, 15,
214 16, 15, 16, 15, 16, 15, 16, 15,
216 static const short quote_calc3_check[] = { 10,
217 10, 40, 124, 40, 10, 10, 10, 10, 10, 61,
218 10, 10, 10, 257, 10, 259, 10, 261, 41, 263,
219 269, 265, 10, 267, 10, -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 -1, 124, -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, 257, -1, 259, -1, 261,
231 -1, 263, -1, 265, -1, 267, -1, -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 259, -1, 259, -1, -1, -1, -1, -1, -1, -1,
240 269, 270, 269, 270, 257, -1, 259, -1, 261, -1,
241 263, -1, 265, -1, 267, -1, 257, 257, 259, 259,
242 261, 261, 263, 263, 265, 265, 267, 267,
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-operator\"","OP_SUB","\"SUB-operator\"","OP_MUL",
260 "\"MUL-operator\"","OP_DIV","\"DIV-operator\"","OP_MOD","\"MOD-operator\"",
261 "OP_AND","\"AND-operator\"","DIGIT","LETTER","UMINUS",
263 static const char *yyrule[] = {
266 "list : list stat '\\n'",
267 "list : list error '\\n'",
269 "stat : LETTER '=' expr",
270 "expr : '(' expr ')'",
271 "expr : expr OP_ADD expr",
272 "expr : expr OP_SUB expr",
273 "expr : expr OP_MUL expr",
274 "expr : expr OP_DIV expr",
275 "expr : expr OP_MOD expr",
276 "expr : expr OP_AND expr",
277 "expr : expr '|' expr",
278 "expr : OP_SUB expr",
282 "number : number DIGIT",
295 /* define the initial stack-sizes */
298 #define YYMAXDEPTH YYSTACKSIZE
301 #define YYSTACKSIZE YYMAXDEPTH
303 #define YYSTACKSIZE 500
304 #define YYMAXDEPTH 500
308 #define YYINITSTACKSIZE 500
318 /* variables for the parser stack */
319 static YYSTACKDATA yystack;
320 #line 73 "quote_calc3.y"
321 /* start of programs */
326 while(!feof(stdin)) {
333 yyerror(const char *s)
335 fprintf(stderr, "%s\n", s);
340 /* lexical analysis routine */
341 /* returns LETTER for a lower case letter, yylval = 0 through 25 */
342 /* return DIGIT for a digit, yylval = 0 through 9 */
343 /* all other characters are returned immediately */
347 while( (c=getchar()) == ' ' ) { /* skip blanks */ }
349 /* c is now nonblank */
361 #line 362 "quote_calc3-s.tab.c"
364 #include <stdio.h> /* needed for printf */
367 #include <stdlib.h> /* needed for malloc, etc */
368 #include <string.h> /* needed for memset */
370 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
371 static int yygrowstack(YYSTACKDATA *data)
378 if ((newsize = data->stacksize) == 0)
379 newsize = YYINITSTACKSIZE;
380 else if (newsize >= YYMAXDEPTH)
382 else if ((newsize *= 2) > YYMAXDEPTH)
383 newsize = YYMAXDEPTH;
385 i = (int) (data->s_mark - data->s_base);
386 newss = (short *)realloc(data->s_base, newsize * sizeof(*newss));
390 data->s_base = newss;
391 data->s_mark = newss + i;
393 newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));
397 data->l_base = newvs;
398 data->l_mark = newvs + i;
400 data->stacksize = newsize;
401 data->s_last = data->s_base + newsize - 1;
405 #if YYPURE || defined(YY_NO_LEAKS)
406 static void yyfreestack(YYSTACKDATA *data)
410 memset(data, 0, sizeof(*data));
413 #define yyfreestack(data) /* nothing */
416 #define YYABORT goto yyabort
417 #define YYREJECT goto yyabort
418 #define YYACCEPT goto yyaccept
419 #define YYERROR goto yyerrlab
424 int yym, yyn, yystate;
428 if ((yys = getenv("YYDEBUG")) != 0)
431 if (yyn >= '0' && yyn <= '9')
442 memset(&yystack, 0, sizeof(yystack));
445 if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow;
446 yystack.s_mark = yystack.s_base;
447 yystack.l_mark = yystack.l_base;
452 if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
455 if ((yychar = YYLEX) < 0) yychar = 0;
460 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
461 if (!yys) yys = "illegal-symbol";
462 printf("%sdebug: state %d, reading %d (%s)\n",
463 YYPREFIX, yystate, yychar, yys);
467 if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
468 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
472 printf("%sdebug: state %d, shifting to state %d\n",
473 YYPREFIX, yystate, yytable[yyn]);
475 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
479 yystate = yytable[yyn];
480 *++yystack.s_mark = yytable[yyn];
481 *++yystack.l_mark = yylval;
483 if (yyerrflag > 0) --yyerrflag;
486 if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
487 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
492 if (yyerrflag) goto yyinrecovery;
494 yyerror("syntax error");
507 if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 &&
508 yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
512 printf("%sdebug: state %d, error recovery shifting\
513 to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]);
515 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
519 yystate = yytable[yyn];
520 *++yystack.s_mark = yytable[yyn];
521 *++yystack.l_mark = yylval;
528 printf("%sdebug: error recovery discarding state %d\n",
529 YYPREFIX, *yystack.s_mark);
531 if (yystack.s_mark <= yystack.s_base) goto yyabort;
539 if (yychar == 0) goto yyabort;
544 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
545 if (!yys) yys = "illegal-symbol";
546 printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
547 YYPREFIX, yystate, yychar, yys);
557 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
558 YYPREFIX, yystate, yyn, yyrule[yyn]);
562 yyval = yystack.l_mark[1-yym];
564 memset(&yyval, 0, sizeof yyval);
568 #line 35 "quote_calc3.y"
572 #line 39 "quote_calc3.y"
573 { printf("%d\n",yystack.l_mark[0]);}
576 #line 41 "quote_calc3.y"
577 { regs[yystack.l_mark[-2]] = yystack.l_mark[0]; }
580 #line 45 "quote_calc3.y"
581 { yyval = yystack.l_mark[-1]; }
584 #line 47 "quote_calc3.y"
585 { yyval = yystack.l_mark[-2] + yystack.l_mark[0]; }
588 #line 49 "quote_calc3.y"
589 { yyval = yystack.l_mark[-2] - yystack.l_mark[0]; }
592 #line 51 "quote_calc3.y"
593 { yyval = yystack.l_mark[-2] * yystack.l_mark[0]; }
596 #line 53 "quote_calc3.y"
597 { yyval = yystack.l_mark[-2] / yystack.l_mark[0]; }
600 #line 55 "quote_calc3.y"
601 { yyval = yystack.l_mark[-2] % yystack.l_mark[0]; }
604 #line 57 "quote_calc3.y"
605 { yyval = yystack.l_mark[-2] & yystack.l_mark[0]; }
608 #line 59 "quote_calc3.y"
609 { yyval = yystack.l_mark[-2] | yystack.l_mark[0]; }
612 #line 61 "quote_calc3.y"
613 { yyval = - yystack.l_mark[0]; }
616 #line 63 "quote_calc3.y"
617 { yyval = regs[yystack.l_mark[0]]; }
620 #line 68 "quote_calc3.y"
621 { yyval = yystack.l_mark[0]; base = (yystack.l_mark[0]==0) ? 8 : 10; }
624 #line 70 "quote_calc3.y"
625 { yyval = base * yystack.l_mark[-1] + yystack.l_mark[0]; }
627 #line 628 "quote_calc3-s.tab.c"
629 yystack.s_mark -= yym;
630 yystate = *yystack.s_mark;
631 yystack.l_mark -= yym;
633 if (yystate == 0 && yym == 0)
637 printf("%sdebug: after reduction, shifting from state 0 to\
638 state %d\n", YYPREFIX, YYFINAL);
641 *++yystack.s_mark = YYFINAL;
642 *++yystack.l_mark = yyval;
645 if ((yychar = YYLEX) < 0) yychar = 0;
650 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
651 if (!yys) yys = "illegal-symbol";
652 printf("%sdebug: state %d, reading %d (%s)\n",
653 YYPREFIX, YYFINAL, yychar, yys);
657 if (yychar == 0) goto yyaccept;
660 if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
661 yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
662 yystate = yytable[yyn];
664 yystate = yydgoto[yym];
667 printf("%sdebug: after reduction, shifting from state %d \
668 to state %d\n", YYPREFIX, *yystack.s_mark, yystate);
670 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
674 *++yystack.s_mark = (short) yystate;
675 *++yystack.l_mark = yyval;
679 yyerror("yacc stack overflow");
682 yyfreestack(&yystack);
686 yyfreestack(&yystack);