meta-modelling in graphically extended bnf: theoretical foundations and applications hong zhu...

66
Meta-Modelling in Meta-Modelling in Graphically Extended BNF: Graphically Extended BNF: Theoretical Foundations and Theoretical Foundations and Applications Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University Oxford OX33 1HX, UK Email: [email protected]

Upload: ashley-williamson

Post on 28-Mar-2015

213 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Meta-Modelling in Meta-Modelling in Graphically Extended BNF:Graphically Extended BNF:Theoretical Foundations and ApplicationsTheoretical Foundations and Applications

Hong ZhuDepartment of Computing and ElectronicsOxford Brookes UniversityOxford OX33 1HX, UKEmail: [email protected]

Page 2: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 2Nov. 16, 2010

Outline Introduction

Motivation and Related works

Graphic extension of BNF Predicate logic induced from GEBNF syntax Semantics of GEBNF

Axiomatisation of syntactic constraints Algebraic semantics of GEBNF

Institution theory of GEBNF Meta-Models Future works

Page 3: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 3Nov. 16, 2010

Introduction Modelling

To represent a system or a set of systems under study at a high level of abstraction.

A model is a set of statements about the system or a set of systems under study

Meta-modelling To model models = To define a set of

models that have certain features

Page 4: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 4Nov. 16, 2010

Meta-Modelling in MDSD defines modelling languages

syntax: usually at the abstract syntax level semantics: usually in the form of a set of basic concepts

underlying the models and their interrelationships example: the meta-model for UML

imposes restrictions on an existing modelling language a subset of the syntactically valid models example: design patterns-a meta-model whose instances

conform to the design pattern extends an existing meta-model

introducing new concepts and their relationship to the existing ones

example: platform specific models - by introducing platform specific model

elements Aspect-oriented modelling - by extending UML meta-model with

basic concepts of aspect-orientation, such as crosscut points, etc.

Page 5: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 5Nov. 16, 2010

Related Work General purpose MM Languages

MOF and UML class diagram + OCL Special Purpose MM Languages (for example:

design patterns) LePUS (Gasparis et al. 2008; Eden 2001, 2002) RBML (France et al. 2004) DPML (Maplesden at el., 2001, 2002) PDL (Albin-Amiot, et al. 2001)

Problems of graphic meta-modelling Expressiveness? Rigorous in semantics? Readability?

Page 6: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 6Nov. 16, 2010

Overview Formal Meta-Modelling

Meta-notation: GEBNF Definition of abstract syntax of modelling languages Predicate logic languages induced from GEBNF syntax

Applications Specification of a non-trivial subset of UML Specification of consistency and completeness

constraints of UML Specification of design patterns

all 23 in GoF Both structural and behavioural features

Theoretical Foundation Axiomatization of syntax constraints Formal semantics of GEBNF syntax definitions Institution of GEBNF meta-models

Graphic Extension of BNF

Page 7: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 7Nov. 16, 2010

The GEBNF NotationIn GEBNF, the abstract syntax of a modelling language is defined as a tuple <R, N, T, S>, where

N is a finite set of non-terminal symbols, T is a finite set of terminal symbols. Each terminal symbol

represents a set of atomic elements that may occur in a model.

R N is the root symbol and S is a finite set of syntax rules in one of the forms of

Y ::= X1 | X2 | …| Xn

Y ::= f1: X1 , f2: X2 , …, fn: Xn

where Y N, f1, f2 , …, fn are called field names, X1, X2, …, Xn are the fields.

Page 8: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 8Nov. 16, 2010

Field Expression

Each field can be an expression:C is an expression, if C is a literal constant of a

terminal symbol, such as a string or number. Y is an expression, if Y N T.Y*, Y+ and [Y] are expressions, if Y N T.Exp(Y)@Z.f is an expression, where

Y, Z N f is a field name in the definition of Z Y is the type of f field in Z's definition Exp(Y) is an expression of Y only using the above rules

Referential occurrence

Page 9: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 9Nov. 16, 2010

Meanings of the GEBNF Notation

Page 10: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 10Nov. 16, 2010

Example 1: Directed Graphs

where Graph is the root symbolGraph, Node and Edge are non-terminal symbolsString and Real are terminal symbols

Page 11: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 11Nov. 16, 2010

