ProtoLang.net

Reference: Literal

☰ Hide Sidebar
TOKEN None
ALIAS None

A Literal is a fixed value written directly into the code. Literals represent actual data rather than references to data stored elsewhere. Every literal has a specific Data Type that determines what kind of value it represents.

Types of Literals

Boolean Literals

Boolean literals represent logical values and can only be True or False.

NEW BOOL x = TRUE
NEW BOOL y = FALSE
PRINTLN x // Displays "TRUE"
PRINTLN y // Displays "FALSE"

Integer Literals

Integer literals represent whole numbers without decimal points. Valid range is -2147483648 to 2147483647 (inclusive).

NEW INT x = 42
NEW INT y = -15
NEW INT z = 0
PRINTLN x // Displays "42"
PRINTLN y // Displays "-15"
PRINTLN z // Displays "0"

Float Literals

Float literals represent numbers with decimal points. They must always include a decimal point, even for whole numbers. Valid range is -1.175494e-38 to 3.402823e+38 (inclusive).

NEW FLOAT x = 3.14
NEW FLOAT y = -2.5
NEW FLOAT z = 1.0
PRINTLN x // Displays "3.14"
PRINTLN y // Displays "-2.5"
PRINTLN z // Displays "1.0"

String Literals

String literals represent text and must be enclosed in double quotes ("). They can contain any Printable ASCII Characters.

NEW STR x = "Hello World!"
NEW STR y = "123"
NEW STR z = ""
PRINTLN x // Displays "Hello World!"
PRINTLN y // Displays "123"
PRINTLN z // Displays ""

Using Literals

Example: Literals in Variable Creation

NEW STR name = "Alice"
NEW INT age = 25
NEW FLOAT height = 5.6
NEW BOOL isStudent = TRUE

Example: Literals in Expressions

NEW INT sum = 10 + 5 // Using Integer Literals
NEW STR greeting = "Hello" .. " " .. "World" // Using String Literals
NEW BOOL check = 5 > 3 // Expression evaluates to Boolean Literal TRUE

Example: Literals in Print Statements

PRINTLN "Direct text output" // String Literal
PRINTLN 42 // Integer Literal
PRINTLN 3.14 // Float Literal
PRINTLN TRUE // Boolean Literal

Important Notes

  • Each literal must match the data type of the variable it's assigned to.
  • Integer literals cannot have decimal points, and Float literals must have decimal points.
  • String literals must always be enclosed in double quotes.
  • Boolean literals are case-sensitive and must be True written or False.

Common Errors

Error: Assigning Integer Literal to Float Variable

NEW FLOAT x = 5 // Runtime error! 5 is an Integer Literal, not a Float Literal
NEW FLOAT y = 5.0 // Correct! 5.0 is a Float Literal

Error: Assigning Float Literal to Integer Variable

NEW INT x = 5.0 // Runtime error! 5.0 is a Float Literal, not an Integer Literal
NEW INT y = 5 // Correct! 5 is an Integer Literal

Error: String Literal without Quotes

NEW STR x = Hello // Syntax error! String Literals must be enclosed in quotes
NEW STR y = "Hello" // Correct! String Literal is enclosed in quotes