|
388 | 388 | \pnum |
389 | 389 | \begin{example} |
390 | 390 | 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 |
393 | 394 | \tcode{0xe}, \tcode{+}, and \tcode{foo} might produce a valid expression (for example, |
394 | 395 | if \tcode{foo} were a macro defined as \tcode{1}). Similarly, the |
395 | 396 | 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. |
398 | 399 | \end{example} |
399 | 400 |
|
400 | 401 | \pnum |
|
575 | 576 | \end{bnf} |
576 | 577 |
|
577 | 578 | \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}. |
581 | 582 |
|
582 | 583 | \pnum |
583 | 584 | 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.% |
586 | 588 | \indextext{number!preprocessing|)} |
587 | 589 |
|
588 | 590 | \rSec1[lex.name]{Identifiers} |
|
1007 | 1009 | \indextext{literal!\idxcode{unsigned}}% |
1008 | 1010 | \indextext{literal!\idxcode{long}}% |
1009 | 1011 | \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. |
1029 | 1032 | \begin{example} |
1030 | 1033 | 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}, |
1032 | 1035 | \tcode{1'048'576}, \tcode{0X100000}, \tcode{0x10'0000}, and |
1033 | 1036 | \tcode{0'004'000'000} all have the same value. |
1034 | 1037 | \end{example} |
|
1042 | 1045 | \indextext{suffix!\idxcode{U}}% |
1043 | 1046 | \indextext{suffix!\idxcode{l}}% |
1044 | 1047 | \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. |
1048 | 1053 |
|
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} |
1051 | 1055 | \\ \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 |
1053 | 1057 | \endfirsthead |
1054 | 1058 | \continuedcaption\\ |
1055 | 1059 | \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 |
1057 | 1061 | \endhead |
1058 | 1062 | none & |
1059 | 1063 | \tcode{int} & |
|
1115 | 1119 | \end{LongTable} |
1116 | 1120 |
|
1117 | 1121 | \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} |
1126 | 1136 | that cannot be represented by any of the allowed types. |
1127 | 1137 |
|
1128 | 1138 | \rSec2[lex.ccon]{Character literals} |
|
1383 | 1393 |
|
1384 | 1394 | \begin{bnf} |
1385 | 1395 | \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} |
1388 | 1397 | \end{bnf} |
1389 | 1398 |
|
1390 | 1399 | \begin{bnf} |
|
1396 | 1405 | \begin{bnf} |
1397 | 1406 | \nontermdef{hexadecimal-fractional-constant}\br |
1398 | 1407 | \opt{hexadecimal-digit-sequence} \terminal{.} hexadecimal-digit-sequence\br |
1399 | | - hexadecimal-digit-sequence \terminal{.} |
| 1408 | + hexadecimal-digit-sequence \opt{\terminal{.}} |
1400 | 1409 | \end{bnf} |
1401 | 1410 |
|
1402 | 1411 | \begin{bnf} |
|
1428 | 1437 | \end{bnf} |
1429 | 1438 |
|
1430 | 1439 | \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} |
1477 | 1440 | \indextext{literal!type of floating-point}% |
1478 | | -unless explicitly specified by a suffix. |
1479 | 1441 | \indextext{literal!\idxcode{float}}% |
1480 | 1442 | \indextext{suffix!\idxcode{F}}% |
1481 | 1443 | \indextext{suffix!\idxcode{f}}% |
1482 | | -The suffixes \tcode{f} and \tcode{F} specify \tcode{float}, |
1483 | 1444 | \indextext{suffix!\idxcode{L}}% |
1484 | 1445 | \indextext{suffix!\idxcode{l}}% |
1485 | 1446 | \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 |
1488 | 1491 | 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. |
1489 | 1497 |
|
1490 | 1498 | \rSec2[lex.string]{String literals} |
1491 | 1499 |
|
|
1852 | 1860 | \nontermdef{user-defined-floating-point-literal}\br |
1853 | 1861 | fractional-constant \opt{exponent-part} ud-suffix\br |
1854 | 1862 | 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 |
1857 | 1864 | \end{bnf} |
1858 | 1865 |
|
1859 | 1866 | \begin{bnf} |
|
0 commit comments