UML Class Diagram (subset)ClassDiagram ::=

classes: Class+, assocs: Rel*, inherits: Rel*, compag: Rel*Class ::= name: String, attrs: Property*, opers: Operation*Operation ::=

name: String, params: Parameter*, isAbstract: [Bool], isQuery: [Bool], isLeaf: [Bool], isNew: [Bool], isStatic: [Bool]

Parameter ::= name: [String], type: [Type], direction: [ParaDirKind], mult: [Multiplicity]

ParaDirKind ::=“in” | “inout” | “out” | “return”Multiplicity ::=lower: [Natural], upper: [Natural | “*”] Property ::= name: String, type: Type,

isStatic: [ Bool], mult: [ Multiplicity]Rel ::= name: [String], source: End, end: EndEnd ::= node: Class, name: [String], mult: [Multiplicity]

Page 12: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 12Nov. 16, 2010

UML Sequence Diagram (subset)SequenceDiagram ::=

lifelines: Lifeline*, msgs: Message*, ordering: Order*

Order::= from: Message, to: MessageLifeline ::=

className: String, objectName: [String], isStatic: Bool, activations: Activation*Activation ::= start, finish: Event, others: Event* Message ::= send, receive: Event, sig: OperationEvent ::= actor: Activation

Page 13: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 13Nov. 16, 2010

Well-Formed Syntax Definitions

A syntax definition <R, N, T, S> in GEBNF is well-formed if it satisfies the following two conditions.Completeness

For each non-terminal symbol X N, there is one and only one syntax rule s S that defines X.

Reachability

For each non-terminal symbol X N, X is reachable from the root R.

Page 14: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 14Nov. 16, 2010

TypesDefinition

Let G=< R, N, T, S> be a GEBNF syntax definition. The set of types of G, denoted by Type(G), is defined inductively as follows.

For all s T N, s is a type, which is called a basic type. P() is a type, called the power type of , if is a type. 1+… + n is a type, called the disjoint union of 1, …, n for

n>1, if 1 … n are types. We also write to denote 1+…+ n.

1 2 is a type, called a function type from 1 to 2, if 1 and 2 are types.

Page 15: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 15Nov. 16, 2010

Induced FunctionsGiven a well-defined GEBNF syntax G = <R, N, T, S>, we write Fun(G) to denote the set of function symbols derived from the syntax rules as follows

A syntax rule ``A ::= B1 | B2 | …| Bn'' introduces a set of functions IsB1, IsB2, …, IsBn of the type A Bool.

A syntax rule ``A ::= f1:B1,…, fn: Bn'' introduces a set of function symbols fi of type A T(Bi), where T(B) is defined as follows.

T(C)=C, if C T N; T([C])=T(C); T([email protected])=T(C); T(C*)= P(T(C)); T(C+)=P(T(C)); T(C1 | … | Cn) = .

Page 16: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 16Nov. 16, 2010

Example 2: Induced Functions

Page 17: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 17Nov. 16, 2010

Induced Predicate Logic Language (FL) From Fun(G), a FL can be defined as

usual [Chiswell 2007]. variables of type TypeGrelations and operators on sets, relations and operators on basic data types

denoted by terminal symbols, equality logic connectives or , and , not , implication

and equivalence , quantifiers for all and exists

Page 18: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 18Nov. 16, 2010

Definition: Inducted Predicate LogicLet be a set of variables, where x V are variables of type .

Each literal constant c of type s T is an expression of type s. Each element v V, i.e. variable of type , is an expression of type Type(G). e.f is an expression of type ', if f is a function symbol of type ', e is an expression

of type { e(x) | Pred(x) } is an expression of type P(e), if x is a variable of type x, e(x) is an

expression of type e and Pred(x) is a predicate on type x. e1 e2, e1 e_2, and e1 - e2 are expressions of type P(), if e1 and e2 are expressions of

type P(). e E is a predicate on type , if e is an expression of type and E is an expression of

type P(). e1 = e2 and e1 e2 are predicates on type , if e1 and e2 are expressions of type R(e_1, …, e_n) is a predicate on type , if e1, …, en are expressions of type , and R is

any n-ary relation symbol on type . e1 e2 and e1 e2 are predicates on type P(), if e1 and e2 are expressions of type P(). p q, p q, p q, p q and p are predicates, if p and q are predicates. xD.(p) and xD.(p) are predicates, if D is a type expression , x is a variable of

