📄 intern_rep.tex
字号:
\chapter{Internal Representation}\label{intern_rep_c}The \hysdel{} program consists of the following major parts:\begin{itemize}\item \cppclass{Expr}: Represents mathematical expressions (e.g. $5x + \sin(0.3)$).\item \cppclass{Symbol}: Represents the variables and parameters declared in the \hysdel{} source.\item \cppclass{Item}: Represents the statements in the \hysdel{} source.\end{itemize}\section{Symbols}Every variable is represented as a \cppclass{Var\_symbol} and each parameter is represented as a\cppclass{Param\_symbol}. Both are subclasses of \cppclass{Symbol} (see Fig.~\ref{Symbol_hierarchy}).\cppclass{Symbol} contains the name of the variable or parameter. A field \code{type} indicates whether the symbolis real or Boolean. Another field gives the \code{kind} of the variable. Possible kinds are: state, input, output orauxiliary variable or a parameter.\figuraeps{symbol_hierarchy}{tbh}{7cm}{Class hierarchy ofSymbol}{Symbol_hierarchy}\subsection{Variables}\label{variable_order} In the \MLD{} model, all variables of the same kind are in a vector. Table\ref{kind-vector} gives the name of each vector. \cppclass{Var\_symbol} has a field \code{count}, which togetherwith the \code{type} defines the index of this variable in itsvector. The order is the same as they were declared in the \hysdel{}source. In $x$, $u$ and $y$, the real variables come before theBoolean ones.\begin{table}\begin{center}\begin{tabular}{ll}variable & name \\\hlinestate (real)& $x_r$ \\state (Boolean)& $x_b$ \\input (real)& $u_r$ \\input (Boolean)& $u_b$ \\output (real)& $y_r$ \\output (Boolean)& $y_b$ \\auxiliary (real) & $z$ \\auxiliary (Boolean) & $d$\end{tabular}\caption{Names of the variable vectors} \label{kind-vector}\end{center}\end{table}\subsection{Parameters}\cppclass{Param\_symbol} contains a pointer to \cppclass{Number}, a class that can store both real and Booleanvalues. If this pointer is \NULL, the parameter is symbolic. When asked to print itself, \cppclass{Param\_symbol}will either print the number it points to or, in the symbolic case, the name of the parameter. Thus, when usingthis class, there is no difference if the parameter is symbolic or not.\subsection{Symbol Table}The \cppclass{Symbol\_table} maintains a list\footnote{we use the map datastructure from the standard templatelibrary, the key is the name of the symbol} of all symbols. It is the only class who can create symbols. This isdone by calling the method \method{Symbol\_table}{create\_symbol}. It creates a symbol of the specified type, kindand name. A proper count is provided. Sometimes it is necessary to create variables that are not declared in the\hysdel{} source. In these cases calling \method{Symbol\_table}{create\_additional} will automatically generate aname. The name is \code{\_\_additional\_$x$}, where $x$ is the number of additional symbols created so far.Finally, symbols can be searched based on their name by calling \method{Symbol\_table}{find\_symbol}.\section{\cppclass{Expr}}\figuraeps{parse_tree}{tbh}{8cm}{An example of a parsetree}{parse_tree}Mathematical expressions are stored as a parse tree (see Fig.~\ref{parse_tree}). The parts that form anexpressions can be structured into three classes, all are subclasses of \cppclass{Expr} (seeFig.~\ref{Expr_hierarchy}):\begin{itemize}\item \cppclass{Binary\_expr} represents binary operators (e.g. addition). This class has two pointers to \cppclass{Expr} for the two arguments. Each binary operator is a subclass of \cppclass{Binary\_expr}.\item \cppclass{Unary\_expr} represents unary operators (e.g. logic not). It has one pointer to \cppclass{Expr} for its argument. Each unary operator is a subclass of \cppclass{Unary\_expr}.\item \cppclass{Terminal\_expr} represents the leafs in the parse tree. It is further subdivided into:\begin{itemize}\item \cppclass{Variable\_expr} stands for a variable. It contains a pointer to \cppclass{Var\_symbol}.\item \cppclass{Parameter\_expr} stands for a parameter. It contains a pointer to \cppclass{Param\_symbol}.\item \cppclass{Number\_expr} contains a \cppclass{Number}.\end{itemize}\end{itemize}Note that at this level there is no distinction between logic and real valued expressions.\figuraeps{Expr_hierarchy}{tbh}{12cm}{Class hierarchy ofExpr}{Expr_hierarchy} As an example, the following code generates the expression $5x + \sin(0.3)$:\begin{verbatim}Expr *_5x = new Mult_expr( new Number_expr(5.0), new Variable_expr(x_symb)); // assuming x_symb existsExpr *_sin03 = new Sin_expr{ new Number_expr(0.3));return new Plus_expr(_5x, _sin03);\end{verbatim}Expressions are either real or Boolean, which is checked using \method{Expr}{is\_real} and\method{Expr}{is\_logic}. \method{Expr}{is\_affine} tells whether the expression is affine or not. A constant isan expression without variables, which is checked by \method{Expr}{is\_const}. If a constant does not contain anysymbolic parameters, it can be represented as a number. If \method{Expr}{is\_number} is true, the\cppclass{Number} is returned by \method{Expr}{compute\_number}.\section{\cppclass{Item}}\label{Item_section}The \hysdel{} grammar knows eight different sections: Automata, Continuous, Output, AD, DA, Logic, Linear andMust. All but the last section are of the form $v=\ldots$, i.e. they define some variable $v$. The statementsthere are represented as \cppclass{Definition\_item}, which contains a pointer to the variable being defined. Anentry in the Must section yields a \cppclass{Constraint\_item}. Both are subclasses of\cppclass{Item}\footnote{for easier reading, we also use the word `item' when referring to \cppclass{Item}}(see~\ref{Item_hierarchy}). All items of a section are stored in a \cppclass{Section}. All \cppclass{Section}'s inturn are stored in \cppclass{Implementation}. The following subsections describe each item in detail. We give the\hysdel{} syntax and the main attributes of the corresponding item class. Finally we state the semanticalconditions that have to be fulfilled for the item to make sense (see also Chapter~\ref{sem_check_c}).\figuraeps{Item_hierarchy}{tbh}{12cm}{Class hierarchy ofItem}{Item_hierarchy}\subsection{Automata}\begin{tabular}{m{.3\textwidth}l}\hysdel{} source & lhs\_var = logic; \\\hlineclass name & \cppclass{Automata\_item} \\attributes & \code{Expr *logic} \\semantical conditions & lhs\_var must be a Boolean state variable \\& logic must be a logic expression\end{tabular}\subsection{Continuous}\begin{tabular}{m{.3\textwidth}l}\hysdel{} source & lhs\_var = affine\_expr; \\\hlineclass name & \cppclass{Continuous\_item} \\attributes & \code{Expr *affine\_expr} \\semantical conditions & lhs\_var must be a real state variable \\& affine\_expr must be affine\footnotemark\end{tabular}\footnotetext{if neither the \cmdop{a} nor \cmdop{5} option areused, \code{affine\_expr} must be linear (seesection~\ref{affine_in_eq_s})}\subsection{Output}\begin{tabular}{m{.3\textwidth}m{.3\textwidth}m{.3\textwidth}}& Boolean output & real output \\\hysdel{} source & lhs\_var = logic; & lhs\_var = affine\_expr; \\\hlinesuperclass & \cppclass{Output\_item} & \cppclass{Output\_item} \\class name & \cppclass{Logic\_output\_item} & \cppclass{Cont\_output\_item} \\attributes & \code{Expr *logic} & \code{Expr *affine\_expr} \\semantical conditions & lhs\_var a Boolean output variable & lhs\_var a real output variable \\& logic must be a logic expression & affine\_expr must beaffine\footnotemark\end{tabular}\footnotetext{if neither the \cmdop{a} nor \cmdop{5} option areused, \code{affine\_expr} must be linear (seesection~\ref{affine_in_eq_s})}\subsection{AD}\begin{tabular}{m{.3\textwidth}m{.65\textwidth}}\hysdel{} source & lhs\_var = affine\_expr $<= 0$ [mme]; \\\hline& (alternative forms possible) \\class name & \cppclass{AD\_item} \\attributes & \code{Expr *affine\_expr} \\ & \code{Min\_max\_eps *mme} \\semantical conditions & lhs\_var must be a Boolean auxiliary variable \\& affine\_expr must be affine \\remark & Min\_max\_eps contains three \cppclass{Expr} for minimum, maximum and epsilon \\ & if no bounds are given, mme is set to \NULL{}\end{tabular}\subsection{DA}\begin{tabular}{m{.3\textwidth}m{.65\textwidth}}\hysdel{} source & lhs\_var = IF cond THEN affine\_then [mme\_then] [ELSE affine\_else [mme\_else]]; \\\hlineclass name & \cppclass{DA\_item} \\attributes & \code{Expr *cond} \\ & \code{Expr *affine\_then, *affine\_else} \\ & \code{Min\_max\_eps *mme\_then, *mme\_else} \\semantical conditions & lhs\_var must be a real auxiliary variable \\& cond must be logic \\& affine\_then and affine\_else must be affine \\remark & if no bounds are given, the corresponding mme attribute is set to \NULL \\ & the ELSE part can be omitted (a default value of zero will be used) \\\end{tabular}\subsection{Logic}\begin{tabular}{m{.3\textwidth}l}\hysdel{} source & lhs\_var = logic\_expr; \\\hlineclass name & \cppclass{Logic\_item} \\attributes & \code{Expr *logic\_expr} \\semantical conditions & lhs\_var must be a Boolean auxiliary variable \\& logic\_expr must be logic\end{tabular}\subsection{Linear}\begin{tabular}{m{.3\textwidth}l}\hysdel{} source & lhs\_var = linear\_expr; \\\hlineclass name & \cppclass{Linear\_item} \\attributes & \code{Expr *affine\_expr} \\semantical conditions & lhs\_var must be a real auxiliary variable \\& affine\_expr must be affine\end{tabular}\subsection{Must}\begin{tabular}{m{.3\textwidth}ll}& logic must & real must \\\hysdel{} source & constraint & aff1 $<=$ aff2 \\\hlinemeaning & constraint must be true & (constraint=aff1-aff2) $<= 0$ \\superclass & \multicolumn{2}{c}{Constraint\_item}\\class name & \cppclass{Logic\_must\_item} & \cppclass{Cont\_must\_item} \\attributes & \multicolumn{2}{c}{\code{Expr *constraint}}\\semantical conditions & constraint is logic & constraint is affine\end{tabular}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -