From: Joel Salomon <JoelCSalomon@Gmail.com>
To: 9fans@cse.psu.edu
Subject: Re: [9fans] cc lexer bug?
Date: Sun, 18 Feb 2007 17:07:09 -0500 [thread overview]
Message-ID: <31f9a933eb03172e356de753a5092e5a@plan9.jp> (raw)
In-Reply-To: <177026a0aecda1f362ae29664a0bcaf8@coraid.com>
> > cpu% cat t.c
> > void foo (void)
> > {
> > double d = 08.7;
> > USED(d);
> > }
> > cpu% 8c t.c
> > t.c:3 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.
>
> 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 compiler, 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%
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 “draft" 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}
…
fractional-constant:
digit-sequence_{opt} . digit-sequence
digit-sequence .
…
digit-sequence:
digit
digit-sequence digit
— no restrictions on the initial digit. You get the same table in
Harbison & Steele, 5th Ed. §2.7.2.
--Joel
next prev parent reply other threads:[~2007-02-18 22:07 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-02-18 20:19 Joel Salomon
2007-02-18 21:22 ` erik quanstrom
2007-02-18 22:07 ` Joel Salomon [this message]
2007-02-18 22:40 ` erik quanstrom
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=31f9a933eb03172e356de753a5092e5a@plan9.jp \
--to=joelcsalomon@gmail.com \
--cc=9fans@cse.psu.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).