Skip to content

Commit 4442319

Browse files
committed
[lex.icon,lex.fcon] Rework description to avoid redundancies.
Also use the grammar non-terminals integer-literal and floating-point-literal throughout the standard.
1 parent 9927929 commit 4442319

File tree

3 files changed

+124
-100
lines changed

3 files changed

+124
-100
lines changed

source/compatibility.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1598,7 +1598,7 @@
15981598
\grammarterm{pp-number} can contain \tcode{p} \grammarterm{sign} and
15991599
\tcode{P} \grammarterm{sign}.
16001600
\rationale
1601-
Necessary to enable hexadecimal floating-point literals.
1601+
Necessary to enable \grammarterm{hexadecimal-floating-point-literal}s.
16021602
\effect
16031603
Valid \CppXIV{} code may fail to compile or produce different results in
16041604
this International Standard. Specifically, character sequences like \tcode{0p+0}

source/lex.tex

Lines changed: 118 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -397,13 +397,14 @@
397397
\pnum
398398
\begin{example}
399399
The program fragment \tcode{0xe+foo} is parsed as a
400-
preprocessing number token (one that is not a valid integer or floating-point
401-
literal token), even though a parse as three preprocessing tokens
400+
preprocessing number token (one that is not a valid
401+
\grammarterm{integer-literal} or \grammarterm{floating-point-literal} token),
402+
even though a parse as three preprocessing tokens
402403
\tcode{0xe}, \tcode{+}, and \tcode{foo} might produce a valid expression (for example,
403404
if \tcode{foo} were a macro defined as \tcode{1}). Similarly, the
404405
program fragment \tcode{1E1} is parsed as a preprocessing number (one
405-
that is a valid floating-point literal token), whether or not \tcode{E} is a
406-
macro name.
406+
that is a valid \grammarterm{floating-point-literal} token),
407+
whether or not \tcode{E} is a macro name.
407408
\end{example}
408409

409410
\pnum
@@ -583,14 +584,15 @@
583584
\end{bnf}
584585

585586
\pnum
586-
Preprocessing number tokens lexically include all integer literal
587-
tokens\iref{lex.icon} and all floating-point literal
588-
tokens\iref{lex.fcon}.
587+
Preprocessing number tokens lexically include
588+
all \grammarterm{integer-literal} tokens\iref{lex.icon} and
589+
all \grammarterm{floating-point-literal} tokens\iref{lex.fcon}.
589590

590591
\pnum
591592
A preprocessing number does not have a type or a value; it acquires both
592-
after a successful conversion to an integer literal token or a floating-point literal
593-
token.%
593+
after a successful conversion to
594+
an \grammarterm{integer-literal} token or
595+
a \grammarterm{floating-point-literal} token.%
594596
\indextext{number!preprocessing|)}
595597

