Skip to content

Commit

Permalink
Fix style issues with unit syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikt-ma committed Oct 6, 2021
1 parent d617ab8 commit 2a0007f
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions chapters/unitexpressions.tex
Expand Up @@ -10,27 +10,25 @@ \chapter{Unit Expressions}\label{unit-expressions}

\section{The Syntax of Unit Expressions}\label{the-syntax-of-unit-expressions}

The Modelica unit string syntax allows neither comments nor white-space, and a unit string shall match the \lstinline[language=grammar]!unit-expression! rule:
\begin{lstlisting}[language=grammar]
unit_expression:
unit_numerator [ "/" unit_denominator ]
unit-expression :
unit-numerator [ "/" unit-denominator ]

unit_numerator:
"1" | unit_factors | "(" unit_expression ")"
unit-numerator :
"1" | unit-factors | "(" unit-expression ")"

unit_denominator:
unit_factor | "(" unit_expression ")"
unit-denominator:
unit-factor | "(" unit-expression ")"
\end{lstlisting}

The unit of measure of a dimension free quantity is denoted by \lstinline!"1"!.
The SI standard does not define any precedence between multiplications and divisions.
The SI standard does not allow multiple units to the right of the division-symbol (\lstinline!/!) since the result is ambiguous; either the divisor shall be enclosed in parentheses, or negative exponents used instead of division, for example, \lstinline!"J/(kg.K)"! may be written as \lstinline!"J.kg-1.K-1"!.

\begin{lstlisting}[language=grammar]
unit_factors:
unit_factor [ unit_mulop unit_factors ]

unit_mulop:
"."
unit-factors :
unit-factor [ "." unit-factors ]
\end{lstlisting}

The SI standard specifies that a multiplication operator symbol is written as space or as a dot.
Expand All @@ -40,32 +38,32 @@ \section{The Syntax of Unit Expressions}\label{the-syntax-of-unit-expressions}
For example, Modelica does not support \lstinline!"Nm"! for newton-meter, but requires it to be written as \lstinline!"N.m"!.

\begin{lstlisting}[language=grammar]
unit_factor:
unit_operand [ unit_exponent ]
unit-factor :
unit-operand [ unit-exponent ]

unit_exponent:
[ "+" | "-" ] integer
unit-exponent :
[ "+" | "-" ] UNSIGNED-INTEGER
\end{lstlisting}

The SI standard uses super-script for the exponentation, and does thus not define any operator symbol for exponentiation.
A \lstinline!unit_factor! consists of a \lstinline!unit_operand! possibly suffixed by a possibly signed integer number, which is interpreted as an exponent.
There must be no spacing between the \lstinline!unit_operand! and a possible \lstinline!unit_exponent!.
A \lstinline[language=grammar]!unit-factor! consists of a \lstinline[language=grammar]!unit-operand! possibly suffixed by a possibly signed integer number, which is interpreted as an exponent.
There must be no spacing between the \lstinline[language=grammar]!unit-operand! and a possible \lstinline[language=grammar]!unit-exponent!.

\begin{lstlisting}[language=grammar]
unit_operand:
unit_symbol | unit_prefix unit_symbol
unit-operand :
UNIT-SYMBOL | UNIT-PREFIX UNIT-SYMBOL

unit_prefix:
Y | Z | E | P | T | G | M | k | h | da | d | c | m | u | n | p | f | a | z | y
UNIT-PREFIX = "Y" | "Z" | "E" | "P" | "T" | "G" | "M" | "k" | "h" | "da"
| "d" | "c" | "m" | "u" | "n" | "p" | "f" | "a" | "z" | "y"
\end{lstlisting}

A \lstinline!unit_symbol! is a string of letters.
A \lstinline[language=grammar]!UNIT-SYMBOL! is a string of letters.
A basic support of units in Modelica should know the basic and derived units of the SI system.
It is possible to support user defined unit symbols.
In the base version Greek letters is not supported, but full names must then be written, for example \lstinline!"Ohm"!.

A \lstinline!unit_operand! should first be interpreted as a \lstinline!unit_symbol! and only if not successful the second alternative assuming a prefixed operand should be exploited.
There must be no spacing between the \lstinline!unit_symbol! and a possible \lstinline!unit_prefix!.
A \lstinline[language=grammar]!unit-operand! should first be interpreted as a \lstinline[language=grammar]!UNIT-SYMBOL! and only if not successful the second alternative assuming a prefixed operand should be exploited.
There must be no spacing between the \lstinline[language=grammar]!UNIT-SYMBOL! and a possible \lstinline[language=grammar]!UNIT-PREFIX!.
The values of the prefixes are according to the ISO standard.
The letter \lstinline!u! is used as a symbol for the prefix micro.

Expand Down

0 comments on commit 2a0007f

Please sign in to comment.