📄 class_overview.tex
字号:
\chapter{Internal Representation}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{\cppclass{Symbol}}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 {\tt type} indicates whether the symbolis real or Boolean. Another field gives the \emph{kind} of the variable. It says whether it is a state, input,output or auxiliary variable or a parameter.\subsection{Variables}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 'count', which together withthe type defines the index of this variable in its vector. Theorder is the same as they were declared in the \hysdel{} source.In $x$, $u$ and $y$, the real variables come before the Booleanones.\begin{table}\label{kind-vector}\begin{tabular}{ll}state & $x$ \\input & $u$ \\output & $y$ \\auxiliary (Boolean) & $\delta$ \\auxiliary (real) & $z$\end{tabular}\caption{Names of the variable vectors}\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{\cppclass{Symbol\_table}}The \cppclass{Symbol\_table} maintains a list of all symbols. It is the only class who can create symbols. This isdone by calling\begin{verbatim} Symbol* Symbol_table::create_symbol(Symb_kind kind, Symb_type type, string name)\end{verbatim}It creates a symbol of the specified type, kind and name. A prober count is provided. Sometimes it is necessary tocreate variables that are not declared in the \hysdel{} source. In these cases calling\begin{verbatim} Symbol* Symbol_table::create_additional(Symb_kind kind, Symb_type type)\end{verbatim}will automatically generate a name. The name is {\tt \_\_additional\_$x$}, where $x$ is the number of additionalsymbols created so far. Finally, symbols can be search for based on their name by calling\begin{verbatim} Symbol* Symbol_table::find_symbol(string name);\end{verbatim}\section{\cppclass{Expr}}Mathematical expressions are stored as a parse tree (see Fig.~\ref{parsetree_example}). The parts that form anexpressions can be structured into three classes, all are subclasses of \cppclass{Expr}:\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 divided into:\begin{itemize}\item \cppclass{Variable\_expr} stands for a variable. It contains a pointer to \constcppclass{Var\_symbol}.\item \cppclass{Parameter\_expr} stands for a parameter. It contains a pointer to \constcppclass{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.As an example, the following code generate 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 determined using{\tt bool is\_real()} and {\tt bool is\_logic()}. {\tt boolis\_affine()} tells whether the expression is affine or not. Aconstant is an expression without variables, which is checked by{\tt is\_const()}. If a constant does not contain any symbolicparameters, it can be represented as a number. If {\tt boolis\_number()} is true, the \cppclass{Number} is generated by {\ttNumber *compute\_number()}. At the moment no output variable canbe used in \cppclass{Expr}.\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}. All items of a section are stored in\cppclass{Section}.\subsection{Automata}\begin{tabular}{ll}\hysdel{} source & lhs\_var = logic; \\class name & \cppclass{Automata\_item} \\attributes & {\tt Expr *logic} \\semantical conditions & lhs\_var must be a Boolean state variable \\& logic must be a logic expression\end{tabular}\subsection{Continuous}\begin{tabular}{ll}\hysdel{} source & lhs\_var = affine\_expr; \\class name & \cppclass{Continuous\_item} \\attributes & {\tt Expr *affine\_expr} \\semantical conditions & lhs\_var must be a real state variable \\& affine\_expr must be affine\end{tabular}\subsection{Output}\begin{tabular}{lll}& Boolean output & real output \\\hysdel{} source & lhs\_var = logic; & lhs\_var = affine\_expr; \\superclass & \cppclass{Output\_item} & \cppclass{Output\_item} \\class name & \cppclass{Logic\_output\_item} & \cppclass{Cont\_output\_item} \\attributes & {\tt Expr *logic} & {\tt 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 be affine\end{tabular}\subsection{AD}\begin{tabular}{ll}\hysdel{} source & lhs\_var = affine\_expr $<= 0$ [mme]; \\class name & \cppclass{AD\_item} \\attributes & {\tt Expr *affine\_expr} \\ & {\tt 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}{ll}\hysdel{} source & lhs\_var = IF cond THEN affine\_then [mme\_then] ELSE affine\_else [mme\_else]; \\class name & \cppclass{DA\_item} \\attributes & {\tt Expr *cond} \\ & {\tt Expr *affine\_then, *affine\_else} \\ & {\tt 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 \\ & if no ELSE part is given, a default value of zero is used as affine\_else \\\end{tabular}\subsection{Logic}\begin{tabular}{ll}\hysdel{} source & lhs\_var = logic\_expr; \\class name & \cppclass{Logic\_item} \\attributes & {\tt Expr *logic\_expr} \\semantical conditions & lhs\_var must be a Boolean auxiliary variable \\& logic\_expr must be logic\end{tabular}\subsection{Linear}\begin{tabular}{ll}\hysdel{} source & lhs\_var = linear\_expr; \\class name & \cppclass{Linear\_item} \\attributes & {\tt Expr *affine\_expr} \\semantical conditions & lhs\_var must be a real auxiliary variable \\& affine\_expr must be affine\end{tabular}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -