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)
20 /* http://dinosaur.compilertools.net/yacc/index.html */
27 typedef struct interval
33 INTERVAL vmul(double, double, INTERVAL);
34 INTERVAL vdiv(double, double, INTERVAL);
36 extern int yylex(void);
37 static void yyerror(const char *s);
46 #undef YYSTYPE_IS_DECLARED
47 #define YYSTYPE_IS_DECLARED 1
49 #ifndef YYSTYPE_IS_DECLARED
50 #define YYSTYPE_IS_DECLARED 1
57 #endif /* !YYSTYPE_IS_DECLARED */
58 #line 58 "/dev/stdout"
60 /* compatibility with bison */
62 /* compatibility with FreeBSD */
63 # ifdef YYPARSE_PARAM_TYPE
64 # define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
66 # define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
69 # define YYPARSE_DECL() yyparse(void)
72 /* Parameters sent to lex. */
74 # define YYLEX_DECL() yylex(void *YYLEX_PARAM)
75 # define YYLEX yylex(YYLEX_PARAM)
77 # define YYLEX_DECL() yylex(void)
78 # define YYLEX yylex()
81 /* Parameters sent to yyerror. */
83 #define YYERROR_DECL() yyerror(const char *s)
86 #define YYERROR_CALL(msg) yyerror(msg)
89 extern int YYPARSE_DECL();
96 static const short yylhs[] = { -1,
97 3, 3, 0, 0, 0, 0, 0, 1, 1, 1,
98 1, 1, 1, 1, 1, 2, 2, 2, 2, 2,
99 2, 2, 2, 2, 2, 2, 2, 2,
101 static const short yylen[] = { 2,
102 0, 2, 2, 2, 4, 4, 2, 1, 1, 3,
103 3, 3, 3, 2, 3, 1, 5, 1, 3, 3,
104 3, 3, 3, 3, 3, 3, 2, 3,
106 static const short yydefred[] = { 0,
107 0, 0, 0, 8, 0, 0, 0, 0, 0, 7,
108 0, 0, 9, 18, 14, 27, 0, 0, 0, 0,
109 0, 0, 3, 0, 0, 0, 0, 4, 0, 0,
110 0, 0, 0, 15, 0, 28, 0, 0, 0, 0,
111 12, 24, 13, 26, 0, 0, 23, 25, 14, 0,
112 0, 0, 0, 0, 5, 6, 0, 0, 0, 12,
115 static const short yydgoto[] = { 7,
118 static const short yysindex[] = { -40,
119 -8, -48, -47, 0, -37, -37, 0, 2, 17, 0,
120 -34, -37, 0, 0, 0, 0, -25, 90, -37, -37,
121 -37, -37, 0, -37, -37, -37, -37, 0, -34, -34,
122 25, 125, 31, 0, -34, 0, -11, 37, -11, 37,
123 0, 0, 0, 0, 37, 37, 0, 0, 0, 111,
124 -34, -34, -34, -34, 0, 0, 118, 69, 69, 0,
127 static const short yyrindex[] = { 0,
128 0, 38, 44, 0, 0, 0, 0, 0, 0, 0,
129 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
130 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
131 0, -9, 0, 0, 0, 0, 51, -3, 56, 61,
132 0, 0, 0, 0, 67, 72, 0, 0, 0, 0,
133 0, 0, 0, 0, 0, 0, 0, 78, 83, 0,
136 static const short yygindex[] = { 0,
139 #define YYTABLESIZE 225
140 static const short yytable[] = { 6,
141 16, 10, 6, 8, 5, 30, 20, 5, 15, 17,
142 29, 23, 11, 12, 31, 34, 21, 19, 35, 20,
143 0, 22, 37, 39, 41, 43, 28, 0, 0, 0,
144 21, 16, 49, 50, 55, 22, 0, 20, 57, 20,
145 56, 20, 0, 21, 19, 0, 20, 9, 22, 0,
146 0, 0, 0, 18, 58, 59, 60, 61, 26, 24,
147 10, 25, 0, 27, 0, 11, 53, 51, 0, 52,
148 22, 54, 26, 24, 0, 25, 19, 27, 26, 9,
149 9, 21, 9, 27, 9, 18, 18, 10, 18, 0,
150 18, 10, 11, 10, 10, 10, 11, 0, 11, 11,
151 11, 22, 0, 22, 0, 22, 0, 19, 0, 19,
152 53, 19, 21, 0, 21, 54, 21, 0, 10, 0,
153 10, 0, 10, 11, 0, 11, 0, 11, 16, 18,
154 36, 26, 24, 0, 25, 33, 27, 0, 0, 0,
155 0, 0, 38, 40, 42, 44, 0, 45, 46, 47,
156 48, 34, 53, 51, 0, 52, 0, 54, 62, 53,
157 51, 0, 52, 0, 54, 0, 21, 19, 0, 20,
158 0, 22, 0, 0, 0, 0, 0, 0, 0, 0,
159 0, 0, 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, 1, 2, 3, 4, 13,
165 static const short yycheck[] = { 40,
166 10, 10, 40, 0, 45, 40, 10, 45, 5, 6,
167 45, 10, 61, 61, 11, 41, 42, 43, 44, 45,
168 -1, 47, 19, 20, 21, 22, 10, -1, -1, -1,
169 42, 41, 29, 30, 10, 47, -1, 41, 35, 43,
170 10, 45, -1, 42, 43, -1, 45, 10, 47, -1,
171 -1, -1, -1, 10, 51, 52, 53, 54, 42, 43,
172 10, 45, -1, 47, -1, 10, 42, 43, -1, 45,
173 10, 47, 42, 43, -1, 45, 10, 47, 42, 42,
174 43, 10, 45, 47, 47, 42, 43, 10, 45, -1,
175 47, 41, 10, 43, 44, 45, 41, -1, 43, 44,
176 45, 41, -1, 43, -1, 45, -1, 41, -1, 43,
177 42, 45, 41, -1, 43, 47, 45, -1, 41, -1,
178 43, -1, 45, 41, -1, 43, -1, 45, 5, 6,
179 41, 42, 43, -1, 45, 12, 47, -1, -1, -1,
180 -1, -1, 19, 20, 21, 22, -1, 24, 25, 26,
181 27, 41, 42, 43, -1, 45, -1, 47, 41, 42,
182 43, -1, 45, -1, 47, -1, 42, 43, -1, 45,
183 -1, 47, -1, -1, -1, -1, -1, -1, -1, -1,
184 -1, -1, -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, 256, 257, 258, 259, 257,
188 258, 259, 257, -1, 259,
194 #define YYMAXTOKEN 260
196 static const char *yyname[] = {
198 "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,
199 0,0,0,0,0,0,0,0,0,"'('","')'","'*'","'+'","','","'-'",0,"'/'",0,0,0,0,0,0,0,0,0,
200 0,0,0,0,"'='",0,0,0,0,0,0,0,0,0,0,0,0,0,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,0,0,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,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,"DREG","VREG","CONST","UMINUS",
207 static const char *yyrule[] = {
210 "lines : lines line",
213 "line : DREG '=' dexp '\\n'",
214 "line : VREG '=' vexp '\\n'",
215 "line : error '\\n'",
218 "dexp : dexp '+' dexp",
219 "dexp : dexp '-' dexp",
220 "dexp : dexp '*' dexp",
221 "dexp : dexp '/' dexp",
223 "dexp : '(' dexp ')'",
225 "vexp : '(' dexp ',' dexp ')'",
227 "vexp : vexp '+' vexp",
228 "vexp : dexp '+' vexp",
229 "vexp : vexp '-' vexp",
230 "vexp : dexp '-' vexp",
231 "vexp : vexp '*' vexp",
232 "vexp : dexp '*' vexp",
233 "vexp : vexp '/' vexp",
234 "vexp : dexp '/' vexp",
236 "vexp : '(' vexp ')'",
249 /* define the initial stack-sizes */
252 #define YYMAXDEPTH YYSTACKSIZE
255 #define YYSTACKSIZE YYMAXDEPTH
257 #define YYSTACKSIZE 500
258 #define YYMAXDEPTH 500
262 #define YYINITSTACKSIZE 500
272 /* variables for the parser stack */
273 static YYSTACKDATA yystack;
275 /* beginning of subroutines section */
277 #define BSZ 50 /* buffer size for floating point numbers */
279 /* lexical analysis */
282 yyerror(const char *s)
284 fprintf(stderr, "%s\n", s);
292 while ((c = getchar()) == ' ')
293 { /* skip over blanks */
298 yylval.ival = c - 'A';
303 yylval.ival = c - 'a';
307 if (isdigit(c) || c == '.')
309 /* gobble up digits, points, exponents */
310 char buf[BSZ + 1], *cp = buf;
311 int dot = 0, expr = 0;
313 for (; (cp - buf) < BSZ; ++cp, c = getchar())
322 return ('.'); /* will cause syntax error */
329 return ('e'); /* will cause syntax error */
338 if ((cp - buf) >= BSZ)
339 printf("constant too long: truncated\n");
341 ungetc(c, stdin); /* push back last char read */
342 yylval.dval = atof(buf);
349 hilo(double a, double b, double c, double d)
351 /* returns the smallest interval containing a, b, c, and d */
352 /* used by *, / routines */
384 vmul(double a, double b, INTERVAL v)
386 return (hilo(a * v.hi, a * v.lo, b * v.hi, b * v.lo));
392 if (v.hi >= 0. && v.lo <= 0.)
394 printf("divisor interval contains 0.\n");
401 vdiv(double a, double b, INTERVAL v)
403 return (hilo(a / v.hi, a / v.lo, b / v.hi, b / v.lo));
405 #line 405 "/dev/stdout"
408 #include <stdio.h> /* needed for printf */
411 #include <stdlib.h> /* needed for malloc, etc */
412 #include <string.h> /* needed for memset */
414 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
415 static int yygrowstack(YYSTACKDATA *data)
422 if ((newsize = data->stacksize) == 0)
423 newsize = YYINITSTACKSIZE;
424 else if (newsize >= YYMAXDEPTH)
426 else if ((newsize *= 2) > YYMAXDEPTH)
427 newsize = YYMAXDEPTH;
429 i = data->s_mark - data->s_base;
430 newss = (short *)realloc(data->s_base, newsize * sizeof(*newss));
434 data->s_base = newss;
435 data->s_mark = newss + i;
437 newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));
441 data->l_base = newvs;
442 data->l_mark = newvs + i;
444 data->stacksize = newsize;
445 data->s_last = data->s_base + newsize - 1;
449 #if YYPURE || defined(YY_NO_LEAKS)
450 static void yyfreestack(YYSTACKDATA *data)
454 memset(data, 0, sizeof(*data));
457 #define yyfreestack(data) /* nothing */
460 #define YYABORT goto yyabort
461 #define YYREJECT goto yyabort
462 #define YYACCEPT goto yyaccept
463 #define YYERROR goto yyerrlab
468 int yym, yyn, yystate;
472 if ((yys = getenv("YYDEBUG")) != 0)
475 if (yyn >= '0' && yyn <= '9')
486 memset(&yystack, 0, sizeof(yystack));
489 if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow;
490 yystack.s_mark = yystack.s_base;
491 yystack.l_mark = yystack.l_base;
496 if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
499 if ((yychar = YYLEX) < 0) yychar = 0;
504 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
505 if (!yys) yys = "illegal-symbol";
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;
588 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
589 if (!yys) yys = "illegal-symbol";
590 printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
591 YYPREFIX, yystate, yychar, yys);
601 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
602 YYPREFIX, yystate, yyn, yyrule[yyn]);
606 yyval = yystack.l_mark[1-yym];
608 memset(&yyval, 0, sizeof yyval);
614 (void) printf("%15.8f\n", yystack.l_mark[-1].dval);
620 (void) printf("(%15.8f, %15.8f)\n", yystack.l_mark[-1].vval.lo, yystack.l_mark[-1].vval.hi);
626 dreg[yystack.l_mark[-3].ival] = yystack.l_mark[-1].dval;
632 vreg[yystack.l_mark[-3].ival] = yystack.l_mark[-1].vval;
644 yyval.dval = dreg[yystack.l_mark[0].ival];
650 yyval.dval = yystack.l_mark[-2].dval + yystack.l_mark[0].dval;
656 yyval.dval = yystack.l_mark[-2].dval - yystack.l_mark[0].dval;
662 yyval.dval = yystack.l_mark[-2].dval * yystack.l_mark[0].dval;
668 yyval.dval = yystack.l_mark[-2].dval / yystack.l_mark[0].dval;
674 yyval.dval = -yystack.l_mark[0].dval;
680 yyval.dval = yystack.l_mark[-1].dval;
686 yyval.vval.hi = yyval.vval.lo = yystack.l_mark[0].dval;
692 yyval.vval.lo = yystack.l_mark[-3].dval;
693 yyval.vval.hi = yystack.l_mark[-1].dval;
694 if ( yyval.vval.lo > yyval.vval.hi )
696 (void) printf("interval out of order\n");
704 yyval.vval = vreg[yystack.l_mark[0].ival];
710 yyval.vval.hi = yystack.l_mark[-2].vval.hi + yystack.l_mark[0].vval.hi;
711 yyval.vval.lo = yystack.l_mark[-2].vval.lo + yystack.l_mark[0].vval.lo;
717 yyval.vval.hi = yystack.l_mark[-2].dval + yystack.l_mark[0].vval.hi;
718 yyval.vval.lo = yystack.l_mark[-2].dval + yystack.l_mark[0].vval.lo;
724 yyval.vval.hi = yystack.l_mark[-2].vval.hi - yystack.l_mark[0].vval.lo;
725 yyval.vval.lo = yystack.l_mark[-2].vval.lo - yystack.l_mark[0].vval.hi;
731 yyval.vval.hi = yystack.l_mark[-2].dval - yystack.l_mark[0].vval.lo;
732 yyval.vval.lo = yystack.l_mark[-2].dval - yystack.l_mark[0].vval.hi;
738 yyval.vval = vmul( yystack.l_mark[-2].vval.lo, yystack.l_mark[-2].vval.hi, yystack.l_mark[0].vval );
744 yyval.vval = vmul (yystack.l_mark[-2].dval, yystack.l_mark[-2].dval, yystack.l_mark[0].vval );
750 if (dcheck(yystack.l_mark[0].vval)) YYERROR;
751 yyval.vval = vdiv ( yystack.l_mark[-2].vval.lo, yystack.l_mark[-2].vval.hi, yystack.l_mark[0].vval );
757 if (dcheck ( yystack.l_mark[0].vval )) YYERROR;
758 yyval.vval = vdiv (yystack.l_mark[-2].dval, yystack.l_mark[-2].dval, yystack.l_mark[0].vval );
764 yyval.vval.hi = -yystack.l_mark[0].vval.lo;
765 yyval.vval.lo = -yystack.l_mark[0].vval.hi;
771 yyval.vval = yystack.l_mark[-1].vval;
774 #line 774 "/dev/stdout"
776 yystack.s_mark -= yym;
777 yystate = *yystack.s_mark;
778 yystack.l_mark -= yym;
780 if (yystate == 0 && yym == 0)
784 printf("%sdebug: after reduction, shifting from state 0 to\
785 state %d\n", YYPREFIX, YYFINAL);
788 *++yystack.s_mark = YYFINAL;
789 *++yystack.l_mark = yyval;
792 if ((yychar = YYLEX) < 0) yychar = 0;
797 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
798 if (!yys) yys = "illegal-symbol";
799 printf("%sdebug: state %d, reading %d (%s)\n",
800 YYPREFIX, YYFINAL, yychar, yys);
804 if (yychar == 0) goto yyaccept;
807 if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
808 yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
809 yystate = yytable[yyn];
811 yystate = yydgoto[yym];
814 printf("%sdebug: after reduction, shifting from state %d \
815 to state %d\n", YYPREFIX, *yystack.s_mark, yystate);
817 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
821 *++yystack.s_mark = (short) yystate;
822 *++yystack.l_mark = yyval;
826 yyerror("yacc stack overflow");
829 yyfreestack(&yystack);
833 yyfreestack(&yystack);