cpu% cat t.c
void foo (void)
{
double d;
d = 08.7;
USED(d);
}
cpu% 8c t.c
t.c:4 syntax error, last name: 8.7
cpu%
This came up as I’m making my lexer for C able to scan numbers. I
tried to understand ken’s code, but it gets very hairy right around
/sys/src/cmd/cc/lex.c:751 — and I think there’s a bug. Or, at least,
an undocumented departure from the ANSI standard; Harbison & Steele
(5E) suggest that “08.7” is a valid floating point constant.
As far as my lexer is concerned (http://www.tip9ug.jp/who/chesky/comp/lex.c,
if anyone cares), it’s using line-at-a-time buffering courtesy of
Brdstr(2), so I’m back to thinking that regcomp(2) + strtod(2) et al.
is the way to go. It won’t handle hex floats, but who cares?
--Joel