Skip to content

Commit

Permalink
Update this text for general subscripting as well.
Browse files Browse the repository at this point in the history
  • Loading branch information
HansOlsson committed Aug 10, 2023
1 parent 76cfe01 commit f2ee984
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions chapters/operatorsandexpressions.tex
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,19 @@ \section{Operator Precedence and Associativity}\label{operator-precedence-and-as
\end{lstlisting}
These are some valid as well as invalid ways to using postfix array index and postfix access:
\begin{lstlisting}[language=modelica]
a[3].x[2] // OK: Component reference of type Real
a[3].x // OK: Component reference of type Real[2]
a.x[2] // OK: Component reference of type Real[3]
a.x // OK: Component reference of type Real[3, 2]
(a.x)[2] // Error: Invalid use of parentheses
a[3] // OK: Component reference of type R
(a[3]).x // Error: Invalid use of parentheses
a[3].x[2] // OK: Component reference of type Real
a[3].x // OK: Component reference of type Real[2]
a.x[2] // OK: Component reference of type Real[3]
a.x[2, :] // Error.
a.x // OK: Component reference of type Real[3, 2]
(a.x)[2] // OK: Component reference of type Real[2] - same as a[2].x[:]
(a.x)[2, :] // OK: Component reference of type Real[2] - same as a[2].x[:]
a[3] // OK: Component reference of type R
(a[3]).x // Error: Invalid use of parentheses
\end{lstlisting}
The relation between \lstinline!a.x!, \lstinline!a.x[2]!, and \lstinline!(a.x)[2]! illustrates the effect of giving higher precedence to array index than postfix access.
Had the precedence been equal, this would have changed the meaning of \lstinline!a.x[2]! to the same thing that \lstinline!(a.x)[2]! tries to express, being a component reference of type \lstinline!Real[2]!.
Had the precedence been equal, this would have changed the meaning of \lstinline!a.x[2]! to the same thing that \lstinline!(a.x)[2]! expresses, being a component reference of type \lstinline!Real[2]!.
Note that \lstinline!(a.x)[2]! was illegal in version 3.6 and earlier.
\end{example}

\begin{example}
Expand Down

0 comments on commit f2ee984

Please sign in to comment.