lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


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".

Source:
http://www.lua.org/source/5.4/llex.c.html#check_next2

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.)

For example:

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.

Perhaps:

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'.

Source:
https://www.lua.org/manual/5.4/manual.html#3.1

Cheers,

Parke