Scala 中浮点字面量的定义是
floatingPointLiteral ::= digit {digit} ‘.’ digit {digit} [exponentPart] [floatType]
| ‘.’ digit {digit} [exponentPart] [floatType]
| digit {digit} exponentPart [floatType]
| digit {digit} [exponentPart] floatType
exponentPart ::= (‘E’ | ‘e’) [‘+’ | ‘-’] digit {digit}
floatType ::= ‘F’ | ‘f’ | ‘D’ | ‘d’
当我尝试输入以点开头的浮点文字时,出现错误:
scala> .123
^
error: ';' expected but double literal found.
如果将这样的文字分配给某个变量,一切都很好
scala> val x = .123
x: Double = 0.123
为什么它会这样?