Skip to content

Syntax

Number literals

Integers and floats are written the way PHP writes them. Rules shared by both:

  • A number may be prefixed by a sign: a minus (-) makes it negative, a plus (+) changes nothing. Whitespace may stand between the sign and the number (- 1 is -1).
  • An underscore (_) separates digits: it stands between two digits and nowhere else, so it neither leads, nor trails, nor doubles.

A decimal integer is a run of digits without a leading zero ([1-9][0-9]*). Other notations are prefixed and described below.

A number written with a separator.

42_04
literal

resultTypeLang\Type\Literal\IntLiteralNode

Prefixed with 0b or 0B, written in the digits 0 and 1.

The number 173.

0b1010_1101
literal

resultTypeLang\Type\Literal\IntLiteralNode

The number -10, the prefix is case-insensitive.

-0B1010
literal

resultTypeLang\Type\Literal\IntLiteralNode

Prefixed with 0o or 0O, written in the digits 0 to 7. For compatibility with older PHP, a leading 0 alone is an octal prefix too.

The number 34.

0o42
literal

resultTypeLang\Type\Literal\IntLiteralNode

Also 34, with the legacy prefix.

042
literal

resultTypeLang\Type\Literal\IntLiteralNode

The number 2195, the prefix is case-insensitive.

0O42_23
literal

resultTypeLang\Type\Literal\IntLiteralNode

Prefixed with 0x or 0X, written in the digits 0 to 9 and the letters A to F in any case.

The number 57005.

0xDEAD
literal

resultTypeLang\Type\Literal\IntLiteralNode

The number 3735928559, the prefix and the letters are case-insensitive.

0XDead_Beef
literal

resultTypeLang\Type\Literal\IntLiteralNode

A float is two runs of digits around a dot ([0-9]+\.[0-9]+), either run may be omitted, but not both. Every run, the exponent included, accepts the separator.

0.9
literal

resultTypeLang\Type\Literal\FloatLiteralNode

The same as 0.9.

.9
literal

resultTypeLang\Type\Literal\FloatLiteralNode

The same as 1.0.

1.
literal

resultTypeLang\Type\Literal\FloatLiteralNode

-0.9
literal

resultTypeLang\Type\Literal\FloatLiteralNode

Separators in every part, the same as 23.45e-67.

2_3.4_5e-6_7
literal

resultTypeLang\Type\Literal\FloatLiteralNode

A number followed by e (or E) and a decimal exponent with an optional sign.

The number 1000.0.

10e2
literal

resultTypeLang\Type\Literal\FloatLiteralNode

The number 0.1, the E is case-insensitive.

10E-2
literal

resultTypeLang\Type\Literal\FloatLiteralNode

The number 1000.0, a plus changes nothing.

10e+2
literal

resultTypeLang\Type\Literal\FloatLiteralNode