Common File Syntax
All domain-specific languages (DSLs) in EvoAl share a common syntax and base concepts. This document explains that syntax and those concepts for users new to EvoAl.
What is EvoAl? EvoAl is a tool that uses domain-specific languages (DSLs) to describe data, definitions, optimisation problems, and surrogate models. Each DSL follows the same basic rules described here.
Fundamentals
Every EvoAl file is organized as a module. Understanding modules is the first step to working with any DSL.
Each DSL file corresponds to exactly one module. A module has a unique name, allowing it to be
referenced from other modules. The following example declares the module com.example. Everything
between the curly braces belongs to this module. In this example, the function helloWorld belongs
to the module com.example.
To use the contents of another module, you must import it. The example below imports everything
from a definitions file containing the module com.example.foo. Since it is just an example, the
imported contents are not used.
import "definitions" from com.example.foo;
module com.example {
// Declares a function named helloWorld that returns nothing (void)
def void helloWorld();
}
Why do we need modules?
When a computer parses a file, it has to assign a meaning to every character sequence it reads.
Often, we as humans use
the same name to mean different things depending on the context. This ambiguity is problematic for
computers, since they cannot guess the intended context. Modules solve this by adding context to a
name, allowing the computer to distinguish between two things with the same name as long as they
belong to different modules. For example, the function helloWorld is part of the module
com.example, and its full, unique name is com.example.helloWorld.
Names
Everything in a DSL file needs a name so EvoAl can identify it. A name must start with a lower- or
upper-case letter or an underscore, and can then continue with any of those characters or digits.
The rule for valid names can be written as the regular expression [a-zA-Z_][a-zA-Z0-9_]*, which
means:
- First character: a letter (
a–zorA–Z) or an underscore (_) - Remaining characters: any letter, digit (
0–9), or underscore
Some examples:
| Name | Valid? | Reason |
|---|---|---|
myVar |
Yes | Starts with a letter |
_count |
Yes | Starts with an underscore |
value1 |
Yes | Digit is allowed after first char |
1stValue |
No | Cannot start with a digit |
If you need more expressive names, EvoAl allows any character sequence as long as you enclose it in
single quotes. For example, 'my special name' is a valid name in EvoAl.
Numbers and Arithmetic
Wherever a value is expected, you can write an expression instead of a single number, e.g.
'probability' := 1 / 30;. A few rules:
/always divides as reals:1 / 5is 0.2, also between two integers. An integer attribute accepts an integral result (10 / 2is 5) and rejects any other (7 / 2) with an error.-is an operator and a sign: numbers have no sign of their own, so4-1and4 - 1are both 3,-4is a negative number, and4 - -3is 7. The sign of an exponent belongs to the number:1.0e-4.- Operators may repeat:
10 - 3 - 2is 5,2 * 5 * 4is 40, and- - 4is 4. - Array elements are expressions:
[-1.0, 2 * 3, 1 / 2].
File Layout
EvoAl derives the expected file location from a module’s name. For example, the module com.example
is expected to be stored at com/example.dl. In other words, dots in the module name correspond to
directory separators, and the last part of the name becomes the file name.
EvoAl checks this rule for every file it loads, the configuration file included: a module
'search' has to be stored in search.ol, not in search-ring.ol. If the names do not match,
EvoAl stops before the run and shows the file and the line, for example:
[ ERROR ] file:/home/user/example/search-ring.ol:11:8: The filename is expected to be 'search.ol'.
Note that the "definitions" part of the import statement determines which file ending EvoAl
appends when looking up the corresponding file.
Import categories and file endings
The following import categories exist and map to these file endings:
| Category | File Ending |
|---|---|
| data | .ddl |
| definitions | .dl |
| optimisation | .ol |
| surrogate | .mll |
Search Path
EvoAl uses a search path to locate modules. It first searches within EvoAl’s own plugins. To make additional modules available, such as your own data or optimisation files, configure the search path using the following parameter:
-Bcore:search-path=<your/path/here>
You can specify multiple paths by separating them with your operating system’s path separator
(: on macOS/Linux, ; on Windows).
Note: At the time of writing, searching within EvoAl’s own plugins is not supported by the Eclipse plugin.
Comments and Documentation
All DSLs support single-line and multi-line comments. Comments are ignored by EvoAl when parsing your file and are intended for human readers.
- Single-line comments start with
//. Everything from that point to the end of the line is ignored. - Multi-line comments start with
/*and end with*/. Everything in between is ignored, even if it spans multiple lines.
// This is a single-line comment
/*
This is a multi-line comment.
It can span multiple lines.
*/