Formalizing homogeneous language embeddings

572 views

Published on

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
572
On SlideShare
0
From Embeds
0
Number of Embeds
147
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Formalizing homogeneous language embeddings

  1. 1. Formalizing Homogeneous Language Embeddings<br />Tony Clark<br />Centre for Model Driven Software Engineering, School of Computing, Thames Valley University<br />tony.clark@tvu.ac.uk<br />http://itcentre.tvu.ac.uk/~clark/<br />Laurence Tratt<br />School of Design Engineering and Computing, Bournemouth University<br />laurie@tratt.net<br />http://tratt.net/laurie/<br />1<br />
  2. 2. Overview<br />Language Factories and DSLs<br />An example and some properties<br />A language model for DSLs<br />The mu-calculus for DSLs<br />Some examples<br />Further work.<br />2<br />
  3. 3. Language Factories<br />The ability to construct new languages by combining precisely defined, reusable, language components and templates.<br />3<br />
  4. 4. Language Component<br />program A<br /> block B<br /> do C<br /> do D<br /> end<br /> do E<br />end<br />A<br />E<br />parse<br />B<br />D<br />C<br />Abstract Syntax Tree<br />σ<br />σ<br />σ<br />σ<br />σ<br />Execution Trace<br />4<br />
  5. 5. Problem Addressed<br />Reusable<br />Language <br />Component<br />Parametric<br />Language <br />Component<br />Questions:<br /><ul><li>how can syntax be merged?
  6. 6. how can semantics be merged?
  7. 7. how can we specify the combination?</li></ul>5<br />
  8. 8. An Application of DSLs<br />let results = <br />langsql:SQL[<br />select name,agefrom Customer where age > 18]<br />inlanghtml:HTML[<br /> <TABLE><br />forname,agein results do<br /> <TR><br /> <TD> name </TD><br /> <TD> age </TD><br /> </TR><br /> </TABLE><br /> ]<br />6<br />
  9. 9. A<br />A Model for DSL Embedding<br />host language(G)<br />E<br />B<br />evalG<br />σ<br />σ<br />σ<br />σ<br />σ<br />σ<br />C<br />V<br />load<br />unload<br />Z<br />W<br />w<br />w<br />w<br />w<br />w<br />evalH<br />Y<br />X<br />embedded language(H)<br />7<br />
  10. 10. The mu-Calculus<br />E ::= V variables | fun(V) E functions | E E applications | (E,E,E) language def | lang E:T[C] language embed | ... <br />8<br />
  11. 11. Abstract Syntax<br />type Exp(T) =Var(String) | Lambda(String,Exp(T)) | Apply(Exp(T),Exp(T)) | (Exp(T),Exp(T),Exp(T)) | Lang(T) | ...<br />9<br />
  12. 12. Semantics<br />evalExp(eval)(s) =<br /> case s of<br /> ... standard SECD except for...<br />(R:():s,e,App:c,d) -> <br /> eval((s,e,c,d):s,e,c,d)<br /> (I:v:s,e,App:c,d) -> <br />eval(v)<br /> end<br />10<br />
  13. 13. Loading and Unloading<br />lang(eval,load,unload):t[c]<br />is equivalent to:<br />I(newState)<br /> where newState = unload(termState,initialState)<br /> where termState = eval(startState)<br /> where startState = load(initialState,parse(t)(c))<br /> where initialState = R()<br />translate terminal embedded to<br />host state<br />produce embedded<br />terminal state<br />install the host<br />state<br />translate host<br />state to embedded initial state<br />reify the host state<br />11<br />
  14. 14. mu-calculus Embedded in Itself<br />Mu = Y(Exp)<br />evalMu = Y(evalExp)<br />loadMu((s,e,c,d),x) = (s,e,x:s,d)<br />unloadMu(s,_) = s<br />muL = (evalMu,loadMu,unloadMu)<br />fun(x) <br />langmuL:Mu[<br /> fun(y) <br />langmuL:Mu[x + y]]<br />12<br />
  15. 15. Let Binding: Semantics<br />type LetExp(T) = Let(String,Let(T),Let(T)) | Exp(T)<br />type Let = Y(LetExp)<br />evalLetExp(eval)(s) =<br /> case s of<br /> (s,e,Let(n,x,b):c,d) -> <br />eval(s,e,x:Let(n,b):c,d)<br /> (v:s,e,Let(n,b):c,d) -> <br /> eval([],e[n->v],[b],(s,e,c,d))<br /> else evalExp(eval)(s)<br /> end<br />13<br />
  16. 16. Let-Binding: Language Definition<br />type Let = Y(LetExp)<br />evalLet = Y(evalLetExp)<br />loadLet((s,e,c,d),x) = (s,e,x:c,d)<br />unoadLet(s,_) = s<br />letL = (evalLet,loadLet,unloadLet)<br />fun(x) <br /> lang letL:Let[<br /> let y = x + 1 in y ]<br />14<br />
  17. 17. Other Examples<br />langletL:Let[let mkArray = fun(limit) langarrayL:Array [ 0 .. limit ]in mkArray(100)]<br />langletL:Let[<br /> let x = ... <br /> in langabortL:Abort[ <br /> stop if(x > 100) ]]<br />15<br />
  18. 18. Review and Further Work<br />mu-Calculus for semantic analysis of language embedding.<br />Further work:<br />Parsing<br />Static Analysis<br />Logic for combining language components<br />Practical considerations<br />16<br />

×