596598
\rSec1[lex.name]{Identifiers}
@@ -1033,28 +1035,38 @@
10331035
\indextext{literal!\idxcode{unsigned}}%
10341036
\indextext{literal!\idxcode{long}}%
10351037
\indextext{literal!base of integer}%
1036-
An \defnx{integer literal}{literal!integer} is a sequence of digits that has no period
1037-
or exponent part, with optional separating single quotes that are ignored
1038-
when determining its value. An integer literal may have a prefix that specifies
1039-
its base and a suffix that specifies its type. The lexically first digit
1040-
of the sequence of digits is the most significant.
1041-
A \defnx{binary integer literal}{literal!binary} (base two) begins with
1042-
\tcode{0b} or \tcode{0B} and consists of a sequence of binary digits.
1043-
An \defnx{octal integer literal}{literal!octal}
1044-
(base eight) begins with the digit \tcode{0} and consists of a
1045-
sequence of octal digits.\footnote{The digits \tcode{8} and \tcode{9} are not octal digits. }
1046-
A \defnx{decimal integer literal}{literal!decimal}
1047-
(base ten) begins with a digit other than \tcode{0} and
1048-
consists of a sequence of decimal digits.
1049-
A \defnx{hexadecimal integer literal}{literal!hexadecimal}
1050-
(base sixteen) begins with
1051-
\tcode{0x} or \tcode{0X} and consists of a sequence of hexadecimal
1052-
digits, which include the decimal digits and the letters \tcode{a}
1053-
through \tcode{f} and \tcode{A} through \tcode{F} with decimal values
1054-
ten through fifteen.
1038+
In an \grammarterm{integer-literal},
1039+
the sequence of
1040+
\grammarterm{binary-digit}s,
1041+
\grammarterm{octal-digit}s,
1042+
\grammarterm{digit}s, or
1043+
\grammarterm{hexadecimal-digit}s
1044+
is interpreted as a base-$N$ number as shown in table \tref{lex.icon.base};
1045+
the lexically first digit of the sequence of digits is the most significant.
1046+
\begin{note}
1047+
The prefix and any optional separating single quotes are ignored
1048+
when determining the value.
1049+
\end{note}
1050+
1051+
\begin{simpletypetable}
1052+
{Base of \grammarterm{integer-literal}{s}}
1053+
{lex.icon.base}
1054+
{lr}
1055+
\topline
1056+
\lhdr{Kind of \grammarterm{integer-literal}} & \rhdr{base $N$} \\ \capsep
1057+
\grammarterm{binary-literal} & 2 \\
1058+
\grammarterm{octal-literal} & 8 \\
1059+
\grammarterm{decimal-literal} & 10 \\
1060+
\grammarterm{hexadecimal-literal} & 16 \\
1061+
\end{simpletypetable}
1062+
1063+
\pnum
1064+
The \grammarterm{hexadecimal-digit}s
1065+
\tcode{a} through \tcode{f} and \tcode{A} through \tcode{F}
1066+
have decimal values ten through fifteen.
10551067
\begin{example}
10561068
The number twelve can be written \tcode{12}, \tcode{014},
1057-
\tcode{0XC}, or \tcode{0b1100}. The integer literals \tcode{1048576},
1069+
\tcode{0XC}, or \tcode{0b1100}. The \grammarterm{integer-literal}s \tcode{1048576},
10581070
\tcode{1'048'576}, \tcode{0X100000}, \tcode{0x10'0000}, and
10591071
\tcode{0'004'000'000} all have the same value.
10601072
\end{example}
@@ -1068,18 +1080,19 @@
10681080
\indextext{suffix!\idxcode{U}}%
10691081
\indextext{suffix!\idxcode{l}}%
10701082
\indextext{suffix!\idxcode{u}}%
1071-
The type of an integer literal is the first of the corresponding list
1072-
in \tref{lex.icon.type} in which its value can be
1073-
represented.
1083+
The type of an \grammarterm{integer-literal} is
1084+
the first type in the list in \tref{lex.icon.type}
1085+
corresponding to its optional \grammarterm{integer-suffix}
1086+
in which its value can be represented.
1087+
An \grammarterm{integer-literal} is a prvalue.
10741088

1075-
\enlargethispage{\baselineskip}%
1076-
\begin{LongTable}{Types of integer literals}{lex.icon.type}{l|l|l}
1089+
\begin{LongTable}{Types of \grammarterm{integer-literal}s}{lex.icon.type}{l|l|l}
10771090
\\ \topline
1078-
\lhdr{Suffix} & \chdr{Decimal literal} & \rhdr{Binary, octal, or hexadecimal literal} \\ \capsep
1091+
\lhdr{\grammarterm{integer-suffix}} & \chdr{\grammarterm{decimal-literal}} & \rhdr{\grammarterm{integer-literal} other than \grammarterm{decimal-literal}} \\ \capsep
10791092
\endfirsthead
10801093
\continuedcaption\\
10811094
\hline
1082-
\lhdr{Suffix} & \chdr{Decimal literal} & \rhdr{Binary, octal, or hexadecimal literal} \\ \capsep
1095+
\lhdr{\grammarterm{integer-suffix}} & \chdr{\grammarterm{decimal-literal}} & \rhdr{\grammarterm{integer-literal} other than \grammarterm{decimal-literal}} \\ \capsep
10831096
\endhead
10841097
none &
10851098
\tcode{int} &
@@ -1141,14 +1154,20 @@
11411154
\end{LongTable}
11421155

11431156
\pnum
1144-
If an integer literal cannot be represented by any type in its list and
1145-
an extended integer type\iref{basic.fundamental} can represent its value, it may have that
1146-
extended integer type. If all of the types in the list for the integer literal
1147-
are signed, the extended integer type shall be signed. If all of the
1148-
types in the list for the integer literal are unsigned, the extended integer
1149-
type shall be unsigned. If the list contains both signed and unsigned
1150-
types, the extended integer type may be signed or unsigned. A program is
1151-
ill-formed if one of its translation units contains an integer literal
1157+
If an \grammarterm{integer-literal}
1158+
cannot be represented by any type in its list and
1159+
an extended integer type\iref{basic.fundamental} can represent its value,
1160+
it may have that extended integer type.
1161+
If all of the types in the list for the \grammarterm{integer-literal}
1162+
are signed,
1163+
the extended integer type shall be signed.
1164+
If all of the types in the list for the \grammarterm{integer-literal}
1165+
are unsigned,
1166+
the extended integer type shall be unsigned.
1167+
If the list contains both signed and unsigned types,
1168+
the extended integer type may be signed or unsigned.
1169+
A program is ill-formed
1170+
if one of its translation units contains an \grammarterm{integer-literal}
11521171
that cannot be represented by any of the allowed types.
11531172

11541173
\rSec2[lex.ccon]{Character literals}
@@ -1454,64 +1473,68 @@
14541473
\end{bnf}
14551474

14561475
\pnum
1457-
\indextext{literal!floating-point}%
1458-
A floating-point literal consists of
1459-
an optional prefix specifying a base,
1460-
an integer part,
1461-
a radix point,
1462-
a fraction part,
1463-
\indextext{suffix!\idxcode{e}}%
1464-
\indextext{suffix!\idxcode{E}}%
1465-
\indextext{suffix!\idxcode{p}}%
1466-
\indextext{suffix!\idxcode{P}}%
1467-
an \tcode{e}, \tcode{E}, \tcode{p} or \tcode{P},
1468-
an optionally signed integer exponent, and
1469-
an optional type suffix.
1470-
The integer and fraction parts both consist of
1471-
a sequence of decimal (base ten) digits if there is no prefix, or
1472-
hexadecimal (base sixteen) digits if the prefix is \tcode{0x} or \tcode{0X}.
1473-
The floating-point literal is a \defnadj{decimal floating-point}{literal} in the former case and
1474-
a \defnadj{hexadecimal floating}{literal} in the latter case.
1475-
Optional separating single quotes in
1476-
a \grammarterm{digit-sequence} or \grammarterm{hexadecimal-digit-sequence}
1477-
are ignored when determining its value.
1478-
\begin{example}
1479-
The floating-point literals \tcode{1.602'176'565e-19} and \tcode{1.602176565e-19}
1480-
have the same value.
1481-
\end{example}
1482-
Either the integer part or the fraction part (not both) can be omitted.
1483-
Either the radix point or the letter \tcode{e} or \tcode{E} and
1484-
the exponent (not both) can be omitted from a decimal floating-point literal.
1485-
The radix point (but not the exponent) can be omitted
1486-
from a hexadecimal floating-point literal.
1487-
The integer part, the optional radix point, and the optional fraction part,
1488-
form the \defn{significand} of the floating-point literal.
1489-
In a decimal floating-point literal, the exponent, if present,
1490-
indicates the power of 10 by which the significand is to be scaled.
1491-
In a hexadecimal floating-point literal, the exponent
1492-
indicates the power of 2 by which the significand is to be scaled.
1493-
\begin{example}
1494-
The floating-point literals \tcode{49.625} and \tcode{0xC.68p+2} have the same value.
1495-
\end{example}
1496-
If the scaled value is in
1497-
the range of representable values for its type, the result is the scaled
1498-
value if representable, else the larger or smaller representable value
1499-
nearest the scaled value, chosen in an \impldef{choice of larger or smaller value of
1500-
floating-point literal} manner.
1501-
\indextext{literal!\idxcode{double}}%
1502-
The type of a floating-point literal is \tcode{double}
15031476
\indextext{literal!type of floating-point}%
1504-
unless explicitly specified by a suffix.
15051477
\indextext{literal!\idxcode{float}}%
15061478
\indextext{suffix!\idxcode{F}}%
15071479
\indextext{suffix!\idxcode{f}}%
1508-
The suffixes \tcode{f} and \tcode{F} specify \tcode{float},
15091480
\indextext{suffix!\idxcode{L}}%
15101481
\indextext{suffix!\idxcode{l}}%
15111482
\indextext{literal!\idxcode{long double}}%
1512-
the suffixes \tcode{l} and \tcode{L} specify \tcode{long}
1513-
\tcode{double}. If the scaled value is not in the range of representable
1483+
The type of a \grammarterm{floating-point-literal} is determined by
1484+
its \grammarterm{floating-point-suffix} as specified in \tref{lex.fcon.type}.
1485+
\begin{simpletypetable}
1486+
{Types of \grammarterm{floating-point-literal}{s}}
1487+
{lex.fcon.type}
1488+
{ll}
1489+
\topline
1490+
\lhdr{\grammarterm{floating-point-suffix}} & \rhdr{type} \\ \capsep
1491+
none & \keyword{double} \\
1492+
\tcode{f} or \tcode{F} & \keyword {float} \\
1493+
\tcode{l} or \tcode{L} & \keyword{long} \keyword{double} \\
1494+
\end{simpletypetable}
1495+
1496+
\pnum
1497+
\indextext{literal!floating-point}%
1498+
The \defn{significand} of a \grammarterm{floating-point-literal}
1499+
is the \grammarterm{fractional-constant} or \grammarterm{digit-sequence}
1500+
of a \grammarterm{decimal-floating-point-literal}
1501+
or the \grammarterm{hexadecimal-fractional-constant}
1502+
or \grammarterm{hexadecimal-digit-sequence}
1503+
of a \grammarterm{hexadecimal-floating-point-literal}.
1504+
In the significand,
1505+
the sequence of \grammarterm{digit}s or \grammarterm{hexadecimal-digit}s
1506+
and optional period are interpreted as a base $N$ real number $s$,
1507+
where $N$ is 10 for a \grammarterm{decimal-floating-point-literal} and
1508+
16 for a \grammarterm{hexadecimal-floating-point-literal}.
1509+
\begin{note}
1510+
Any optional separating single quotes are ignored when determining the value.
1511+
\end{note}
1512+
If an \grammarterm{exponent-part} or \grammarterm{binary-exponent-part}
1513+
is present,
1514+
the exponent $e$ of the \grammarterm{floating-point-literal}
1515+
is the result of interpreting
1516+
the sequence of an optional \grammarterm{sign} and the \grammarterm{digit}s
1517+
as a base-10 integer.
1518+
Otherwise, the exponent $e$ is 0.
1519+
The scaled value of the literal is
1520+
$s \times 10^e$ for a \grammarterm{decimal-floating-point-literal} and
1521+
$s \times 2^e$ for a \grammarterm{hexadecimal-floating-point-literal}.
1522+
\begin{example}
1523+
The \grammarterm{floating-point-literal}{s}
1524+
\tcode{49.625} and \tcode{0xC.68p+2} have the same value.
1525+
The \grammarterm{floating-point-literal}{s}
1526+
\tcode{1.602'176'565e-19} and \tcode{1.602176565e-19}
1527+
have the same value.
1528+
\end{example}
1529+
1530+
\pnum
1531+
If the scaled value is not in the range of representable
15141532
values for its type, the program is ill-formed.
1533+
Otherwise, the value of a \grammarterm{floating-point-literal}
1534+
is the scaled value if representable,
1535+
else the larger or smaller representable value nearest the scaled value,
1536+
chosen in an \impldef{choice of larger or smaller value of
1537+
\grammarterm{floating-point-literal}} manner.
15151538

15161539
\rSec2[lex.string]{String literals}
15171540

@@ -1878,8 +1901,7 @@
18781901
\nontermdef{user-defined-floating-point-literal}\br
18791902
fractional-constant \opt{exponent-part} ud-suffix\br
18801903
digit-sequence exponent-part ud-suffix\br
1881-
hexadecimal-prefix hexadecimal-fractional-constant binary-exponent-part ud-suffix\br
1882-
hexadecimal-prefix hexadecimal-digit-sequence binary-exponent-part ud-suffix
1904+
hexadecimal-prefix hexadecimal-fractional-constant binary-exponent-part ud-suffix
18831905
\end{bnf}
18841906

18851907
\begin{bnf}

source/time.tex

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1886,14 +1886,16 @@
18861886
suffixes \tcode{h}, \tcode{min}, \tcode{s}, \tcode{ms}, \tcode{us}, \tcode{ns}
18871887
denote duration values of the corresponding types \tcode{hours}, \tcode{minutes},
18881888
\tcode{seconds}, \tcode{milliseconds}, \tcode{microseconds}, and \tcode{nanoseconds}
1889-
respectively if they are applied to integral literals.
1889+
respectively if they are applied to \grammarterm{integer-literal}{s}.
18901890

18911891
\pnum
1892-
If any of these suffixes are applied to a floating-point literal the result is a
1892+
If any of these suffixes are applied to a \grammarterm{floating-point-literal}
1893+
the result is a
18931894
\tcode{chrono::duration} literal with an unspecified floating-point representation.
18941895

18951896
\pnum
1896-
If any of these suffixes are applied to an integer literal and the resulting
1897+
If any of these suffixes are applied to an \grammarterm{integer-literal}
1898+
and the resulting
18971899
\tcode{chrono::duration} value cannot be represented in the result type because
18981900
of overflow, the program is ill-formed.
18991901

0 commit comments

Comments
 (0)