type , and p is a predicate.

)(GType

VV

It is first order, if we restrict type to be a terminal or non-terminal symbol s

Page 19: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 19Nov. 16, 2010

Example 3: Function: the set of nodes in a graph g that

have no weight associated with them

Predicate: node x reaches node y in a graph g:

Page 20: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 20Nov. 16, 2010

Constraints on UML In a sequence diagram, every message must start an

activation

Every message to an activation must be for an operation of a concrete class:

If a message is for a static operation, then the lifeline must be a class lifeline; but if a message is for a non-static operation, the lifeline must be an object lifeline:

Every class in the class diagram must appear in the sequence diagram:

Page 21: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 21Nov. 16, 2010

Meta-Modelling in GEBNF + FPL The Approach

Defining the abstract syntax of a modelling language in GEBNF

Defining a predicate p such that the required subset of models are those that satisfy the predicate

Examplestrongly connected graphs

Page 22: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 22Nov. 16, 2010

Example 4: The Object Adapter DP

In GoF book:

Indicate where messages can be sent to rather than a component of the pattern!

In general, there can be a set of such methods!

Page 23: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 23Nov. 16, 2010

Formal Spec of the Object Adapter DP

where predicates are defined using the function symbols induced from the GEBNF definition of UML class diagrams and sequence diagrams.

Page 24: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 24Nov. 16, 2010

Axiomatization of Syntax Constraints (1)Optional Elements

Consider two syntax definitions of a non-terminal symbol A A ::= …, f: [B], … . (1)A ::= ... , g: B , … . (2)

Similarity: Both functions f and g have the type A B,

Difference: For (1), an occurrence of an element of type B in an element of type A is

optional, i.e. f is a partial function For (2), an occurrence of an element of type B is not optional. i.e. g is a

total function. Formalisation:

for each non-optional function symbol g, we require it satisfying the following condition.

x A . (x.g )where means undefined.

Page 25: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 25Nov. 16, 2010

Axiomatization of Syntax Constraints (2)Non-Empty Repetitions

Consider two syntax definitions of a non-terminal symbol A A ::= …, f: B*, … . (1)A ::= ... , g: B+ , … . (2)

Similarity: Both functions f and g have the type A P(B),

Difference: For (1), the set of element of type B in an element of type A is a set (can

be the empty set), For (2), the set of element of type B in an element of type A is a non-

empty set . Formalisation:

for each non-empty repetition function symbol g, we require it satisfying the following condition.

x A . (x.g )

Page 26: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 26Nov. 16, 2010

Axiomatization of Syntax Constraints (3)

Creative Occurrences Consider two syntax definitions of non-terminal symbols Y and Z that both contains non-terminal symbol X

Y ::= …, f: E(X), … . (1)Z ::= ... , g: E’(X) , … . (2)

Both functions f and g have elements of type X as components.

What are the relationships between these elements of type X ?

Page 27: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 27Nov. 16, 2010

FormalisationSituation 1: Two simple type creative

occurrences

Y ::= …, f: E(X), … . (1) Z ::= ... , g: E’(X), … . (2)

where E(X) and E’(X) is one of the expressions X, [ X ], and (X1 | …| X | …| Xn)

Axiom:

Page 28: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 28Nov. 16, 2010

Situation 2: Two set type creative occurrences

Y ::= …, f: E(X), … . (1) Z ::= ... , g: E’(X), … . (2)

where E(X) and E’(X) is one of the expressions X*, and X+,

Axiom:

or simply:

Page 29: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 29Nov. 16, 2010

Situation 3: Two creative occurrences of different types

Y ::= …, f: E(X), … . (1) Z ::= ... , g: E’(X), … . (2)

where E(X) is one of the expressions X, [ X ], and (X1 | …|

X | …| Xn) E’(X) is one of the expressions X*, and X+

Axiom:

Page 30: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 30Nov. 16, 2010

Axiomatization of Syntax Constraints (4)

Referential Occurrences Consider two syntax definitions of a non-terminal

symbol A A ::= …, f: B, … . (1)A ::= ... , f’: [email protected] , … . (2)

Similarity: Both functions f and g have the type A B,

Difference: For (1), the element of type B in an element of type A

is a new element in the model, For (2), the element of type B in an element of type A

is an existing element in the model, already in C.g.

Page 31: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 31Nov. 16, 2010

FormalisationSituation 1: Single reference to single element

Y ::= ... , g: E(X), … . (1)Z ::= …, f: [email protected], … . (2)

where E(X) is one of the expressions X, [ X ], and (X1 | …| X | …| Xn)

Axiom:

Page 32: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 32Nov. 16, 2010

Situation 2: Single reference to set of elements

Y ::= ... , g: E(X), … . (1)Z ::= …, f: [email protected], … . (2)

where E(X) is one of the expressions

X*, and X+

Axiom:

Page 33: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 33Nov. 16, 2010

Situation 3: Set reference to set of elements

Y ::= ... , g: E(X), … . (1)Z ::= …, f: E’(X)@Y.g, … . (2)

where E(X) and E’(X) are one of the expressions X*, and X+

Axiom:

Page 34: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 34Nov. 16, 2010

Example 5 There are two referential occurrences of

non-terminal symbols in the GEBNF syntax definition of directed graphs.

Thus, the functions to and from must satisfy the following conditions.

Page 35: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 35Nov. 16, 2010

Definition: Let G be any well-formed syntax definition in GEBNF. We write Axiom(G) to denote the set of constraints derived from G according to the above rules.

Example: Axiom(DG) contains the following axioms:

Page 36: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 36Nov. 16, 2010

Algebraic Semantics of GEBNFLet G= < R, N, T, S> be a GEBNF syntax definition The signature induced from G: G = (N T, FG),

where FG=Fun(G) is the set of function symbols induced from G.

G-algebra A: {Ax | x NT} of sets {f | FG }, a set of functions, where if is of type X

Y, then f is a function from set AX to the set [[ Y ]], where

Page 37: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 37Nov. 16, 2010

Algebra without Junk

A G-algebra A contains no junk, if

|AR|=1

for all sN and all eAs, we can define a function f : R P(s) in PL such that for some m AR we have e f(m).

There is one and only one root element

Every element in a model must be accessible from the root

Page 38: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 38Nov. 16, 2010

Example 6: Model as Algebra

Page 39: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 39Nov. 16, 2010

Satisfaction of Constraints Assignment in an G-algebra A

a mapping from the set V of variables to the elements of the algebra.

Evaluation of an expression e under an assignment is written [[e]]. (See paper for definition )

A predicate p is true in A under assignment written A |= p, if [[p]] = true.

A predicate p is true in A and written A |= p, if for all assignments in A, A |= p.

Page 40: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 40Nov. 16, 2010

Evaluation of Expressions and Predicates

Page 41: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 41Nov. 16, 2010

Page 42: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 42Nov. 16, 2010

Valid Models A G–algebra A without junk is a syntactically

valid model with respect to G, if for all pAxiom(G), we have that A |= p.

Let MM=(G, p) be a meta-model G is a GEBNF syntax definition and p is a predicate in the FOL induced from G.

The semantics of the meta-model MM is a subset of syntactically valid models of G that satisfy the predicate p.

• This is the standard treatment of predicate logic in the model theory of mathematical logics. [Chiswell 2007]

Page 43: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 43Nov. 16, 2010

Institution of Meta-Models We prove the following statements, thus the institution

structure of meta-models GEBNF syntax definitions + Syntax morphisms form a category Valid models (i.e. algebras) of GEBNF syntax definitions +

homomorphisms between algebras form a category Translation of FL sentences through syntax morphisms is a

functor Translation of valid models through syntax morphisms is a

functor Translations of sentences and models through a syntax

morphism are truth invariant

J. A. Goguen and R. M. Burstall, Institutions: Abstract model theory for specification and programming, J. ACM, vol.39, no.1, pp. 95--146, 1992.

Page 44: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 44Nov. 16, 2010

Review: CategoryA category C consists of

a class Cobj of objects and a class Cm of morphisms or arrows between objects

together with the following three operations: dom: Cm Cobj; codom: Cm Cobj; id: Cobj Cm,

where for all morphisms f, dom(f)=A is called the domain of the morphism f; codom(f)=B the codomain, and the morphism f is from object A=dom(f) to object B=codom(f),

written f : A B. For each object A, id(A) is the identity morphism that its domain

and codomain are A. id(A) is also written as idA.

Page 45: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 45Nov. 16, 2010

There is a partial operation o on Cm, called composition of morphisms. The composition of morphisms f and g, written

f o g, is defined, if dom(f) = codom(g). The result of composition f o g is a morphism

from dom(g) to codom(f). The composition operation has the following

properties. For all morphisms f, g, and h, (f o g) o h = f o (g o h) idA o f = f, if codom(f) = A g o idA = g, if dom(g) = A.

Page 46: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 46Nov. 16, 2010

Syntax MorphismsA syntax morphism from G to H, written :G H, is a pair (m, f) of mappings m: NG NH and f: Fun(G) Fun(H)

that satisfy the following two conditions: Root preservation: m(RG)=RH; Type preservation: for all opFun(G),

(op: A B) (f(op): m(A) m(B)),where we naturally extend the mapping m to type expressions.

Page 47: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 47Nov. 16, 2010

Example 7: Syntax Morphism GEBNF Syntax Definition AR:

Map::= cities: City+, routes: Route*

City::= name, country: :String, population: Real

Route::= depart, arrive: City, distance: Real, flights: TimeDay*

Syntax Morphism from DG to AR: m = (Graph Map, Node City, Edge Route), f = ( nodes cities, edges routes,

name name, weight population,

to arrive, from depart,

weight distance)

Page 48: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 48Nov. 16, 2010

The Category of GEBNF Definition: (Composition of syntax morphisms)

Assume that =(m, f): GH and =(n, g):HJ be syntax morphisms.

The composition of to , written o , is defined as (m o n, f o g).

Definition (Identity Syntax Morphisms) IdG is defined as the pair of mappings (idN, idFun(G) )

Lemma: The above definitions are sound Theorem:

Let Obj be the set of well-formed GEBNF syntax definitions,

Let Mor be the set of syntax morphisms on Obj. (Obj, Mor) is a category.

It is denoted by GEB in the sequel.

Page 49: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 49Nov. 16, 2010

Review: Functor Let C, D be two categories. A functor F from C

to D consists of two mappings: an object mapping Fobj : Cobj Dobj, and a morphism mapping Fm : Cm Dm

They have the following properties. for all morphisms f: A B of category C,

Fm(f) : Fobj(A) Fobj(B). for all morphisms f and g in C,

Fm(f o g) = Fm(f) o Fm(g). for all objects A in category C,

Fm(idA) = idFobj(A).

Page 50: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 50Nov. 16, 2010

Translation of Sentences Given a syntax morphism =(m, f) from GEBNF

defined modelling language G to H, we can define a translation between the PLs induced from them.

Definition: Senobj(G) denotes the set of predicates on the root of G.

Define mapping Senm() from Senobj(G) to Senobj(H):

For each predicate p in Senobj(G),

Each variable v of type in predicate p is replaced by a variable

v' of type m(). Each op Fun(G) in predicate p is replaced by the function

symbol f(op).

Page 51: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 51Nov. 16, 2010

Example 8: Translation of Sentence Consider the syntax morphism defined in

Example 7. The reaches predicate defined in Example 4 can be translated into the following sentence in PLAR.

Page 52: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 52Nov. 16, 2010

Theorem:The pair (Senobj, Senm) is a functor from category GEB to the category SET of sentences in the corresponding induced FLs.

Page 53: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 53Nov. 16, 2010

Constraint Preserving Syntax Morphisms

DefinitionA syntax morphism from G to H is constraint preserving, if for all constraint cAxiom(G) we have that Axiom(H) Sen(c).

Informally, constraint preserving means that the syntax constraints that GEBNF syntax definition G imposes on models are all satisfied by the modelling language defined by H when the notations in G is translated into notations in H.

Page 54: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 54Nov. 16, 2010

Example 9: Constraint Preserving Syntax Morphism

Consider the syntax morphism given in Example 7. It is constraint preserving because for each constraint c

in Axiom(DG), we can prove that Axiom(AR) c', where c' is the translation of c into PLAR according to the syntax morphism.

For instance, the following constraint c on directed graph c = gGraph.(g.nodes )

is translated into c’ = gMap.(g.cities )

according to the syntax morphism. It is easy to see that Axiom(AR) c' because c'

Axiom(AR).

Page 55: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 55Nov. 16, 2010

Constraint Preservation Sub-Category Theorem

The set of well-formed GEBNF syntax definitions as objects and the set of constraint preserving syntax morphisms between them as morphisms form a category

This category is a full sub-category of GEB, because the following statements are true.

For all well-formed GEBNF syntax definition G, IdG is constraint preserving.

If and are constraint preserving syntax morphisms, so is o provided that they are composable.

We write GEBNF to denote this category.

Page 56: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 56Nov. 16, 2010

Translation of Models Lemma:

The models in any given modeling language defined by a GEBNF syntax definition G is a category, where the morphisms are the homomorphisms between the models (i.e. the algebras).

Definition: For each syntax morphism =(m,f) from G to H, the mapping U from category MODH to category MODG is defined as follows.

Let B |MODH|. We define an G-algebra A: For each sNG, As = Bm(s);

For each function symbol op Fun(G), the function op A

is the function f(op) in B.

Denoted by MODG

Page 57: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 57Nov. 16, 2010

Example 10: Translation of ModelsConsider the model of AR shown in (a).

It can be translated into the model of directed graph shown in (b) when the syntax morphism defined in Example 7 is applied.

Page 58: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 58Nov. 16, 2010

Theorem:For each syntax morphism =(m,f) from G to H, the mapping U from objects of category MODH to the objects of category MODG and its naturally induced mapping on homomorphisms is a functor from MODH to MODG.

Page 59: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 59Nov. 16, 2010

Theorem:Let Obj={ MODG | G |GEB| } and

Mor={U | ||GEB}||}.

