caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Edgar Friendly <thelema314@gmail.com>
To: caml-list <caml-list@yquem.inria.fr>
Subject: Float literals
Date: Tue, 26 Jun 2007 15:08:37 -0500	[thread overview]
Message-ID: <46817245.4020305@gmail.com> (raw)

In writing a syntax highlighter for Ocaml, I've dug into the code for
float literals:

let float_literal =
  ['0'-'9'] ['0'-'9' '_']*
  ('.' ['0'-'9' '_']* )?
  (['e' 'E'] ['+' '-']? ['0'-'9'] ['0'-'9' '_']*)?

This matches what the reference manual says about float literals:

float-literal	::=	[-] (0…9) { 0…9∣ _ } [. { 0…9∣ _ }] [(e∣ E) [+∣ -]
(0…9) { 0…9∣ _ }]

But it doesn't match some expectations I have about float literals.  The
following are all float literals:

3.14      (* no problem here *)
6.022E23  (* no problem here *)
9.109e-31 (* still no problem *)
2.        (* a float - blank decimal part *)
1e6       (* an integer?  no, a float without a .  Problem.*)
13        (* valid as a float, according to the above definition *)

Does anyone else find the last two cases kind of odd?  Maybe it's not a
big deal because the 1e6 is scientific notation, which is float-y, and
the last one is always parsed as an integer, I assume because of
precedence in the lexing functions.

E.


             reply	other threads:[~2007-06-26 20:06 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-26 20:08 Edgar Friendly [this message]
2007-06-26 20:38 ` [Caml-list] " Erik de Castro Lopo
2007-06-27  4:10   ` Jon Harrop
2007-06-27  4:48     ` Edgar Friendly
2007-06-26 20:48 ` Robert Roessler

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=46817245.4020305@gmail.com \
    --to=thelema314@gmail.com \
    --cc=caml-list@yquem.inria.fr \
    /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).