語法:
NumericLiteral ::
DecimalLiteral
HexIntegerLiteral
DecimalLiteral ::
DecimalIntegerLiteral . DecimalDigitsopt ExponentPartopt
. DecimalDigits ExponentPartopt DecimalIntegerLiteral
ExponentPartopt
DecimalIntegerLiteral ::
0
NonZeroDigit DecimalDigitsopt
DecimalDigits ::
DecimalDigit
DecimalDigits DecimalDigit
DecimalDigit :: one of 0
1 2 3 4 5 6 7 8 9
NonZeroDigit :: one of
1 2 3 4 5 6 7 8 9
ExponentPart ::
ExponentIndicator SignedInteger
ExponentIndicator :: one of
e E
SignedInteger ::
DecimalDigits
+ DecimalDigits
- DecimalDigits
HexIntegerLiteral ::
0x HexDigit
0X HexDigit
HexIntegerLiteral HexDigit
HexDigit :: one of
0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F
源字符中的 NumericLiteral 后面不允許緊跟著 IdentifierStart 或 DecimalDigit。
注:例如:
3in
是錯(cuò)誤的,不存在兩個(gè)輸入元素 3 和 in。
語義:
一個(gè)數(shù)值字面量代表一個(gè) Number 類型的值。此值取決于兩個(gè)步驟:第一,由字面量得出的數(shù)學(xué)值 (mathematical value)(MV);第二,這個(gè)數(shù)學(xué)值按照后面描述的規(guī)則舍入。
- NumericLiteral::DecimalLiteral 的 MV 是 DecimalLiteral 的 MV。
- NumericLiteral :: HexIntegerLiteral 的 MV 是 HexIntegerLiteral 的 MV。
- DecimalLiteral :: DecimalIntegerLiteral . 的 MV 是 DecimalIntegerLiteral 的 MV 是。
- DecimalLiteral :: DecimalIntegerLiteral . DecimalDigits 的 MV 是 DecimalIntegerLiteral 的 MV 加上 (DecimalDigits 的 MV 乘 10-n), 這里的 n 是 DecimalDigits 的字符個(gè)數(shù)。
- DecimalLiteral :: DecimalIntegerLiteral . ExponentPart 的 MV 是 DecimalIntegerLiteral 的 MV 乘 10e, 這里的 e 是 ExponentPart 的 MV。
- DecimalLiteral :: DecimalIntegerLiteral . DecimalDigits ExponentPart 的 MV 是 (DecimalIntegerLiteral 的 MV 加 (DecimalDigits 的 MV 乘 10-n)) 乘 10e, 這里的 n 是 DecimalDigits 的字符個(gè)數(shù),e 是 ExponentPart 的 MV。
- DecimalLiteral ::. DecimalDigits 的 MV 是 DecimalDigits 的 MV 乘 10-n, 這里的 n 是 DecimalDigits 的字符個(gè)數(shù)。
- DecimalLiteral ::. DecimalDigits ExponentPart 的 MV 是 DecimalDigits 的 MV 乘 10e-n, 這里的 n 是 DecimalDigits 的字符個(gè)數(shù),e 是 ExponentPart 的 MV。
- DecimalLiteral :: DecimalIntegerLiteral 的 MV 是 DecimalIntegerLiteral 的 MV。
- DecimalLiteral :: DecimalIntegerLiteral ExponentPart 的 MV 是 DecimalIntegerLiteral 的 MV 乘 10e, 這里的 e 是 ExponentPart 的 MV。
- DecimalIntegerLiteral :: 0 的 MV 是 0。
- DecimalIntegerLiteral :: NonZeroDigit DecimalDigits 的 MV 是 (NonZeroDigit 的 MV 乘 10n) 加 DecimalDigits 的 MV, 這里的 n 是 DecimalDigits 的字符個(gè)數(shù)。
- DecimalDigits :: DecimalDigit 的 MV 是 DecimalDigit 的 MV。
- DecimalDigits :: DecimalDigits DecimalDigit 的 MV 是 (DecimalDigits 的 MV 乘 10) 加 DecimalDigit 的 MV。
- ExponentPart :: ExponentIndicator SignedInteger 的 MV 是 SignedInteger 的 MV。
- SignedInteger :: DecimalDigits 的 MV 是 DecimalDigits 的 MV。
- SignedInteger :: + DecimalDigits 的 MV 是 DecimalDigits 的 MV。
- SignedInteger :: - DecimalDigits 的 MV 是 DecimalDigits 的 MV 取負(fù)。
- DecimalDigit :: 0 或 HexDigit :: 0 的 MV 是 0。
- DecimalDigit :: 1 或 NonZeroDigit :: 1 或 HexDigit :: 1 的 MV 是 1。
- DecimalDigit :: 2 或 NonZeroDigit :: 2 或 HexDigit :: 2 的 MV 是 2。
- DecimalDigit :: 3 或 NonZeroDigit :: 3 或 HexDigit :: 3 的 MV 是 3。
- DecimalDigit :: 4 或 NonZeroDigit :: 4 或 HexDigit :: 4 的 MV 是 4。
- DecimalDigit :: 5 或 NonZeroDigit :: 5 或 HexDigit :: 5 的 MV 是 5。
- DecimalDigit :: 6 或 NonZeroDigit :: 6 或 HexDigit :: 6 的 MV 是 6。
- DecimalDigit :: 7 或 NonZeroDigit :: 7 或 HexDigit :: 7 的 MV 是 7。
- DecimalDigit :: 8 或 NonZeroDigit :: 8 或 HexDigit :: 8 的 MV 是 8。
- DecimalDigit :: 9 或 NonZeroDigit :: 9 或 HexDigit :: 9 的 MV 是 9。
- HexDigit :: a 或 HexDigit :: A 的 MV 是 10。
- HexDigit :: b 或 HexDigit :: B 的 MV 是 11。
- HexDigit :: c 或 HexDigit :: C 的 MV 是 12。
- HexDigit :: d 或 HexDigit :: D 的 MV 是 13。
- HexDigit :: e 或 HexDigit :: E 的 MV 是 14。
- HexDigit :: f 或 HexDigit :: F 的 MV 是 15。
- HexIntegerLiteral :: 0x HexDigit 的 MV 是 HexDigit 的 MV。
- HexIntegerLiteral :: 0X HexDigit 的 MV 是 HexDigit 的 MV。
- HexIntegerLiteral :: HexIntegerLiteral HexDigit 的 MV 是 (HexIntegerLiteral 的 MV 乘 16) 加 HexDigit 的 MV。
數(shù)值字面量的確切 MV 值一旦被確定,它就會舍入成 Number 類型的值。如果 MV 是 0,那么舍入值是 +0;否則,舍入值必須是 MV 對應(yīng)的準(zhǔn)確數(shù)字值(8.5 中定義),除非此字面量是有效數(shù)字超過 20 位的 DecimalLiteral,這種情況下,數(shù)字值可以用下面兩種方式產(chǎn)生的 MV 值確定:一,將 20 位后的每個(gè)有效數(shù)字用 0 替換后產(chǎn)生的 MV,二,將 20 位后的每個(gè)有效數(shù)字用 0 替換,并且遞增第 20 位有效數(shù)字位置的字面量值,產(chǎn)生的 MV。如果一個(gè)數(shù)字是 ExponentPart 的一部分,并且:
- 它不是 0;或
- 它的左側(cè)是非零數(shù)字,它的右側(cè)是不在 ExponentPart 的非零數(shù)字。
符合標(biāo)準(zhǔn)的實(shí)現(xiàn),在處理嚴(yán)格模式代碼(見 10.1.1)時(shí),按照 B.1.1 的描述,不得擴(kuò)展 NumericLiteral 包含 OctalIntegerLiteral 的語法。
更多建議: