TOC PREV NEXT

Moritz Geometry Editor


Variable Syntax


The variable name can consist of up to 64 letters, digits, and underscores (‘_’). The name is case sensitive. A variable definition must contain one and only one equal sign (‘=’) that must follow the first variable name. A number or expression must follow the equal sign. The definition must start with a percent sign (‘%’) in the first column.

A variable expression consists of numbers, variable names (starting with %), and the arithmetic operators +, , *, and /. There can be no more than 64 elements (numbers, names and operators) in the expression. There must be one and only one arithmetic operator between numbers or names. The first element can be
+, , or a name or number; it cannot be * or /. The last element cannot be an operator.

Referenced variables must have been already defined and must precede the variable in which it is referenced in the order the variables are stored in memory (that order can be viewed by selecting Program Order in the variable window). Circular references are not allowed.

An expression must start with a variable name, optionally preceded by a sign. The first element cannot be a number.
2.54 - %Width
is an invalid expression.

Definitions and expressions must be on a single line. In a surface or body definition, separate expressions representing different coefficients can be on different lines.

Scientific notation is supported for numbers with some restrictions. The number must contain ‘e’, ‘E’, ‘d’, or ‘D’ preceded by a digit or decimal point (‘.’). The letter must be followed by a sign (‘
+’ or ‘’) that in turn must be followed by a digit. Some examples of invalid scientific notation are 2+4, 1e9, D7, and E+2.

Expressions can be used when in defining a value in a body or a surface description if
the expression does not contain spaces. Spaces are used to separate one coefficient from the other. For example,
1 SPH 0 0 0 %a-%b
will have a radius (5th argument) given by %a-%b but
1 SPH 0 0 0 %a - %b
will generate an error stating the body definition uses too many coefficients. Spaces are permitted in variable definitions.

The arithmetic is performed in the order the operators are encountered from left to right. There is no operator precedence.
%P5 = %P4 - %P3 + %P2
sets the value of %P5 to the value of %P4 minus the value of %P3 plus the value of %P2.
%EM = %AR * %D1 + %GR
causes the value of %EM to be set to
%AR x %D1 + %GR.
In this example, the result of the arithmetic is as expected. The definition
%X = %A + %B * %C
is interpreted as
%X = %C x (%A + %B),
not as
%X = %A + (%B x %C).
The latter formula is achieved by
%X = %B*%C+%A
When a variable is referenced in an expression, its value is used as if it were a simple number rather having its definition expanded; one need not worry about precedance rules for the operators in the referenced definition.


White Rock Science
http://www.whiterockscience.com/wrs.html
505 672 1105
email
 
TOC PREV NEXT