Eclipse Modeling Framework (EMF)

The Eclipse Modeling Framework (EMF) can be used to describe other languages (meta-language)

ECore Model

An example of an Ecore model can be drawn like this:

ecore model

So what is the structure of this model? We could define this as a meta-model (meta-meta-language?)

see Ecore metamodel on the eclipse website here.

ECore Model Elements

EObject : All these model elements below extend EObject. EObject is the base of all model elements in the same way that all java classes extend Object.

EPackage:

EClass : represents a class, with zero or more attributes and zero or more references.

EAttribute : represents an attribute which has a name and a type.

EReference : represents one end of an association between two classes. It has flag to indicate if it represent a containment and a reference class to which it points.

EDataType : represents the type of an attribute, e.g. int, float or java.util.Date

Generating an ECore model

From Xtext

The grammar file not only defines the synatx of a text file, but also how it maps to an ECore model.

There are 4 types of rule.

Rule type Returns identified by Used by
Parser Rules EClass   Parser
Enum Rules EEnum start with 'enum' Parser
Datatype Rules EDatatype (EString is implied if none has been explicitly declared)

rules that do not:

  • call other parser rules
  • contain any actions
  • contain assignments
Parser
Terminal Rules EDatatype start with 'terminal' Lex

rule types

If we want a Syntax element to map to a model element then we should preceed it with one of the following forms:

Syntax Element Model Element
myName =  
myName += returns list
myName ?= returns true/false

he grammar file not only specifies the grammar and generates the lexer and parser but it also has an additional function, to specify the mapping to the Ecore model.

I am not planning to fully explain the ECore (EMF) model structure here, but roughly, we have an EPackage and inside that a set of EClasses and inside that a set of EDatatype, EReference. and EAttribute s, Like this:

EPackage {
   EClass MyModel {
        containment entities : Entity[]
   }
   EClass Entity {
        name : EString
        extends : Entity // the crosslink
   }
}

ECore model and GMF

More on ECore here

Further Reading


metadata block
see also:
Correspondence about this page

Book Shop - Further reading.

Where I can, I have put links to Amazon for books that are relevant to the subject, click on the appropriate country flag to get more details of the book or to buy it from them.

 

 

Commercial Software Shop

Where I can, I have put links to Amazon for commercial software, not directly related to this site, but related to the subject being discussed, click on the appropriate country flag to get more details of the software or to buy it from them.

 

This site may have errors. Don't use for critical systems.

Copyright (c) 1998-2017 Martin John Baker - All rights reserved - privacy policy.