-
Notifications
You must be signed in to change notification settings - Fork 1
Homework Part 2 ‐ Textual Modeling
The goal of this homework is to create our first textual modeling framework. In this task we will provide a formal grammar for complex Cyber–physical systems, which enables us to model a smart home (as in the previous homework).
For the development of the grammar, we will use the Langium framework. For the development, we can use the online editor as well (available here). The initial project is available here: https://github.com/ftsrg-edu/ase-labs/tree/hw2-starter . To start the homework, copy the branch to your repository or clone your repository and execute the following commands inside it:
git remote add ase-labs https://github.com/ftsrg-edu/ase-labs.git
git fetch ase-labs
git switch hw2-starter
git push -u origin
During this task, we need to do two things:
- We develop a grammar in the hw-2.langium file available here: https://github.com/ftsrg-edu/ase-labs/blob/hw2-starter/src/language/hw-2.langium
- We check if we can parse an example document successfully. Tests will execute the parsing, but we can try out our grammar during development in the online editor by copying the example document into the "Content" window.
The initial version of the hw-2.langium contains a minimal version of the homework, and we can modify this file freely.
During this task, we will create our modeling language for smart home environments. The initial version of the hw-2.langium should be able to parse a simple version of our models, like this:
repository {
// there will be a section for different softwares
}
market {
// there will be a section for different computers
}
cps SmartHome {
// This will be a simplified specification for our smart home
}
In this task, we will create a grammar for specifying different kind of computers in our network. Each computer is specified in the following way:
- First, we start with the keyword computer.
- Then we will continue with a name (like
RaspBerr5M2G
). - Then we need to specify the performance of the processor with the
processor
keyword and the frequency in GHz (e.g.,2.6 GHz
). - Optionally, we can specify the number of cores (like
4 cores
). - Then we need to specify the memory of the computers with the
memory
keyword followed by the memory capacity defined in integer GB (e.g.,2 GB
). - Each computer specification is closed by a semicolon (
;
).
Each specification can contain an arbitrary number of computers. Therefore, we should be able to parse the following document:
repository {
}
market {
computer RaspBerr5M2G processor 2.4 GHz 4 cores memory 2 GB;
computer RaspBerr5M4G processor 2.4 GHz 4 cores memory 4 GB;
computer RaspBerr5M8G processor 2.4 GHz 4 cores memory 8 GB;
computer PersonalComputer processor 3.6 GHz memory 32 GB;
}
cps SmartHome {
}
Next, we will create the grammar for different software.
- Each software start with the keyword
software
. - Then comes the name of the software (like
RaspberryOS
). - Then optionally we can specify a number of dependencies with the
depends
andon
keywords, then referring to the name of the other software. For eample,depends on BasicSensorDriverPack RaspberryOS
means that a software is depending on bothBasicSensorDriverPack
andRaspberryOS
. If we writedepends on
in a software, we need to specify at least a sinlge dependency. - Then optionally again, we can specify the memory requirements with the
requires
andmemory
keywords, followed by the memory requirement measurement in GB (like1 GB
). - We finish all specification with a semicolon (
;
).
Each specification can contain an arbitrary number of software. Therefore, we should be able to parse the following document:
repository {
software RaspberryOS requires memory 1 GB;
software BasicSensorDriverPack depends on RaspberryOS;
software RabbitMQApp depends on BasicSensorDriverPack RaspberryOS;
software FedoraWorkstation requires memory 4 GB;
software OpenControlPanel depends on FedoraWorkstation;
}
market {
computer RaspBerr5M2G processor 2.4 GHz 4 cores memory 2 GB;
computer RaspBerr5M4G processor 2.4 GHz 4 cores memory 4 GB;
computer RaspBerr5M8G processor 2.4 GHz 4 cores memory 8 GB;
computer PersonalComputer processor 3.6 GHz memory 32 GB;
}
cps SmartHome {
}
With the computer and software repository, we can specify our CPS:
- Each cps starts with the keyword
cps
. - Then a name.
- Then a network specification inside curly brackets
{ }
.
The *network is specified with computers and connections (in any order).
A computer is specified in the following way:
- First, we start with the keyword
computer
. - Then we need to refer to a computer type previously specified in the
repository
section. - Then we need to name our computer.
- Then we can list the content of the computer within curly brackets
{ }
. In this grammar, we support two kinds of content (in any order)- We can add instructions to install a hardware with the
add
keyword, which can be "Thermometer", "HeatController", "SmokeDetector", or "FireAlarm" (likeadd Thermometer
). - Amd we can add instructions to install a software from the marketplace with the
install
keyword (likeinstall RaspberryOS
).
- We can add instructions to install a hardware with the
Additionally, the network can contain connections which are specified with the -o)-
operators between the name of two computers (like termometer1 -o)- heatController
). The order of the connection and computer specification is arbitrary.
Therefore, we should be able to write documents in our language like this:
repository {
software RaspberryOS requires memory 1 GB;
software BasicSensorDriverPack depends on RaspberryOS;
software RabbitMQApp depends on BasicSensorDriverPack RaspberryOS;
software FedoraWorkstation requires memory 4 GB;
software OpenControlPanel depends on FedoraWorkstation;
}
market {
computer RaspBerr5M2G processor 2.4 GHz 4 cores memory 2 GB;
computer RaspBerr5M4G processor 2.4 GHz 4 cores memory 4 GB;
computer RaspBerr5M8G processor 2.4 GHz 4 cores memory 8 GB;
computer PersonalComputer processor 3.6 GHz memory 32 GB;
}
cps SmartHome {
computer RaspBerr5M2G termometer1 {
add Thermometer
install RaspberryOS
install BasicSensorDriverPack
}
computer RaspBerr5M2G termometer2 {
add Thermometer
install RaspberryOS
install BasicSensorDriverPack
}
computer RaspBerr5M2G heatController {
install RaspberryOS
install BasicSensorDriverPack
add HeatController
}
termometer1 -o)- heatController
termometer2 -o)- heatController
computer RaspBerr5M2G smokeDetector {
add SmokeDetector
add FireAlarm
install RaspberryOS
install BasicSensorDriverPack
}
smokeDetector -o)- smokeDetector
}
Please extend the grammar with at least 2 extra keywords! The grammar should accept all of the previous documents!
- Moodle, Textual Modeling lecture
- Laboratory material: https://github.com/ftsrg-edu/ase-labs/wiki/Practice-4-%E2%80%90-Textual-editors
- Langium framework documentation https://langium.org/docs/introduction/