2 static const char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93";
8 #define YYPATCH 20140101
11 #define yyclearin (yychar = YYEMPTY)
12 #define yyerrok (yyerrflag = 0)
13 #define YYRECOVERING() (yyerrflag != 0)
19 #line 2 "quote_calc.y"
27 static void yyerror(const char *s);
29 #line 29 "/dev/stdout"
35 /* compatibility with bison */
37 /* compatibility with FreeBSD */
38 # ifdef YYPARSE_PARAM_TYPE
39 # define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
41 # define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
44 # define YYPARSE_DECL() yyparse(void)
47 /* Parameters sent to lex. */
49 # define YYLEX_DECL() yylex(void *YYLEX_PARAM)
50 # define YYLEX yylex(YYLEX_PARAM)
52 # define YYLEX_DECL() yylex(void)
53 # define YYLEX yylex()
56 /* Parameters sent to yyerror. */
58 #define YYERROR_DECL() yyerror(const char *s)
61 #define YYERROR_CALL(msg) yyerror(msg)
64 extern int YYPARSE_DECL();
82 static const short yylhs[] = { -1,
83 0, 0, 0, 1, 1, 2, 2, 2, 2, 2,
84 2, 2, 2, 2, 2, 2, 3, 3,
86 static const short yylen[] = { 2,
87 0, 3, 3, 1, 3, 3, 3, 3, 3, 3,
88 3, 3, 3, 2, 1, 1, 1, 2,
90 static const short yydefred[] = { 1,
91 0, 0, 0, 17, 0, 0, 0, 0, 0, 3,
92 15, 0, 0, 0, 2, 0, 0, 0, 0, 0,
93 0, 0, 18, 0, 6, 0, 0, 0, 0, 0,
96 static const short yydgoto[] = { 1,
99 static const short yysindex[] = { 0,
100 -38, 5, -36, 0, -51, -36, 7, -121, -248, 0,
101 0, -243, -36, -22, 0, -36, -36, -36, -36, -36,
102 -36, -36, 0, -121, 0, -121, -121, -121, -121, -121,
105 static const short yyrindex[] = { 0,
106 0, 0, 0, 0, -9, 0, 0, 13, -10, 0,
107 0, -5, 0, 0, 0, 0, 0, 0, 0, 0,
108 0, 0, 0, 15, 0, -3, -2, -1, 1, 2,
111 static const short yygindex[] = { 0,
114 #define YYTABLESIZE 258
115 static const short yytable[] = { 16,
116 15, 6, 22, 6, 14, 13, 7, 8, 9, 13,
117 10, 11, 12, 16, 10, 17, 15, 18, 25, 19,
118 23, 20, 4, 21, 5, 0, 0, 0, 0, 0,
119 16, 0, 0, 0, 0, 14, 13, 7, 8, 9,
120 0, 10, 11, 12, 12, 0, 0, 14, 0, 0,
121 0, 0, 0, 0, 24, 0, 0, 26, 27, 28,
122 29, 30, 31, 32, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0,
126 0, 22, 0, 0, 0, 0, 0, 0, 0, 0,
127 0, 0, 0, 16, 15, 0, 0, 0, 14, 13,
128 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
129 0, 0, 0, 0, 0, 16, 0, 17, 0, 18,
130 0, 19, 0, 20, 0, 21, 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, 0, 0, 0,
137 0, 0, 0, 0, 0, 0, 0, 2, 0, 0,
138 3, 0, 3, 0, 0, 0, 0, 0, 0, 0,
139 4, 5, 4, 11, 16, 0, 17, 0, 18, 0,
140 19, 0, 20, 0, 21, 0, 16, 15, 16, 15,
141 16, 15, 16, 15, 16, 15, 16, 15,
143 static const short yycheck[] = { 10,
144 10, 40, 124, 40, 10, 10, 10, 10, 10, 61,
145 10, 10, 10, 257, 10, 259, 10, 261, 41, 263,
146 269, 265, 10, 267, 10, -1, -1, -1, -1, -1,
147 41, -1, -1, -1, -1, 41, 41, 41, 41, 41,
148 -1, 41, 41, 41, 3, -1, -1, 6, -1, -1,
149 -1, -1, -1, -1, 13, -1, -1, 16, 17, 18,
150 19, 20, 21, 22, -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, -1, -1, -1, -1, -1, -1, -1, -1, -1,
154 -1, 124, -1, -1, -1, -1, -1, -1, -1, -1,
155 -1, -1, -1, 124, 124, -1, -1, -1, 124, 124,
156 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
157 -1, -1, -1, -1, -1, 257, -1, 259, -1, 261,
158 -1, 263, -1, 265, -1, 267, -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, -1, -1, -1,
165 -1, -1, -1, -1, -1, -1, -1, 256, -1, -1,
166 259, -1, 259, -1, -1, -1, -1, -1, -1, -1,
167 269, 270, 269, 270, 257, -1, 259, -1, 261, -1,
168 263, -1, 265, -1, 267, -1, 257, 257, 259, 259,
169 261, 261, 263, 263, 265, 265, 267, 267,
175 #define YYMAXTOKEN 271
176 #define YYTRANSLATE(a) ((a) > YYMAXTOKEN ? (YYMAXTOKEN + 1) : (a))
178 static const char *yyname[] = {
180 "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,
181 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,
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,
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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
186 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
187 0,0,0,0,0,0,"OP_ADD","\"ADD\"","OP_SUB","\"SUB\"","OP_MUL","\"MUL\"","OP_DIV",
188 "\"DIV\"","OP_MOD","\"MOD\"","OP_AND","\"AND\"","DIGIT","LETTER","UMINUS",
191 static const char *yyrule[] = {
194 "list : list stat '\\n'",
195 "list : list error '\\n'",
197 "stat : LETTER '=' expr",
198 "expr : '(' expr ')'",
199 "expr : expr OP_ADD expr",
200 "expr : expr OP_SUB expr",
201 "expr : expr OP_MUL expr",
202 "expr : expr OP_DIV expr",
203 "expr : expr OP_MOD expr",
204 "expr : expr OP_AND expr",
205 "expr : expr '|' expr",
206 "expr : OP_SUB expr",
210 "number : number DIGIT",
223 /* define the initial stack-sizes */
226 #define YYMAXDEPTH YYSTACKSIZE
229 #define YYSTACKSIZE YYMAXDEPTH
231 #define YYSTACKSIZE 10000
232 #define YYMAXDEPTH 10000
236 #define YYINITSTACKSIZE 200
246 /* variables for the parser stack */
247 static YYSTACKDATA yystack;
248 #line 73 "quote_calc.y"
249 /* start of programs */
254 while(!feof(stdin)) {
261 yyerror(const char *s)
263 fprintf(stderr, "%s\n", s);
268 /* lexical analysis routine */
269 /* returns LETTER for a lower case letter, yylval = 0 through 25 */
270 /* return DIGIT for a digit, yylval = 0 through 9 */
271 /* all other characters are returned immediately */
275 while( (c=getchar()) == ' ' ) { /* skip blanks */ }
277 /* c is now nonblank */
289 #line 288 "/dev/stdout"
292 #include <stdio.h> /* needed for printf */
295 #include <stdlib.h> /* needed for malloc, etc */
296 #include <string.h> /* needed for memset */
298 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
299 static int yygrowstack(YYSTACKDATA *data)
306 if ((newsize = data->stacksize) == 0)
307 newsize = YYINITSTACKSIZE;
308 else if (newsize >= YYMAXDEPTH)
310 else if ((newsize *= 2) > YYMAXDEPTH)
311 newsize = YYMAXDEPTH;
313 i = (int) (data->s_mark - data->s_base);
314 newss = (short *)realloc(data->s_base, newsize * sizeof(*newss));
318 data->s_base = newss;
319 data->s_mark = newss + i;
321 newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));
325 data->l_base = newvs;
326 data->l_mark = newvs + i;
328 data->stacksize = newsize;
329 data->s_last = data->s_base + newsize - 1;
333 #if YYPURE || defined(YY_NO_LEAKS)
334 static void yyfreestack(YYSTACKDATA *data)
338 memset(data, 0, sizeof(*data));
341 #define yyfreestack(data) /* nothing */
344 #define YYABORT goto yyabort
345 #define YYREJECT goto yyabort
346 #define YYACCEPT goto yyaccept
347 #define YYERROR goto yyerrlab
352 int yym, yyn, yystate;
356 if ((yys = getenv("YYDEBUG")) != 0)
359 if (yyn >= '0' && yyn <= '9')
370 memset(&yystack, 0, sizeof(yystack));
373 if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow;
374 yystack.s_mark = yystack.s_base;
375 yystack.l_mark = yystack.l_base;
380 if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
383 if ((yychar = YYLEX) < 0) yychar = 0;
387 yys = yyname[YYTRANSLATE(yychar)];
388 printf("%sdebug: state %d, reading %d (%s)\n",
389 YYPREFIX, yystate, yychar, yys);
393 if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
394 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
398 printf("%sdebug: state %d, shifting to state %d\n",
399 YYPREFIX, yystate, yytable[yyn]);
401 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
405 yystate = yytable[yyn];
406 *++yystack.s_mark = yytable[yyn];
407 *++yystack.l_mark = yylval;
409 if (yyerrflag > 0) --yyerrflag;
412 if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
413 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
418 if (yyerrflag) goto yyinrecovery;
420 yyerror("syntax error");
433 if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 &&
434 yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
438 printf("%sdebug: state %d, error recovery shifting\
439 to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]);
441 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
445 yystate = yytable[yyn];
446 *++yystack.s_mark = yytable[yyn];
447 *++yystack.l_mark = yylval;
454 printf("%sdebug: error recovery discarding state %d\n",
455 YYPREFIX, *yystack.s_mark);
457 if (yystack.s_mark <= yystack.s_base) goto yyabort;
465 if (yychar == 0) goto yyabort;
469 yys = yyname[YYTRANSLATE(yychar)];
470 printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
471 YYPREFIX, yystate, yychar, yys);
481 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
482 YYPREFIX, yystate, yyn, yyrule[yyn]);
486 yyval = yystack.l_mark[1-yym];
488 memset(&yyval, 0, sizeof yyval);
492 #line 35 "quote_calc.y"
496 #line 39 "quote_calc.y"
497 { printf("%d\n",yystack.l_mark[0]);}
500 #line 41 "quote_calc.y"
501 { regs[yystack.l_mark[-2]] = yystack.l_mark[0]; }
504 #line 45 "quote_calc.y"
505 { yyval = yystack.l_mark[-1]; }
508 #line 47 "quote_calc.y"
509 { yyval = yystack.l_mark[-2] + yystack.l_mark[0]; }
512 #line 49 "quote_calc.y"
513 { yyval = yystack.l_mark[-2] - yystack.l_mark[0]; }
516 #line 51 "quote_calc.y"
517 { yyval = yystack.l_mark[-2] * yystack.l_mark[0]; }
520 #line 53 "quote_calc.y"
521 { yyval = yystack.l_mark[-2] / yystack.l_mark[0]; }
524 #line 55 "quote_calc.y"
525 { yyval = yystack.l_mark[-2] % yystack.l_mark[0]; }
528 #line 57 "quote_calc.y"
529 { yyval = yystack.l_mark[-2] & yystack.l_mark[0]; }
532 #line 59 "quote_calc.y"
533 { yyval = yystack.l_mark[-2] | yystack.l_mark[0]; }
536 #line 61 "quote_calc.y"
537 { yyval = - yystack.l_mark[0]; }
540 #line 63 "quote_calc.y"
541 { yyval = regs[yystack.l_mark[0]]; }
544 #line 68 "quote_calc.y"
545 { yyval = yystack.l_mark[0]; base = (yystack.l_mark[0]==0) ? 8 : 10; }
548 #line 70 "quote_calc.y"
549 { yyval = base * yystack.l_mark[-1] + yystack.l_mark[0]; }
551 #line 550 "/dev/stdout"
553 yystack.s_mark -= yym;
554 yystate = *yystack.s_mark;
555 yystack.l_mark -= yym;
557 if (yystate == 0 && yym == 0)
561 printf("%sdebug: after reduction, shifting from state 0 to\
562 state %d\n", YYPREFIX, YYFINAL);
565 *++yystack.s_mark = YYFINAL;
566 *++yystack.l_mark = yyval;
569 if ((yychar = YYLEX) < 0) yychar = 0;
573 yys = yyname[YYTRANSLATE(yychar)];
574 printf("%sdebug: state %d, reading %d (%s)\n",
575 YYPREFIX, YYFINAL, yychar, yys);
579 if (yychar == 0) goto yyaccept;
582 if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
583 yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
584 yystate = yytable[yyn];
586 yystate = yydgoto[yym];
589 printf("%sdebug: after reduction, shifting from state %d \
590 to state %d\n", YYPREFIX, *yystack.s_mark, yystate);
592 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
596 *++yystack.s_mark = (short) yystate;
597 *++yystack.l_mark = yyval;
601 yyerror("yacc stack overflow");
604 yyfreestack(&yystack);
608 yyfreestack(&yystack);