Skip to content

Commit ca98470

Browse files
committed
[lex.icon,lex.fcon] Rework description to avoid redundancies.
1 parent 235e9a0 commit ca98470

File tree

3 files changed

+112
-103
lines changed

3 files changed

+112
-103
lines changed

source/compatibility.tex

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

source/lex.tex

Lines changed: 106 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -388,13 +388,14 @@
388388
\pnum
389389
\begin{example}
390390
The program fragment \tcode{0xe+foo} is parsed as a
391-
preprocessing number token (one that is not a valid integer or floating-point
392-
literal token), even though a parse as three preprocessing tokens
391+
preprocessing number token (one that is not a valid
392+
\grammarterm{integer-literal} or \grammarterm{floating-point-literal} token),
393+
even though a parse as three preprocessing tokens
393394
\tcode{0xe}, \tcode{+}, and \tcode{foo} might produce a valid expression (for example,
394395
if \tcode{foo} were a macro defined as \tcode{1}). Similarly, the
395396
program fragment \tcode{1E1} is parsed as a preprocessing number (one
396-
that is a valid floating-point literal token), whether or not \tcode{E} is a
397-
macro name.
397+
that is a valid \grammarterm{floating-point-literal} token),
398+
whether or not \tcode{E} is a macro name.
398399
\end{example}
399400

400401
\pnum
@@ -575,14 +576,15 @@
575576
\end{bnf}
576577

577578
\pnum
578-
Preprocessing number tokens lexically include all integer literal
579-
tokens\iref{lex.icon} and all floating-point literal
580-
tokens\iref{lex.fcon}.
579+
Preprocessing number tokens lexically include
580+
all \grammarterm{integer-literal} tokens\iref{lex.icon} and
581+
all \grammarterm{floating-point-literal} tokens\iref{lex.fcon}.
581582

582583
\pnum
583584
A preprocessing number does not have a type or a value; it acquires both
584-
after a successful conversion to an integer literal token or a floating-point literal
585-
token.%
585+
after a successful conversion to
586+
an \grammarterm{integer-literal} token or
587+
a \grammarterm{floating-point-literal} token.%
586588
\indextext{number!preprocessing|)}
587589

