Front page | perl.perl5.porters |
Postings from January 2005
RE: unusual expression
Thread Previous
|
Thread Next
From:
John P. Linderman
Date:
January 17, 2005 03:27
Subject:
RE: unusual expression
Message ID:
200501171126.GAA09154@raptor.research.att.com
Near the start of scan_num in toke.c, there's a comment
Read a number in any of the formats that Perl accepts:
\d(_?\d)*(\.(\d(_?\d)*)?)?[Ee][\+\-]?(\d(_?\d)*) 12 12.34 12.
\.\d(_?\d)*[Ee][\+\-]?(\d(_?\d)*) .34
0b[01](_?[01])*
0[0-7](_?[0-7])*
0x[0-9A-Fa-f](_?[0-9A-Fa-f])*
That's the closest thing I could find to a "formal definition"
of a floating point literal. The definitions don't include all the
ways an underbar can sneak in and trigger a syntax warning, but
still be accepted, but they're a great start. However, it's not
reasonable to expect ordinary users to discover them there.
(It would have taken me quite a while to find them if Mark
hadn't directed my attention to the neighborhood).
I looked around for user-friendly documentation, but I came up dry.
(My Camel is out on loan, but the Second Edition on my neighbor's
desk didn't seem to have formal definitions for floating literals).
There's something related in perldata and perlfaq4, but they address
strings that can be used as numbers, so, for example, underbars are
out in that context, but acceptable in literals.
Formal descriptions, like those above, would not only be a nice
addition to the user documentation. They'd be a guideline for those
tinkering with the code. Just how many underbars can come between
the E and the sign before a warning turns into an outright error?
[eE]_?[+-]?[_\d]*\d_* # at most one
[eE]_*[+-]?[_\d]*\d_* # any number
[eE][+-]?[_\d]*\d_* # none
Barring some sort of formal definitions, the C code determines the
language (pretty much what happened to trigger this whole thread)
rather than the language determining the parser, and that
just seems wrong. -- jpl
Thread Previous
|
Thread Next