⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 expr.tex

📁 由matlab开发的hybrid系统的描述语言
💻 TEX
字号:
\chapter{\cppclass{Expr}}\section{Introduction}\hysdel{} is a description language for hybrid systems. Theassociated compiler has been realized using the standard compilerconstruction set: Bison (Yacc clone) + C language + Lex. The aimof this document is not to recall the basic of compilerconstruction which are indeed a prerequisite before reading thispaper. The aim is to drive the coder through the source code of\hysdel{}.\section{Mathematical expressions}\hysdel{} deals with two different kinds of mathematicalexpressions: (i) \emph{Affine} expressions and (ii) \emph{scalar}expressions. The first are expression where the symbols declaredas variables appear only with power zero or one and are multipliedby a scalar coefficient. The latter are any mathematical operationinvolving symbols declared as parameters.A crude implementation would declare two different syntax entitiesfor affine expressions and scalar expressions, as \hysdel{} 0.76(see CVS tag: {\tt hydsel0-76}). This however turned out to be abuggy implementation as the code reported in the file {\ttbuggy01.hys} showed. What was wron with the implementation was thehigh number of shift/reduce and reduce/reduce conflicts in thegrammar (e.g.: Operator ``+'' was defined both in {\tt affexp} andin {\tt scalarexp})The solution to this problem was to completely redesign thegrammar for those two expressions. The new grammar unifies thescalar expression and the linear expression in one new\emph{generic} expression. Implicit casts transform the genericexpression in affine expression or scalar expression when needed.To contain the number of modifications needed the genericexpression builds up the tree of the mathematical expression. Thistree is converted to an {\tt struct aff} or to a {\tt double}number, when the cast is required.The syntactic tree is a collections of {\tt gen} nodes:\begin{verbatim}struct gen {    int             op;         /* name of the operator */    int             nargin;     /* number of arguments */                                /* (0=leaf, 1=unary, 2=binary)*/    int             constant;   /* 1 if all the subtree is a constant */    double         *value;      /* value, if can be computed */    struct gen     *leftside;   /* left side of the operator */    struct gen     *rightside;  /* right side of the operator */    struct symrec  *symbol;     /* link to the entry in the symtable */                                /* used only for the leafs */};\end{verbatim}each node is linked to:\begin{itemize}  \item One node (using the {\tt rightside} pointer), if the operator is unary ({\tt nargin = 1})  \item Two nodes (using the {\tt rightside} and {\tt leftside} pointers), if the operator is binary ({\tt nargin = 2}).\end{itemize}Leafs are marked with {\tt nargin = 0} and are of tree kinds: (i)Numerical values, (ii) Parameters, and (iii) Variables. In thecase of parameters and variables, the pointer {\tt symbol} pointsto the right entry in the symbol table.The integer {\tt op} stores the operator that this noderepresents. For binary operators, this is the {\tt char}representing the operator, for unary operators and leafs, this isthe token value reported by the parser.The pointer {\tt value} stores the numerical value of the resultof the operation, if applicable. It is null if the value of theoperations up to the current node cannot be computed, otherwise itrefer to a memory area where the value is stored.The value {\tt constant} is 1 if the node represent operationsinvolving only constants\footnote{As now the fact that {\ttconstant = 1} implies that {\tt value != 0}, in the future, whenthe parametric \hysdel{} will be implemented, this will not bevalid any longer. Parametric \hysdel{} allows parameters in theparameters section to be uninitialized at compile time. Thereforeit will be possible that a node is constant, but the actual valuedepends on uninitialized parameters and therefore the pointer willbe null.}.The grammar for the {\tt genexp} is the following:\begin{verbatim}genexp:   NUM                 | '(' REAL BOOLVARIABLE ')'        | PARAMETER           | REALVARIABLE        | genexp '+' genexp   | genexp '-' genexp        | genexp '*' genexp   | genexp '/' genexp        | genexp '^' genexp   | '('genexp')'        | '-' genexp          | COS '(' genexp ')'        | EXP '(' genexp ')'  | SIN '(' genexp ')'        | SQRT '(' genexp ')' | LOG '(' genexp ')'\end{verbatim}\figuraeps{gen_tree}{t!}{.8\hsize}{Example of tree generatedtranslating an expression}{fig:gen_tree} Figure~\ref{fig:gen_tree}reports an example of generated tree. Once that this is castedinto affine expression or scalar expression, the syntax is checkedagain. In the proposed example the conversion to scalar expressionwill succeed if and only if all the referenced symbols aredeclared as parameters. Conversion to affine expression willsucceed if at least $s$ or $c$ are declared as parameters.\subsection{Future Developments}The aim of this section is to give some hints to who willimplement the parametric \hysdel{}.The first thing to do is to replace the field {\tt double coeff}in the structure {\tt aff} with the field {\tt gen *coeff}. Thisallows the coefficient to be something different from a number.The functions that perform the casts ({\tt gen2affine} and {\ttgen2scalar}) should be redesigned to keep into account thatscalars and coefficients of affine expression can be lacking anumerical value.All the functions that manipulate the affine structure should bedouble checked and fixed to deal with generic expressions insteadof numerical coefficients. In particular the output function thatwrites the matrices should be able to output the right entries inthe right place.Finally the generated \matlab{} script ({\tt hout.m}, the outputof \hysdel{}) should check that all the uninitialized parametersare provided by \matlab{}.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -