Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


Info
titleXtext tutorials

The two Xtext tutorials are stand-alone tutorials. You do not need to do the Xtext I tutorial in order to perform the Xtext II tutorial. Ask your supervisor which tutorial suits you best.

This installment of our little series of tutorials will be all about Xtend, a programming language that looks very similar to Java, but which adds some very convenient features. Xtend code compiles to Java and and was developed using Xtext. In fact, once you gain experience working with Xtend you will probably appreciate the power of Xtext even more.

...

Exciting stuff, so let's begin

 

Table of Contents

Preliminaries

We have prepared a metamodel of our simple imperative programming language:

...

  • Model files have the file extension ".imperative", while textual files have the file extension ".pseudo". When saving a model using EMF, the file extension of the file you save the model into will determine the output format.
  • Each IfStatement requires both, a statement for the true case and a statement for the false case. You will not always need both. Use a Block statement as an empty statement when required.

Writing the Transformation

Now that you have familiarized yourself with the programming language's metamodel it's time to start working on your transformation:

...

What Should the Imperative Program Do?

Icon

The imperative program model should not describe a completely working program, complete with command-line parsing for input arguments and printing out the program's output. Instead, think of the program to magically receive those variables marked as input variables, and to magically output whatever it is the program returns (using the Return statement). In the next tutorial, you will use Xtend's code generation features to generate working source code in your favourite programming language. The code you generate will contain a wrapper around your actual programming, including code that actually initializes the input variables and outputs the returned expression.

Testing the Transformation

You will need a way to test the transformation, so we will have to make it available through the UI. Eclipse plug-ins often come with a separate UI plug-in that contains the UI contributions, with the base plug-in only offering the functionality itself. In our case, our base plug-in contains the transformation code, and the UI plug-in we will be creating next contains a menu contribution to make the transformation available.

...