home‎ > ‎

DSL - switching from Xtext to MPS

posted Feb 22, 2011, 9:40 AM by Daniel Stieger   [ updated Feb 25, 2011, 12:18 AM ]
According to wikipedia, "a domain-specific language (DSL) is a programming language or specification language dedicated to a particular problem domain, a particular problem representation technique, and/or a particular solution technique." Currently we are aiming at a DSL in order to describe medium sized enterprise-applications. In accordance with domain-driven-design (DDD) we want to describe entities and services with our DSL, additionally we need a type document and worklfows (statemachines) for documents.

While implementing DSL's in declarative style is quite easy to accomplish with xtext (i.e. an entity declaration language), defining control flows get's quite consuming (e.g. for services). After introducing statements and expressions in our DSL, the xtext language structure got more complicated than we imagined. Furthermore, a typesystem was needed and new requirements towards a collection language (analogous to the collection language in xtend) emerged. To put it briefly, we found ourself implementing a DSL which embeds elements of a programming language. A lot of work, a lot of errors, a lot of problems. Would n it be smart to built our DSL on top of basic language elements (like expressions or a collection language)? This would allow us to focus more on our problem domain.

This is where language orientated programming and MPS from jetbrains comes into play. MPS allows you to built a DSL on top of a java base-language implementation. Of course you do not have to embed all language elements available in java. Just select those important to your DSL (e.g. expressions). Following this idea (after evaluating MPS), our approach changed slightly. Instead of developing our DSL from scratch, we rely on jetbrains java base-language implementation and build our DSL on top.

Starting with MPS seems the be a little bit harder compared to xtext since MPS is more abstract at a first glance. However, plenty of documentation and tutorials are available which allow self-study. We found the following tutorials especially helpful (starting from basic to more sophisticated topics):

  1. MPS calculator-tutorial:  http://www.jetbrains.com/mps/docs/tutorial.html

  2. LWC11 MPS tutorial: http://code.google.com/p/mps-lwc11/wiki/GettingStarted

  3. Mirko Richter´s MPS tutorial:  http://www.compago.de/confluence/display/md/Extending+MPS+BaseLanguage+by+Example+-+Complete
    (very interesting tutorial - shows base-language enhancements. You can find his tutorial as printable pdf in the attachments section below, images
     are rescaled and embedded between the text )

Good luck while doing "monkey see, monkey do" ....

Daniel Stieger,
Feb 23, 2011, 12:16 AM