|
|
The definition language lets EvoAl extenders specify their extension for the domain-specific languages. For this purpose, it provides capabilities to describe types and functions and allows you to define constants. The files follow the standard [file structure](DSL/Common File Syntax) and have the file ending ```.dl```. Whether you must define constants, functions or types—or all—depends on the extension you create.
|
|
|
|
|
|
# Constants
|
|
|
A constant is a non-changeable value that can be used in any DSL, e.g. the constant π. π is a value that can come in handy in many situations. Therefore, we can define it using the following
|
|
|
specification in a definition module:
|
|
|
|
|
|
```
|
|
|
module de.evoal.core.math {
|
|
|
const real PI := 3.1415926535;
|
|
|
}
|
|
|
```
|
|
|
|
|
|
As described in the [common file syntax page](DSL/Common File Syntax), we can also use the name π itself:
|
|
|
```
|
|
|
module de.evoal.core.math {
|
|
|
const real 'π' := 3.1415926535;
|
|
|
}
|
|
|
```
|
|
|
|
|
|
The keyword ```const``` tells EvoAl that a constant definition follows. Then, we have to specify the type of the constant. Existing types are described in the section below. Afterwards, the constant's name is defined, followed by the constant value.
|
|
|
|
|
|
# Types
|
|
|
In EvoAl, data is typed, meaning every expression has a type. EvoAl pre-defines a limited set of basic data types to use: ```boolean```, ```int```, ```real```, ```string```, and ```void```. Additionally, every type can be used in an array as well as shown in the following example:
|
|
|
|
|
|
```
|
|
|
import "definitions" from de.evoal.core.math;
|
|
|
|
|
|
module com.example {
|
|
|
|
|
|
const boolean booleanValue := true;
|
|
|
|
|
|
const int integerValue := 1;
|
|
|
|
|
|
const real realValue := 2.0;
|
|
|
|
|
|
const string stringValue := "Hello EvoAl";
|
|
|
|
|
|
const array array int twoDimensional := [
|
|
|
[1, 2],
|
|
|
[3, 4]
|
|
|
];
|
|
|
|
|
|
// the example is continued below
|
|
|
}
|
|
|
```
|
|
|
|
|
|
Furthermore, it is possible to use a self-defined [structure type](DSL/Definition-Language#structured-types) by using ```instance <structured type name>``` and self-defined [data](DSL/Data Definition Language). We will explain these data types in the corresponding sections on [structure types](DSL/Definition-Language#structured-types) and the [Data Description Language](DSL/Data Definition Language).
|
|
|
|
|
|
|
|
|
# Functions
|
|
|
In some cases, EvoAl allows you to define functions, for instance, goodness-of-fit measures for the surrogate training. A function definition starts with the keyword `def`. After that, a function has a return type, which may be `void` if your method does not return a value. Afterwards, you specify the function's name and the list of parameters (enclosed by parentheses).
|
|
|
|
|
|
```
|
|
|
// ...
|
|
|
def void 'my-function'(expression parameter);
|
|
|
|
|
|
// the example is continued below
|
|
|
```
|
|
|
|
|
|
The shown code-snipped defines a function called `my-function` of type `void` that expects a single parameter. In this case, the parameter is expected to be an expression of some type that the function will interpret.
|
|
|
|
|
|
|
|
|
# Structured types
|
|
|
A type allows you to specify structured data. It is comparable to classes from object-oriented programming languages (except for no methods) or structures.
|
|
|
|
|
|
```
|
|
|
// ...
|
|
|
|
|
|
abstract type shape {
|
|
|
x : int := 0;
|
|
|
y : int := 0;
|
|
|
}
|
|
|
|
|
|
type circle extends shape {
|
|
|
circumference : real := 2 * 'π' * 4.0;
|
|
|
}
|
|
|
|
|
|
// the example is continued below
|
|
|
```
|
|
|
|
|
|
The example above defines an abstract type named ```shape``` in the module ```com.example```. The abstract modifier tells EvoAl that this type cannot be used in one of the other DSL files. Instead, it can be referenced by other type definitions. The ```shape``` defines two integer attributes, called ```x``` and ```y``` and assigns them a default value.
|
|
|
|
|
|
In the example, the type ```circle``` extends the ```shape```. This means the circle inherits all attributes of ```shape``` and adds the ```circumference``` attribute. In this case, the default value is more complex and uses the afore-defined constant ```'π'``` from module ```de.evoal.core.math```.
|
|
|
|
|
|
# Documentation
|
|
|
Like well-known programming languages like Java, EvoAl interprets multi-line comments in front declarations (constants, functions, types, and attributes) as the declaration's documentation. Documenting your definition files will help users to use your extensions since they will see the documentation as a tooltip. Thus, we suggest you to document your extensions properly. |
|
|
\ No newline at end of file |