Few notes on how to implement the Modelica Language Specification in Xtext
Modelica, Xtext and EMF
Modelica is a language for modeling of physical systems built on object-oriented constructs to facilitate reuse of modeling knowledge. Modelica language, in the scope of this exercise, is just another domain specific language (DSL).
Xtext is a framework for development of programming languages and domain-specific languages.
The topic of this article has been covered by others. The following list is a reference to similar resources found online:
- ModelicaML – the project provides an UML profile for Modelica and a set of tools for models development and model to model translation. The project uses Xtext as framework for the development of specialized editors and defines a Xtext grammar linked to an existing Modelica EMF model. The Xtext grammar is available from the repository of the MDT project
- OneModelica – is a promising project of an Eclipse-based Modelica IDE. The specialized editors are derived using Xtext starting from an optimised implementation of the language specification. OneModelica source code has not been released (yet?) but the Xtext grammar is available in Appendix A of the dissertation An Integrated Development Environment with Enhanced Domain-Specific Interactive Model Validation by Roland Samlus (however, a first attempt to compile the grammar at hand was unsuccessful)
The Xtext grammar of the Modelica language is available on GitHub. This particular implementation tries to be as much as possible compliant with the language specification version 3.3 rev.1, with the exceptions detailed below.
- different implementation of comments
- addition of unary arithmetic to deal with signed numbers
- custom implementation of Annotation (to be completed)