An expression is a piece of Expr code that produces a value.
The simplest expressions are numbers, strings, and calculations:
5; 2 + 3; 'Hello';
The expression `2 + 3` produces the value `5`.
Most Expr statements end with a semicolon `;`.
Expr can be used like a calculator:
2 + 3; 10 - 4; 6 * 7; 20 / 5;
Operators follow normal calculation rules:
2 + 3 * 5; // 17 (2 + 3) * 5; // 25
Parentheses make the order explicit. Use them when the expression should be easy to read, especially in machine logic.
Text values are written as strings.
'Hello'; 'Tool change'; 'Probing started';
Strings are useful for names, messages, labels, and values passed to functions that expect text.
A variable stores a value so it can be reused later.
a = 10; b = 20; result = a + b; result;
This script stores `10` in `a`, stores `20` in `b`, calculates `a + b`, and stores the result in `result`.
The final line evaluates to `30`.
Expr scripts usually contain several statements.
toolDiameter = 6; radius = toolDiameter / 2; radius;
The last expression is often the value you are interested in. In this example, the final value is `3`.
Some Expr scripts are used mainly for their actions, such as setting variables, calling functions, showing dialogs, or running machine workflow logic. In those scripts, the final value may be less important than what the script does.
Comments are notes for the person reading the script. They are ignored when the script runs.
// Calculate tool radius toolDiameter = 6; radius = toolDiameter / 2;
Use comments to explain why something is done, especially in probing, ATC, safety, or machine-specific scripts.
Most statements need a semicolon:
a = 10; b = 20; a + b;
If a script reports an error near the next line, check the previous line for a missing `;`.
This is valid:
2 + 3 * 5;
But this is often clearer:
2 + (3 * 5);
When a calculation controls machine behavior, prefer the clearer version.
Read this script and predict the final value:
width = 40; height = 25; area = width * height; area;
The final value is `1000`.