(Obj, Mor) is a category.

It is denoted by CAT.

GEBNF syntax

Syntax morphism

Page 60: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 60Nov. 16, 2010

Model Translation Functor Definition:

Define MODobj: |GEB| |CATop| as

MODobj(G)= Mod(G);Define MODm: ||GEB|| ||CATop}|| as

MODm(u)= Uop

where for an arrow : a b, op is the inverse arrow of .

Theorem:MOD=(MODobj, MODm) is a functor from GEB to CATop.

Page 61: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 61Nov. 16, 2010

Review: Institution

Page 62: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 62Nov. 16, 2010

GEBNF Institution Theorem:

The tuple (GEB, MOD, Sen, |=) is an institution. In particular, we have that:

The truth of a sentence is invariant under the translation of sentence and the models.

Page 63: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 63Nov. 16, 2010

Example 11: Truth Invariance under Translation

Both statements are true

Both statements are false

Page 64: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 64Nov. 16, 2010

Conclusion

The GEBNF approach to meta-modelling can lay its theoretical foundation on the basis of mathematical logic and the theory of institutions.

Page 65: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 65Nov. 16, 2010

Future Work Application to model transformation Developing software tools to support

meta-modelling in GEBNF Application of theory to facilitate a meta-

model extension mechanism Investigation into the theoretical

