Integrated Model-driven Development Environments for Equation-based Object-oriented Languages




НазваниеIntegrated Model-driven Development Environments for Equation-based Object-oriented Languages
страница14/55
Дата04.10.2012
Размер0.98 Mb.
ТипДокументы
1   ...   10   11   12   13   14   15   16   17   ...   55

3.3High-level Data Structures


To support simple meta-modeling features the MetaModelica extends the Modelica language with new constructs which we present in the following.

3.3.1Union-types


To facilitate meta-modeling of abstract syntax trees we also need to introduce the possibility to declare recursive tree data structures in Modelica, e.g.:

uniontype Exp

record RCONST Real x1; end RCONST;

record PLUS Exp x1; Exp x2; end PLUS;

record SUB Exp x1; Exp x2; end SUB;

record MUL Exp x1; Exp x2; end MUL;

record DIV Exp x1; Exp x2; end DIV;

record NEG Exp x1; end NEG;

end Exp;

A small expression tree, of the expression 12+5*13, is depicted in Figure 3 -20. Using the record constructors PLUS, MUL, RCONST, this tree can be constructed by the expression PLUS(RCONST(12), MUL( RCONST(5), RCONST(13)))



Figure 3 20. Abstract syntax tree of the expression 12+5*13

The uniontype construct has the following properties:

  • Union types can be recursive, i.e., reference themselves. This is the case in the above Exp example, where Exp is referenced inside its member record types.

  • Record declarations declared within a union type are automatically inherited into the enclosing scope of the union type declaration.

  • Union types can be polymorphic

  • A record type may currently only belong to one union type. This restriction may be removed in the future, by introducing polymorphic variants.

This is a preliminary union type design, which however is very close (just different syntax) to similar datatype constructs in declarative languages such as Haskell, Standard ML, OCaml, and RML. The union types can model any abstract syntax tree while the match expressions are used to model the semantics, composition or transformation of the specified language.

3.3.2Lists, Tuples and Option Types


Besides union-types, the MetaModelica language extends Modelica with new high-level types that improve the meta-modeling capability of the language. All these constructs can be type-parameterized.

3.3.2.1Lists


Lists are very useful data structures that are highly used in imperative or functional programming. The syntax of a list is a comma-separated list of values or variables of the same type, e.g. {..., ...}. The following is a list of integers, using the list data constructor:

{1, 2, 3, 4}

The declaration of list variables uses a Java like syntax. For example a variable with its value described by the list above has the following declaration:

list varName;

In MetaModelica the list constructor {..., ...} is overloaded because the Modelica language already contains the same syntax for array construction. The MetaModelica compiler prototype deduces from the context and the variable declarations if the constructor refers to an array or a list. In the pattern matching context, the list constructor is used for the list decomposition.

List can also be constructed/deconstructed using the cons operator :: that constructs/deconstructs a list from its head and its tail (the rest of the list):

1::{2, 3, 4} = {1, 2, 3, 4};

The nil keyword can be used to specify an empty list and is equivalent to {}.

3.3.2.2 Tuples


Tuples are like records, but without field names. They can be used directly, without previous declaration of a corresponding tuple type. The syntax of a tuple is a comma-separated list of values or variables, e.g. (..., ..., ...). The following is a tuple of a real value and a string value, using the tuple data constructor:

(3.14, "this is a string")

The declaration of tuple variables uses a Java like syntax. For example a variable with its value described by the tuple above has the following declaration:

tuple varName;

Tuples already existed in a limited way in previous versions of Modelica since functions with multiple results are called using a tuple for receiving results, e.g.:

(a,b,c) := foo(x, 2, 3, 5);

In the pattern matching context the syntax that constructs the tuple,. reverses its semantics and it used to access the values of its elements.

3.3.2.3Options


Option types are used to model optional constructs. The option types are similar to C/C++ or Java null values. The values of a variable of this type can be NONE or SOME(value):

SOME(3.14);

NONE();

The declaration of option variables uses a Java like syntax. For example a variable with its value described by the option above has the following declaration:

Option varName;

The SOME(...) and NONE() constructors are also used for decomposing option values in the pattern matching context. An option type can also be viewed as a union type consisting of two records SOME (with one field) and NONE (with no fields).
1   ...   10   11   12   13   14   15   16   17   ...   55

Похожие:

Integrated Model-driven Development Environments for Equation-based Object-oriented Languages iconThe Domain Analysis Integrated in an Object Oriented Development Methodology

Integrated Model-driven Development Environments for Equation-based Object-oriented Languages iconHypergraph-based Object-oriented Model for gis application

Integrated Model-driven Development Environments for Equation-based Object-oriented Languages iconObject-Oriented Object-Oriented Languages

Integrated Model-driven Development Environments for Equation-based Object-oriented Languages iconApplying uml and Patterns: An Introduction to Object-Oriented Analysis and Design and Iterative Development (3rd Edition)

Integrated Model-driven Development Environments for Equation-based Object-oriented Languages iconModel Development of a Total Integrated Maintenance System

Integrated Model-driven Development Environments for Equation-based Object-oriented Languages iconAn integrated framework for model-based flow assurance in deep-water oil and gas production

Integrated Model-driven Development Environments for Equation-based Object-oriented Languages iconThis paper introduces the basic concepts of Agile Database Techniques, and effective ways to go about the Data-Oriented aspects of Object Oriented software

Integrated Model-driven Development Environments for Equation-based Object-oriented Languages iconObject-Oriented Metrics: an Annotated Bibliography

Integrated Model-driven Development Environments for Equation-based Object-oriented Languages iconAn Introduction and Brief Examination of Object-Oriented Data Modeling

Integrated Model-driven Development Environments for Equation-based Object-oriented Languages iconAn Object-Oriented Support Tool for the Design of Casting Procedures

Разместите кнопку на своём сайте:
Библиотека


База данных защищена авторским правом ©lib.znate.ru 2014
обратиться к администрации
Библиотека
Главная страница