1 /* original parser id follows */
2 /* yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93" */
3 /* (use YYMAJOR/YYMINOR for ifdefs dependent on parser version) */
8 #define YYCHECK "yyyymmdd"
11 #define yyclearin (yychar = YYEMPTY)
12 #define yyerrok (yyerrflag = 0)
13 #define YYRECOVERING() (yyerrflag != 0)
18 #define yyparse quote_calc4_parse
22 #define yylex quote_calc4_lex
26 #define yyerror quote_calc4_error
30 #define yychar quote_calc4_char
34 #define yyval quote_calc4_val
38 #define yylval quote_calc4_lval
42 #define yydebug quote_calc4_debug
46 #define yynerrs quote_calc4_nerrs
50 #define yyerrflag quote_calc4_errflag
51 #endif /* yyerrflag */
54 #define yylhs quote_calc4_lhs
58 #define yylen quote_calc4_len
62 #define yydefred quote_calc4_defred
66 #define yydgoto quote_calc4_dgoto
70 #define yysindex quote_calc4_sindex
74 #define yyrindex quote_calc4_rindex
78 #define yygindex quote_calc4_gindex
82 #define yytable quote_calc4_table
86 #define yycheck quote_calc4_check
90 #define yyname quote_calc4_name
94 #define yyrule quote_calc4_rule
96 #define YYPREFIX "quote_calc4_"
100 #line 2 "quote_calc4.y"
108 static void yyerror(const char *s);
110 #line 111 "quote_calc4-s.tab.c"
112 #if ! defined(YYSTYPE) && ! defined(YYSTYPE_IS_DECLARED)
113 /* Default: YYSTYPE is the semantic value type. */
115 # define YYSTYPE_IS_DECLARED 1
118 /* compatibility with bison */
120 /* compatibility with FreeBSD */
121 # ifdef YYPARSE_PARAM_TYPE
122 # define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
124 # define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
127 # define YYPARSE_DECL() yyparse(void)
130 /* Parameters sent to lex. */
132 # define YYLEX_DECL() yylex(void *YYLEX_PARAM)
133 # define YYLEX yylex(YYLEX_PARAM)
135 # define YYLEX_DECL() yylex(void)
136 # define YYLEX yylex()
139 /* Parameters sent to yyerror. */
141 #define YYERROR_DECL() yyerror(const char *s)
144 #define YYERROR_CALL(msg) yyerror(msg)
147 extern int YYPARSE_DECL();
158 #define YYERRCODE 256
160 static const YYINT quote_calc4_lhs[] = { -1,
161 0, 0, 0, 1, 1, 2, 2, 2, 2, 2,
162 2, 2, 2, 2, 2, 2, 3, 3,
164 static const YYINT quote_calc4_len[] = { 2,
165 0, 3, 3, 1, 3, 3, 3, 3, 3, 3,
166 3, 3, 3, 2, 1, 1, 1, 2,
168 static const YYINT quote_calc4_defred[] = { 1,
169 0, 0, 0, 17, 0, 0, 0, 0, 0, 3,
170 15, 0, 0, 0, 2, 0, 0, 0, 0, 0,
171 0, 0, 18, 0, 6, 0, 0, 0, 0, 0,
174 static const YYINT quote_calc4_dgoto[] = { 1,
177 static const YYINT quote_calc4_sindex[] = { 0,
178 -38, 4, -36, 0, -51, -36, 6, -121, -249, 0,
179 0, -243, -36, -23, 0, -36, -36, -36, -36, -36,
180 -36, -36, 0, -121, 0, -121, -121, -121, -121, -121,
183 static const YYINT quote_calc4_rindex[] = { 0,
184 0, 0, 0, 0, -9, 0, 0, 12, -10, 0,
185 0, -5, 0, 0, 0, 0, 0, 0, 0, 0,
186 0, 0, 0, 14, 0, -3, -2, -1, 1, 2,
189 static const YYINT quote_calc4_gindex[] = { 0,
192 #define YYTABLESIZE 259
193 static const YYINT quote_calc4_table[] = { 16,
194 15, 6, 22, 6, 14, 13, 7, 8, 9, 13,
195 10, 11, 12, 10, 16, 15, 17, 25, 18, 23,
196 19, 4, 20, 5, 21, 0, 0, 0, 0, 0,
197 16, 0, 0, 0, 0, 14, 13, 7, 8, 9,
198 0, 10, 11, 12, 12, 0, 0, 14, 0, 0,
199 0, 0, 0, 0, 24, 0, 0, 26, 27, 28,
200 29, 30, 31, 32, 0, 0, 0, 0, 0, 0,
201 0, 0, 0, 0, 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 22, 0, 0, 0, 0, 0, 0, 0, 0, 0,
205 0, 0, 0, 16, 15, 0, 0, 0, 14, 13,
206 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
207 0, 0, 0, 0, 0, 0, 16, 0, 17, 0,
208 18, 0, 19, 0, 20, 0, 21, 0, 0, 0,
209 0, 0, 0, 0, 0, 0, 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, 2, 0, 0,
216 0, 3, 0, 3, 0, 0, 0, 0, 0, 0,
217 4, 5, 4, 11, 16, 0, 17, 0, 18, 0,
218 19, 0, 20, 0, 21, 0, 0, 16, 15, 16,
219 15, 16, 15, 16, 15, 16, 15, 16, 15,
221 static const YYINT quote_calc4_check[] = { 10,
222 10, 40, 124, 40, 10, 10, 10, 10, 10, 61,
223 10, 10, 10, 10, 258, 10, 260, 41, 262, 269,
224 264, 10, 266, 10, 268, -1, -1, -1, -1, -1,
225 41, -1, -1, -1, -1, 41, 41, 41, 41, 41,
226 -1, 41, 41, 41, 3, -1, -1, 6, -1, -1,
227 -1, -1, -1, -1, 13, -1, -1, 16, 17, 18,
228 19, 20, 21, 22, -1, -1, -1, -1, -1, -1,
229 -1, -1, -1, -1, -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 124, -1, -1, -1, -1, -1, -1, -1, -1, -1,
233 -1, -1, -1, 124, 124, -1, -1, -1, 124, 124,
234 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
235 -1, -1, -1, -1, -1, -1, 258, -1, 260, -1,
236 262, -1, 264, -1, 266, -1, 268, -1, -1, -1,
237 -1, -1, -1, -1, -1, -1, -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, 256, -1, -1,
244 -1, 260, -1, 260, -1, -1, -1, -1, -1, -1,
245 269, 270, 269, 270, 258, -1, 260, -1, 262, -1,
246 264, -1, 266, -1, 268, -1, -1, 258, 258, 260,
247 260, 262, 262, 264, 264, 266, 266, 268, 268,
253 #define YYMAXTOKEN 271
254 #define YYUNDFTOKEN 277
255 #define YYTRANSLATE(a) ((a) > YYMAXTOKEN ? YYUNDFTOKEN : (a))
257 static const char *const quote_calc4_name[] = {
259 "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,
260 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,
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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
266 0,0,0,0,0,0,"OP_ADD","\"ADD-operator\"","OP_SUB","\"SUB-operator\"","OP_MUL",
267 "\"MUL-operator\"","OP_DIV","\"DIV-operator\"","OP_MOD","\"MOD-operator\"",
268 "OP_AND","\"AND-operator\"","DIGIT","LETTER","UMINUS",0,0,0,0,0,
271 static const char *const quote_calc4_rule[] = {
274 "list : list stat '\\n'",
275 "list : list error '\\n'",
277 "stat : LETTER '=' expr",
278 "expr : '(' expr ')'",
279 "expr : expr \"ADD-operator\" expr",
280 "expr : expr \"SUB-operator\" expr",
281 "expr : expr \"MUL-operator\" expr",
282 "expr : expr \"DIV-operator\" expr",
283 "expr : expr \"MOD-operator\" expr",
284 "expr : expr \"AND-operator\" expr",
285 "expr : expr '|' expr",
286 "expr : \"SUB-operator\" expr",
290 "number : number DIGIT",
303 /* define the initial stack-sizes */
306 #define YYMAXDEPTH YYSTACKSIZE
309 #define YYSTACKSIZE YYMAXDEPTH
311 #define YYSTACKSIZE 10000
312 #define YYMAXDEPTH 10000
316 #define YYINITSTACKSIZE 200
326 /* variables for the parser stack */
327 static YYSTACKDATA yystack;
328 #line 73 "quote_calc4.y"
329 /* start of programs */
334 while(!feof(stdin)) {
341 yyerror(const char *s)
343 fprintf(stderr, "%s\n", s);
348 /* lexical analysis routine */
349 /* returns LETTER for a lower case letter, yylval = 0 through 25 */
350 /* return DIGIT for a digit, yylval = 0 through 9 */
351 /* all other characters are returned immediately */
355 while( (c=getchar()) == ' ' ) { /* skip blanks */ }
357 /* c is now nonblank */
369 #line 370 "quote_calc4-s.tab.c"
372 #include <stdio.h> /* needed for printf */
375 #include <stdlib.h> /* needed for malloc, etc */
376 #include <string.h> /* needed for memset */
378 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
379 static int yygrowstack(YYSTACKDATA *data)
386 if ((newsize = data->stacksize) == 0)
387 newsize = YYINITSTACKSIZE;
388 else if (newsize >= YYMAXDEPTH)
390 else if ((newsize *= 2) > YYMAXDEPTH)
391 newsize = YYMAXDEPTH;
393 i = (int) (data->s_mark - data->s_base);
394 newss = (YYINT *)realloc(data->s_base, newsize * sizeof(*newss));
398 data->s_base = newss;
399 data->s_mark = newss + i;
401 newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));
405 data->l_base = newvs;
406 data->l_mark = newvs + i;
408 data->stacksize = newsize;
409 data->s_last = data->s_base + newsize - 1;
413 #if YYPURE || defined(YY_NO_LEAKS)
414 static void yyfreestack(YYSTACKDATA *data)
418 memset(data, 0, sizeof(*data));
421 #define yyfreestack(data) /* nothing */
424 #define YYABORT goto yyabort
425 #define YYREJECT goto yyabort
426 #define YYACCEPT goto yyaccept
427 #define YYERROR goto yyerrlab
432 int yym, yyn, yystate;
436 if ((yys = getenv("YYDEBUG")) != 0)
439 if (yyn >= '0' && yyn <= '9')
452 memset(&yystack, 0, sizeof(yystack));
455 if (yystack.s_base == NULL && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
456 yystack.s_mark = yystack.s_base;
457 yystack.l_mark = yystack.l_base;
462 if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
466 if (yychar < 0) yychar = YYEOF;
470 if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN];
471 printf("%sdebug: state %d, reading %d (%s)\n",
472 YYPREFIX, yystate, yychar, yys);
476 if (((yyn = yysindex[yystate]) != 0) && (yyn += yychar) >= 0 &&
477 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar)
481 printf("%sdebug: state %d, shifting to state %d\n",
482 YYPREFIX, yystate, yytable[yyn]);
484 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
485 yystate = yytable[yyn];
486 *++yystack.s_mark = yytable[yyn];
487 *++yystack.l_mark = yylval;
489 if (yyerrflag > 0) --yyerrflag;
492 if (((yyn = yyrindex[yystate]) != 0) && (yyn += yychar) >= 0 &&
493 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar)
498 if (yyerrflag != 0) goto yyinrecovery;
500 YYERROR_CALL("syntax error");
502 goto yyerrlab; /* redundant goto avoids 'unused label' warning */
512 if (((yyn = yysindex[*yystack.s_mark]) != 0) && (yyn += YYERRCODE) >= 0 &&
513 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) 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) == YYENOMEM) goto yyoverflow;
521 yystate = yytable[yyn];
522 *++yystack.s_mark = yytable[yyn];
523 *++yystack.l_mark = yylval;
530 printf("%sdebug: error recovery discarding state %d\n",
531 YYPREFIX, *yystack.s_mark);
533 if (yystack.s_mark <= yystack.s_base) goto yyabort;
541 if (yychar == YYEOF) goto yyabort;
545 if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN];
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);
569 #line 35 "quote_calc4.y"
573 #line 39 "quote_calc4.y"
574 { printf("%d\n",yystack.l_mark[0]);}
577 #line 41 "quote_calc4.y"
578 { regs[yystack.l_mark[-2]] = yystack.l_mark[0]; }
581 #line 45 "quote_calc4.y"
582 { yyval = yystack.l_mark[-1]; }
585 #line 47 "quote_calc4.y"
586 { yyval = yystack.l_mark[-2] + yystack.l_mark[0]; }
589 #line 49 "quote_calc4.y"
590 { yyval = yystack.l_mark[-2] - yystack.l_mark[0]; }
593 #line 51 "quote_calc4.y"
594 { yyval = yystack.l_mark[-2] * yystack.l_mark[0]; }
597 #line 53 "quote_calc4.y"
598 { yyval = yystack.l_mark[-2] / yystack.l_mark[0]; }
601 #line 55 "quote_calc4.y"
602 { yyval = yystack.l_mark[-2] % yystack.l_mark[0]; }
605 #line 57 "quote_calc4.y"
606 { yyval = yystack.l_mark[-2] & yystack.l_mark[0]; }
609 #line 59 "quote_calc4.y"
610 { yyval = yystack.l_mark[-2] | yystack.l_mark[0]; }
613 #line 61 "quote_calc4.y"
614 { yyval = - yystack.l_mark[0]; }
617 #line 63 "quote_calc4.y"
618 { yyval = regs[yystack.l_mark[0]]; }
621 #line 68 "quote_calc4.y"
622 { yyval = yystack.l_mark[0]; base = (yystack.l_mark[0]==0) ? 8 : 10; }
625 #line 70 "quote_calc4.y"
626 { yyval = base * yystack.l_mark[-1] + yystack.l_mark[0]; }
628 #line 629 "quote_calc4-s.tab.c"
630 yystack.s_mark -= yym;
631 yystate = *yystack.s_mark;
632 yystack.l_mark -= yym;
634 if (yystate == 0 && yym == 0)
638 printf("%sdebug: after reduction, shifting from state 0 to\
639 state %d\n", YYPREFIX, YYFINAL);
642 *++yystack.s_mark = YYFINAL;
643 *++yystack.l_mark = yyval;
647 if (yychar < 0) yychar = YYEOF;
651 if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN];
652 printf("%sdebug: state %d, reading %d (%s)\n",
653 YYPREFIX, YYFINAL, yychar, yys);
657 if (yychar == YYEOF) goto yyaccept;
660 if (((yyn = yygindex[yym]) != 0) && (yyn += yystate) >= 0 &&
661 yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) 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) == YYENOMEM) goto yyoverflow;
671 *++yystack.s_mark = (YYINT) yystate;
672 *++yystack.l_mark = yyval;
676 YYERROR_CALL("yacc stack overflow");
679 yyfreestack(&yystack);
683 yyfreestack(&yystack);