Skip to content

Commit

Permalink
Merge pull request modelica#3547 from henrikt-ma/cleanup/member-access
Browse files Browse the repository at this point in the history
Don't speak of postfix operators
  • Loading branch information
HansOlsson authored Jul 5, 2024
2 parents af0be8d + e19ac36 commit 2362dbc
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions chapters/operatorsandexpressions.tex
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ \section{Operator Precedence and Associativity}\label{operator-precedence-and-as
\caption{%
Operators in order of precedence from highest to lowest.
Operators with different precedence are separated by horizontal lines.
All operators are binary except the postfix operators and those shown as unary together with \emph{expr}, the conditional operator, the array construction operator
All operators are binary except array index, member access, function call, those shown as unary together with \emph{expr}, the conditional operator, the array construction operator
% Beware that the array construction operator, normally expressed as \lstinline!{ }! needs escaped braces inside \caption.
% This isn't handled correctly by LaTeXML, as reported here:
% - https://github.com/brucemiller/LaTeXML/issues/1377 (fixed on master 2022-12-10)
Expand All @@ -63,11 +63,11 @@ \section{Operator Precedence and Associativity}\label{operator-precedence-and-as
\tablehead{Operator group} & \tablehead{Assoc.} & \tablehead{Operator syntax} & \tablehead{Examples}\\
\hline
\hline
Postfix array index & left & {\lstinline![]!} & {\lstinline!arr[index]!}\\
Array index & left & {\lstinline![]!} & {\lstinline!arr[index]!}\\
\hline
Postfix access & left & {\lstinline!.!} & {\lstinline!a.b!}\\
Member access & left & {\lstinline!.!} & {\lstinline!a.b!}\\
\hline
Postfix function call & none & {\lstinline!$\mathit{funcName}$($\mathit{args}$)!} & {\lstinline!sin(4.36)!}\\
Function call & none & {\lstinline!$\mathit{funcName}$($\mathit{args}$)!} & {\lstinline!sin(4.36)!}\\
\hline
Array construction & left$^{\dagger}$ & {\lstinline!{$\mathit{expr}$, $\mathit{expr}$, $\ldots$}!} & {\lstinline!{2, 3}!}\\
Horizontal concatenation & left$^{\dagger}$ & {\lstinline![$\mathit{expr}$, $\mathit{expr}$, $\ldots$]!} & {\lstinline![5, 6]!}\\
Expand Down Expand Up @@ -103,20 +103,20 @@ \section{Operator Precedence and Associativity}\label{operator-precedence-and-as
\end{center}
\end{table}

The postfix array index and postfix access operators can both be part of a \lstinline[language=grammar]!component-reference! (one of the alternative productions for \lstinline[language=grammar]!primary! in the grammar) and be applied to general expressions when the left operand is parenthesized.
Directly using both postfix access operator and postfix array index in a \lstinline[language=grammar]!component-reference! has a special intuitive meaning.
The array index and member access operators can both be part of a \lstinline[language=grammar]!component-reference! (one of the alternative productions for \lstinline[language=grammar]!primary! in the grammar) and be applied to general expressions when the left operand is parenthesized.
Directly using both member access and array index in a \lstinline[language=grammar]!component-reference! has a special intuitive meaning.
See \cref{indexing} and \cref{member-access-operator}.

\begin{example}
Relative precedence of postfix array index and postfix access.
Relative precedence of array index and member access.
Consider the following definition of the array variable \lstinline!a!:
\begin{lstlisting}[language=modelica]
record R
Real[2] x;
end R;
R[3] a;
\end{lstlisting}
These are some valid as well as invalid ways to using postfix array index and postfix access:
These are some valid as well as invalid ways to using array index and member 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]
Expand All @@ -130,7 +130,7 @@ \section{Operator Precedence and Associativity}\label{operator-precedence-and-as
(a[3]).x[1] // Error.
((a[3]).x)[1] // OK: Like a[3].x[1], but not a component reference
\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.
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 member 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]! expresses, being a component reference of type \lstinline!Real[2]!.
\end{example}

Expand Down

0 comments on commit 2362dbc

Please sign in to comment.