Syntax & Variables
Data Types
Section titled “Data Types”Tulpar supports the following data types:
| Type | Description | Example |
|---|---|---|
int | Integer numbers | int x = 42; |
float | Floating-point numbers | float pi = 3.14; |
str | UTF-8 strings | str name = "Hamza"; |
bool | Boolean values | bool flag = true; |
array | Mixed-type arrays | array mix = [1, "text", 3.14]; |
arrayInt | Type-safe integer arrays | arrayInt nums = [1, 2, 3]; |
arrayFloat | Type-safe float arrays | arrayFloat vals = [1.5, 2.5]; |
arrayStr | Type-safe string arrays | arrayStr names = ["Ada", "Linus"]; |
arrayBool | Type-safe boolean arrays | arrayBool flags = [true, false]; |
arrayJson | JSON-like objects | arrayJson obj = {"key": "value"}; |
Variables and Constants
Section titled “Variables and Constants”Variables are declared with their type:
Number Literals
Section titled “Number Literals”Integers can be written in four bases. Underscores are not allowed — keep large numbers readable with comments instead.
| Form | Example | Decimal value |
|---|---|---|
| Decimal | 255 | 255 |
| Hexadecimal | 0xFF | 255 |
| Octal | 0o755 | 493 |
| Binary | 0b1010 | 10 |
Floating-point numbers accept the standard C-style forms:
float pi = 3.14;float small = 1.0e-5;float large = 6.02e23;Integers above i64 range trigger a compile-time warning and are
clamped to INT64_MAX (2^63 − 1).
Strings & interpolation
Section titled “Strings & interpolation”Strings are UTF-8 and concatenate with +. When either side of + is a
string, the other operand is coerced to its text form automatically —
"count: " + 5 is "count: 5", no toString() needed.
For readable interpolation, use a t-string — prefix a string literal
with t and embed expressions in { }:
str name = "Hamza";int age = 24;
// t-string: expressions in { } are evaluated and stitched in.print(t"{name} is {age} years old");
// Any expression works inside the braces.int a = 3; int b = 4;print(t"sum = {a + b}, bigger = {a > b}");
// Index access (inner quotes are fine):json user = {"name": "Ada", "role": "admin"};print(t"user {user["name"]} ({user["role"]})");
// A literal brace is written \{ ... \}print(t"\{not interpolated\} but {age} is");A t-string always produces a str, even when it is only an
interpolation (t"{n}"). Write a literal brace as \{ / \}. The plain
+ concatenation is still available when you prefer it.
Operator Precedence
Section titled “Operator Precedence”Operators are listed from lowest to highest precedence. Operators on the same row have equal precedence and associate left-to-right unless noted.
| Tier | Operators | Associativity |
|---|---|---|
| 1 (lowest) | = += -= *= /= | right |
| 2 | || | left |
| 3 | && | left |
| 4 | == != | left |
| 5 | < > <= >= | left |
| 6 | + - (binary) | left |
| 7 | * / % | left |
| 8 | - (unary), ! | right |
| 9 (highest) | ++ -- (postfix), () call, [] index, . member | left |
Use parentheses when in doubt — they read better than relying on precedence rules across more than one tier:
// Both compile, but the parenthesised form is clearer.int score = a + b * c; // = a + (b * c)int score = a + (b * c);Comments
Section titled “Comments”Tulpar supports single-line and multi-line comments: