Skip to content

Commit

Permalink
Merge pull request modelica#3434 from henrikt-ma/external-call-consta…
Browse files Browse the repository at this point in the history
…nt-argument

External call constant arguments and literals
  • Loading branch information
HansOlsson committed Nov 9, 2023
2 parents 6367899 + dfb1864 commit 8d587bf
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 44 deletions.
2 changes: 1 addition & 1 deletion chapters/functions.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1984,7 +1984,7 @@ \section{External Function Interface}\label{external-function-interface}

The {\lstinline[language=grammar]!external-function-call!} specification allows functions whose prototypes do not match the default assumptions as defined below to be called. It also gives the name used to call the external function. If the external call is not given explicitly, this name is assumed to be the same as the Modelica name.

The only permissible kinds of expressions in the argument list are component references, scalar constants, and the function {\lstinline!size!} applied to an array and a constant dimension number.
The only permissible kinds of expressions in the argument list are component references, scalar constant expressions, and the function {\lstinline!size!} applied to an array and a constant dimension number.
The annotations are used to pass additional information to the compiler when necessary.

A component reference to a component that is part of an input or output
Expand Down
81 changes: 38 additions & 43 deletions chapters/lexicalstructure.tex
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
\chapter{Lexical Structure}\label{lexical-structure}

This chapter describes several of the basic building blocks of Modelica
such as characters and lexical units including identifiers and literals.
Without question, the smallest building blocks in Modelica are single
characters belonging to a character set. Characters are combined to form
lexical units, also called tokens. These tokens are detected by the
lexical analysis part of the Modelica translator. Examples of tokens are
literal constants, identifiers, and operators. Comments are not really
lexical units since they are eventually discarded. On the other hand,
comments are detected by the lexical analyzer before being thrown away.

The information presented here is derived from the more formal
specification in \cref{modelica-concrete-syntax}.
This chapter describes several of the basic building blocks of Modelica such as characters and lexical units including identifiers and literals.
Without question, the smallest building blocks in Modelica are single characters belonging to a character set.
Characters are combined to form lexical units, also called tokens.
These tokens are detected by the lexical analysis part of the Modelica translator.
Examples of tokens are literals, identifiers, and operators.
Comments are not really lexical units since they are eventually discarded.
On the other hand, comments are detected by the lexical analyzer before being thrown away.

The information presented here is derived from the more formal specification in \cref{modelica-concrete-syntax}.


\section{Character Set}\label{character-set}

The character set of the Modelica language is Unicode, but restricted to the Unicode characters corresponding to 7-bit ASCII characters for identifiers; see \cref{lexical-conventions}.


\section{Comments}\label{comments}

There are two kinds of comments in Modelica which are not lexical units in the language and therefore are treated as white-space by a Modelica translator.
Expand Down Expand Up @@ -49,10 +48,9 @@ \section{Comments}\label{comments}
//end Valid;
\end{lstlisting}

There is also a description-string, that is part of the Modelica language and
therefore not ignored by the Modelica translator. Such a description-string may
occur at the end of a declaration, equation, or statement or at the
beginning of a class definition. For example:
There is also a description-string, that is part of the Modelica language and therefore not ignored by the Modelica translator.
Such a description-string may occur at the end of a declaration, equation, or statement or at the beginning of a class definition.
For example:
\begin{lstlisting}[language=modelica]
model TempResistor "Temperature dependent resistor"
$\ldots$
Expand All @@ -61,11 +59,13 @@ \section{Comments}\label{comments}
end TempResistor;
\end{lstlisting}


\section{Identifiers, Names, and Keywords}\label{identifiers-names-and-keywords}

\willintroduce{Identifiers} are sequences of letters, digits, and other characters such as underscore, which are used for \emph{naming} various items in the language.
Certain combinations of letters are \willintroduce{keywords} represented as \emph{reserved} words in the Modelica grammar and are therefore not available as identifiers.


\subsection{Identifiers}\label{identifiers}

Modelica \firstuse[identifier]{identifiers}, used for naming classes, variables, constants, and other items, are of two forms.
Expand All @@ -90,6 +90,7 @@ \subsection{Identifiers}\label{identifiers}
| "\a" | "\b" | "\f" | "\n" | "\r" | "\t" | "\v"
\end{lstlisting}


\subsection{Names}\label{names}

A \firstuse{name} is an identifier with a certain interpretation or meaning.
Expand All @@ -110,6 +111,7 @@ \subsection{Names}\label{names}
A component reference: \lstinline!Ele.Resistor.u[21].r!
\end{example}


\subsection{Modelica Keywords}\label{modelica-keywords}

The following Modelica \firstuse[keyword]{keywords} are reserved words that cannot be used where \lstinline[language=grammar]!IDENT! is expected in the language grammar (\cref{modelica-concrete-syntax}):
Expand Down Expand Up @@ -144,18 +146,20 @@ \subsection{Modelica Keywords}\label{modelica-keywords}
\end{lstlisting}
\end{example}

\section{Literal Constants}\label{literal-constants}

\firstuse[literal (constant)]{Literals} (or \firstuse[---]{literal constants}) are unnamed constants used to build expressions, and have different forms depending on their type.
\section{Literals}\label{literals}

\firstuse[literal]{Literals} are unnamed constants used to build expressions, and have different forms depending on their type.
Each of the predefined types in Modelica has a way of expressing unnamed constants of the corresponding type, which is presented in the ensuing subsections.
Additionally, array literals and record literals can be expressed.


\subsection{Floating Point Numbers}\label{floating-point-numbers}

A floating point number is expressed as a decimal number in the form of a sequence of decimal digits followed by a decimal point, followed by decimal digits, followed by an exponent indicated by \lstinline!E! or \lstinline!e! followed by a sign and one or more decimal digits.
The various parts can be omitted, see \lstinline[language=grammar]!UNSIGNED-REAL! in~\cref{lexical-conventions} for details and also the examples below.
The minimal recommended range is that of IEEE double precision floating point numbers, for which the largest representable positive number is $1.7976931348623157\times10^{308}$ and the smallest positive number is $2.2250738585072014\times 10^{-308}$.
For example, the following are floating point number literal constants:
For example, the following are floating point number literals:
\begin{lstlisting}[language=modelica]
22.5, 3.141592653589793, 1.2E-35
\end{lstlisting}
Expand All @@ -166,8 +170,8 @@ \subsection{Floating Point Numbers}\label{floating-point-numbers}
13., 13E0, 1.3e1, 0.13E2, .13E2
\end{lstlisting}
The last variant shows that that the leading zero is optional (in that case decimal digits must be present).
Note that \lstinline!13! is not in this list, since it is not a floating point number,
but can be converted to a floating point number.
Note that \lstinline!13! is not in this list, since it is not a floating point number, but can be converted to a floating point number.


\subsection{Integer Literals}\label{integer-literals}

Expand All @@ -186,10 +190,12 @@ \subsection{Integer Literals}\label{integer-literals}
Negative numbers are formed by unary minus followed by an integer literal.
\end{nonnormative}


\subsection{Boolean Literals}\label{boolean-literals}

The two \lstinline!Boolean! literal values are \lstinline!true!\indexinline{true} and \lstinline!false!\indexinline{false}.


\subsection{Strings}\label{strings}

String literals appear between double quotes as in \lstinline!"between"!.
Expand Down Expand Up @@ -217,38 +223,27 @@ \subsection{Strings}\label{strings}
\end{tabular}
\end{center}

For example, a string literal containing a tab, the words: \emph{This is},
double quote, space, the word: \emph{between}, double quote, space, the word:
\emph{us}, and new-line, would appear as follows:
For example, a string literal containing a tab, the words: \emph{This is}, double quote, space, the word: \emph{between}, double quote, space, the word: \emph{us}, and new-line, would appear as follows:
\begin{lstlisting}[language=modelica]
"\tThis is\" between\" us\n"
\end{lstlisting}

Concatenation of string literals in certain situations (see the Modelica
grammar) is denoted by the + operator in Modelica, e.g., \lstinline!"a"! + \lstinline!"b"!
becomes \lstinline!"ab"!. This is useful for expressing long string literals that
need to be written on several lines.
Concatenation of string literals in certain situations (see the Modelica grammar) is denoted by the + operator in Modelica, e.g., \lstinline!"a"! + \lstinline!"b"! becomes \lstinline!"ab"!.
This is useful for expressing long string literals that need to be written on several lines.

The \lstinline!"\n"! character is used to conceptually indicate the
end of a line within a Modelica string. Any Modelica program that needs
to recognize line endings can check for a single \lstinline!"\n"!
character to do so on any platform. It is the responsibility of a
Modelica implementation to make any necessary transformations to other
representations when writing to or reading from a text file.
The \lstinline!"\n"! character is used to conceptually indicate the end of a line within a Modelica string.
Any Modelica program that needs to recognize line endings can check for a single \lstinline!"\n"! character to do so on any platform.
It is the responsibility of a Modelica implementation to make any necessary transformations to other representations when writing to or reading from a text file.

\begin{nonnormative}
For example, a \lstinline!"\n"! is written and read as-is in a Unix or Linux implementation, but written as
\lstinline!"\r\n"! pair, and converted back to \lstinline!"\n"! when read in a Windows implementation.
\end{nonnormative}

\begin{nonnormative}
For long string comments, e.g., the \lstinline!info! annotation to
store the documentation of a model, it would be very inconvenient, if
the string concatenation operator would have to be used for every line
of documentation. It is assumed that a Modelica tool supports the
non-printable newline character when browsing or editing a string
literal. For example, the following statement defines one string that
contains (non-printable) newline characters:
For long string comments, e.g., the \lstinline!info! annotation to store the documentation of a model, it would be very inconvenient, if the string concatenation operator would have to be used for every line of documentation.
It is assumed that a Modelica tool supports the non-printable newline character when browsing or editing a string literal.
For example, the following statement defines one string that contains (non-printable) newline characters:
\begin{lstlisting}[language=modelica]
assert(noEvent(length > s_small),
"The distance between the origin of frame_a and the origin of frame_b
Expand All @@ -261,7 +256,7 @@ \subsection{Strings}\label{strings}
\end{lstlisting}
\end{nonnormative}


\section{Operator Symbols}\label{operator-symbols}

The predefined operator symbols are formally defined on page \pageref{lexical-conventions} and
summarized in the table of operators in \cref{operator-precedence-and-associativity}.
The predefined operator symbols are formally defined on page \pageref{lexical-conventions} and summarized in the table of operators in \cref{operator-precedence-and-associativity}.

0 comments on commit 8d587bf

Please sign in to comment.