Structure of mathematical and conditional expressionsAdded by IBM on October 10, 2012 | Version 1 (Original)
|An XFDL compute can be either a mathematical or conditional expression. Tags: computes, conditional expressions, mathematical expressions, decisions, logic, ? :
operator, ternary operator, || operator, &&
operator, ! operator, order of precedence, operations: order of operations, XFDL, 8.0, spec
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.
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 are left 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).
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 are left 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).
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