588590
\rSec1[lex.name]{Identifiers}
@@ -1007,28 +1009,29 @@
10071009
\indextext{literal!\idxcode{unsigned}}%
10081010
\indextext{literal!\idxcode{long}}%
10091011
\indextext{literal!base of integer}%
1010-
An \defnx{integer literal}{literal!integer} is a sequence of digits that has no period
1011-
or exponent part, with optional separating single quotes that are ignored
1012-
when determining its value. An integer literal may have a prefix that specifies
1013-
its base and a suffix that specifies its type. The lexically first digit
1014-
of the sequence of digits is the most significant.
1015-
A \defnx{binary integer literal}{literal!binary} (base two) begins with
1016-
\tcode{0b} or \tcode{0B} and consists of a sequence of binary digits.
1017-
An \defnx{octal integer literal}{literal!octal}
1018-
(base eight) begins with the digit \tcode{0} and consists of a
1019-
sequence of octal digits.\footnote{The digits \tcode{8} and \tcode{9} are not octal digits. }
1020-
A \defnx{decimal integer literal}{literal!decimal}
1021-
(base ten) begins with a digit other than \tcode{0} and
1022-
consists of a sequence of decimal digits.
1023-
A \defnx{hexadecimal integer literal}{literal!hexadecimal}
1024-
(base sixteen) begins with
1025-
\tcode{0x} or \tcode{0X} and consists of a sequence of hexadecimal
1026-
digits, which include the decimal digits and the letters \tcode{a}
1027-
through \tcode{f} and \tcode{A} through \tcode{F} with decimal values
1028-
ten through fifteen.
1012+
In an \grammarterm{integer-literal},
1013+
the sequence of digits is interpreted as a base-$N$ number
1014+
as shown in table \tref{lex.icon.base};
1015+
the lexically first digit of the sequence of digits is the most significant and
1016+
optional separating single quotes are ignored when determining the value.
1017+
\begin{simpletypetable}
1018+
{Base of \grammarterm{integer-literal}{s}}
1019+
{lex.icon.base}
1020+
{lr}
1021+
\topline
1022+
\lhdr{Kind of \grammarterm{integer-literal}} & \rhdr{base $N$} \\ \capsep
1023+
\grammarterm{binary-literal} & 2 \\
1024+
\grammarterm{octal-literal} & 8 \\
1025+
\grammarterm{decimal-literal} & 10 \\
1026+
\grammarterm{hexadecimal-literal} & 16 \\
1027+
\end{simpletypetable}
1028+
1029+
In a \grammarterm{hexadecimal-literal},
1030+
the letters \tcode{a} through \tcode{f} and \tcode{A} through \tcode{F}
1031+
have decimal values ten through fifteen.
10291032
\begin{example}
10301033
The number twelve can be written \tcode{12}, \tcode{014},
1031-
\tcode{0XC}, or \tcode{0b1100}. The integer literals \tcode{1048576},
1034+
\tcode{0XC}, or \tcode{0b1100}. The \grammarterm{integer-literal}s \tcode{1048576},
10321035
\tcode{1'048'576}, \tcode{0X100000}, \tcode{0x10'0000}, and
10331036
\tcode{0'004'000'000} all have the same value.
10341037
\end{example}
@@ -1042,18 +1045,19 @@
10421045
\indextext{suffix!\idxcode{U}}%
10431046
\indextext{suffix!\idxcode{l}}%
10441047
\indextext{suffix!\idxcode{u}}%
1045-
The type of an integer literal is the first of the corresponding list
1046-
in \tref{lex.icon.type} in which its value can be
1047-
represented.
1048+
Using the optional \grammarterm{integer-suffix},
1049+
the type of an \grammarterm{integer-literal} is
1050+
the first of the corresponding list in \tref{lex.icon.type}
1051+
in which its value can be represented.
1052+
An \grammarterm{integer-literal} is a prvalue.
10481053

1049-
\enlargethispage{\baselineskip}%
1050-
\begin{LongTable}{Types of integer literals}{lex.icon.type}{l|l|l}
1054+
\begin{LongTable}{Types of \grammarterm{integer-literal}s}{lex.icon.type}{l|l|l}
10511055
\\ \topline
1052-
\lhdr{Suffix} & \chdr{Decimal literal} & \rhdr{Binary, octal, or hexadecimal literal} \\ \capsep
1056+
\lhdr{\grammarterm{integer-suffix}} & \chdr{\grammarterm{decimal-literal}} & \rhdr{\grammarterm{integer-literal} other than \grammarterm{decimal-literal}} \\ \capsep
10531057
\endfirsthead
10541058
\continuedcaption\\
10551059
\hline
1056-
\lhdr{Suffix} & \chdr{Decimal literal} & \rhdr{Binary, octal, or hexadecimal literal} \\ \capsep
1060+
\lhdr{\grammarterm{integer-suffix}} & \chdr{\grammarterm{decimal-literal}} & \rhdr{\grammarterm{integer-literal} other than \grammarterm{decimal-literal}} \\ \capsep
10571061
\endhead
10581062
none &
10591063
\tcode{int} &
@@ -1115,14 +1119,20 @@
11151119
\end{LongTable}
11161120

11171121
\pnum
1118-
If an integer literal cannot be represented by any type in its list and
1119-
an extended integer type\iref{basic.fundamental} can represent its value, it may have that
1120-
extended integer type. If all of the types in the list for the integer literal
1121-
are signed, the extended integer type shall be signed. If all of the
1122-
types in the list for the integer literal are unsigned, the extended integer
1123-
type shall be unsigned. If the list contains both signed and unsigned
1124-
types, the extended integer type may be signed or unsigned. A program is
1125-
ill-formed if one of its translation units contains an integer literal
1122+
If an \grammarterm{integer-literal}
1123+
cannot be represented by any type in its list and
1124+
an extended integer type\iref{basic.fundamental} can represent its value,
1125+
it may have that extended integer type.
1126+
If all of the types in the list for the \grammarterm{integer-literal}
1127+
are signed,
1128+
the extended integer type shall be signed.
1129+
If all of the types in the list for the \grammarterm{integer-literal}
1130+
are unsigned,
1131+
the extended integer type shall be unsigned.
1132+
If the list contains both signed and unsigned types,
1133+
the extended integer type may be signed or unsigned.
1134+
A program is ill-formed
1135+
if one of its translation units contains an \grammarterm{integer-literal}
11261136
that cannot be represented by any of the allowed types.
11271137

11281138
\rSec2[lex.ccon]{Character literals}
@@ -1383,8 +1393,7 @@
13831393

13841394
\begin{bnf}
13851395
\nontermdef{hexadecimal-floating-point-literal}\br
1386-
hexadecimal-prefix hexadecimal-fractional-constant binary-exponent-part \opt{floating-point-suffix}\br
1387-
hexadecimal-prefix hexadecimal-digit-sequence binary-exponent-part \opt{floating-point-suffix}
1396+
hexadecimal-prefix hexadecimal-fractional-constant binary-exponent-part \opt{floating-point-suffix}
13881397
\end{bnf}
13891398

13901399
\begin{bnf}
@@ -1396,7 +1405,7 @@
13961405
\begin{bnf}
13971406
\nontermdef{hexadecimal-fractional-constant}\br
13981407
\opt{hexadecimal-digit-sequence} \terminal{.} hexadecimal-digit-sequence\br
1399-
hexadecimal-digit-sequence \terminal{.}
1408+
hexadecimal-digit-sequence \opt{\terminal{.}}
14001409
\end{bnf}
14011410

14021411
\begin{bnf}
@@ -1428,64 +1437,63 @@
14281437
\end{bnf}
14291438

14301439
\pnum
1431-
\indextext{literal!floating-point}%
1432-
A floating-point literal consists of
1433-
an optional prefix specifying a base,
1434-
an integer part,
1435-
a radix point,
1436-
a fraction part,
1437-
\indextext{suffix!\idxcode{e}}%
1438-
\indextext{suffix!\idxcode{E}}%
1439-
\indextext{suffix!\idxcode{p}}%
1440-
\indextext{suffix!\idxcode{P}}%
1441-
an \tcode{e}, \tcode{E}, \tcode{p} or \tcode{P},
1442-
an optionally signed integer exponent, and
1443-
an optional type suffix.
1444-
The integer and fraction parts both consist of
1445-
a sequence of decimal (base ten) digits if there is no prefix, or
1446-
hexadecimal (base sixteen) digits if the prefix is \tcode{0x} or \tcode{0X}.
1447-
The floating-point literal is a \defnadj{decimal floating-point}{literal} in the former case and
1448-
a \defnadj{hexadecimal floating}{literal} in the latter case.
1449-
Optional separating single quotes in
1450-
a \grammarterm{digit-sequence} or \grammarterm{hexadecimal-digit-sequence}
1451-
are ignored when determining its value.
1452-
\begin{example}
1453-
The floating-point literals \tcode{1.602'176'565e-19} and \tcode{1.602176565e-19}
1454-
have the same value.
1455-
\end{example}
1456-
Either the integer part or the fraction part (not both) can be omitted.
1457-
Either the radix point or the letter \tcode{e} or \tcode{E} and
1458-
the exponent (not both) can be omitted from a decimal floating-point literal.
1459-
The radix point (but not the exponent) can be omitted
1460-
from a hexadecimal floating-point literal.
1461-
The integer part, the optional radix point, and the optional fraction part,
1462-
form the \defn{significand} of the floating-point literal.
1463-
In a decimal floating-point literal, the exponent, if present,
1464-
indicates the power of 10 by which the significand is to be scaled.
1465-
In a hexadecimal floating-point literal, the exponent
1466-
indicates the power of 2 by which the significand is to be scaled.
1467-
\begin{example}
1468-
The floating-point literals \tcode{49.625} and \tcode{0xC.68p+2} have the same value.
1469-
\end{example}
1470-
If the scaled value is in
1471-
the range of representable values for its type, the result is the scaled
1472-
value if representable, else the larger or smaller representable value
1473-
nearest the scaled value, chosen in an \impldef{choice of larger or smaller value of
1474-
floating-point literal} manner.
1475-
\indextext{literal!\idxcode{double}}%
1476-
The type of a floating-point literal is \tcode{double}
14771440
\indextext{literal!type of floating-point}%
1478-
unless explicitly specified by a suffix.
14791441
\indextext{literal!\idxcode{float}}%
14801442
\indextext{suffix!\idxcode{F}}%
14811443
\indextext{suffix!\idxcode{f}}%
1482-
The suffixes \tcode{f} and \tcode{F} specify \tcode{float},
14831444
\indextext{suffix!\idxcode{L}}%
14841445
\indextext{suffix!\idxcode{l}}%
14851446
\indextext{literal!\idxcode{long double}}%
1486-
the suffixes \tcode{l} and \tcode{L} specify \tcode{long}
1487-
\tcode{double}. If the scaled value is not in the range of representable
1447+
The type of a \grammarterm{floating-point-literal} is determined by
1448+
its \grammarterm{floating-point-suffix} as specified in \tref{lex.fcon.type}.
1449+
\begin{simpletypetable}
1450+
{Types of \grammarterm{floating-point-literal}{s}}
1451+
{lex.fcon.type}
1452+
{ll}
1453+
\topline
1454+
\lhdr{\grammarterm{floating-point-suffix}} & \rhdr{type} \\ \capsep
1455+
none & \keyword{double} \\
1456+
\tcode{f} or \tcode{F} & \keyword {float} \\
1457+
\tcode{l} or \tcode{L} & \keyword{long} \keyword{double} \\
1458+
\end{simpletypetable}
1459+
1460+
\pnum
1461+
\indextext{literal!floating-point}%
1462+
The \defn{significand} of a \grammarterm{floating-point-literal}
1463+
is the \grammarterm{fractional-constant} or \grammarterm{digit-sequence}
1464+
of a \grammarterm{decimal-floating-point-literal}
1465+
or the \grammarterm{hexadecimal-fractional-constant}
1466+
of a \grammarterm{hexadecimal-floating-point-literal}.
1467+
A \grammarterm{digit-sequence} is interpreted as a decimal (base ten) number.
1468+
A \grammarterm{hexadecimal-digit-sequence} is interpreted
1469+
as a hexadecimal (base sixteen) number.
1470+
In a \grammarterm{decimal-floating-point-literal},
1471+
the \grammarterm{exponent-part}, if present,
1472+
indicates the power of 10 by which the significand is to be scaled.
1473+
In a \grammarterm{hexadecimal-floating-point-literal},
1474+
the \grammarterm{binary-exponent-part}
1475+
indicates the power of 2 by which the significand is to be scaled.
1476+
\begin{example}
1477+
The \grammarterm{floating-point-literal}{s}
1478+
\tcode{49.625} and \tcode{0xC.68p+2} have the same value.
1479+
\end{example}
1480+
Optional separating single quotes in
1481+
a \grammarterm{digit-sequence} or \grammarterm{hexadecimal-digit-sequence}
1482+
are ignored when determining
1483+
the value of a \grammarterm{floating-point-literal} value.
1484+
\begin{example}
1485+
The \grammarterm{floating-point-literal}{s} \tcode{1.602'176'565e-19} and \tcode{1.602176565e-19}
1486+
have the same value.
1487+
\end{example}
1488+
1489+
\pnum
1490+
If the scaled value is not in the range of representable
14881491
values for its type, the program is ill-formed.
1492+
Otherwise, the value of a \grammarterm{floating-point-literal}
1493+
is the scaled value if representable,
1494+
else the larger or smaller representable value nearest the scaled value,
1495+
chosen in an \impldef{choice of larger or smaller value of
1496+
\grammarterm{floating-point-literal}} manner.
14891497

14901498
\rSec2[lex.string]{String literals}
14911499

@@ -1852,8 +1860,7 @@
18521860
\nontermdef{user-defined-floating-point-literal}\br
18531861
fractional-constant \opt{exponent-part} ud-suffix\br
18541862
digit-sequence exponent-part ud-suffix\br
1855-
hexadecimal-prefix hexadecimal-fractional-constant binary-exponent-part ud-suffix\br
1856-
hexadecimal-prefix hexadecimal-digit-sequence binary-exponent-part ud-suffix
1863+
hexadecimal-prefix hexadecimal-fractional-constant binary-exponent-part ud-suffix
18571864
\end{bnf}
18581865

18591866
\begin{bnf}

source/time.tex

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

18881888
\pnum
1889-
If any of these suffixes are applied to a floating-point literal the result is a
1889+
If any of these suffixes are applied to a \grammarterm{floating-point-literal}
1890+
the result is a
18901891
\tcode{chrono::duration} literal with an unspecified floating-point representation.
18911892

18921893
\pnum
1893-
If any of these suffixes are applied to an integer literal and the resulting
1894+
If any of these suffixes are applied to an \grammarterm{integer-literal}
1895+
and the resulting
18941896
\tcode{chrono::duration} value cannot be represented in the result type because
18951897
of overflow, the program is ill-formed.
18961898

0 commit comments

Comments
 (0)