Resolution of Logical Expressions in Variables
When processing eScripts, DSM is able to resolve logical expressions within variables. For example, the variable %[=3 + 5]% is resolved to 8.
Nesting variables with brackets is useful and practical, for example %[=3 * %x% + 5]%.
The basic syntax for processing logical expressions is the following: %[=<logical expression>]%
The logical expression is in square brackets and introduced by the equals sign. Logical expressions may also contain variables.
They may also include a large number of different operators.
The following table lists all of the operators with an example.
Operators in Logical Expressions
Priority | Associativity | Operator | Description | Example | Result |
---|---|---|---|---|---|
1 | unary | ( ) | Brackets | 2 * (3 + 2) | 10 |
1 | unary | | | | Amount (value without sign) | | - 5 | | 5 |
1 | unary | sqrt | Square root | sqrt 16 | 4 |
1 | unary | round | Rounded to the next number The number following ...,5 is rounded |
round 2.6 | 3 |
1 | unary | floor | Round off | floor 1.9 | 1 |
1 | unary | ceil | Round up | ceil 1.1 | 2 |
1 | unary | trunc | Truncate and/or round off to zero | trunc 1.7 | 1 |
1 | unary | frac | Fraction | frac 1.3 | 0.3 |
1 | unary | sgn | Sign | sgn -7 | -1 |
1 | unary | ln | Natural logarithm | ln 1 | 0 |
1 | unary | log | Common logarithm | log 100 | 2 |
1 | unary | exp | Exponential function | exp 1 | 2.718… |
1 | unary | pi | Pi constant | pi | 3.141… |
1 | unary | sin | Sine | sin 30 | 0.5 |
1 | unary | cos | Cosine | cos 0 | 1 |
1 | unary | tan | Tangent | tan 45 | 1 |
2 | right | ^ | Potency | 2 ^ 3 | 8 |
3 | left | * | Multiplication | 2 * 2 | 4 |
3 | left | / | Division | 9 / 3 | 3 |
3 | left | div | Integer division | 7 div 3 | 2 |
3 | left | mod | Remainder | 7 mod 3 | 1 |
4 | left | + | Addition | 3 + 5 | 8 |
4 | left | - | Subtraction | 9 - 2 | 7 |
5 | left | choose | Binomial coefficient Specifies the number of different methods you can use to select k objects from a quantity of n different objects |
49 choose 6 | 13983816 |
6 | left | max | Maximum Returns the larger of two values. |
1 max 10 | 10 |
6 | left | min | Minimum Returns the smaller of two values |
10 min 100 | 10 |
7 | left | & | Combining strings | 10 & 7 | 107 |
8 | no | > | Compare 'greater' than | 3 > 3 | 0 |
8 | no | < | Compare 'smaller' than | 4 < 5 | 1 |
8 | no | >= | Compare 'greater' than or 'equal' | 3 >= 0 | 1 |
8 | no | <= | Compare 'smaller' than or 'equal' | 4 <= 4 | 1 |
8 | no | <> | Compare 'unequal' | 2 <> 5 | 1 |
8 | no | != | Compare 'unequal' | 6 != 6 | 0 |
8 | no | == | Compare 'equal' | 2 == 2 | 1 |
9 | unary | not |
Logical NOT |
not 1 | 0 |
10 | left | and | Logical AND Equals 1 if both operands are unequal 0. |
1 and 0 | 0 |
11 | left | xor | Logical, exclusive OR Equals 1 if one operand is 0 and the other unequal 0. |
1 xor 0 | 1 |
12 | left | or |
Logical OR |
1 or 1 | 1 |
13 | right | ?: |
Selection |
5 > 2 ? 8 : 16 | 8 |
Precedence and associativity are important if there are several operators used in one expression.
Precedence specifies the order in which operators are evaluated if there are no brackets. For example, multiplication has the priority 3, addition has the priority 4. Therefore 5+6*2 = 5+(6*2)=17 and not 5+6)*2=22.
Associativity, however, specifies the order in which operators of the same precedence are processed (left to right or right to left).
Left-associative: 7-2-1 = (7-2)-1=4 and not 7-(2-1)=4
Right-associative: 2^2^3 = 2^(2^3)=256 and not(2^2)^3=64
Comparisons do not have associativity since -1<=2<5<=5 equals1<=2 and 2<5 and 5<=5