Skip to content

Commit

Permalink
Avoid paragraph columns in operator precedence table
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikt-ma committed Sep 27, 2020
1 parent 9d64106 commit 87302b7
Showing 1 changed file with 43 additions and 44 deletions.
87 changes: 43 additions & 44 deletions chapters/operatorsandexpressions.tex
Original file line number Diff line number Diff line change
Expand Up @@ -36,53 +36,52 @@ \section{Operator Precedence and Associativity}\label{operator-precedence-and-as
an expression. An operator with higher precedence is evaluated before an
operator with lower precedence in the same expression.

The following table presents all the expression operators in order of
precedence from highest to lowest, as derived from the Modelica grammar
in \cref{modelica-concrete-syntax}. All operators are binary except the postfix operators and
those shown as unary together with \emph{expr}, the conditional
operator, the array construction operator \lstinline!{ }! and concatenation
operator \lstinline![ ]!, and the array range constructor which is either binary
or ternary. Operators with the same precedence occur at the same line of
the table:
The following table presents all the expression operators in order of precedence.
\begin{table}[H]
\caption{Operators.}
\begin{tabular}{|p{5cm}|p{5cm}|p{4cm}|}
% Beware that the array construction operator, normally expressed as \lstinline!{ }! needs escaped braces inside \caption.
\caption{Operators in order of precedence from highest to lowest, as derived from the Modelica grammar in \cref{modelica-concrete-syntax}. All operators are binary except the postfix operators and those shown as unary together with \emph{expr}, the conditional operator, the array construction operator \lstinline!\{ \}! and concatenation operator \lstinline![ ]!, and the array range constructor which is either binary or ternary. Operators with the same precedence occur at the same table row.}\label{tab:operator-precedence}
\begin{center}
\begin{tabular}{l|l|l}
\hline
\tablehead{Operator group} & \tablehead{Operator syntax} & \tablehead{Examples}\\
\hline
\hline
Postfix array index operator & \lstinline![]! & \lstinline!arr[index]!\\
\hline
Postfix access operator & \lstinline!.! & \lstinline!a.b!\\
\hline
Postfix function call & \lstinline!$\mathit{funcName}$($\mathit{functionArguments}$)! & \lstinline!sin(4.36)!\\
\hline
Array construction & \lstinline!{$\mathit{expressions}$}! & \lstinline!{2, 3}!\\
Horizontal concatenation & \lstinline![$\mathit{expressions}$]! & \lstinline![5, 6]!\\
Vertical concatenation & \lstinline![$\mathit{expressions}$; $\mathit{expressions}\ldots$]! & \lstinline![2, 3; 7, 8]!\\
\hline
Exponentiation & \ \lstinline!^! & \lstinline!2 ^ 3!\\
\hline
Multiplicative & \lstinline!* /! & \lstinline!2 * 3!, \lstinline!2 / 3!\\
Elementwise multiplicative & \lstinline!.* ./! & \lstinline![1, 2; 3, 4] .* [2, 3; 5, 6]!\\
\hline
Additive & \lstinline!+ -! & \lstinline!1 + 2!\\
Additive unary & \lstinline!+$\mathit{expr}$ -$\mathit{expr}$! & \lstinline!-0.5!\\
Array elementwise additive & \lstinline!.+ .-! & \lstinline![1, 2; 3, 4] .+ [2, 3; 5, 6]!\\
\hline
Relational & \lstinline!< <= > >= == <>! & \lstinline!a < b!, \lstinline!a <= b!, \lstinline!a > b!, \ldots\\
\hline
Unary negation & \lstinline!not $\mathit{expr}$! & \lstinline!not b1!\\
\hline
Logical and & \lstinline!and! & \lstinline!b1 and b2!\\
\hline
Logical or & \lstinline!or! & \lstinline!b1 or b2!\\
\hline
\multirow{2}{*}{Array range} & \lstinline!$\mathit{expr}$ : $\mathit{expr}$! & \lstinline!1 : 5!\\
& \lstinline!$\mathit{expr}$ : $\mathit{expr}$ : $\mathit{expr}$! & \lstinline!start : step : stop!\\
\hline
Conditional & \lstinline!if $\mathit{expr}$ then $\mathit{expr}$ else $\mathit{expr}$! & \lstinline!if b then 3 else x!\\
\hline
Named argument & \lstinline!$\mathit{ident}$ = $\mathit{expr}$! & \lstinline!x = 2.26!\\
\hline
\tablehead{Operator Group} & \tablehead{Operator Syntax} & \tablehead{Examples}\\ \hline
postfix array index operator & \lstinline![]! & \lstinline!arr[index]! \\ \hline
postfix access operator & \lstinline!.! & \lstinline!a.b! \\ \hline
postfix function call & \lstinline!$\mathit{funcName}$($\mathit{functionArguments}$)! & \lstinline!sin(4.36)! \\ \hline
array construct/concat & \begin{tabular}{@{}p{5cm}@{}}
\lstinline!{$\mathit{expressions}$}!\\
\lstinline![$\mathit{expressions}$]!\\
\lstinline![$\mathit{expressions}$; $\mathit{expressions}\ldots$]!
\end{tabular} & \begin{tabular}{@{}p{5cm}@{}}
\lstinline!{2,3}! \\
\lstinline![5,6]! \\
\lstinline![2,3; 7,8]!
\end{tabular} \\ \hline
exponentiation & \ \lstinline!^! & \lstinline!2^3! \\ \hline
multiplicative and array elementwise multiplicative & \lstinline!* / .* ./! & \begin{tabular}{@{}p{5cm}@{}}
\lstinline!2*3!, \lstinline!2/3! \\
\lstinline![1,2;3,4].*[2,3;5,6]!
\end{tabular} \\ \hline
additive and array elementwise additive & \lstinline!+ - +$\mathit{expr}$ -$\mathit{expr}$ .+ .-! & \lstinline![1,2;3,4].+[2,3;5,6]!\\ \hline
relational & \lstinline!< <= > >= == <>! &
\lstinline!a<b!, \lstinline!a<=b!, \lstinline!a>b!, \ldots\\ \hline
unary negation & \lstinline!not $\mathit{expr}$! & \lstinline!not b1! \\ \hline
logical and & \lstinline!and! & \lstinline!b1 and b2! \\ \hline
logical or & \lstinline!or! & \lstinline!b1 or b2!\\ \hline
array range & \begin{tabular}{@{}p{5cm}@{}}
\lstinline!$\mathit{expr}$ : $\mathit{expr}$! \\
\lstinline!$\mathit{expr}$ : $\mathit{expr}$ : $\mathit{expr}$!
\end{tabular} & \begin{tabular}{@{}p{5cm}@{}}
\lstinline!1:5! \\
\lstinline!start:step:stop!
\end{tabular} \\ \hline
conditional & \lstinline!if $\mathit{expr}$ then $\mathit{expr}$ else $\mathit{expr}$! & \lstinline!if b then 3 else x!\\ \hline
named argument & \lstinline!$\mathit{ident}$ = $\mathit{expr}$! & \lstinline!x = 2.26!\\ \hline
\end{tabular}
\label{tab:operator-precedence}
\end{center}
\end{table}

The conditional operator may also include elseif-clauses. Equality \lstinline!=! and
Expand Down

0 comments on commit 87302b7

Please sign in to comment.