-
Notifications
You must be signed in to change notification settings - Fork 5
Literals
Viper currently supports only one type of numerical literal - integers. Integers must be typed in base 10(decimal/denary):
2
55
-
0
If you require a negative number, use the-
unary operator before the literal. Integer literals will always have a type ofi32
, however the compiler may change this to match the target type.
You may use a character literal instead of an integer for readability and simplicity. Unlike integer literals, character literals have a type of i8
.
Character literals may only contain one character and must be surrounded by single quotes('
):
'H'
' '
'8'
'@'
Character literals may also contain escape sequences:
-
'\n'
- A newline(ASCII code 10) -
'\0'
- A null terminator(ASCII code 0) -
'\''
- An escaped single quote, in case of need to store a single quote -
'\"'
- An escaped double quote, should be only used in string literals as these can be typed in a character literal
String literals contain text/a sequence of characters. Like all other literals, they are constant and cannot be assigned to. They can contain 0 or more characters, and will always have a null terminator(\0
) at the end. They must be surrounded by double quotes("
):
"Hello"
"123"
"@!"
String literals may contain the same escape sequences as character literals. They always have a type of i8*
Wiki created by @solar-mist and @Kami