Skip to content

Commit 2e9b1e7

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 c7f12d2 commit 2e9b1e7

File tree

3 files changed

+122
-103
lines changed

3 files changed

+122
-103
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: 116 additions & 99 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,39 @@
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+
In a \grammarterm{hexadecimal-literal},
1065+
the \grammarterm{hexadecimal-digit}s
1066+
\tcode{a} through \tcode{f} and \tcode{A} through \tcode{F}
1067+
have decimal values ten through fifteen.
10551068
\begin{example}
10561069
The number twelve can be written \tcode{12}, \tcode{014},
1057-
\tcode{0XC}, or \tcode{0b1100}. The integer literals \tcode{1048576},
1070+
\tcode{0XC}, or \tcode{0b1100}. The \grammarterm{integer-literal}s \tcode{1048576},
10581071
\tcode{1'048'576}, \tcode{0X100000}, \tcode{0x10'0000}, and
10591072
\tcode{0'004'000'000} all have the same value.
10601073
\end{example}
@@ -1068,18 +1081,19 @@
10681081
\indextext{suffix!\idxcode{U}}%
10691082
\indextext{suffix!\idxcode{l}}%
10701083
\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.
1084+
Using the optional \grammarterm{integer-suffix},
1085+
the type of an \grammarterm{integer-literal} is
1086+
the first of the corresponding list in \tref{lex.icon.type}
1087+
in which its value can be represented.
1088+
An \grammarterm{integer-literal} is a prvalue.
10741089

1075-
\enlargethispage{\baselineskip}%
1076-
\begin{LongTable}{Types of integer literals}{lex.icon.type}{l|l|l}
1090+
\begin{LongTable}{Types of \grammarterm{integer-literal}s}{lex.icon.type}{l|l|l}
10771091
\\ \topline
1078-
\lhdr{Suffix} & \chdr{Decimal literal} & \rhdr{Binary, octal, or hexadecimal literal} \\ \capsep
1092+
\lhdr{\grammarterm{integer-suffix}} & \chdr{\grammarterm{decimal-literal}} & \rhdr{\grammarterm{integer-literal} other than \grammarterm{decimal-literal}} \\ \capsep
10791093
\endfirsthead
10801094
\continuedcaption\\
10811095
\hline
1082-
\lhdr{Suffix} & \chdr{Decimal literal} & \rhdr{Binary, octal, or hexadecimal literal} \\ \capsep
1096+
\lhdr{\grammarterm{integer-suffix}} & \chdr{\grammarterm{decimal-literal}} & \rhdr{\grammarterm{integer-literal} other than \grammarterm{decimal-literal}} \\ \capsep
10831097
\endhead
10841098
none &
10851099
\tcode{int} &
@@ -1141,14 +1155,20 @@
11411155
\end{LongTable}
11421156

11431157
\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
1158+
If an \grammarterm{integer-literal}
1159+
cannot be represented by any type in its list and
1160+
an extended integer type\iref{basic.fundamental} can represent its value,
1161+
it may have that extended integer type.
1162+
If all of the types in the list for the \grammarterm{integer-literal}
1163+
are signed,
1164+
the extended integer type shall be signed.
1165+
If all of the types in the list for the \grammarterm{integer-literal}
1166+
are unsigned,
1167+
the extended integer type shall be unsigned.
1168+
If the list contains both signed and unsigned types,
1169+
the extended integer type may be signed or unsigned.
1170+
A program is ill-formed
1171+
if one of its translation units contains an \grammarterm{integer-literal}
11521172
that cannot be represented by any of the allowed types.
11531173

11541174
\rSec2[lex.ccon]{Character literals}
@@ -1409,8 +1429,7 @@
14091429

14101430
\begin{bnf}
14111431
\nontermdef{hexadecimal-floating-point-literal}\br
1412-
hexadecimal-prefix hexadecimal-fractional-constant binary-exponent-part \opt{floating-point-suffix}\br
1413-
hexadecimal-prefix hexadecimal-digit-sequence binary-exponent-part \opt{floating-point-suffix}
1432+
hexadecimal-prefix hexadecimal-fractional-constant binary-exponent-part \opt{floating-point-suffix}
14141433
\end{bnf}
14151434

14161435
\begin{bnf}
@@ -1422,7 +1441,7 @@
14221441
\begin{bnf}
14231442
\nontermdef{hexadecimal-fractional-constant}\br
14241443
\opt{hexadecimal-digit-sequence} \terminal{.} hexadecimal-digit-sequence\br
1425-
hexadecimal-digit-sequence \terminal{.}
1444+
hexadecimal-digit-sequence \opt{\terminal{.}}
14261445
\end{bnf}
14271446

14281447
\begin{bnf}
@@ -1454,64 +1473,63 @@
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+
of a \grammarterm{hexadecimal-floating-point-literal}.
1503+
A \grammarterm{digit-sequence} is interpreted as a decimal (base ten) number.
1504+
A \grammarterm{hexadecimal-digit-sequence} is interpreted
1505+
as a hexadecimal (base sixteen) number.
1506+
In a \grammarterm{decimal-floating-point-literal},
1507+
the \grammarterm{exponent-part}, if present,
1508+
indicates the power of 10 by which the significand is to be scaled.
1509+
In a \grammarterm{hexadecimal-floating-point-literal},
1510+
the \grammarterm{binary-exponent-part}
1511+
indicates the power of 2 by which the significand is to be scaled.
1512+
\begin{example}
1513+
The \grammarterm{floating-point-literal}{s}
1514+
\tcode{49.625} and \tcode{0xC.68p+2} have the same value.
1515+
\end{example}
1516+
Optional separating single quotes in
1517+
a \grammarterm{digit-sequence} or \grammarterm{hexadecimal-digit-sequence}
1518+
are ignored when determining
1519+
the value of a \grammarterm{floating-point-literal} value.
1520+
\begin{example}
1521+
The \grammarterm{floating-point-literal}{s} \tcode{1.602'176'565e-19} and \tcode{1.602176565e-19}
1522+
have the same value.
1523+
\end{example}
1524+
1525+
\pnum
1526+
If the scaled value is not in the range of representable
15141527
values for its type, the program is ill-formed.
1528+
Otherwise, the value of a \grammarterm{floating-point-literal}
1529+
is the scaled value if representable,
1530+
else the larger or smaller representable value nearest the scaled value,
1531+
chosen in an \impldef{choice of larger or smaller value of
1532+
\grammarterm{floating-point-literal}} manner.
15151533

15161534
\rSec2[lex.string]{String literals}
15171535

@@ -1878,8 +1896,7 @@
18781896
\nontermdef{user-defined-floating-point-literal}\br
18791897
fractional-constant \opt{exponent-part} ud-suffix\br
18801898
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
1899+
hexadecimal-prefix hexadecimal-fractional-constant binary-exponent-part ud-suffix
18831900
\end{bnf}
18841901

18851902
\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)