Software Language Engineering (SLE): design exercices
1. Exercice 1: component architecture DSL
We would like to design a small component architecture DSL that can be used to design the different types of components of a software architecture. The goal is to be able to define software components, and their relationships, without (yet) considering what programming langauges and framework will be used for their implementation.
The expected DSL should allow the definition of an architecture, which contains a set of connector interfaces, a set of component types, and a system (where instances of component types are created and linked).
-
A connector interface simply has a name.
A more realistic DSL should also allow the definition of possible operations or messages allowed by a given connector interface, to design how actual data or control is sent between components. -
A component type has a name, and contains a set of connectors.
-
A connector has a name, a connector interface, and can either provide or require.
-
-
A system has a set of component instances, and a set of links.
-
A component instance has a name, references a component type.
-
A link has a source component instance, a provides connector (of said source instance), a target component instance, and a requires connector (of said target instance).
-
1.1. Question 1
Propose an abstract syntax design for this DSL using a UML class diagram (ie. a metamodel).
1.2. Question 2
Consider that we have a web application architecture, where a frontend uses both a domain API provided by a backend, and a DOM API provided by a web browser. In addition, the backend uses an alert service provided by the frontend to trigger the spontaneous display of an alert message.
Using your abstract syntax, give an abstract syntax tree (AST) corresponding to this description.
1.3. Question 3
The current abstract syntax can be used to create wrong architecture models. Why?
What addditional constraints should be formalized with our abstract syntax to ensure no wrong models could be made?
1.4. Question 4
Using the model of Question 2 as an example, propose a textual concrete syntax for this DSL. Underline the keywords of the textual syntax.
1.5. Question 5
The semantics of this DSL is rather straightforward:
-
each ComponentInstance represents a future software component,
-
each ComponentType define what a given instance should provide/require,
-
all Connectors restrict what links can be made between instances, both because of their type (provides/requires) and because of their ConnectorInterface.
But let’s fast-forward and imagine we implement a semantics for this DSL in the form of a code generator that generates Java code, what could we automatically generate?
2. Exercice 2: robot programming DSL
2.1. Version 1
We would like to design a small robot programming DSL that can be used to program small moving robots with motors and lights. A robot program should define a sequence of actions (moving, rotating, turning light on, etc.) that the robot shall perform when asked.
The DSL should first allow the definition of a robot simulation, which has a a name, a set of declared robots, and a set of declared programs.
-
A robot is declared with a name, and with a set of components. A component also has a name, and can be either a light or a motor. A motor has a power value, and a position (either left or right)
-
A program is declared with a name, and is specific to a robot already defined. A program is a set of commands which can be of different types:
-
changing the color of a given light of the robot (possibilities are: green, red, blue, yellow, none),
-
moving forward a given distance in centimeters,
-
rotating the robot a given angle and a given direction (left or right).
-
2.1.1. Question 1
Propose an abstract syntax design for this DSL using a UML class diagram (ie. a metamodel).
2.1.2. Question 2
Consider that we have a simulation with one robot, two lights, two motors − one with a power of 10, the second with a power of 20. A program is defined for this robot where the robot moves forward 10 centimeters, rotates 45° right, sets its first light to yellow, and moves forward 20 centimeters.
Using your abstract syntax, give an abstract syntax tree (AST) corresponding to this description.