a dstl to bridge concrete and abstract syntax

Post on 13-Apr-2017

137 Views

Category:

Engineering

7 Downloads

Preview:

Click to see full reader

TRANSCRIPT

A DSTL ToBridge Concrete and

Abstract SyntaxAdolfo Sánchez-Barbudo Herrera, Edward D. Willink and

Richard F. Paige

Agenda

● Scope● Problem● Solution● Comparative Study

2

Scope● Complex Textual Modeling Languages

○ CS is textual (particularly, defined by a grammar)○ AS is model-based (particularly, defined by a meta-model)○ Complex Language = AS definition can not be directly inferred from CS definition

● Examples○ Languages specified by OMG, such as OCL and QVT languages.○ OCL specification defines the CS via a grammar (Clause 9.3)○ OCL specification defines the AS via a meta-model (Clause 8) ○ OCL specification describes how to obtain AS from CS (Clause 9.4)

3

Agenda

● Scope● Problem● Solution● Comparative Study

4

Problem● Related works (e.g. Xtext) allow to map CS grammars to AS meta-models, but...● let … in x.y -- an OCL expression

○ ‘y’ is a navigation (i.e. a PropertyCallExp in the AS)○ ‘x’ ? → It depends on the context

y:PropertyCallExp

x:VariableExp

ownedSource

x:PropertyCallExp

self:VariableExp

y:PropertyCallExp

ownedSource ownedSource

‘x’ is a variable name

‘x’ is aproperty name (i.e self.x.y)

5

Problem II

CallExpCS:PrimaryExpCS ( ('.' | '->') NameExpCS)*

NameExpCS:SimpleNameCS (RoundedBracketClauseCS)?

SimpleNameCS:ID;

RoundedBracketClauseCS:'(' (ExpCS (',' ExpCS)* )? ')'

OCLExpression

OperationCallExp

VariableExp

PropertyCallExp

Problem: Syntactically, it can not be determined if a simple name corresponds to a PropertyCallExp or VariableExp

6

Problem III● Support to non-simple (i.e. 1-1) CS2AS mappings

○ e.g. a NameExpCS may map to a VariableExp and PropertyCallExp (output pattern)

● Support to cross-references computation○ e.g. an OCLExpression is a TypedElement: it requires a type cross-reference to be computed

● Name resolution○ Special case of cross-reference computation○ e.g. a VariableExp requires to refer to a Variable.

● CS Disambiguation○ e.g. a NameExpCS may map to either an OperationCallExp, or a PropertyCallExp, or a

VariableExp

7

Agenda

● Scope● Problem● Solution● Comparative Study

8

Solution

Generates

Manual artefactGenerated artefact

ASMM

conformsTo

ASModel

conformsTo

TextualInput

CSGrammar

CSMM

Parser

CS Model

conformsTo

(e.g. like Xtext)

M2M tx

from toCS2ASBridge

(modelware)

9

Solution II● (External) DSTL to bridge CS and AS (meta-models).● Why is domain-specific

○ Just one input domain and one output domain (no in-place tx)○ Specific constructs for name resolution○ Specific guards semantics for disambiguation rules

● Features:○ Declarative (M2M) language○ Resuses Essential OCL as expressions language○ Currently, four sections

■ helpers■ mappings■ disambiguation rules■ name resolution

10

DSTL: Helpers● To define contextual operations

helpers {NameExpCS::parentAsCallExpCS() : CallExpCS =

let container = self.oclContainer()in if container.oclIsKindOf(CallExpCS) then container.oclAsType(CallExpCS) else null endif

NameExpCS::isNameExpOfACallExpCS() : Boolean =let parentCallExpCS = parentAsCallExpCS()in parentCallExpCS <> null and parentCallExpCS.nameExp = self }

body

resultcontext

11

DSTL: Mappings● To define mappings between CS and AS (meta-)classes

mappings {map PropertyCallExp from NameExpCS

when isPropCallExpWithImplicitSource {ownedSource := let referredVar = trace.lookup(Variable, 'self')

in VariableExp {referredVariable = referredVar,type = referredVar.type }

referredProperty := trace.lookupExported(Property,trace.ownedSource.type, expName),

type := trace.referredProperty?.type}}

Mapping guard

AS property initialization

To access AS domain from the CS one Lookup

expressions

Target AS term

Source CS term

12

DSTL: Mappings II● Multi-way mappings (same NameExpCS mapped to different outcomes)

mappings {map PropertyCallExp from NameExpCS

when isPropCallExpWithImplicitSource { … }map PropertyCallExp from NameExpCS

when isPropCallExpWithExplicitSource { … }map OperationCallExp from NameExpCS

when isOpCallExpWithExplicitSource { … }map OperationCallExp from NameExpCS

when isOpCallExpWithExplicitSource { … }map VariableExp from NameExpCS

when isVariableExp { … } }

Same source (CS)

Differenttargets (AS)

13

DSTL: Disambiguation Rules● To define disambiguation rules

disambiguation {NameExpCS {

isOpCallExpWithImplicitSource := roundedBrackets <> nulland not isNameExpOfACallExpCS()

isOpCallExpWithExplicitSource := roundedBrackets <> nulland isNameExpOfACallExpCS()

isPropCallExpWithExplicitSource := roundedBrackets = nulland isNameExpOfACallExpCS()

isVariableExp := … isPropCallExpWithImplicitSource := …

} }

CS element to disambiguate

Disambiguation rule name

Boolean-valued expression

Important: Order matters14

Name Resolution● Activity to solve AS cross-references, which involve a name-based lookup

