The Generator Demos provide task-oriented description of how to implement a language generator in MPS.
It consists of six related demos. Each demo is based on the previous one and demonstrates more advanced (yet sometimes just different) features, practices and approaches.
The problem we are 'solving' in these demos is generation of a Java Swing GUI from XML.
Although all demos are logically related, we will create a fresh generator in each of the demos. Because a generator can't exist in itself we will create a new language in each demo as well to wrap the generator.
Those languages (except for the last one in demo6) do not introduce own concepts. Instead they give new semantic to existing concepts.
For instance, xml element with name 'button' is not just an xml element any more but 'virtual concept' representing GUI component button.
Note that this is not a way the Language Oriented Programming is normally done. Languages usually are not 'virtual'. But this approach allows us to focus upon our topic - generators development, and leave other aspects of language development out of scope of this document.
Best of all is to install JetBrains MPS on your computer, set-up demo project and carry out all the steps described in demos.
This way you will gain great experience in generators development and beyond.
The second option is to read the documentation and, perhaps, browse generator demo project included into MPS build. The generator demo project includes all the demo languages and generators, as well as test models which we are going to create in these demos.
The generator demo project is located at:
In this demos we are going to define new semantic for xml elements, create test models with some xml in them and generate java code from that xml.
To start with, let's add the 'jetbrains.mps.sampleXML' language to the 'generator_demo' project.
Now the 'jetbrains.mps.sampleXML' language is easily accessible.
Now let's write some xml.
In the model 'text1' create Document and give it name 'Button'.
Result of the text generation will be shown in MPS output view and it will be more or less the same xml as we have on input.
Now we are all set to go on and define semantics for those otherwise meaningless xml concepts.
Demonstrates usage of root mapping rule and root template; property-macro; SWITCH-macro and template switch.
We will also set-up an IntelliJ IDEA project to review and run our generated java applications.
Demonstrates usage of conditional root rule; LOOP-macro and abandon root rule.
Demonstrates usage of weaving rule; template declaration and template fragment; mapping label; 'unique name' service; reference-macro and IF/INCLUDE/MAP_SRC macros.
Demonstrates usage of reduction rule, COPY_SRC-macro and more advanced reference-macro with reference resolving by mapping label.
Explains how to use generation scripts and how to create utility classes in generator.
In this demo we will create a 'real' language defining it own higher-level concepts (button and label) and see how languages are integrated together.
This demo explains in greater details the generation process in MPS and demonstrates usage of transient models and generation tracer tool.