Chapter 2. Define abstract syntax

2.1. Terminology and format used in this tutorial

  1. meta-model / Ecore model: both terms are used to point to the meta-model level. “Ecore model” corresponds to the Eclipse terminology for a meta-model specified in Ecore.

  2. instance: in the context of this tutorial, the term “instance” is used to refer to an instance of a meta-model i.e. of an Ecore model. Sometimes we will talk about instance-model (an Ecore model which is an instance of the meta-model) so don't get confused.

  3. model object / root class: in the scope of the EMF dynamic editor, these terms designate the model root class that contains all other ones. This is usually a good practice to define a class which is the only one in a model to have no container (i.e. which has no “black-diamonded” relation pointing to it).[1]

  4. containment: this term designates an important property of classes associations. This property has to be appropriately set[2], in such a way that all the elements of an instance-model should be accessed from the root class of the model, which is aimed at being the highest-level container.

2.2. Define the metamodel

The fisrt step is to focus on the concept of the language that you want to implement. These concepts define the abstract syntax of the language. Usually, it is represented by an ecore metamodel which is the starting point of this tutorial.

So first things first! Let's create the ecore file which is a class-diagram where a class represents a main concept of the language. We won't forget to set up its nsURI. As a standard ecore file, any ecore aware tools can be used to visualize it. To that extent, you can choose to generate/initialize its ecorediag file which contains the graphical informations of the metamodel elements. Then, you can generate the model code provided by EMF genmodel.

With Kermeta, you can also "program" your metamodel. Instead of designing it with its representation, you'll textually define the concepts of your metamodel. By calling the generate ecore metamodel on your Kermeta program source (.kmt), you obtain the ecore file.

[Tip]Tip

If you want to learn more about how to create an ecore metamodel with eclipse, please refer to the "How to create metamodel tutorial".

[Note]Note

An overview of an ecore diagram is available inside the examples below :



[2] EReferenceattributereference