SDM: Week 9 Lab
Week 9 Lab
This lab is an invitation to explore code generation from a (textual) domain specific language. We'll work in Epsilon Live again. I'll give some basic suggestions of what to do here, but you should feel free to get side-tracked and explore differently.
Start in the State Machine to Java example. Begin by looking at the metamodel. Click the ? at the top right of its section to look at the documentation for the Emfatic language in which it is expressed: the key point to understand is that Emfatic is a textual language for the ecode metamodelling language which is part of EMF (click that link at the top of the Emfatic page and read about EMF ecore).
Note that although Epsilon Live allows you to see a graphical visualisation of your metamodel, it does not allow you to interact with the graphical version. It could - that is, it is possible to have an interface in which you can edit a (meta)model using either a textual or a graphical representation, and see either updated as you do so, because they share the same underlying information - and the Eclipse toolset does that, i.e. it allows you to both read and write ecore as a graphical language. I decided not to use Eclipse much this year but if you are curious you could (optionally) have a look at the old labs:
http://www.inf.ed.ac.uk/teaching/courses/sdm/labs/ocl.html
http://www.inf.ed.ac.uk/teaching/courses/sdm/labs/xtext.html
- they might be a bit hard going without in-person support though.
Notice that the textual and graphical notations for ecore have practically identical information content. In general bidirectional transformations can maintain consistency between models (and it could be that one was graphical and the other textual, as here) even if there is sigificant information in each model that is not present in the other. You could think of the ability to interact with a metamodel either by editing its textual presentation, or by editing its graphical presentation, as a particularly simple example of a bidirectional transformation. Epsilon Live only gives you one direction of the consistency restoration: you can edit the text, and have the graphical view updated (but not vice versa).
Feel free (now or later) to modify the metamodel and see what difference it makes...
Next, look at the model (top right) and check you understand how the model you see conforms to the metamodel. Click the symbol to look at its graphical representation too. Make sure you understand what you're seeing: not a specially-designed graphical syntax for the modelling language whose abstract syntax is defined by the metamodel, but "just" an instance diagram corresponding to the metamodel. Again, try modifying the model and seeing whether what happens is what you expect.
Now look at the EGL model-to-text program in the top left. Run it and look at the Java produced.
Next, modify the example so that:
- the metaclass State has a boolean attribute accepting
- the model has state A accepting, the other states not accepting
- the generated program will print true or false, depending on whether the final state reached by following the input string round the state diagram is accepting or not. So, for example, if you should get something like:
[foxley]perdita: java App ABC
false
[foxley]perdita: java App BCA
true
[foxley]perdita: java App BCD
Exception in thread "main" java.lang.IllegalStateException
Do do it yourself! But if you want to see my version it should work to look at
Once that's working, can you modify the model (without touching the EGL template program!) so that java App BCD will print true?