Structure of mathematical and conditional expressionsAdded by IBM on August 8, 2013 | Version 1 (Original)
|An XFDL compute can be either a mathematical or conditional expression.
A conditional expression has three parts separated by the ternary ?: operator. The first part is a Decision, which yields a Boolean result. The consequences for a true and false boolean result recurse to the definition of Compute, permitting arbitrary nesting of decision logic.
Table 1. Compute table
The decision logic can apply logical-or (|| or 'or'), logical-and (&& or 'and'), and logical negation (!) to the results of logical comparisons. The logical operators remain associative, and the comparison operators cannot be chained (e.g. a < b < c is illegal). The order of operations gives greatest precedence to negation, then logical-and, and least precedence to logical-or. To override this, parentheses can be used (e.g., the parentheses in (a<b || c<d) && e!=f cause the logical-or to occur first, and no parentheses are required if the logical-and should be performed first).
Table 2. Decision table
Compute ::= Expr | Decision '?' Compute ':' Compute
A mathematical expression, denoted Expr, can include addition, subtraction, string concatenation (+.), multiplication, division, integer modulus, unary minus, and exponentiation. All mathematical operators remain associative except unary minus and exponentiation. Further, proper order of operations is observed. Parentheses can be used to override the order of operations as shown in the non-terminal symbol named Value (defined later).
Table 3. Expr expressions
Decision ::= Decision ('||' | 'or') AndDecision | AndDecision
AndDecision ::= AndDecision ('&&' | 'and') NotDecision | NotDecision
NotDecision ::= '!' Comparison | Comparison
Comparison ::= '(' Decision ')' | Expr ('<' | '>' | '<=' | '>=' | '==' |
Expr ::= Expr '+' Term | Expr '-' Term | Expr '+.' Term | Term
Term ::= Term '*' NFactor | Term '/' NFactor | Term '%' NFactor | NFactor
Nfactor ::= Factor | '-' Factor
Factor ::= Value '^' NFactor | Value