Skip to content

Commit

Permalink
Describe associativity as property of operator precedence group
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikt-ma committed Feb 17, 2022
1 parent c76717e commit cf9072e
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions chapters/operatorsandexpressions.tex
Expand Up @@ -26,12 +26,12 @@ \section{Operator Precedence and Associativity}\label{operator-precedence-and-as
An operator with higher precedence is evaluated before an operator with lower precedence in the same expression.
For example, `\lstinline!*!' having higher precedence than `\lstinline!+!' means that \lstinline!1 + 2 * 3! becomes evaluated as \lstinline!1 + (2 * 3)!.

Operator associativity are used to determine the order of evaluation when operators have equal precedence.
Precedence group associativity is used to determine the order of evaluation when operators belong to the same group of equal precedence.
Left associativity means that evaluation proceeds from left to right.
For example, left associativity of binary `\lstinline!-!' means that \lstinline!1 - 2 - 3! becomes evaluated as \lstinline!(1 - 2) - 3!.
Right associativity means evaluation from right to left, but there are no operators with this associativity in Modelica.
An operator may also be non-associative, meaning that evaluation order cannot be determined based on associativity.
For example, non-associativity of `\lstinline!<!' means that \lstinline!1 < 2 < 3! is an invalid expression.
For example, left associativity of binary additive operators means that \lstinline!1 - 2 - 3! becomes evaluated as \lstinline!(1 - 2) - 3!.
Right associativity means evaluation from right to left, but there is no precedence group with this associativity in Modelica.
A precedence group may also be non-associative, meaning that evaluation order cannot be determined based on associativity.
For example, non-associativity of relational operators means that \lstinline!1 < 2 < 3! is an invalid expression.
Note that the operators don't need to be identical for associativity to matter; also \lstinline!1 == 2 < 3! is invalid, and \lstinline!1 - 2 + 3! becomes evaluated as \lstinline!(1 - 2) + 3!.

The following table presents the precedence and associativity of all the expression operators, consistent with and complementing information that can be derived from the Modelica grammar in \cref{modelica-concrete-syntax}.
Expand Down

0 comments on commit cf9072e

Please sign in to comment.