184.108.40.206.5 Order of Evaluation in Statements
When a script is executed, it is sent to the LabTalk interpreter and evaluated as follows:
The script is broken down into its component statements
Statements are identified by type using the following recognition order: assignment, macro, command, arithmetic, and function. The interpreter first looks for an exposed (not hidden in parentheses or quotation marks) assignment operator. If none is found, it looks to see if the first word is a macro name. It then checks if the first word is a command name. The interpreter then looks for an arithmetic operation, and finally, the interpreter checks whether the statement is a function.
The recognition order can have significant effect on script functions. For example, the following assignment statement:
type = 1;
assigns the value 1 to the variable type. This occurs even though type is (also) a LabTalk command, since assignments come before commands in recognition order. However, since commands precede arithmetic expressions in recognition order, in the following statement:
type + 1;
the command is carried out first, and the string, + 1, prints out.
The statements are executed in the order received, using the following evaluation priority
- Assignment statements: String variables to the left of the assignment operator are not expressed unless enclosed by parentheses. Otherwise, all string variables are expressed, and all special notation ( %() and $()) is substitution processed.
- Command statements: If a command is a raw string, it is not sent to the substitution processor. Otherwise, all special notation is substitution processed.
- Arithmetic statements: All expressions are substitution processed and expressed.