/MACRO_SYNTAX_Expressions

Explanation of KUIP expression syntax.

KUIP has a built-in parser for different kinds of expressions: arithmetic expressions, boolean expressions, string expressions, and "garbage expressions".

/MACRO/SYNTAX/Expressions/Arithmetic

Explanation of arithmetic expression syntax.

The syntactic elements for building arithmetic expressions are:

expr ::= number | vector-name (for scalar vectors) | vector-name(expr) | vector-name(expr,expr) | vector-name(expr,expr,expr) | [variable-name] (if value is numeric or the name of a scalar vector) | [variable-name](expr...) (if value is a vector name) | alias-name (if value is numeric constant) | $system-function(...) | - expr | expr + expr | expr - expr | expr * expr | expr / expr | (expr) | ABS(expr) | INT(expr) | MOD(expr,expr)

They can be used in the macro statements DO, FOR, and EXITM, in macro variable assignments, as system function arguments where a numeric value is expected, or as the argument to the $EVAL function.

Note that all arithmetic operations are done in floating point, i.e., "5/2" becomes "2.5". If a floating point result appears in a place where an integer is expected, for example as an index, the value is truncated.

/MACRO/SYNTAX/Expressions/Boolean

Explanation of Boolean expression syntax.

Boolean expressions can only be used in the macro statements IF, WHILE, and REPEAT. The possible syntactic elements are shown below.

bool ::= expr rel-op expr | string eq-op string | expr eq-op string | .NOT. bool | bool .AND. bool | bool .OR. bool | ( bool ) rel-op ::= .LT. | .LE. | .GT. | .GE. | < | <= | > | >= | eq-op eq-op ::= .EQ. | .NE. | = | <>

/MACRO/SYNTAX/Expressions/String

Explanation of string expression syntax.

String expressions can be used in the macro statements CASE, FOR, and EXITM, in macro variable assignments, as system function arguments where a string value is expected, or as the argument to the $EVAL function. They may be constructed from the syntactic elements shown below.

string ::= quoted-string | unquoted-string | string // string (concatenation) | expr // string (expr represented as string) | [variable-name] | alias-name | $system-function(...)

/MACRO/SYNTAX/Expressions/Garbage

Explanation of "garbage" expression syntax.

Expressions which do not satisfy any of the other syntax rules we want to call "garbage" expressions. For example,

s = $OS$MACHINE

is not a proper string expression. Unless they appear in a macro statement where specifically only an arithmetic or a boolean expression is allowed, KUIP does not complain about these syntax errors. Instead the following transformations are applied:

o alias substitution o macro variable replacement; values containing a blank character are implicitly quoted o system function calls are replaced one by one with their value provided that the argument is a syntactically correct expression o string concatenation