As with comments, Dyvil also mostly inherits the syntax for number literals from Java.
Integer literals are the most basic type of number literals. There are four types for different bases available, all of which are indicated with different prefixes.
- All sorts can have as many leading zeros (after the prefix) as necessary.
- Leading minus signs
-are not part of the tokens. They are always treated as a separate token by the parser.
- Base-16 digits
Fcan also be lowercase
Integer Literals can only be in the range
. Otherwise, the compiler or REPL will cause a syntax error. For a greater range of values, Long Literals have to be used.
For integer literals, the primitive type
Long Literals work much like integer literals. However, they have to be disambiguated by adding a trailing
Long Literals allow a range of values from
Integer and Long Literals may have an arbitrary number of underscores
_in between digits, to increase readability.
Floating Point Literals can be used to express numbers with decimal places. Unlike Integer Literals, they are only available as base-10 and base-16 literals.
0x1A.3F // base-16
It is also possible to add an exponent to floating point literals:
1.5e4 -> 1500.0
0.3e-2 -> 0.003
0.4e10 -> 4000000000.0
Valid Floating-Point Literals cannot start or end with a period symbol
.. Thus, the following expressions are illegal in Dyvil:
Dpostfix to explicitly declare it, the type of floating point literals will be inferred as
double. However, it is recommended to always add the postfix characters for clarity.
Float Literals can be created by suffixing a normal Floating-Point Literal with an
F. This will treat the literal as a
floatvalue and will infer that type for the literal.
Double Literals are Floating-Point-Literals suffixed with a
Dcharacter. Their type will then be inferred to