@aussiemike &
@unlockedcomposites
I am going to add to this conversation as "the devils advocate" as adding variables could potentially open a catering size can of worms.
If the variable is simply a text substitution then this could be implemented fairly easily. Once you start looking at numerical expressions (add, subtract, multiply, divide, etc) then things get really ugly really quickly. Something such as brackets in an expression would throw a spanner into the gears of the G code processor as the line of text could not be processed left-to-right in a single pass.
As part of my day job I build and maintain training simulators for chemical plant operators. Back in 2000/2001 I wrote a utility which converted PLC code (IEC 61131-3 structured text) into a programming language that could be compiled on a PC. The tool that I used to tackle the problem was
YACC (Yet Another Compiler Compiler) which actually dramatically reduces the complexity of the problem (from "insanely difficult" to "hard").
WARNING - Complex technical information follows
What happens is the line of text is broken into "words" (token) which is passed to the parser engine code generated by YACC. The parser engine takes one token at a time and adds them to a queue, as soon as a rule matches with the last N tokens it will replace the matched tokens with a token that represents the result of that rule. I know that sounds abstract but a worked example might make it a little easier to understand.
Input buffer: "X = 1 + 2 * 3"
Equivalent tokens: "X", "=", "1", "+", "2", "*", "3", EndOfLine
Processing:
Step #1: "X" (No rules match)
Step #2: "X", "=" (No rules match)
Step #3: "X", "=", "1" (Multiple rules match - hold until unique rule is found)
Step #4: "X", "=", "1", "+" (Multiple rules match - hold until unique rule is found)
Step #5: "X", "=", "1", "+", "2" (Multiple rules match - hold until unique rule is found)
Step #6: "X", "=", "1", "+", "2", "*" (Multiple rules match - hold until unique rule is found)
Step #7: "X", "=", "1", "+", "2", "*", "3" (Multiple rules match - hold until unique rule is found)
Step #8: "X", "=", "1", "+", "2", "*", "3", EndOfLine (Multiplication rule fires)
Step #9: "X", "=", "1", "+", "6", EndOfLine (Addition rule fires)
Step #10: "X", "=", "7", EndOfLine (Assignment rule fires)
Step #11: Assignment, EndOfLine (No further rules available)
Looking at my old code the following are the rules used for a numerical assignment, including the relevant operator precedence (one rule per line):
assignment_statement: variable '=' expression
expression: term
| expression '+' term
| expression '-' term
term: power_expression
| term '*' power_expression
| term '/' power_expression
| term MOD power_expression
power_expression: unary_expression
| power_expression '^' unary_expression
unary_expression: primary_expression
| '-' primary_expression
primary_expression: literal_constant
| variable
| '(' expression ')'
If you start adding conditional expressions and flow control then the "Jump To Line" functionality of MASSO is immediately broken.