○ From an AS element another named AS element needs to be found in the model.○ Declaratively, it’s matter of how named elements are contributed to lookup scopes.○ Scopes are key data structures that keep all visible named element within that scope.

● Scopes:○ Current Scope ○ Exported Scope○ Nested Scopes

15

Name Resolution II● Current Scope

class C1 {prop p1 : String;op getP1(): String = p1;

}

:ExpressionInOCL

:PropertyCallExp

class C2 {op getP1() : String = p1;

}

:ExpressionInOCL

:PropertyCallExp

C1:Class

p1:Property

getP1:Operation

referredProperty

C2:Class

getP1:Operation

referredProperty

16

Name Resolution III● Exported Scope

class C1 {prop p1 : String;op getP1(): String

= p1;}

class C2 {prop c1 : C1;op getP1() : String

= c1.p1;}

:ExpressionInOCL

:PropertyCallExp

:ExpressionInOCL

:PropertyCallExp

C1:Class

p1:Property

getP1:Operation

referredProperty

getP1:Operation

referredProperty

:PropertyCallExp

referredProperty

C2:Class

c1:Property

17

Name Resolution IV● Nested Scope (name oclusssion)

-- valid expression which -- evaluates to falselet v = ‘foo’in let v = ‘bar’ in v = ‘foo’

‘foo’:StringLiteralExp

:LetExp

:LetExp

v:Variable

v:Variable

‘bar’:StringLiteralExp

‘foo’:StringLiteralExp

‘=’:OperationCallExp

:VariableExp

‘v’ -> Variable (‘foo’)

‘v’ -> Variable (‘bar’)parent

nested

18

DSTL: Name Resolution● To define name resolution

targets {NamedElement using name; -- ’name’: property used to identify ’targets’Property; -- ’using’ is optional: extends a fully defined ’target’ element }

inputs {SimpleNameCS using name; -- ’name’: property used to match ’targets’ }

providers {Class {

in current-scope provides occluding ownedProperties;

in exported-scope provides ownedProperties; } } 19

DSTL: Name Resolution II● Slightly more complex name resolution

providers {Class {

in current-scope providesoccluding ownedPropertiesoccluding getAllSuperClasses().ownedProperties;

in exported-scope providesownedPropertiesoccluding getAllSuperClasses().ownedProperties;

} }

20

DSTL: Name Resolution III● Expressions to perform name-based lookups

trace.lookup(Variable, 'self')

Kind of target to look up

trace.lookupExported(Property,trace.ownedSource.type, expName)

The lookup input (a String)Lookup in current scope

Lookup in a exported scope

Kind of target to look up

Actual element providing the exported scope

The lookup input (a SimpleNameCS)

21

Agenda

● Scope● Problem● Solution● Comparative Study

22

Comparative Study: Gra2Mol● Gra2Mol

○ DSTL can be used for the same purpose: bridging CS and AS syntax

○ Map arbitrary grammars to arbitrary AS meta-models

Source Target Nature Query Language

Gra2Mol GrammarTerms

AS MMTerms

Declarative Structure-Shy (Xpath Like)

CS2ASDSTL

CS MMTerms

AS MMTerms

Declarative Statically Typed(Essent. OCL)

23

Qualitative Study● Gra2Mol pros:

○ Query Language is more concise (few and effort-saving navigation operators)

○ Provides a language extensibility mechanism

● CS2AS DSTL pros:○ OCL has more expressive power (beyond simple model navigation)

○ AS model can be navigated (Gra2Mol QL only operates at CS level)

○ No coupling with a parsing technology

○ Declarative name resolution section saves encoding lookup algorithms

■ to resolve name-based cross-references

○ Ordering-based disambiguation rules description

■ to overcome their admitted limitation of having to define exclusive rule guards.

24

Quantitative Study: Examplecompany :

’company’ STRING ’{’ department* ’}’ EOF;department :

’department’ STRING ’{’ department_manager department_employees department* ’}’;department_manager : ’manager’ employee;department_employees :

(’employee’ employee)*;employee :

STRING ’{’ ’address’ STRING’salary’ FLOAT(’mentor’ STRING)? ’}’; 25

Quantitative Study: Gra2Molrule 'mapDepartment'

from department dto Departmentqueries mElem : /d/department_manager/#employee; eElem : /d/department_employees/#employee; dElem : /d/#department;mappings name = removeQuotes d.STRING; manager = mElem; employees = eElem; subdepts = dElem; end_rule 26

Quantitative Study: CS2AS DSTLmappings {

map Department from department {name := name;manager := department_manager.employee.trace;employees := department_employees.employee.trace; subdepts := deparment.trace;

} }

27

Quantitative Study: Inputs Generator

● Nd: No of (top level) departments● Ns: No of subdeparments

○ per departement/subdepartment

● Ne: No of employees○ per departement/subdepartment

● Ds: Depth level of (sub)departments

ID Size (bytes)

Elements Nd Ns Ne Ds

1 1,238 22 3 0 3 1

2 6,105 97 3 3 4 2

3 149,951 701 1 1 3 100

4 42,805 708 1 100 3 2

5 223,848 3061 4 4 5 4

6 1,018,254 11901 10 4 10 4

7 9,794,276 109341 10 5 10 5 28

Quantitative Study: Results

● CS2AS tx execution measured● Overall: 10-fold improvement● Input topology does not impact to

our solution

29

Thanks you very much !!!!

asbh500@york.ac.uk / me@adolfosbh.co

@adolfosbh

Questions ?

30

top related