Expr is a language runtime embedded in the host application.
The core language defines parsing, expressions, values, variables, functions, classes, objects, control flow, errors, and evaluation behavior. The host decides where Expr is used, which session is attached, which output stream receives text, which built-in objects are available, and which compatibility options are enabled for a specific context.
Most user scripts should use normal Expr syntax. Host integration features are for specific application contexts such as G-code expression evaluation, custom dialogs, probing scripts, ATC scripts, file import helpers, and interactive MDI use.
Expr is responsible for language semantics:
The host application is responsible for application policy:
Expr should not be treated as a standalone sandbox. If a host exposes side-effect operations, scripts can use those operations.
Expr can be used in several different host contexts.
| Context | Typical behavior |
|---|---|
| Interactive or MDI evaluation | The host can use a named session so variables, functions, and classes persist between commands. |
| G-code expression evaluation | The host can enable G-code compatibility options and connect Expr variables to G-code parameters. |
| Custom dialogs and forms | Scripts can construct GUI objects and react to callbacks. |
| ATC, probing, and automation scripts | Scripts can use Expr as an alternative to longer G-code script sequences. |
| File import, export, and processing helpers | Scripts can use file format objects, dialogs, arrays, maps, and data buffers. |
| Background or asynchronous work | Host objects such as timers, serial monitors, or Python tasks can invoke callbacks later. |
The available objects and the persistence of variables depend on the context selected by the host.
Compatibility options are selected by the host for a specific evaluation context. They are not recommended for normal Expr source files unless that context requires them.
Wrapper markers are host or G-code embedding syntax, not core Expr syntax.
A host context may allow Expr text to be embedded inside wrapper markers such as {! ... !}. The host extracts or marks the Expr portion before evaluation.
Do not use wrapper markers in ordinary Expr include files or standalone Expr scripts.
Hash variables are a G-code compatibility option.
When Expr is called from G-code expression evaluation, the host can enable hash-variable syntax so Expr variables and G-code parameters refer to the same values in that context.
Examples of compatibility forms include:
#1 #name #<name>
Use normal Expr identifiers in normal scripts:
speed = 1200; depth = -1.5;
See Lexical basics.
The host can enable named operator compatibility for older or embedded contexts.
Examples include `AND`, `OR`, `XOR`, `NOT`, `DIV`, `MOD`, `EQ`, `NE`, `GE`, `LE`, `GT`, and `LT`.
Normal Expr scripts should use the standard symbolic operators described in Operators.
//= is a host-editable comment form when modifiable-comment compatibility is enabled.
It is not ordinary comment syntax for normal Expr scripts. Use // and /* ... */ for normal comments.
See Lexical basics.
Included files are parsed with default Expr parsing options.
They do not inherit caller compatibility options such as G-code hash variables, named operators, wrapper markers, or modifiable comments.
This keeps shared include files predictable and portable between host contexts.
See Include system.
Each evaluation runs in an Expr session. The host chooses the session name, or it can evaluate without relying on persistent session state.
A host can:
Root variables, user-defined functions, and user-defined classes persist only when the same named session is reused.
// first evaluation in a persistent host session part_count = 1; // later evaluation in the same host session part_count += 1; print(part_count);
The global `session` object exposes session inspection and management for contexts where the host allows it.
See Execution model and sessions and session.
Functions such as `print()` and `printf()` write to the output sink selected by the host.
Depending on context, output may appear in a console, message/log panel, debug output, script result view, or another host-defined destination.
`enable_print(false)` can suppress print output for the current evaluation context when available:
enable_print(false); print('hidden'); enable_print(true); print('visible');
See Output, Formatting, Clipboard, and Errors.
Path handling is host-defined.
The `path()` function returns the profile path. `path(relativePath)` resolves profile-relative paths that start with `.` and source-relative paths that do not.
profile = path(); script = path('./scripts/probe.expr');
Other objects that load or save files also depend on host path policy and platform behavior. Examples include file dialogs, image data, image streams, byte buffers, Python files, and crypto file operations.
Use `path(…)` or host file dialogs when scripts should be portable between machines.
See Platform and Paths, Include system, and Dialogs.
Some built-in functions and objects are pure language helpers. Others are bridges to host services.
Important host-facing groups include:
| Area | Reference | Examples |
|---|---|---|
| Output, clipboard, dialogs, platform, paths | Output, Formatting, Clipboard, and Errors, Dialog Functions, Platform and Paths | `print()`, `printf()`, `enable_print()`, `to_clipboard()`, `from_clipboard()`, `msgdlg_ok()`, `platform()`, `path()` |
| Global objects | Global objects | `settings`, `controller`, `session`, `python` |
| Dialog objects | Dialogs | `file_open()`, `file_save()`, `msg_ok()`, `msg_ok_cancel()`, `msg_yes_no()`, `msg_password()` |
| GUI objects | GUI objects | `window()`, `panel()`, `textinput()`, `numinput()`, `image()`, `splitpanel()` |
| File format I/O | File Format I/O | `image_data()`, `image_stream()` |
| Collections and buffers | Collections | `array()`, `map()`, `bytes()` |
| Utilities | Utils | `crypto()`, `timer(callback)` |
| Communication | Comm | `serial()` |
A host build or context can expose additional application-specific globals. Scripts that depend on such globals are host-specific.
When Expr is used from G-code, the host can evaluate Expr expressions as part of G-code parsing or script execution.
In this mode, the host may:
This does not change normal Expr file syntax. Shared Expr include files should use strict Expr syntax and normal variable names.
Some host objects store callable Expr references and invoke them later.
Examples include:
A callback runs in a new evaluation context connected to the relevant session selected by the object or host.
If callback state must survive after the original evaluation ends, keep it in the object instance or in a named session.
class Counter() { Count = 0; function OnTimer(n) { Count += 1; print('timer call ', Count); } } counter = Counter(); t = timer(counter.OnTimer); t.start(1000, 3);
Callback errors are reported through the object or host error path. A host object may stop the operation after a callback error.
See Execution model and sessions, timer, and serial.
Expr is not a security sandbox.
A script can only do what the host exposes, but exposed objects may allow side effects such as:
Host-side recommendations:
For scripts intended to be reused in different contexts:
Previous: Execution model and sessions
Next: Limits and performance