Bit and Pieces Again Presentation for CAMPaM workshop by Anneke - - PowerPoint PPT Presentation

bit and pieces again
SMART_READER_LITE
LIVE PREVIEW

Bit and Pieces Again Presentation for CAMPaM workshop by Anneke - - PowerPoint PPT Presentation

Bit and Pieces Again Presentation for CAMPaM workshop by Anneke Kleppe Contents OCL Using OCL in UML Semantics: Denotational meta-modeling Grasland: Defining languages Concrete textual syntax Future work Sideline:


slide-1
SLIDE 1

Bit and Pieces Again

Presentation for CAMPaM workshop by Anneke Kleppe

slide-2
SLIDE 2

4/27/2006 1

Contents

OCL Using OCL in UML Semantics: Denotational meta-modeling Grasland: Defining languages Concrete textual syntax Future work Sideline: MDA/MDE

slide-3
SLIDE 3

Part 1

Object Constraint Language Version 2.0

slide-4
SLIDE 4

4/27/2006 3

OCL

What is OCL?

Query language on UML models based on

set theory and first order logic

context Program::findType(name: String) : Type body: types->any( t : Type | t.name = name )

slide-5
SLIDE 5

4/27/2006 4

2001-2003: OCL version 2

OMG only wanted definition of abstract

syntax

We gave them:

Abstract syntax Concrete syntax, plus mapping to abstract Semantics

Formal by Mark Richters, Hamburg Univ. UML-based by AK.

slide-6
SLIDE 6

4/27/2006 5

OCL 2.0 Abstract syntax

Defined using meta-model Explicitly defines the associations with

meta-classes in the UML meta-model

slide-7
SLIDE 7

4/27/2006 6

Types Package

Classifier DataType Primitive VoidType OclMessageType CollectionType TupleType SetType SequenceType OrderedSetType BagType OclModelElementType

elementType

slide-8
SLIDE 8

4/27/2006 7

Expressions PACKAGE

ModelElement Classifier ModelPropertyCallExp PropertyCallExp IfExp LiteralExp VariableExp IteratorExp LoopExp IterateExp OclExpression

type type

VariableDeclaration

body iterators referredVariable

OclMessageExp

slide-9
SLIDE 9

4/27/2006 8

Direct Integration With UML

ModelPropertyCallExp OperationCallExp AssociationEndCallExp NavigationCallExp OclExpression AttributeCallExp

arguments

AssociationClassCallExp Attribute AssociationClass AssociationEnd Operation

slide-10
SLIDE 10

4/27/2006 9

Abstract vs. Concrete Syntax

This is an example of the concrete syntax: Formal mapping from concrete to abstract syntax using

attribute grammar

context getYoungCustomers() : Set(Customer) body: customers->select( c | c.age < 18 ) Concrete Syntax Abstract Syntax mapping

slide-11
SLIDE 11

4/27/2006 10

Abstract vs. Concrete Syntax

Standard Concrete Syntax OCL Abstract Syntax mapping Alternative Concrete Syntax 1 mappings Alternative Concrete Syntax 3 Alternative Concrete Syntax 2

slide-12
SLIDE 12

4/27/2006 11

Alternative Concrete Syntax

Business Modeling Syntax: See:

The Object Constraint Language, Getting Your Models

Ready for MDA

Octopus: an Eclipse based IDE for OCL

context getYoungCustomers() : Set(Customer) body: customers->select( c | c.age < 18 ) body: SELECT c : Customer FROM customers WHERE c.age < 18

slide-13
SLIDE 13

4/27/2006 12

OCL Text Files

Concrete syntax for OCL files formalized

package OclBoek::RandL context LoyaltyAccount::points init: 0 context LoyaltyProgram::getServices(): Set(Service) body: partners.deliveredServices->asSet() context CustomerCard::myLevel : ServiceLevel derive: Membership.currentLevel endpackage

slide-14
SLIDE 14

Part 2

Using OCL in UML

slide-15
SLIDE 15

4/27/2006 14

Where to use OCL in UML

Anywhere UML talks about Expression Specific examples:

Pre- and post-conditions Invariants Initial values of attributes and associations Derivation rules Bodies of query operations State invariants Definition of additional attributes and operations Guards in state machines Choice or guard expressions in interaction diagrams Choice expressions in activity diagrams

  • Etc. etc.
slide-16
SLIDE 16

4/27/2006 15

Pre- and Postconditions

Used to specify operations

context Order::place() pre : checkOk() and status = OrderStatus::InPreparation post: status = OrderStatus::Placed

«enumeration» OrderStatus + InPreparation: + Paid: + Placed: + Delivered:

