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)
21 /* http://dinosaur.compilertools.net/yacc/index.html */
28 typedef struct interval
34 INTERVAL vmul(double, double, INTERVAL);
35 INTERVAL vdiv(double, double, INTERVAL);
37 extern int yylex(void);
38 static void yyerror(const char *s);
47 #undef YYSTYPE_IS_DECLARED
48 #define YYSTYPE_IS_DECLARED 1
50 #ifndef YYSTYPE_IS_DECLARED
51 #define YYSTYPE_IS_DECLARED 1
58 #endif /* !YYSTYPE_IS_DECLARED */
59 #line 59 "/dev/stdout"
61 /* compatibility with bison */
63 /* compatibility with FreeBSD */
64 # ifdef YYPARSE_PARAM_TYPE
65 # define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
67 # define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
70 # define YYPARSE_DECL() yyparse(void)
73 /* Parameters sent to lex. */
75 # define YYLEX_DECL() yylex(void *YYLEX_PARAM)
76 # define YYLEX yylex(YYLEX_PARAM)
78 # define YYLEX_DECL() yylex(void)
79 # define YYLEX yylex()
82 /* Parameters sent to yyerror. */
84 #define YYERROR_DECL() yyerror(const char *s)
87 #define YYERROR_CALL(msg) yyerror(msg)
90 extern int YYPARSE_DECL();
97 static const short yylhs[] = { -1,
98 3, 3, 0, 0, 0, 0, 0, 1, 1, 1,
99 1, 1, 1, 1, 1, 2, 2, 2, 2, 2,
100 2, 2, 2, 2, 2, 2, 2, 2,
102 static const short yylen[] = { 2,
103 0, 2, 2, 2, 4, 4, 2, 1, 1, 3,
104 3, 3, 3, 2, 3, 1, 5, 1, 3, 3,
105 3, 3, 3, 3, 3, 3, 2, 3,
107 static const short yydefred[] = { 0,
108 0, 0, 0, 8, 0, 0, 0, 0, 0, 7,
109 0, 0, 9, 18, 14, 27, 0, 0, 0, 0,
110 0, 0, 3, 0, 0, 0, 0, 4, 0, 0,
111 0, 0, 0, 15, 0, 28, 0, 0, 0, 0,
112 12, 24, 13, 26, 0, 0, 23, 25, 14, 0,
113 0, 0, 0, 0, 5, 6, 0, 0, 0, 12,
116 static const short yydgoto[] = { 7,
119 static const short yysindex[] = { -40,
120 -8, -48, -47, 0, -37, -37, 0, 2, 17, 0,
121 -34, -37, 0, 0, 0, 0, -25, 90, -37, -37,
122 -37, -37, 0, -37, -37, -37, -37, 0, -34, -34,
123 25, 125, 31, 0, -34, 0, -11, 37, -11, 37,
124 0, 0, 0, 0, 37, 37, 0, 0, 0, 111,
125 -34, -34, -34, -34, 0, 0, 118, 69, 69, 0,
128 static const short yyrindex[] = { 0,
129 0, 38, 44, 0, 0, 0, 0, 0, 0, 0,
130 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
131 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
132 0, -9, 0, 0, 0, 0, 51, -3, 56, 61,
133 0, 0, 0, 0, 67, 72, 0, 0, 0, 0,
134 0, 0, 0, 0, 0, 0, 0, 78, 83, 0,
137 static const short yygindex[] = { 0,
140 #define YYTABLESIZE 225
141 static const short yytable[] = { 6,
142 16, 10, 6, 8, 5, 30, 20, 5, 15, 17,
143 29, 23, 11, 12, 31, 34, 21, 19, 35, 20,
144 0, 22, 37, 39, 41, 43, 28, 0, 0, 0,
145 21, 16, 49, 50, 55, 22, 0, 20, 57, 20,
146 56, 20, 0, 21, 19, 0, 20, 9, 22, 0,
147 0, 0, 0, 18, 58, 59, 60, 61, 26, 24,
148 10, 25, 0, 27, 0, 11, 53, 51, 0, 52,
149 22, 54, 26, 24, 0, 25, 19, 27, 26, 9,
150 9, 21, 9, 27, 9, 18, 18, 10, 18, 0,
151 18, 10, 11, 10, 10, 10, 11, 0, 11, 11,
152 11, 22, 0, 22, 0, 22, 0, 19, 0, 19,
153 53, 19, 21, 0, 21, 54, 21, 0, 10, 0,
154 10, 0, 10, 11, 0, 11, 0, 11, 16, 18,
155 36, 26, 24, 0, 25, 33, 27, 0, 0, 0,
156 0, 0, 38, 40, 42, 44, 0, 45, 46, 47,
157 48, 34, 53, 51, 0, 52, 0, 54, 62, 53,
158 51, 0, 52, 0, 54, 0, 21, 19, 0, 20,
159 0, 22, 0, 0, 0, 0, 0, 0, 0, 0,
160 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
161 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
162 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
163 0, 0, 0, 0, 0, 1, 2, 3, 4, 13,
166 static const short yycheck[] = { 40,
167 10, 10, 40, 0, 45, 40, 10, 45, 5, 6,
168 45, 10, 61, 61, 11, 41, 42, 43, 44, 45,
169 -1, 47, 19, 20, 21, 22, 10, -1, -1, -1,
170 42, 41, 29, 30, 10, 47, -1, 41, 35, 43,
171 10, 45, -1, 42, 43, -1, 45, 10, 47, -1,
172 -1, -1, -1, 10, 51, 52, 53, 54, 42, 43,
173 10, 45, -1, 47, -1, 10, 42, 43, -1, 45,
174 10, 47, 42, 43, -1, 45, 10, 47, 42, 42,
175 43, 10, 45, 47, 47, 42, 43, 10, 45, -1,
176 47, 41, 10, 43, 44, 45, 41, -1, 43, 44,
177 45, 41, -1, 43, -1, 45, -1, 41, -1, 43,
178 42, 45, 41, -1, 43, 47, 45, -1, 41, -1,
179 43, -1, 45, 41, -1, 43, -1, 45, 5, 6,
180 41, 42, 43, -1, 45, 12, 47, -1, -1, -1,
181 -1, -1, 19, 20, 21, 22, -1, 24, 25, 26,
182 27, 41, 42, 43, -1, 45, -1, 47, 41, 42,
183 43, -1, 45, -1, 47, -1, 42, 43, -1, 45,
184 -1, 47, -1, -1, -1, -1, -1, -1, -1, -1,
185 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
186 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
187 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
188 -1, -1, -1, -1, -1, 256, 257, 258, 259, 257,
189 258, 259, 257, -1, 259,
195 #define YYMAXTOKEN 260
196 #define YYTRANSLATE(a) ((a) > YYMAXTOKEN ? (YYMAXTOKEN + 1) : (a))
198 static const char *yyname[] = {
200 "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,
201 0,0,0,0,0,0,0,0,0,"'('","')'","'*'","'+'","','","'-'",0,"'/'",0,0,0,0,0,0,0,0,0,
202 0,0,0,0,"'='",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
203 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
204 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
205 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
206 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
207 0,0,"DREG","VREG","CONST","UMINUS","illegal-symbol",
209 static const char *yyrule[] = {
212 "lines : lines line",
215 "line : DREG '=' dexp '\\n'",
216 "line : VREG '=' vexp '\\n'",
217 "line : error '\\n'",
220 "dexp : dexp '+' dexp",
221 "dexp : dexp '-' dexp",
222 "dexp : dexp '*' dexp",
223 "dexp : dexp '/' dexp",
225 "dexp : '(' dexp ')'",
227 "vexp : '(' dexp ',' dexp ')'",
229 "vexp : vexp '+' vexp",
230 "vexp : dexp '+' vexp",
231 "vexp : vexp '-' vexp",
232 "vexp : dexp '-' vexp",
233 "vexp : vexp '*' vexp",
234 "vexp : dexp '*' vexp",
235 "vexp : vexp '/' vexp",
236 "vexp : dexp '/' vexp",
238 "vexp : '(' vexp ')'",
251 /* define the initial stack-sizes */
254 #define YYMAXDEPTH YYSTACKSIZE
257 #define YYSTACKSIZE YYMAXDEPTH
259 #define YYSTACKSIZE 10000
260 #define YYMAXDEPTH 10000
264 #define YYINITSTACKSIZE 200
274 /* variables for the parser stack */
275 static YYSTACKDATA yystack;
277 /* beginning of subroutines section */
279 #define BSZ 50 /* buffer size for floating point numbers */
281 /* lexical analysis */
284 yyerror(const char *s)
286 fprintf(stderr, "%s\n", s);
294 while ((c = getchar()) == ' ')
295 { /* skip over blanks */
300 yylval.ival = c - 'A';
305 yylval.ival = c - 'a';
309 if (isdigit(c) || c == '.')
311 /* gobble up digits, points, exponents */
312 char buf[BSZ + 1], *cp = buf;
313 int dot = 0, expr = 0;
315 for (; (cp - buf) < BSZ; ++cp, c = getchar())
324 return ('.'); /* will cause syntax error */
331 return ('e'); /* will cause syntax error */
340 if ((cp - buf) >= BSZ)
341 printf("constant too long: truncated\n");
343 ungetc(c, stdin); /* push back last char read */
344 yylval.dval = atof(buf);
351 hilo(double a, double b, double c, double d)
353 /* returns the smallest interval containing a, b, c, and d */
354 /* used by *, / routines */
386 vmul(double a, double b, INTERVAL v)
388 return (hilo(a * v.hi, a * v.lo, b * v.hi, b * v.lo));
394 if (v.hi >= 0. && v.lo <= 0.)
396 printf("divisor interval contains 0.\n");
403 vdiv(double a, double b, INTERVAL v)
405 return (hilo(a / v.hi, a / v.lo, b / v.hi, b / v.lo));
407 #line 406 "/dev/stdout"
410 #include <stdio.h> /* needed for printf */
413 #include <stdlib.h> /* needed for malloc, etc */
414 #include <string.h> /* needed for memset */
416 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
417 static int yygrowstack(YYSTACKDATA *data)
424 if ((newsize = data->stacksize) == 0)
425 newsize = YYINITSTACKSIZE;
426 else if (newsize >= YYMAXDEPTH)
428 else if ((newsize *= 2) > YYMAXDEPTH)
429 newsize = YYMAXDEPTH;
431 i = (int) (data->s_mark - data->s_base);
432 newss = (short *)realloc(data->s_base, newsize * sizeof(*newss));
436 data->s_base = newss;
437 data->s_mark = newss + i;
439 newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));
443 data->l_base = newvs;
444 data->l_mark = newvs + i;
446 data->stacksize = newsize;
447 data->s_last = data->s_base + newsize - 1;
451 #if YYPURE || defined(YY_NO_LEAKS)
452 static void yyfreestack(YYSTACKDATA *data)
456 memset(data, 0, sizeof(*data));
459 #define yyfreestack(data) /* nothing */
462 #define YYABORT goto yyabort
463 #define YYREJECT goto yyabort
464 #define YYACCEPT goto yyaccept
465 #define YYERROR goto yyerrlab
470 int yym, yyn, yystate;
474 if ((yys = getenv("YYDEBUG")) != 0)
477 if (yyn >= '0' && yyn <= '9')
488 memset(&yystack, 0, sizeof(yystack));
491 if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow;
492 yystack.s_mark = yystack.s_base;
493 yystack.l_mark = yystack.l_base;
498 if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
501 if ((yychar = YYLEX) < 0) yychar = 0;
505 yys = yyname[YYTRANSLATE(yychar)];
506 printf("%sdebug: state %d, reading %d (%s)\n",
507 YYPREFIX, yystate, yychar, yys);
511 if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
512 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
516 printf("%sdebug: state %d, shifting to state %d\n",
517 YYPREFIX, yystate, yytable[yyn]);
519 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
523 yystate = yytable[yyn];
524 *++yystack.s_mark = yytable[yyn];
525 *++yystack.l_mark = yylval;
527 if (yyerrflag > 0) --yyerrflag;
530 if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
531 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
536 if (yyerrflag) goto yyinrecovery;
538 yyerror("syntax error");
551 if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 &&
552 yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
556 printf("%sdebug: state %d, error recovery shifting\
557 to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]);
559 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
563 yystate = yytable[yyn];
564 *++yystack.s_mark = yytable[yyn];
565 *++yystack.l_mark = yylval;
572 printf("%sdebug: error recovery discarding state %d\n",
573 YYPREFIX, *yystack.s_mark);
575 if (yystack.s_mark <= yystack.s_base) goto yyabort;
583 if (yychar == 0) goto yyabort;
587 yys = yyname[YYTRANSLATE(yychar)];
588 printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
589 YYPREFIX, yystate, yychar, yys);
599 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
600 YYPREFIX, yystate, yyn, yyrule[yyn]);
604 yyval = yystack.l_mark[1-yym];
606 memset(&yyval, 0, sizeof yyval);
612 (void) printf("%15.8f\n", yystack.l_mark[-1].dval);
618 (void) printf("(%15.8f, %15.8f)\n", yystack.l_mark[-1].vval.lo, yystack.l_mark[-1].vval.hi);
624 dreg[yystack.l_mark[-3].ival] = yystack.l_mark[-1].dval;
630 vreg[yystack.l_mark[-3].ival] = yystack.l_mark[-1].vval;
642 yyval.dval = dreg[yystack.l_mark[0].ival];
648 yyval.dval = yystack.l_mark[-2].dval + yystack.l_mark[0].dval;
654 yyval.dval = yystack.l_mark[-2].dval - yystack.l_mark[0].dval;
660 yyval.dval = yystack.l_mark[-2].dval * yystack.l_mark[0].dval;
666 yyval.dval = yystack.l_mark[-2].dval / yystack.l_mark[0].dval;
672 yyval.dval = -yystack.l_mark[0].dval;
678 yyval.dval = yystack.l_mark[-1].dval;
684 yyval.vval.hi = yyval.vval.lo = yystack.l_mark[0].dval;
690 yyval.vval.lo = yystack.l_mark[-3].dval;
691 yyval.vval.hi = yystack.l_mark[-1].dval;
692 if ( yyval.vval.lo > yyval.vval.hi )
694 (void) printf("interval out of order\n");
702 yyval.vval = vreg[yystack.l_mark[0].ival];
708 yyval.vval.hi = yystack.l_mark[-2].vval.hi + yystack.l_mark[0].vval.hi;
709 yyval.vval.lo = yystack.l_mark[-2].vval.lo + yystack.l_mark[0].vval.lo;
715 yyval.vval.hi = yystack.l_mark[-2].dval + yystack.l_mark[0].vval.hi;
716 yyval.vval.lo = yystack.l_mark[-2].dval + yystack.l_mark[0].vval.lo;
722 yyval.vval.hi = yystack.l_mark[-2].vval.hi - yystack.l_mark[0].vval.lo;
723 yyval.vval.lo = yystack.l_mark[-2].vval.lo - yystack.l_mark[0].vval.hi;
729 yyval.vval.hi = yystack.l_mark[-2].dval - yystack.l_mark[0].vval.lo;
730 yyval.vval.lo = yystack.l_mark[-2].dval - yystack.l_mark[0].vval.hi;
736 yyval.vval = vmul( yystack.l_mark[-2].vval.lo, yystack.l_mark[-2].vval.hi, yystack.l_mark[0].vval );
742 yyval.vval = vmul (yystack.l_mark[-2].dval, yystack.l_mark[-2].dval, yystack.l_mark[0].vval );
748 if (dcheck(yystack.l_mark[0].vval)) YYERROR;
749 yyval.vval = vdiv ( yystack.l_mark[-2].vval.lo, yystack.l_mark[-2].vval.hi, yystack.l_mark[0].vval );
755 if (dcheck ( yystack.l_mark[0].vval )) YYERROR;
756 yyval.vval = vdiv (yystack.l_mark[-2].dval, yystack.l_mark[-2].dval, yystack.l_mark[0].vval );
762 yyval.vval.hi = -yystack.l_mark[0].vval.lo;
763 yyval.vval.lo = -yystack.l_mark[0].vval.hi;
769 yyval.vval = yystack.l_mark[-1].vval;
772 #line 771 "/dev/stdout"
774 yystack.s_mark -= yym;
775 yystate = *yystack.s_mark;
776 yystack.l_mark -= yym;
778 if (yystate == 0 && yym == 0)
782 printf("%sdebug: after reduction, shifting from state 0 to\
783 state %d\n", YYPREFIX, YYFINAL);
786 *++yystack.s_mark = YYFINAL;
787 *++yystack.l_mark = yyval;
790 if ((yychar = YYLEX) < 0) yychar = 0;
794 yys = yyname[YYTRANSLATE(yychar)];
795 printf("%sdebug: state %d, reading %d (%s)\n",
796 YYPREFIX, YYFINAL, yychar, yys);
800 if (yychar == 0) goto yyaccept;
803 if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
804 yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
805 yystate = yytable[yyn];
807 yystate = yydgoto[yym];
810 printf("%sdebug: after reduction, shifting from state %d \
811 to state %d\n", YYPREFIX, *yystack.s_mark, yystate);
813 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
817 *++yystack.s_mark = (short) yystate;
818 *++yystack.l_mark = yyval;
822 yyerror("yacc stack overflow");
825 yyfreestack(&yystack);
829 yyfreestack(&yystack);