Keywords & grammar
Reserved words
These identifiers are reserved by the lexer and can't be used as variable, function, struct or parameter names:
| Keyword | Used for |
|---|---|
let | Mutable variable declaration |
const | Immutable variable declaration |
if / elseif / else | Conditional branches (note: elseif, one word) |
while | Loop while a condition holds |
foreach | Loop over an array, map or string |
break / continue | Loop control (only valid inside a loop body) |
return | Return from a function |
func | Introduces a function declaration, paired with define |
define | Introduces a function's parameter list and body |
struct | Struct declaration |
null | The null literal |
true / false | Boolean literals |
output, request, typeof, assert and require are not keywords -they're ordinary identifiers that happen to be pre-bound to built-in functions in every scope. See the built-ins reference.
Comments
Only single-line // comments exist -there's no /* block */ form.
Literal forms
| Form | Example |
|---|---|
| Number | 42, 3.14 -base-10 only, no hex/octal/binary/underscored digits |
| String | "text" -double quotes only, see escape sequences |
| Boolean | true, false |
| Null | null |
| Array | [1, 2, 3] |
| Map | { key: value } -literal keys must be bare identifiers |
| Tuple | (1, 2), one-element (1,), empty (,,) |
| Function | define(a, b) { ... } |
Grammar summary
An informal summary, not a formal EBNF grammar -see the parser source for the exact rules.
program ::= statement*
statement ::= letDecl | constDecl | funcDecl | structDecl
| ifStmt | whileStmt | foreachStmt
| breakStmt | continueStmt | returnStmt
| exprStmt | block
letDecl ::= "let" (IDENTIFIER | destructurePattern) "=" expression ";"
constDecl ::= "const" (IDENTIFIER | destructurePattern) "=" expression ";"
funcDecl ::= "func" IDENTIFIER "=" "define" "(" params? ")" block
structDecl ::= "struct" IDENTIFIER "{" (field | funcDecl)* "}"
field ::= IDENTIFIER ("=" expression)? ";"
params ::= param ("," param)*
param ::= IDENTIFIER ("=" expression)?
ifStmt ::= "if" "(" expression ")" block
("elseif" "(" expression ")" block)*
("else" block)?
whileStmt ::= "while" "(" expression ")" block
foreachStmt ::= "foreach" "(" IDENTIFIER ":" expression ")" block
returnStmt ::= "return" expression? ";"
block ::= "{" statement* "}"
destructurePattern ::= "(" IDENTIFIER "," (IDENTIFIER ",")* ")"
| "(" IDENTIFIER ",)" // single-element form
expression ::= assignment
assignment ::= (call ".")? IDENTIFIER ("=" | "+=" | "-=" | "*=" | "/=" | "%=") assignment
| IDENTIFIER ("++" | "--")
| logicalOr
logicalOr ::= logicalAnd ("||" logicalAnd)*
logicalAnd ::= equality ("&&" equality)*
equality ::= comparison (("==" | "!=") comparison)*
comparison ::= term (("<" | "<=" | ">" | ">=") term)*
term ::= factor (("+" | "-") factor)*
factor ::= unary (("*" | "/" | "%") unary)*
unary ::= ("!" | "-") unary | call
call ::= primary ("(" args? ")" | "." IDENTIFIER | "[" expression "]")*
primary ::= NUMBER | STRING | BOOLEAN | "null" | IDENTIFIER
| "define" "(" params? ")" block
| "[" (expression ("," expression)*)? "]"
| "{" (IDENTIFIER ":" expression ("," IDENTIFIER ":" expression)*)? "}"
| "(" tupleOrGroup ")"