Order + date: String +/ extra: Integer +/ price: Integer + number: Integer + status: OrderStatus + checkOk() : Boolean + place()

slide-17
SLIDE 17

4/27/2006 16

Invariants

Used to specify invariants

context Order inv: price > 0 inv: disks->isUnique(label) context Dvd inv : duration <= Dvd::maxDuration

Dvd + duration: Integer + label: String + price: Integer + maxDuration: Integer Order + date: String +/ extra: Integer +/ price: Integer + number: Integer + status: OrderStatus + checkOk() : Boolean + place() 1..* +disks 1 +order

slide-18
SLIDE 18

4/27/2006 17

Initial values and derivation rules

Used to specify initial values Used to specify derived values

context DVD::label init: ‘default title’ context Order::price derive: disks.price->sum() + extra context Order::extra derive: if clips.price->sum() < 15 then 2 else 0 endif

Dvd + duration: Integer + label: String + price: Integer + maxDuration: Integer Order + date: String +/ extra: Integer +/ price: Integer + number: Integer + status: OrderStatus + checkOk() : Boolean + place() 1..* +disks 1 +order

slide-19
SLIDE 19

4/27/2006 18

Body values

Used to specify the full body of

  • perations

context Order::checkOk() : Boolean body: self.customer.creditcard.expiration. isAfter(Date::today()) context Order::getArtists() : Set(Artist) body: disks.clips.artist->asSet()

Order + date: String +/ extra: Integer +/ price: Integer + number: Integer + status: OrderStatus + checkOk() : Boolean + place() + getArtists() : set(Artist) Dvd + duration: Integer + label: String + price: Integer + maxDuration: Integer Clip + genre: Genre + duration: Integer + price: Integer + title: String + play(Integer) : Boolean Artist + name: String + solo: Boolean Customer + address: String + age: Integer + name: String + allDelivered() : Boolean Creditcard + expiration: Date + name: String + number: Integer «datatype» Date + day: Integer + month: Month + year: Integer + isBefore(Date) : Boolean + isAfter(Date) : Boolean + today() : Date 1..* +disks 1 +order 1..* +clips 0..* +dvd 0..* +clips 0..* +artist 0..* +orders 1 +customer 1 +customer 1 +creditcard

slide-20
SLIDE 20

4/27/2006 19

State charts

Initial preliminary final

«Invariant» {status = OrderStatus::InPreparation} «Invariant» {status <> OrderStatus::InPreparation}

place() [self.checkOk()]

Order + date: String +/ extra: Integer +/ price: Integer + number: Integer + status: OrderStatus + checkOk() : Boolean + place() + getArtists() : set(Artist) «enumeration» OrderStatus + InPreparation: + Paid: + Placed: + Delivered:

slide-21
SLIDE 21

4/27/2006 20

Sequence Diagrams

clip :Clip

  • pt play example

[clip.duration > 0] Actor1 play

slide-22
SLIDE 22

4/27/2006 21

Defining additional attributes

context Order::price derive: disks.price->sum() + extra context Order::extra derive: if disks.price->sum() < 15 then 2 else 0 endif context Order def: basePrice : Integer = disks.price->sum() context Order::price derive: basePrice + extra context Order::extra derive: if basePrice < 15 then 2 else 0 endif

Order + date: String +/ extra: Integer +/ price: Integer + number: Integer + status: OrderStatus + checkOk() : Boolean + place()

slide-23
SLIDE 23

4/27/2006 22

Activity Models

initialize place order

[self.checkOk()] [not self.checkOk()]

refuse and send message to Customer

slide-24
SLIDE 24

Part 3

Defining semantics

slide-25
SLIDE 25

4/27/2006 24

UML-based semantics

Denotational metamodeling (pUML

group)

Build UML model of semantic domain and

map the abstract syntax to it using UML associations

Report: Unification of static and dynamic

