#define BSZ 50
/* buffer size for floating point numbers */
/* lexcial analysis */
yylex() {
register c;
while((c=getchar())==> >)
{/* skip over blanks */}
if (isupper(c)) {
yylval.ival= c->A>;
return(VREG);
}
if (islower(c)) {
yylval.ival= c->a>;
return(DREG);
}
if (isdigit(c) || c==>.>) {
/* gobble up digits, points, exponents */
char buf[BSZ+1], *cp=buf;
int dot= 0, exp= 0;
for (; (cp-buf)<BSZ; ++cp,c=get char() ){
*cp= c;
if (isdigit(c)) continue;
if (c==>.>){
if (dot++ || exp) return(>.>);
/* will cause syntax error */
continue;
}
if (c==>e>){
if (exp++) return(>e>);
/* will cause syntax error */
continue;
}
/* end of number */
break;
}
*cp= >\0>;
if ((cp-buf) >= BSZ)
printf("constant too long: truncated\n");
else ungetc(c,stdin);
/* push back last char read */
yylval.dval= atof(buf);
return(CONST);
}
return(c);
}
|