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 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;
}
This example specifies the module de.evoal.core.math
, which must be stored in de/evoal/core/math.dl
.
As described in the common file syntax page, 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—real
in this case—of the constant.
Existing types are described in the following types section.
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 by using instance <structured type name>
and self-defined data.
We will explain these data types in the corresponding sections on structure types and the Data Description 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 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.