From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <31f9a933eb03172e356de753a5092e5a@plan9.jp> To: 9fans@cse.psu.edu Subject: Re: [9fans] cc lexer bug? From: Joel Salomon Date: Sun, 18 Feb 2007 17:07:09 -0500 In-Reply-To: <177026a0aecda1f362ae29664a0bcaf8@coraid.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Topicbox-Message-UUID: 115d30b8-ead2-11e9-9d60-3106f5b1d025 > > cpu% cat t.c > > void foo (void) > > { > > double d =3D 08.7; > > USED(d); > > } > > cpu% 8c t.c > > t.c:3 syntax error, last name: 8.7 > > cpu%=20 > >=20 > > This came up as I=E2=80=99m making my lexer for C able to scan number= s. I > > tried to understand ken=E2=80=99s code, but it gets very hairy right = around > > /sys/src/cmd/cc/lex.c:751 =E2=80=94 and I think there=E2=80=99s a bug= . >=20 > you're right, that's wrong. but the question is do you really want > that to work? In kencc, maybe not; in a class project designed to implement a C89 compi= ler, definitely yes. > in that case, one could always remove the goto ncu on line 757. cpu% grep -n 'goto ncu;' /sys/src/cmd/cc/lex.c 778: goto ncu; 788: goto ncu; 801: goto ncu; 808: goto ncu; cpu%=20 I think you mean the one on 788. I'm far from comfortable enough with the code here to suggest a patch, though. Certainly not comfortable enough to incorporate it into my lexer. > however, for better or worse, octal constants start with a 0. 08.7 > feels like a syntax error to me. i am a little suprised that gcc > accepts 08.7. are you sure that that's actually in the standard? >>From the ISO standard (the freely available =E2=80=9Cdraft" C99+TG1+TG2 = standard): 6.4.4.2 Floating constants Syntax floating-constant: decimal-floating-constant hexadecimal-floating-constant decimal-floating-constant: fractional-constant exponent-part_{opt} floating-suffix_{opt} digit-sequence exponent-part floating-suffix_{opt} =E2=80=A6 fractional-constant: digit-sequence_{opt} . digit-sequence digit-sequence . =E2=80=A6 digit-sequence: digit digit-sequence digit =E2=80=94 no restrictions on the initial digit. You get the same table i= n Harbison & Steele, 5th Ed. =C2=A72.7.2. --Joel