This page is a compact lookup for Expr syntax.
It is not a tutorial. For explanations and examples, use the linked reference chapters.
Expr source is a sequence of statements.
Normal expression statements require a semicolon. Block-style statements and declarations can omit the trailing semicolon, but a semicolon is accepted after them.
a = 1; if(a > 0) { print('positive'); }; function Add(a, b) { return a + b; }
Recommended style is one statement per line, semicolons after ordinary expressions, and braces for blocks.
See Lexical basics.
| Item | Form | Notes |
|---|---|---|
| Identifier | `[A-Za-z_][A-Za-z0-9_]*` | Case-sensitive. Use ASCII identifiers. |
| Number literal | decimal number | Stored as a 64-bit floating-point number. |
| String literal | single-quoted, double-quoted, backtick, or triple double-quoted | Triple double-quoted strings are raw multiline strings. |
| Line comment | // comment | Continues to the end of the line. |
| Block comment | not supported | Use line comments. |
| Statement terminator | `;` | Required after normal expression statements. |
G-code hash variables, wrapper markers, named operators, and modifiable comments are host compatibility features. They are not normal strict Expr syntax.
See Host integration.
Core keywords:
if else loop while for return break continue include as set function class true false
Reserved contextual names:
this
Do not use keywords as ordinary variable, function, class, parameter, method, or property names.
Built-in function names are not hard-reserved. A user-defined function can shadow a built-in function in the active session. Avoid this unless it is deliberate and clearly documented.
Built-in global object names such as `settings`, `controller`, `session`, and `python` are protected global names and cannot be overwritten.
See Variables and assignment and Built-in objects.
This grammar is intentionally compact. It describes normal strict Expr source. Host compatibility syntax is not included.
program = { top_statement } ;
top_statement = include_statement [ ";" ]
| function_declaration [ ";" ]
| class_declaration [ ";" ]
| statement ;
statement = block [ ";" ]
| if_expression [ ";" ]
| loop_expression [ ";" ]
| while_expression [ ";" ]
| for_expression [ ";" ]
| return_statement ";"
| break_statement ";"
| continue_statement ";"
| expression ";" ;
block = "{" { statement } "}" ;
include_statement = "include" string_literal [ "as" identifier ] ;
function_declaration= "function" qualified_identifier "(" [ parameter_list ] ")" block ;
class_declaration = "class" qualified_identifier "(" [ parameter_list ] ")" class_block ;
class_block = "{" { field_statement | method_declaration } "}" ;
field_statement = expression ";" ;
method_declaration = "function" identifier "(" [ parameter_list ] ")" block ;
parameter_list = identifier { "," identifier } ;
argument_list = expression { "," expression } ;
qualified_identifier= identifier [ "::" identifier ] ;
if_expression = "if" "(" expression ")" statement_or_block [ "else" statement_or_block ] ;
loop_expression = "loop" "(" expression ")" statement_or_block ;
while_expression = "while" "(" expression ")" statement_or_block ;
for_expression = "for" "(" [ expression ] ";" [ expression ] ";" [ expression ] ")" statement_or_block ;
statement_or_block = block | statement ;
return_statement = "return" [ expression ] ;
break_statement = "break" ;
continue_statement = "continue" ;
expression = assignment ;
assignment = conditional_expression
| assignable assignment_operator assignment ;
conditional_expression
= logical_or [ "?" expression ":" expression ] ;
logical_or = logical_xor { "||" logical_xor } ;
logical_xor = logical_and { "^^" logical_and } ;
logical_and = bitwise_or { "&&" bitwise_or } ;
bitwise_or = bitwise_xor { "|" bitwise_xor } ;
bitwise_xor = bitwise_and { "^" bitwise_and } ;
bitwise_and = equality { "&" equality } ;
equality = relational { ( "==" | "!=" ) relational } ;
relational = shift { ( ">" | ">=" | "<" | "<=" ) shift } ;
shift = additive { ( "<<" | ">>" ) additive } ;
additive = multiplicative { ( "+" | "-" ) multiplicative } ;
multiplicative = power { ( "*" | "/" | "%" ) power } ;
power = unary { "**" unary } ;
unary = [ "+" | "-" | "!" | "~" | "++" | "--" ] postfix ;
postfix = primary { "++" | "--" | member_access } ;
member_access = "." identifier [ "(" [ argument_list ] ")" ] ;
primary = literal
| identifier
| qualified_identifier "(" [ argument_list ] ")"
| "this"
| "(" expression ")"
| block
| if_expression
| loop_expression
| while_expression
| for_expression ;
assignable = identifier
| "set" identifier
| primary "." identifier ;
assignment_operator = "=" | "+=" | "-=" | "*=" | "/=" | "%=" | "**="
| "&=" | "|=" | "^=" | "<<=" | ">>=" ;
literal = number_literal | string_literal | "true" | "false" ;
Notes:
| Construct | Form | Notes |
|---|---|---|
| Include | `include 'file.expr'` | Top-level only. Semicolon optional. |
| Namespaced include | `include 'file.expr' as Name` | Imported functions and classes use the alias namespace. |
| Function | `function Name(a, b) { … }` | Top-level function stored in the active session. |
| Namespaced function | `function Ns::Name(a, b) { … }` | Defines a function with a namespace qualifier. |
| Class | `class Name(a, b) { … }` | Top-level class constructor stored in the active session. |
| Namespaced class | `class Ns::Name(a, b) { … }` | Defines a class with a namespace qualifier. |
See Include system, Functions, and Classes and user-defined objects.
Higher rows bind before lower rows.
| Level | Operators | Associativity | Notes |
|---|---|---|---|
| 1 highest | parentheses (...), call f(...), method call obj.m(...), property access obj.x | left-to-right | grouping, call, and member access |
| 2 | postfix x++, x-- | left-to-right | modifiable numeric variable required |
| 3 | prefix ++x, --x | right-to-left | modifiable numeric variable required |
| 4 | unary +x, -x, !x, ~x, NOT x | right-to-left | named NOT requires named-operator compatibility |
| 5 | power ** | right-to-left | numeric operands |
| 6 | multiply, divide, modulo *, /, %, DIV, MOD | left-to-right | named forms require named-operator compatibility |
| 7 | add, subtract +, - | left-to-right | + concatenates if a string is involved |
| 8 | shift <<, >> | left-to-right | finite numeric operands, shift count 0 to 63 |
| 9 | relational <, <=, >, >=, LT, LE, GT, GE | left-to-right | relational operators require numeric operands |
| 10 | equality ==, !=, EQ, NE | left-to-right | no cross-type equality coercion |
| 11 | bitwise AND & | left-to-right | finite numeric operands |
| 12 | bitwise XOR ^ | left-to-right | finite numeric operands |
| 13 | bitwise OR | | left-to-right | finite numeric operands |
| 14 | logical AND &&, AND | left-to-right | short-circuits; named form requires compatibility |
| 15 | logical XOR ^^, XOR | left-to-right | evaluates both sides; named form requires compatibility |
| 16 | logical OR ||, OR | left-to-right | short-circuits; named form requires compatibility |
| 17 | conditional ?: | right-to-left | evaluates only the selected result expression |
| 18 lowest | assignment =, +=, -=, *=, /=, %=, **=, &=, |=, ^=, <<=, >>= | right-to-left | target must be assignable |
Named operators are accepted only when the host enables named-operator compatibility mode. Prefer symbolic operators in normal Expr scripts.
Logical compound assignment forms are not part of Expr syntax:
a &&= b; // not supported a ||= b; // not supported a ^^= b; // not supported
See Operators and Expression rules.
Expr runtime values are grouped into these core categories:
| Category | Examples | Notes |
|---|---|---|
| None | `none()` | Missing or intentionally cleared value. |
| Number | `1`, `3.14`, `nan()` | 64-bit floating-point number. |
| String | `'abc'`, `“abc”`, `abc`, """abc""" | Text value. |
| Object | arrays, maps, built-in objects, user objects, callable references | Object-specific methods and properties depend on the object. |
`true` and `false` are boolean-style numeric values, not a separate boolean type.
See Type system and Objects.
| Form | Meaning | Where allowed |
|---|---|---|
| `name = value;` | Assigns a root/session variable unless a local or object field with that name is active. | Top level, blocks, functions, methods, constructors. |
| `set name = value;` | Creates or updates a local variable in the current local scope. | Blocks, functions, methods, constructors. Not top level. |
| `this.name = value;` | Not supported. Use bare field assignment inside a class constructor or method. | Class constructor or method context. |
| `object.name = value;` | Not supported. Object properties are read-only from outside the object. Use methods to change object state. | Object/property access. |
| `function Name(…) { … }` | Defines a user function in the active session. | Top level, or inside class body for methods. |
| `class Name(…) { … }` | Defines a user class in the active session. | Top level only. |
See Scope and set and Variables and assignment.
| Feature | Example | Enabled by | Notes |
|---|---|---|---|
| Named operators | `AND`, `OR`, `DIV`, `EQ` | Host named-operator option | Compatibility syntax. |
| Hash variables | `#1`, `#name`, `#<name>` | Host G-code hash-variable option | Used when Expr evaluates G-code expressions. |
| Wrapper markers | {! ... !} | Host or G-code wrapper handling | Not core Expr syntax. |
| Modifiable comments | //= | Host modifiable-comment option | Host-editable comment form. |
Included files do not inherit these compatibility options.
See Host integration and Lexical basics.
Previous: Limits and performance
Next: Glossary