[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: The Lua lexer's read_numeral() function and corresponding reference documentation
- From: Parke <parke.nexus@...>
- Date: Fri, 10 Sep 2021 17:58:17 -0700
The comment preceding the read_numeral() function in version 5.4.3 of
Lua's lexer says:
> Roughly, [read_numeral()] accepts the following pattern:
> %d(%x|%.|([Ee][+-]?))* | 0[Xx](%x|%.|([Pp][+-]?))*
The above pattern starts with "%d(%x".
Why the %x?
I'd expect "%d(%d".
Somewhat relatedly, the Lua Reference manual says:
> Hexadecimal constants also accept [...] plus an optional binary exponent [...]
The exponent is not written in binary. The exponent appears to be
written in decimal. (At the same time, the base is 2.)
0x1p9 is 512.0.
0x1pa is an error. It is not 1024.0.
0x1p10 is 1024.0. It is not 2.0
The notation (decimal or binary) used to write an exponent is entirely
independent from the base that is paired with the exponent.
A numeric constant (or numeral) can be written with an optional
fractional part and an optional BASE-10 EXPONENT WRITTEN IN DECIMAL,
marked by a letter 'e' or 'E'. Lua also accepts hexadecimal constants,
which start with 0x or 0X. Hexadecimal constants also accept an
optional fractional part plus an optional BASE-2 EXPONENT WRITTEN IN
DECIMAL, marked by a letter 'p' or 'P'.