Here are some current or proposed infix operations with three operands.
- In C bool?exp1:exp2 means what “(bool|exp1|exp2)” or
“if bool then exp1 else exp2 fi” mean in Algol 68.
- In some language “a<b<c” means the same as “a<b and b<c”.
- For floating point operands “a+b*c” and “b*c+a” should specify the fused multiply add with superior semantics that is available on many machines.
- In JavaScript and ActionScript a.b(c) means something different from (a.b)(c).
All of these parsings can be specified with a slightly modified BNF.
I illustrate with the proposal for the fused operation.
If <fact> is the syntactic category of expressions with with operators of precedence greater than multiply then we have productions:
- <term> := <fact> | <term> * <fact> | <term> / <fact> | (<poly>)
- <add> := + | −
- <poly> := <term> | <poly> <add> <fact> | <poly> <add> <term> * <fact> | <term> * <fact> <add> <poly>
Where precedence terminology is used to define expression semantics, one can simply say that whenever multiplication operators take precedence over addition operators, the fused multiply add is to be used.