Skip to content

Commit

Permalink
Reorder examples in order of operator appearance in table
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikt-ma committed Feb 17, 2022
1 parent 2ca9a28 commit c76717e
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions chapters/operatorsandexpressions.tex
Original file line number Diff line number Diff line change
Expand Up @@ -124,29 +124,31 @@ \section{Operator Precedence and Associativity}\label{operator-precedence-and-as
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]!.
\end{example}

\begin{example}
Non-associative exponentiation and array range operator (note that the array range operator only takes scalar operands):
\begin{lstlisting}[language=modelica]
x ^ y ^ z // Not legal, use parentheses to make it clear.
a : b : c : d // Not legal, and parentheses cannot make it legal.
\end{lstlisting}
\end{example}

The additive unary expressions are only allowed in the first term of a sum, that is, not immediately to the right of any of the additive or elementwise additive operators.
For example, \lstinline!1 + -1 + 1! is an invalid expression (not parseable according to \cref{modelica-concrete-syntax}), whereas both \lstinline!1 + (-1) + 1! and \lstinline!-1 + 1 + 1! are fine.

The conditional operator may also include \lstinline!elseif!-branches.

Equality \lstinline!=! and assignment \lstinline!:=! are not expression operators since they are allowed only in equations and in assignment statements respectively.

\begin{nonnormative}
\begin{example}
The unary minus and plus in Modelica is slightly different than in Mathematica\footnote{\emph{Mathematica} is a registered trademark of Wolfram Research Inc.} and in MATLAB\footnote{\emph{MATLAB} is a registered trademark of MathWorks Inc.}, since the following expressions are illegal (whereas in Mathematica and in MATLAB these are valid expressions):
% Using $\hspace{0pt}$ below to work around https://github.com/brucemiller/LaTeXML/issues/1399
\begin{lstlisting}[language=modelica]
2*$\hspace{0pt}$-2 // = -4 in Mathematica/MATLAB; is illegal in Modelica
-$\hspace{0pt}$-2 // = 2 in Mathematica/MATLAB; is illegal in Modelica
+$\hspace{0pt}$+2 // = 2 in Mathematica/MATLAB; is illegal in Modelica
2-$\hspace{0pt}$-2 // = 4 in Mathematica/MATLAB; is illegal in Modelica
\end{lstlisting}
% Using $\hspace{0pt}$ to work around https://github.com/brucemiller/LaTeXML/issues/1399
\end{example}

Non-associative exponentiation and array range operator (note that the array range operator only takes scalar operands):
\begin{lstlisting}[language=modelica]
x ^ y ^ z // Not legal, use parentheses to make it clear.
a : b : c : d // Not legal, and parentheses cannot make it legal.
\end{lstlisting}
\end{nonnormative}
The conditional operator may also include \lstinline!elseif!-branches.

Equality \lstinline!=! and assignment \lstinline!:=! are not expression operators since they are allowed only in equations and in assignment statements respectively.

\begin{nonnormative}
The operator precedence table is useful when generating textual representations of Modelica expression trees.
Expand Down

0 comments on commit c76717e

Please sign in to comment.