foundation of meta-models in UML class diagrams and OCL

Page 66: Meta-Modelling in Graphically Extended BNF: Theoretical Foundations and Applications Hong Zhu Department of Computing and Electronics Oxford Brookes University

Seminar at Shanghai Jiaotong University 66Nov. 16, 2010

References Zhu, H. and Shan, L. Well-formedness, consistency and

completeness of graphic models, Proc. of UKSIM'06, pp.47~53 , Apr. 2006.

Bayley, I. and Zhu, H. Specifying behavioural features of design patterns in first order logic, Proc. of COMPSAC'08, pp. 203~210, Aug. 2008.

Zhu, H., Bayley, I., Shan, L. and Amphlett, R. Tool support for design pattern recognition at model level, Proc. of COMPSAC'09, pp. 228~233 , July 2009.

Shan, L. and Zhu, H. Semantics of metamodels in UML, Proc. of TASE'09. pp.55~62, July 2009.

Bayley, I. and Zhu, H. Formal specication of the variants and behavioural features of design patterns, Journal of Systems and Software, vol. 83, no. 2, pp.209~221, Feb. 2010.

Zhu, H. On The Theoretical Foundation of Meta-Modelling in Graphically Extended BNF and First Order Logic, Prof. of TASE 2010, pp95-104, Aug. 2010.