KerMeta-Tutorial
9 pages
Slovak
Le téléchargement nécessite un accès à la bibliothèque YouScribe
Tout savoir sur nos offres
9 pages
Slovak
Le téléchargement nécessite un accès à la bibliothèque YouScribe
Tout savoir sur nos offres

Description

Kermeta tutorial 1adding behavior to a metamodelFranck Chauvel, Zoé Drey, Didier VojtisekAbstractThis tutorial show how you can specify behavior of a metamodelusing Kermeta.Kermeta tutorial 1adding behavior to a metamodelFranck Chauvel, Zoé Drey, Didier VojtisekPublished Build date: 12-June-2006Table of ContentsPreface .......................................................................................................................... vChapter 1. The basis of metamodel execution .......................................... 1Chapter 2. Specifying behavior of Finite State Machine metamodel ....... 2Chapter 3. Running your FSM ..................................................................... 43.1. A main ............................................................................................................ 43.2. Initial state for the State Machine ................................................................... 43.2.1. The programmatic way .......................................................................... 43.2.2. Loading model from a modeler ............................................................... 43.3. Interactivity .................................................................................................... 43.3.1. Some interactivity .................................................................................. 43.3.2. More ................................................................................... ...

Informations

Publié par
Nombre de lectures 193
Langue Slovak

Extrait

Kermeta tutorial 1
adding behavior to a metamodel
Franck Chauvel, Zoé Drey, Didier Vojtisek
Abstract
This tutorial show how you can specify behavior of a metamodel
using Kermeta.
Kermeta tutorial 1
adding behavior to a metamodel
Franck Chauvel, Zoé Drey, Didier Vojtisek
Published Build date: 12-June-2006
Table of Contents
Preface .......................................................................................................................... v
Chapter 1. The basis of metamodel execution .......................................... 1
Chapter 2. Specifying behavior of Finite State Machine metamodel ....... 2
Chapter 3. Running your FSM ..................................................................... 4
3.1. A main ............................................................................................................ 4
3.2. Initial state for the State Machine ................................................................... 4
3.2.1. The programmatic way .......................................................................... 4
3.2.2. Loading model from a modeler ............................................................... 4
3.3. Interactivity .................................................................................................... 4
3.3.1. Some interactivity .................................................................................. 4
3.3.2. More interactivity ................................................................................... 4
iv
C
HAPTER
Preface
Kermeta is a language dedicated to build executable meta-models as MOF is defined to build
meta-data models. So the aim of this short document is to present the textual syntax of Kermeta.
Kermeta is an simple object-oriented language like Java or Eiffel. To be short we could say Ker-
meta, is an object oriented meta-language.
This tutorial will show you how to add a behavior to your metamodel and how to use it. This is
the first of a serie of several tutorials illustring the various uses cases of Kermeta.
Important
Kermeta is an evolving software and despite that we put a lot of attention to this document,
it may contain errors (more likely in the code samples). If you find any error or have some in-
formation that improves this document, please send it to us using the bugtracker in the
forge: http://gforge.inria.fr/tracker/?group_id=32
Last check: v0.1.0
Tip
The most uptodate version of this document is available online from http://www.kermeta.org .
v
C
HAPTER
1
The basis of metamodel
execution
Kermeta is a metamodeling language allows describing both the structure and the behavior of models.
The basis is quite simple, Ecore, EMOF, MOF allows you to define the structure of your metamodel
including the declaration of operations. However, none of them will allow to specify what are the ex-
pected behavior of those operations.
For example, you can specify the metamodel of a language like a workflow, Java or Kermeta itself, ...
To illustrate this tutorial, let's take a very simple language : a Finite State Machine.
Note
There are other use cases for Kermeta. This will be the subject for other tutorials.
1
C
HAPTER
2
Specifying behavior of Finite
State Machine metamodel
[TODO change this sample with the working one from the CVS.]
In fact, we represent here IO/state-machines where inputs and outputs can be attached on each trans-
ition. To illustrate finites-state machines, here is a simple example. This state machine works on
simple words built with the {a,b} alphabet and replaces “ab” sequence by “ba” sequences and vice-
versa.
Here, we present this finite-state machine in a specific graphical syntax where states are presented as
circles and transitions by arrow between circles. Input and outputs are present above transitions. Here,
“a/b” say that we consume an “a” to produce a “b”.
This simple states-machines can be modelled and executed easily in Kermeta. See the following meta-
model presented in a class diagram syntax.
2
Thanks to the ecore2kmt, you can use any ecore modeller to create the structure of your metamodel.
For example, the simple reflexive tree editor from emf, or graphical editors like Omondo, TopCaseD
and GMF. You'll obtain a version where the operations have an empty body.
package
fsm;
require
kermeta
using
kermeta::standard
// Some data types mapped to the kermeta standard library
alias
String : kermeta::standard::String;
alias
Character : kermeta::standard::Character;
class
FSM
{
attribute
ownedState : set State[0..*]#owningFSM
reference
initialState : State[1..1]
reference
currentState : State
operation
run(input : String) : String
raises
FSMException
is do
// reset if there is no current state
if
currentState == void
then
reset
end
// initialise result
result
:= ""
from var
i : Integer
init
0
until
input.size == i
loop
result
:=
result
+ currentState.step(input.elementAt(i)).toString()
i := i + 1
end
end
operation
reset() : Void
is do
currentState := initialState
end
}
class
State {
attribute
name : String
reference
owningFSM : FSM#ownedState
attribute
outgoingTransition : set Transition[0..*]#source
reference
incomingTransition : set Transition[0..*]#target
operation
step(c : Character) : Character
raises
FSMException
is do
// Get the valid transitions
var
validTransitions : Collection<Transition>
validTransitions :=
outgoingTransition.select { t |
t.input.equals(c) }
// Check if there is one and only one valid transition
if
validTransitions.empty
then raise
NoTransition.new
end
if
validTransitions.size > 1
then raise
NonDeterminism.new
end
// fire the transition
result
:= validTransitions.one.fire
end
}
class
Transition {
reference
source : State[1..1]#outgoingTransition
reference
target : State[1..1]#incomingTransition
attribute
output : Character
attribute
input : Character
operation
fire() : Character
is do
// update FSM current state
source.owningFSM.currentState := target
result
:= output
end
}
abstract class
FSMException {}
class
NonDeterminism
inherits
FSMException {}
class
NoTransition
inherits
FSMException {}
Specifying behavior of Finite State Ma-
chine metamodel
3
C
HAPTER
3
Running your FSM
3.1. A main
3.2. Initial state for the State Machine
3.2.1. The programmatic way
3.2.2. Loading model from a modeler
reflexive tree editor
custom graphical editor (using TopCaseD or GMF)
Note
A more complete version of the FSM metamodel is developed in the Kermeta EMF tutorial. It
demonstrates more completly how to load an initial FSM model. The files can be donwloaded from
www.kermeta.org.
3.3. Interactivity
3.3.1. Some interactivity
simple textual interpreter
3.3.2. More interactivity
full interaction using call to Java.
4
  • Univers Univers
  • Ebooks Ebooks
  • Livres audio Livres audio
  • Presse Presse
  • Podcasts Podcasts
  • BD BD
  • Documents Documents