1 %IDENT "check variant syntax features"
4 // http://dinosaur.compilertools.net/yacc/index.html */
11 typedef struct interval
17 INTERVAL vmul(double, double, INTERVAL);
18 INTERVAL vdiv(double, double, INTERVAL);
20 extern int yylex(void);
21 static void yyerror(const char *s);
34 int ival; // dreg & vreg array index values
35 double dval; // floating point values
36 INTERVAL vval; // interval values
39 %token <ival> DREG VREG // indices into dreg, vreg arrays */
40 %token <dval> CONST // floating point constant */
42 %type <dval> dexp // expression */
43 %type <vval> vexp // interval expression */
45 // precedence information about the operators */
47 %< '+' '-' // %< is an obsolete synonym for %left
49 %> UMINUS // precedence for unary minus;
50 // %> is an obsolete synonym for %right
52 \\ // beginning of rules section; \\ is an obsolete synonym for %%
60 (void) printf("%15.8f\n", $1);
64 (void) printf("(%15.8f, %15.8f)\n", $1.lo, $1.hi);
83 $<dval>$ = dreg[$<ival>1]; // $$ & $1 are sufficient here
101 | '-' dexp %prec UMINUS
115 | '(' dexp ',' dexp ')'
121 (void) printf("interval out of order\n");
131 $$.hi = $1.hi + $3.hi;
132 $$.lo = $1.lo + $3.lo;
141 $$.hi = $1.hi - $3.lo;
142 $$.lo = $1.lo - $3.hi;
151 $$ = vmul( $1.lo, $1.hi, $3 );
155 $$ = vmul ($1, $1, $3 );
159 if (dcheck($3)) YYERROR;
160 $$ = vdiv ( $1.lo, $1.hi, $3 );
164 if (dcheck ( $3 )) YYERROR;
165 $$ = vdiv ($1, $1, $3 );
167 | '-' vexp %prec UMINUS
178 \\ /* beginning of subroutines section */
180 #define BSZ 50 /* buffer size for floating point numbers */
182 /* lexical analysis */
185 yyerror(const char *s)
187 fprintf(stderr, "%s\n", s);
195 while ((c = getchar()) == ' ')
196 { /* skip over blanks */
201 yylval.ival = c - 'A';
206 yylval.ival = c - 'a';
210 if (isdigit(c) || c == '.')
212 /* gobble up digits, points, exponents */
213 char buf[BSZ + 1], *cp = buf;
214 int dot = 0, expr = 0;
216 for (; (cp - buf) < BSZ; ++cp, c = getchar())
225 return ('.'); /* will cause syntax error */
232 return ('e'); /* will cause syntax error */
241 if ((cp - buf) >= BSZ)
242 printf("constant too long: truncated\n");
244 ungetc(c, stdin); /* push back last char read */
245 yylval.dval = atof(buf);
252 hilo(double a, double b, double c, double d)
254 /* returns the smallest interval containing a, b, c, and d */
255 /* used by *, / routines */
287 vmul(double a, double b, INTERVAL v)
289 return (hilo(a * v.hi, a * v.lo, b * v.hi, b * v.lo));
295 if (v.hi >= 0. && v.lo <= 0.)
297 printf("divisor interval contains 0.\n");
304 vdiv(double a, double b, INTERVAL v)
306 return (hilo(a / v.hi, a / v.lo, b / v.hi, b / v.lo));