semantics of UML (http://www.klasse.nl/research/uml- semantics.html)

slide-26
SLIDE 26

4/27/2006 25

Semantics for OCL

Types Expressions OCL Abtract Syntax OCL Domain Values Evaluations Expression-Evaluation Type-Value OCL AS Domain Mapping

slide-27
SLIDE 27

4/27/2006 26

Example 1

+myType Class

(from abstract syntax)

Object

(from semantic domain)

0..n +semantic mapping 0..n Slot

(from semantic domain)

0..n +attrSlots 0..n Attribute

(from abstract syntax)

0..n +attributes 0..n 0..n +semantic mapping 0..n Type

(from abstract syntax)

1 Value

(from semantic domain)

0..1 +myValue 0..1 0..n +semantic mapping 0..n

slide-28
SLIDE 28

4/27/2006 27

Example 2

OperCall

(from abstract syntax)

OperDecl

(from abstract syntax)

+calls OperExecution

(from semantic domain)

slide-29
SLIDE 29

4/27/2006 28

Weakness

How to model the dynamics of the semantic

domain (SD)?

Answer J.H. Hausmann: Dynamic Denotational

Metamodeling

SD model contains operations which are defined by

graph transformation rules

Needs explicit calling of these operations

Our answer: Operational Denotational

Metamodeling ???

TAAL project

slide-30
SLIDE 30

4/27/2006 29

TAAL project

Abstract syntax is captured in program graph Semantic domain is captured in execution

graph

Execution graph = value graph + frame graph

Value graph: objects and their links Frame graph: info on running processes

Graph transformation rules specify changes in

execution graph

Based on occurences of nodes and edges in both

program and execution graph

slide-31
SLIDE 31

4/27/2006 30

Example: abstract syntax

1 Expression ObjectType 0..1 +superType 0..1 CreateExp +type 1

slide-32
SLIDE 32

4/27/2006 31

Example: semantic domain

ConstrFrame

(from framegraph)

ObjectVal

(from v aluegraph)

Value

(from valuegraph)

Frame

(from framegraph)

0..1 +caller 0..1 0..n +auxiliaries 0..n 0..1 +self 0..1 +self 0..1 0..1 OperFrame

(from framegraph)

slide-33
SLIDE 33

4/27/2006 32

Example rule

Black: required Green: created Blue: deleted

slide-34
SLIDE 34

4/27/2006 33

More on TAAL

Application of rules builds LTS that can

be simulated and investigated

Report at

http://www.cs.utwente.nl/~ kastenbe/papers

/taal.pdf

Paper at FMOODS, June ’06, by

Kastenberg, Kleppe & Rensink

slide-35
SLIDE 35

Part 4

Defining Languages

slide-36
SLIDE 36

4/27/2006 35

Grasland, 2006 - 2008

Graphs for Software Language Definitions Goal: to develop a formalism for defining

software languages using graphs and graph transformations

And tool support

slide-37
SLIDE 37

4/27/2006 36

Language

Definition A language is a 5-tuple L = < AS,

CSS, SD, MS, SMC> consisting of

an abstract syntax (AS), a set of concrete syntaxes (CSS), a set of syntax mappings (SMC), a semantic domain (SD), and a semantic mapping (MS).

(from paper to appear in ECMDA ’06 by Kleppe)

slide-38
SLIDE 38

4/27/2006 37

Mappings and MDA

syntax transformation sema ntic definition transformation stream-base d transformation view transformation refactoring h y b r i d s y n t a x t r a n s f

  • r

m a t i

  • n

structure transformation Conc rete syntax Cn1 Abst ract syntax A1 Sema ntic domai n S1 Conc rete syntax Cn2 Abst ract syntax A2 Sema ntic domai n S2 syntax transformation sema ntic definition transformation

= part of language definition

slide-39
SLIDE 39

4/27/2006 38

Two types of semantics

Direct: semantic definition transformation Translational: structure transformation

(L1 -> L2) + semantic definition transformation of L2

slide-40
SLIDE 40

4/27/2006 39

Language definition 2

syntax transformation sema ntic definition transformation stream-base d transformation view transformation refactoring h y b r i d s y n t a x t r a n s f

  • r

m a t i

  • n

structure transformation Conc rete syntax Cn1 Abst ract syntax A1 Sema ntic domai n S1 Conc rete syntax Cn2 Abst ract syntax A2 Sema ntic domai n S2 syntax transformation sema ntic definition transformation

= part of language definition

slide-41
SLIDE 41

4/27/2006 40

Grasland formalism

Metamodel to define CS, AS and SD

(restricted form of UML)

Metamodel is type-graph of all possible

models

Graph transformations to define syntax

and semantic mapping

  • r syntax and structure transformation
slide-42
SLIDE 42

Part 5

Concrete textual syntax

slide-43
SLIDE 43

4/27/2006 42

Generating textual CS

Algorithm (and implementation) to

transform an AS metamodel into a CS metamodel

CS metamodel defines a tree or forest

Algorithm (and implementation) to

transform a CS metamodel into parser generator input (JavaCC)

LL(n) parser

slide-44
SLIDE 44

4/27/2006 43

Generation of Language-IDE

Only input is AS metamodel

CS metamodel AS metamodel BNFrules text CS model of text AS model of text

parser unparser

is generated

analyser de-analyser

slide-45
SLIDE 45

4/27/2006 44

AS -> CS transformation

Transformation rules:

AS metaclass -> CS metaclass AS composite association -> CS composite

association

AS non-composite association -> CS composite

association to (new) Ref class

AS non-primitive attribute -> CS composite

association

Some classes and associations may be hidden

Rules needed for analyser to determine their value

slide-46
SLIDE 46

4/27/2006 45

Example AS metamodel

+operations TypeDecl name : String conformsTo() findSignature() OperDecl 1 +type 1 0..1 0..n +owner 0..1 {ordered} 0..n ObjectType findAttribute() 0..1 +constructor 0..1 0..1 +superType 0..1 VarDecl name : String 1 +type 1 0..1 0..n 0..1 +params {ordered} 0..n 0..1 0..n 0..1 +localVars {ordered} 0..n 1 0..n 1 +attributes {ordered} 0..n

slide-47
SLIDE 47

4/27/2006 46

Restrictions on AS

No association classes No interfaces No states Two-way associations allowed Non-composite associations allowed Non-primitive attribute types allowed Operations?

slide-48
SLIDE 48

4/27/2006 47

Example CS metamodel

ParsedOperDecl name : String ParsedVarDecl name : String 0..n +params 0..n {ordered} 0..n +localVars 0..n {ordered} ParsedTypeDecl name : String 0..n +operations 0..n 0..n +attributes 0..n ParsedTypeRef name : String 1 +type 1 0..1 +returnType 0..1 0..1 +superType 0..1

slide-49
SLIDE 49

4/27/2006 48

Restrictions on CS for text

Only composite associations All attributes have primitive type No interfaces, states, operations, and other

fancy stuff

Tooling uses property file for ordering, and for

keywords in BNF rules

Class: begin_class, end_class Association end: begin_list, end_list, separator

slide-50
SLIDE 50

4/27/2006 49

CS to BNF transformation

Transformation rules:

CS metaclass -> BNF rule CS inheritance -> BNF choice CS (primitive) attribute -> BNF special token

for strings, numbers etc.

Keywords -> BNF tokens

Some keywords may be empty or

mandatory

Lookaheads added Different formats for lists (16?)

slide-51
SLIDE 51

4/27/2006 50

Example Properties file

TYPEDECL_ORDER_1=name TYPEDECL_ORDER_2=superType TYPEDECL_ORDER_3=attributes TYPEDECL_ORDER_4=operations TYPEDECL_ATTRIBUTES_NAV_END=SEMICOLON TYPEDECL_ATTRIBUTES_NAV_SEPARATOR=SEMI

COLON

TYPEDECL_BEGIN=class TYPEDECL_END=endclass

slide-52
SLIDE 52

4/27/2006 51

Example BNF rules

ParsedTypeDecl_CS ::= <TYPEDECL_BEGIN> <IDENTIFIER> [ <TYPEDECL_SUPERTYPE_NAV_BEGIN> ParsedTypeRef_CS] [ParsedVarDecl_CS (<SEMICOLON> ParsedVarDecl_CS)* <SEMICOLON> ] (ParsedOperDecl_CS)* <TYPEDECL_END> ParsedVarDecl_CS ::= <IDENTIFIER> <COLON> ParsedTypeRef_CS [ <ASSIGN> ParsedExpression_CS] ParsedTypeRef_CS ::= <IDENTIFIER> ParsedOperDecl_CS ::= <IDENTIFIER> <OPERDECL_PARAMS_NAV_BEGIN> [ParsedVarDecl_CS (<COMMA> ParsedVarDecl_CS)*] <OPERDECL_PARAMS_NAV_END> [ <COLON> ParsedTypeRef_CS] [ <OPERDECL_LOCALVARS_NAV_BEGIN> ParsedVarDecl_CS (<SEMICOLON> ParsedVarDecl_CS)* <SEMICOLON> ]

slide-53
SLIDE 53

Part 6

Future work 2007 - …

slide-54
SLIDE 54

4/27/2006 53

Visual concrete syntax

Generation of input for visual editor

generator

Parser often incorporated in editor Separate CS metamodel

slide-55
SLIDE 55

4/27/2006 54

Semantic units

Unit combining

Part of AS metamodel (1) Part of SD model (2) Mapping from 1 to 2

Assumption: any language can be build

from a combination of semantic units

CS(es) added to this combination Goal: library of semantics units Problem: which combinations are allowed

slide-56
SLIDE 56

4/27/2006 55

Complete language-IDE

Editor Parser/analyser Deparser/De-analyser

For each concrete syntax

Simulator

Based on AS and mapping to SD

Translator?

Based on two AS-es and their mappings???

slide-57
SLIDE 57

4/27/2006 56

Open question

For textual languages:

Parse (derivation) tree represents application

  • f production rules

CS metamodel is type graph of parse trees

What is a metamodel w.r.t. other

languages?