SDM: Week 10 Lab

Xtext with the MDENet Education Platform

In this (new, experimental) lab you will have a play with the (new, experimental) MDENet Education Platform. The aim is to give you some hands-on experience with xtext, to supplement the course material on xtext. Xtext is examinable; use of the MDENet Education Platform is not! We'll be using a simplified version of an assignment designed by Steffen Zschaler of KCL, who directs MDENet.

In a new tab open the MDENet Education Platform and click on xtext languge workbench. (For now - feel free to explore the other options too.) It will look somewhat familiar - the MDENet Education Platform builds on the Epsilon Live platform which you have already met (but does things that cannot).

You'll see an xtext grammar for a simple turtle graphics language: study it carefully. The i in the top right of the screen will take you to the xtext reference material if you need to look anything up. Here is a copy for reference (you're about to move on and not have it in front of you any more):

grammar uk.kcl.inf.mdd1.Turtles with org.eclipse.xtext.common.Terminals
generate turtles "http://www.kcl.uk/inf/mdd1/Turtles"
TurtleProgram:
    statements += Statement*
;
Statement:
    MoveStatement | 
    TurnStatement
;
MoveStatement:
    command = MoveCommand '(' steps=INT ')'
;
enum MoveCommand:
    forward='forward' | backward='backward'
;

TurnStatement:
    'turn' direction=TurnCommand 'by' degrees=INT 'degrees'
;

enum TurnCommand:
    left | right
;

When you are ready press the green arrow button near the top right, which will generate an editor for the turtles language. You can ignore a few errors and warnings, e.g. about logging - you should after a while get a Success message, and a Turtles Editor menu item should appear on the left. Click it, and you'll get a different window editor that lets you experiment with the language.

Try writing small programs in the turtles language - for example, can you write a program to go forward three units and then turn left through a right angle? Notice what happens when you make mistakes.

Try clicking the diagram button in the top right of the pane where you're writing your program - you will get a graphical representation of your program. What's happening under the hood: xtext is generating a metamodel from the xtext grammar of the turtles language, and using the correspondence between the grammar and the metamodel, it creates a correspondence between a (textual) program that conforms to the grammar, and a (diagrammatic) model that conforms to the metamodel. This is an example of having two different concrete syntaxes for "the same" language.

Sadly, at present, the "generate code" button in your program pane does nothing! We don't have a means, in the education platform, to illustrate a turtle carrying out the program.  If you go on to use the full xtext tools, though, you can do that kind of thing.

Next, go back to the grammar and change it. Start with small changes like using different keywords or a different way to specify how much to turn; go on to more interesting changes like introducing different kinds of statements (swim, perhaps, or lay eggs...). Generate code and try out your new language. You can even delete the turtle grammar entirely and write a new language... Check that you get what you expect in the model diagram (at a certain point in my play, I didn't...I think I found a bug in the EP, which may or may not still be there when you try this...).

 

As an optional extra, here's the lab I used in week 10 last year, in case anyone would like to have a go at it:

Extra Lab

This final lab of the course is optional, open-ended and challenging! Have fun, if it seems interesting to you.

The idea is to get some hands-on experience with Sirius. These are separate suggestions, roughly in increasing order of size:

  1. Go to the Sirius Web page https://www.eclipse.org/sirius/sirius-web.html and follow the Start Here instructions to register and gain access to a page containing a few test and sample projects (you can log in with the username and password you set, despite the suggestion that you might have to wait for an email). You can't do a lot with them, but have a browse.
  2. Visit https://github.com/eclipse-sirius/sirius-web and follow the QuickStart (it may not be as quick as all that, if you don't already have Docker).
  3. Moving away from Sirius Web to (old) Sirius Desktop, visit https://www.eclipse.org/sirius/gallery.html and browse it, to get an idea of some DSMLs that various users have developed. I was tempted to suggest you follow the Mindstorms tutorial (second in the list) but its github has not been updated in 6 years so, while watching the tutorial videos might be useful, I don't much fancy your chances of getting the hands-on part to work (do boast on Piazza if you do!) The first entry in the list, the Capella workbench, however, does seem to be up to date. You could download Capella and try following the Toy Catapult tutorial here: https://www.eclipse.org/capella/getstarted.html  Note that the Capella tool, introduced here as an interesting example of what can be done on top of Sirius, is in its own right a tool supporting a modelling language and development method for systems architecture, which is a whole 'nother kettle of fish and definitely not examinable. If you do look at this, though, you might like to bear it in mind in the guest lecture on Friday.
  4. Explore the Eclipse ecosystem...

(You might also be interested in this lab from the last version of the course, so I'll put the link here - but note that EuGENia has proved pretty delicate, and its own developers now suggest using Sirius instead. One of the lessons is that there are a lot of moving parts in a tools ecosystem for graphical DSMLs and it really takes full-time engineers, not researchers doing it as a small part of their work, to maintain such an ecosystem. Define a graphical DSML using EuGENia)

License
All rights reserved The University of Edinburgh