Issue 14582: OCL 2.1 7.4.7 Inconsistent Operator Associativity and Precedence (ocl2-rtf) Source: Model Driven Solutions (Dr. Edward Willink, ed(at)willink.me.uk) Nature: Uncategorized Issue Severity: Summary: Issue 11098 resolved the missing precedence of let-in as lowest. This requires "2 * let a:Integer=1 in a + 1" to be interpreted as "(2 * (let a:Integer=1 in a)) + 1" making use of a non-trivial let body surprising and needlessly complicated. The problem with the open-ended right hand side can be resolved by assigning let-in the highest atomic expression precedence and defining its resolution as right-associative. The above example then has the obvious meaning "2 * (let a:Integer=1 in (a + 1))". Issue 6544 introduces ^ and ^^ at higher precedence than . and ->. However since these operators can only return left hand arguments for each other, there is no need to assign these to different levels. if-then-else-endif has an intermediate precedence in OCL 2.1. Since this term has keywords at start and end, the term is equivalent to an atomic expression. In so far as precedence is meaningful it is a high precedence. Parentheses should be bulletted at high precedence. Non commutative operators such as / have no defined order of evaluation leaving the value of "8 / 4 / 2" undefined. Binary operators should be specified as left-associative; i.e "(8 / 4) / 2". Section 9.3.2 duplicates 7.4.7. Resolution: Revised Text: In 7.4.7 replace • message-expression operators: "^" and "^^" • dot and arrow operations: “.” and “->” by • call expressions: "^","^^", “.” and “->” In 7.4.7 remove • “if-then-else-endif” and • “let-in” then add • literal and variable expressions, “(“ and “)”, “if-then-else-endif” • “let-in” above • @pre In 7.4.7 replace Parentheses “(“ and “)” can be used to change precedence. by • “in” All infix operators are left associative, equal precedence operators are evaluated left to right. A let expression is both high precedence and low precedence; high on the left so that a let expression behaves as an atomic value in operations, low on the right so that the in-expression can be an arbitrary expression. "a + let ... in a + let ... in a + a" is "a + (let ... in (a + (let ... in (a + a))))". Parentheses “(“ and “)” can be used to change precedence and associativity. Remove Section 9.3.2 Actions taken: October 27, 2009: received issue April 25, 2011: closed issue Discussion: A non-duplicate replacement for 9.3.2 appears as a practical grammar provided in the resolution to Issue 10439. right-associativity is perhaps not the correct word for the hybrid behaviour of letin that is very high precedence on the left for "let" but very low precedence on the right for "in" to allow the let body to be an arbitrary expression. End of Annotations:===== ronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AtAEABRG5krUnw4T/2dsb2JhbACCJS6XPL17hD8E Date: Tue, 27 Oct 2009 08:03:35 +0000 From: Ed Willink User-Agent: Thunderbird 2.0.0.22 (Windows/20090605) To: issues@omg.org Subject: OCL 2.1 7.4.7 Inconsistent Operator Associativity and Precedence X-Plusnet-Relay: 8b0c82d408ace729f6c8653c356fed8d Hi Issue 11098 resolved the missing precedence of let-in as lowest. This requires "2 * let a:Integer=1 in a + 1" to be interpreted as "(2 * (let a:Integer=1 in a)) + 1" making use of a non-trivial let body surprising and needlessly complicated. The problem with the open-ended right hand side can be resolved by assigning let-in the highest atomic expression precedence and defining its resolution as right-associative. The above example then has the obvious meaning "2 * (let a:Integer=1 in (a + 1))". Issue 6544 introduces ^ and ^^ at higher precedence than . and ->. However since these operators can only return left hand arguments for each other, there is no need to assign these to different levels. if-then-else-endif has an intermediate precedence in OCL 2.1. Since this term has keywords at start and end, the term is equivalent to an atomic expression. In so far as precedence is meaningful it is a high precedence. Parentheses should be bulletted at high precedence. Non commutative operators such as / have no defined order of evaluation leaving the value of "8 / 4 / 2" undefined. Binary operators should be specified as left-associative; i.e "(8 / 4) / 2". Section 9.3.2 duplicates 7.4.7. Regards Ed Willink X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApoEAJ+q5krUnw4S/2dsb2JhbADaE4Q/BA Date: Tue, 27 Oct 2009 15:13:11 +0000 From: Ed Willink User-Agent: Thunderbird 2.0.0.22 (Windows/20090605) To: ocl2-rtf@omg.org Subject: Re: Issue 14582 Inconsistent Operator Associativity and Precedence X-Plusnet-Relay: f92ecc454b4117f02b729bd52af1c7e0 Hi Mariano Attached defines equi-precedence operators as left associative, and makes sense of the if-then-else-endif, let-in, ^ and ^^ precedences. Regards Ed Willink