/* $Id: look.y,v 1.1 2004/03/30 07:19:17 jmuelmen Exp $ */ %{ #include #include #include extern char *look_yytext; int look_yylex (); void look_yyerror (const char *s); void look_gen (double, double, double); static double Rd; static double Rv; static double Rw; %} %token RES %start dac_list %% res : RES { char *rs = strstr(look_yytext, "= ") + 2; double r; *strstr(rs, " ") = 0; r = atof(rs); $$ = (signed int)look_yytext[1]; switch (look_yytext[1]) { case 'd': Rd = r; break; case 'v': Rv = r; break; case 'w': Rw = r; break; default: $$ = -1; yyerror("Funny resistor."); break; } } ; dac : res res res { if ($1 == -1 || $2 == -1 || $3 == -1) { fprintf(stderr, "Refusing to work with funny" " resistors\n"); exit(1); } if ($1 == $2 || $1 == $3 || $2 == $3) { fprintf(stderr, "Refusing to work with funny" " resistors\n"); exit(1); } look_gen(Rd, Rv, Rw); } ; dac_list : | dac dac_list ; %% void look_yyerror (const char *s) { fprintf(stderr, "%s\n", s); }