Skip to content

NaoMod/FSM-with-MPS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FSM with MPS

This project shows an implementation of a Domain Specific Language for Finite State Machines with the language workbench MPS.

To properly run the project, you will need to download a specific MPS plugin. Plugins management is done in File > Settings > Plugins. Then, search for MPS Table Editor Component in the marketplace and install the plugin.

Using the DSL

Models can be created using the DSL in the solution naomod.fsm.sandbox.

Solution Menu

A FSM is already modeled in the ExampleFSM. You can play with it, but we suggest that you create your own instead of modifying the example.

Example FSM

To create a new FSM, right-click on the sandbox_model, and choose New > FSM. This will open a new window where you can enter a name for your FSM. By placing your cursor on the dots and pressing enter, a new state will be added to this FSM.

New FSM

This state needs to be named. Keywords initial and final can also be used : place your cursor before the state text, begin typing the keyword and press Ctrl+Space to autocomplete. For each state, outgoing transitions can be specified in the table next to it. Place your cursor on the last line of the table and press Enter to add a new entry. Possible target state can be browsed by pressing Ctrl+Space, while input and output are just regular strings. To add more states, place your cursor at the end of the file and press Enter.

To launch an execution of your automata place your cursor on the first line and either click the lightbulb icon or press Alt+Enter. Then choose 'Run the Interpreter', a small UI should appear.

Interpreter Intention

You can then enter your input and press the 'Compute Step' button to trigger the transition with said input (if it exists). The output string of the last transition as well as the current state are displayed in dedicated fields. To check if the execution is successful (ie. the current state is final), press the 'End' button. The 'Computation Result' field will show the outcome of the execution.

Exploring the Definition

The definition of this DSL is done in the language naomod.fsm.

Language

The structure aspect describes the abstract syntax of the DSL. Concepts and their properties are defined, as well as the relations between them.

The editor aspect handles the defintion of the concrete syntax for our language. The plugin de.slisson.mps.tables is used to manipulate the tabular notation.

The constraints aspect is used to describe part of the static semantics, the other part is in the typesystem aspect.

The behavior aspect describes operationnal semantics for the State concept, as well as classes implementing the interpreter. FSMInterpreter is the interpreter itself, FSMContext is the class storing the execution context and is used by the interpreter, and UI handles the graphical interface used by the user to interact with the interpreter. The button launching the interpreter is described in the intention aspect.

If changes are made to the language definition, make sure to rebuild it by right-clicking on 'naomod.fsm' and choosing 'Rebuild Language'.

References

  • https://www.jetbrains.com/help/mps/mps-user-s-guide.html

  • https://mps.rocks/

  • Voelter, M., Benz, S., Dietrich, C., Engelmann, B., Helander, M., Kats, L. C. L., Visser, E., & Wachsmuth, G. (2013). DSL Engineering—Designing, Implementing and Using Domain-Specific Languages. dslbook.org.

  • Voelter, M. (2013). Language and IDE Modularization and Composition with MPS. In R. Lämmel, J. Saraiva, & J. Visser (Éds.), Generative and Transformational Techniques in Software Engineering IV: International Summer School, GTTSE 2011, Braga, Portugal, July 3-9, 2011. Revised Papers (p. 383‑430). Springer. https://doi.org/10.1007/978-3-642-35992-7_11