Panther Search Documentation Tutorials Devlog Downloads Source Code

Literals

Panther
Documentation


Literals are ephemeral expressions that allow expressing a fixed value directly.

Integer Literals

Integer literals are expressions that represent an unsigned integral value. They are fluid and thus not explicitly typed, but they may only convert to integral types. They are represented as one of the following:

An integer literal may optionally have a suffix of scientific notation which is: an E or an e, followed by an optional + or - (omitting is equivalent to +), followed by 1 or more decimal digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9).

Integer literals may optionally be broken up by underscores ( _ ) anywhere except for the beginning. This means that 12_345_ is equivalent to 12345.

Float Literals

Float literals are expressions that represent an unsigned floating value. They are fluid and thus not explicitly typed, but they may only convert to floating types. They are represented by one of the following:

Float literals may optionally be broken up by underscores ( _ ) anywhere except for the beginning. This means that 1_234.5 is equivalent to 1234.5.

Boolean Literals

Boolean literals are expressions represent a single boolean value. They are type Bool and are represented by the following:

Character Literals

Character literals are expressions that represent a single character and are represented as ASCII. They are type Char. They are represented by two single-quote characters (') containing one the following:

String Literals

String literals are expressions that represent a string of text. They are type [Char:N;'\0'] where N is the number of characters in the string literal. They are represented by two double-quotes characters (") containing 0 or more of the following:

Notes

As suggested by the type, string literals automatically have a null-terminator appended. This means that "\0" is represented in memory as two null-terminator.

Unlike languages like C/C++ and Zig, nothing special needs to be done to allow string literals to be multi-line.

Examples

Panther
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
// integer literals def INTEGER: Int = 12; def SCIENTIFIC_INTEGER: USize = 14e2; // 1400 def BINARY_FLUID_INTEGER = 0b11010; // 26 // float literals def FLOAT: F32 = 12.4; // boolean literals def BOOL: Bool = true; // character literals def CHARACTER: Char = 'a'; def NULL_TERMINATOR: Char = '\0'; // string literals literals def STRING_LITERAL: [Char:28;'\0'] = "Hello, I am a string literal"; def MULTI_LINE_STRING_LITERAL: [Char:38;'\0'] = "Hello, I am a multi-line\n string literal";