Teeny Language Reference
This reference describes the subset of Teeny that your compiler UI currently supports.
Literals: numbers, strings, arrays
Teeny supports numeric literals, string literals and array literals.
let n = 3.14 let msg = "hello" let xs = [1, 2, 3] print msg
Numbers
Integers and decimals
- 10
- 42
- 3.14
Strings
Double or single quoted strings
- "hello"
- 'world'
Arrays
Array literals using [ ... ]
- [1, 2, 3]
- ["hello", "world"]
Variables and assignment
Use `let` to declare variables. You can also reassign existing variables and array elements.
let x = 10 let y = 20 x = x + 1 let sum = x + y print sum
Expressions
Expressions can include arithmetic operators (+, -, *, /) and comparisons (<, >).
let a = 1 + 2 let b = 3 * 4 let bigger = b > 10 print bigger
Indexing and member access
Index into arrays using `arr[0]` syntax.
let xs = [1, 2, 3] xs[0] = 10 print xs[0]
Control flow: if, while, for
Control flow uses parentheses after the keyword and a single statement as the body.
if (condition) statement [else statement]
Single-statement form (no block parsing yet)
- if(x > 5) return 5;
- if(x = 5) return 5;
while (condition) statement
Single-statement form
- while (true) return 5;
- while (x > 5) return 5;
for (init; test; update) statement
Block parsing with { ... } is not supported yet
- for(let i = 0; i < 10; i++) return 5
- for(; i < 10; i++) return 5
- Try switching x around in the conditions and watch how the AST changes.
- For loops: keep the body as a single statement (e.g. `return ...`).