Search code examples
mps

Generate Different Text Languages from one DSL with MPS


I'm looking for a way to generate code in several different languages, good start will be ObjC, Java for Android, Unity and JavaScript (Cordova), for repeated code. Currently I'm writing the code manually over and over in each language. I'm looking at MPS and thinking on developing one DSL and generate from it the different code for each language.

My question is does MPS allow to create different TextGen for different languages?


Solution

  • Yes, MPS allows you to target different languages. Surely you need to distinguish between two logical "phases" of the generation process in MPS - the generator, which performs model transformations, and textgen, which transforms models into text. The generator typically transforms the DSL into a general-purpose language (still represented as an AST), while the textgen defined for that general-purpose language transforms the code into text. Several such general-purpose "base" languages currently exist - Java, C, XML and a few prototypes.

    Transforming a DSL directly into text through textgen defined for the DSL is also possible, but feasible for simple DSL only.