Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General subscripting #3395

Merged
merged 9 commits into from Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions chapters/arrays.tex
Expand Up @@ -55,6 +55,7 @@ \section{Array Declarations}\label{array-declarations}
\item
Binding equations of the form \lstinline!x1 = x2! are allowed for arrays independent of whether the index types of dimensions are subtypes of \lstinline!Integer!, \lstinline!Boolean!, or enumeration types.
\end{itemize}
Operations constructing arrays (e.g., matrix multiplication, indexing, array constructors) only generate arrays index by \lstinline!Integer!.
HansOlsson marked this conversation as resolved.
Show resolved Hide resolved

% IMPROVETOP
\begin{table}[H]
Expand Down Expand Up @@ -946,6 +947,9 @@ \section{Indexing}\label{array-indexing}\label{indexing}
The number of dimensions of the expression is reduced by the number of scalar index arguments.
If the number of index arguments is smaller than the number of dimensions of the array, the trailing indices will use `\lstinline!:!'.

It is possible to index a general expression by enclosing it in parenthesis.
Note that the grammar is left factored and allows indexing of \lstinline[language=grammar]!output-expression-list!, but only indexing of an expression is syntactically valid.
HansOlsson marked this conversation as resolved.
Show resolved Hide resolved

It is also possible to use the array access operator to assign to element/elements of an array in algorithm sections.
This is called an \firstuse[assignment statement!indexed]{indexed assignment statement}.
If the index is an array the assignments take place in the order given by the index array.
Expand All @@ -972,6 +976,10 @@ \section{Indexing}\label{array-indexing}\label{indexing}
v[{j, k}] := {2, 3}; // Same as: v[j] := 2; v[k] := 3;
v[{1, 1}] := {2, 3}; // Same as: v[1] := 3;
\end{lstlisting}
Array indexing of general expression:
\begin{lstlisting}[language=modelica]
(a*a)[:, j] // Vector of the j'th column of a*a
\end{lstlisting}
If \lstinline!x! is a vector, \lstinline!x[1]! is a scalar, but the slice \lstinline!x[1:5]! is a vector
(a vector-valued or colon index expression causes a vector to be returned).
\end{example}
Expand Down
2 changes: 1 addition & 1 deletion chapters/syntax.tex
Expand Up @@ -398,7 +398,7 @@ \subsection{Expressions}\label{expressions1}
| true
| ( component-reference | der | initial | pure ) function-call-args
| component-reference
| "(" output-expression-list ")"
| "(" output-expression-list ")" { array-subscripts }
HansOlsson marked this conversation as resolved.
Show resolved Hide resolved
| "[" expression-list { ";" expression-list } "]"
| "{" array-arguments "}"
| end
Expand Down