formalizing homogeneous language embeddings tony clark centre for model driven software engineering,...

16
Formalizing Homogeneous Language Embeddings Tony Clark Centre for Model Driven Software Engineering, School of Computing, Thames Valley University [email protected] http://itcentre.tvu.ac.uk/~clark/ Laurence Tratt School of Design Engineering and Computing, Bournemouth University [email protected] http://tratt.net/laurie/ 1

Upload: hilda-lewis

Post on 16-Dec-2015

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Formalizing Homogeneous Language Embeddings Tony Clark Centre for Model Driven Software Engineering, School of Computing, Thames Valley University tony.clark@tvu.ac.uk

1

Formalizing Homogeneous Language Embeddings

Tony Clark Centre for Model Driven Software Engineering, School of Computing, Thames Valley University

[email protected]://itcentre.tvu.ac.uk/~clark/

Laurence TrattSchool of Design Engineering and Computing, Bournemouth University

[email protected]://tratt.net/laurie/

Page 2: Formalizing Homogeneous Language Embeddings Tony Clark Centre for Model Driven Software Engineering, School of Computing, Thames Valley University tony.clark@tvu.ac.uk

2

Overview

• Language Factories and DSLs• An example and some properties• A language model for DSLs• The mu-calculus for DSLs• Some examples• Further work.

Page 3: Formalizing Homogeneous Language Embeddings Tony Clark Centre for Model Driven Software Engineering, School of Computing, Thames Valley University tony.clark@tvu.ac.uk

3

Language Factories

The ability to construct new languages by combining precisely defined, reusable, language components and templates.

Page 4: Formalizing Homogeneous Language Embeddings Tony Clark Centre for Model Driven Software Engineering, School of Computing, Thames Valley University tony.clark@tvu.ac.uk

4

Language Component

A

B

C D

E

σ σ σ σ σ

Abstract Syntax Tree

Execution Trace

program A block B do C do D end do Eend

parse

Page 5: Formalizing Homogeneous Language Embeddings Tony Clark Centre for Model Driven Software Engineering, School of Computing, Thames Valley University tony.clark@tvu.ac.uk

5

Problem Addressed

ParametricLanguage Component

ReusableLanguage Component

Questions:• how can syntax be merged?• how can semantics be merged?• how can we specify the combination?

Page 6: Formalizing Homogeneous Language Embeddings Tony Clark Centre for Model Driven Software Engineering, School of Computing, Thames Valley University tony.clark@tvu.ac.uk

6

An Application of DSLs

let results = lang sql:SQL[ select name,age from Customer where age > 18]in lang html:HTML[ <TABLE> for name,age in results do <TR> <TD> name </TD> <TD> age </TD> </TR> </TABLE> ]

Page 7: Formalizing Homogeneous Language Embeddings Tony Clark Centre for Model Driven Software Engineering, School of Computing, Thames Valley University tony.clark@tvu.ac.uk

7

A

B

C

E

V

W

X Y

Z

σ σ σ σ σ

w w w w w

σ

load unload

host language(G)

embedded language(H)

A Model for DSL Embedding

evalH

evalG

Page 8: Formalizing Homogeneous Language Embeddings Tony Clark Centre for Model Driven Software Engineering, School of Computing, Thames Valley University tony.clark@tvu.ac.uk

8

The mu-Calculus

E ::= V variables | fun(V) E functions | E E applications | (E,E,E) language def | lang E:T[C] language embed | ...

Page 9: Formalizing Homogeneous Language Embeddings Tony Clark Centre for Model Driven Software Engineering, School of Computing, Thames Valley University tony.clark@tvu.ac.uk

9

Abstract Syntax

type Exp(T) = Var(String) | Lambda(String,Exp(T)) | Apply(Exp(T),Exp(T)) | (Exp(T),Exp(T),Exp(T)) | Lang(T) | ...

Page 10: Formalizing Homogeneous Language Embeddings Tony Clark Centre for Model Driven Software Engineering, School of Computing, Thames Valley University tony.clark@tvu.ac.uk

10

Semantics

evalExp(eval)(s) = case s of ... standard SECD except for... (R:():s,e,App:c,d) -> eval((s,e,c,d):s,e,c,d) (I:v:s,e,App:c,d) -> eval(v) end

Page 11: Formalizing Homogeneous Language Embeddings Tony Clark Centre for Model Driven Software Engineering, School of Computing, Thames Valley University tony.clark@tvu.ac.uk

11

Loading and Unloadinglang(eval,load,unload):t[c]

is equivalent to:

I(newState) where newState = unload(termState,initialState) where termState = eval(startState) where startState = load(initialState,parse(t)(c)) where initialState = R()

reify the host state

translate hoststate to embedded

initial state

produce embeddedterminal state

translate terminal embedded to

host state

install the hoststate

Page 12: Formalizing Homogeneous Language Embeddings Tony Clark Centre for Model Driven Software Engineering, School of Computing, Thames Valley University tony.clark@tvu.ac.uk

12

mu-calculus Embedded in ItselfMu = Y(Exp)evalMu = Y(evalExp)loadMu((s,e,c,d),x) = (s,e,x:s,d)unloadMu(s,_) = smuL = (evalMu,loadMu,unloadMu)

fun(x) lang muL:Mu[ fun(y) lang muL:Mu[x + y]]

Page 13: Formalizing Homogeneous Language Embeddings Tony Clark Centre for Model Driven Software Engineering, School of Computing, Thames Valley University tony.clark@tvu.ac.uk

13

Let Binding: Semanticstype LetExp(T) = Let(String,Let(T),Let(T)) | Exp(T)

type Let = Y(LetExp)

evalLetExp(eval)(s) = case s of (s,e,Let(n,x,b):c,d) -> eval(s,e,x:Let(n,b):c,d) (v:s,e,Let(n,b):c,d) -> eval([],e[n->v],[b],(s,e,c,d)) else evalExp(eval)(s) end

Page 14: Formalizing Homogeneous Language Embeddings Tony Clark Centre for Model Driven Software Engineering, School of Computing, Thames Valley University tony.clark@tvu.ac.uk

14

Let-Binding: Language Definition

type Let = Y(LetExp)evalLet = Y(evalLetExp)loadLet((s,e,c,d),x) = (s,e,x:c,d)unoadLet(s,_) = sletL = (evalLet,loadLet,unloadLet)

fun(x) lang letL:Let[ let y = x + 1 in y ]

Page 15: Formalizing Homogeneous Language Embeddings Tony Clark Centre for Model Driven Software Engineering, School of Computing, Thames Valley University tony.clark@tvu.ac.uk

15

Other Exampleslang letL:Let[let mkArray = fun(limit) lang arrayL:Array [ 0 .. limit ]in mkArray(100)]

lang letL:Let[ let x = ... in lang abortL:Abort[ stop if(x > 100) ]]

Page 16: Formalizing Homogeneous Language Embeddings Tony Clark Centre for Model Driven Software Engineering, School of Computing, Thames Valley University tony.clark@tvu.ac.uk

16

Review and Further Work

• mu-Calculus for semantic analysis of language embedding.

• Further work:– Parsing– Static Analysis– Logic for combining language components– Practical considerations