SlideShare a Scribd company logo
1 of 61
Download to read offline
A Language Designer’s Workbench 
A one-stop shop for implementation and verification of language designs 
Eelco Visser, Guido Wachsmuth, Andrew Tolmach 
Pierre Neron, Vlad Vergu, Augusto Passalaqua, Gabriël Konat
parser 
type checker 
code generator 
interpreter 
parser 
error recovery 
syntax highlighting 
outline 
code completion 
navigation 
type checker 
debugger 
syntax definition 
static semantics 
dynamic semantics 
abstract syntax 
type system 
operational 
semantics 
type soundness 
proof
Language Design
Language Engineering 
Syntax 
Checker 
Name 
Resolver 
Type 
Checker 
Code 
Generator
Semantics Engineering 
Abstract 
Syntax 
Type 
System 
Dynamic 
Semantics 
Transform
Language Design 
Syntax 
Definition 
Name 
Binding 
Type 
Constraints 
Dynamic 
Semantics 
Transform 
Language Designer’s Workbench
Language Design 
Syntax 
Name 
Type 
Dynamic 
Languages 
Transform 
Definition 
Binding 
Constraints 
Semantics 
Declarative Meta-Multi-purpose Language Designer’s Workbench
Language Design 
SDF3 NaBL TS DynSem Stratego 
Language Designer’s Workbench: First Prototype
module PCF 
sorts Exp Param Type 
templates 
Exp.Var = [[ID]] 
Exp.App = [[Exp] [Exp]] {left} 
Exp.Fun = [ 
fun [Param] ( 
[Exp] 
) 
] 
Exp.Fix = [ 
fix [Param] ( 
[Exp] 
) 
] 
Exp.Let = [ 
let [ID] : [Type] = 
[Exp] 
in [Exp] 
] 
Exp.Num = [[INT]] 
Exp.Add = [[Exp] + [Exp]] {left} 
Exp.Sub = [[Exp] - [Exp]] {left} 
Exp.Mul = [[Exp] * [Exp]] {left} 
Exp = [([Exp])] {bracket} 
Exp.Ifz = [ 
ifz [Exp] then 
[Exp] 
else 
[Exp] 
] 
Type.IntType = [int] 
Type.FunType = [[Type] -> [Type]] 
Param.Param = [[ID] : [Type]] 
context-free priorities 
Exp.App > Exp.Mul > {left: Exp.Add Exp.Sub} 
> Exp.Ifz 
First Little (Big) Step: PCF in Spoofax 
module types 
type rules 
Var(x) : t 
where definition of x : t 
Param(x, t) : t 
Fun(p, e) : FunType(tp, te) 
where p : tp and e : te 
App(e1, e2) : tr 
where e1 : FunType(tf, tr) and e2 : ta 
and tf == ta 
else error "type mismatch" on e2 
Fix(p, e) : tp 
where p : tp and e : te 
and tp == te 
else error "type mismatch" on p 
Let(x, tx, e1, e2) : t2 
where e2 : t2 and e1 : t1 
and t1 == tx 
else error "type mismatch" on e1 
Num(i) : IntType() 
Ifz(e1, e2, e3) : t2 
where e1 : IntType() and e2 : t2 and e3 : t3 
and t2 == t3 
else error "types not compatible" on e3 
e@Add(e1, e2) + e@Sub(e1, e2) + e@Mul(e1, e2) : IntType() 
where e1 : IntType() 
else error "Int type expected" on e 
and e2 : IntType() 
else error "Int type expected" on e 
module semantics 
rules 
E env |- Var(x) --> v 
where env[x] => T(e, env'), 
E env' |- e --> v 
E env |- Fun(Param(x, t), e) --> C(x, e, env) 
E env |- App(e1, e2) --> v 
where E env |- e1 --> C(x, e, env'), 
E {x |--> T(e2, env), env'} |- e --> v 
E env |- Fix(Param(x, t), e) --> v 
where 
E {x |--> T(Fix(Param(x,t),e),env), env} |- e --> v 
E env |- Let(x, t, e1, e2) --> v 
where E {x |--> T(e1, env), env} |- e2 --> v 
rules 
Num(i) --> I(i) 
Ifz(e1, e2, e3) --> v 
where e1 --> I(i), i = 0, e2 --> v 
Ifz(e1, e2, e3) --> v 
where e1 --> I(i), i != 0, e3 --> v 
Add(e1, e2) --> I(addInt(i, j)) 
where e1 --> I(i), e2 --> I(j) 
Sub(e1, e2) --> I(subInt(i, j)) 
where e1 --> I(i), e2 --> I(j) 
Mul(e1, e2) --> I(mulInt(i, j)) 
where e1 --> I(i), e2 --> I(j) 
module names 
namespaces Variable 
binding rules 
Var(x) : 
refers to Variable x 
Param(x, t) : 
defines Variable x of type t 
Fun(p, e) : 
scopes Variable 
Fix(p, e) : 
scopes Variable 
Let(x, t, e1, e2) : 
defines Variable x of type t in e2 
SDF3 NaBL TS DynSem
Syntax Definition
Syntax = Tree Structure 
parse(prettyprint(t)) = t 
No need to understand 
how parse works! 
Exp.Fun 
Param ( Exp ) 
Exp.App 
Exp 
Exp.Ifz 
ifz Exp then Exp else Exp 
Exp.Add 
Exp + Exp 
Exp.Var 
ID 
fun 
Exp
Exp.Fun 
Param ( Exp ) 
Exp.App 
Exp 
Exp.Ifz 
ifz Exp then Exp else Exp 
Exp.Add 
Exp + Exp 
context-free syntax 
Exp.Fun = [ 
fun [Param] ( 
[Exp] 
) 
] 
Exp.Ifz = [ 
ifz [Exp] then 
[Exp] 
else 
[Exp] 
] 
Exp.App = [[Exp] [Exp]] {left} 
Exp.Add = <<Exp> + <Exp>> 
Exp.Var = <<ID>> 
Exp.Var 
ID 
fun 
Exp 
SDF3 : Syntax Definition Formalism
Multi-Purpose Declarative Syntax Definition 
Exp.Ifz = [ 
ifz [Exp] then 
[Exp] 
else 
[Exp] 
] 
Parser 
Error recovery rules 
Pretty-Printer 
Abstract syntax tree schema 
Syntactic coloring 
Syntactic completion templates 
Folding rules 
Outline rules 
Syntax Definition
Type Constraints
let fac : int -> int = 
fix f : int -> int ( 
fun n : int ( 
ifz n then 1 else n * f (n - 1) 
) 
) 
in (fac 3) 
is this expression well-typed?
let fac : int -> int = 
fix f : int -> int ( 
fun n : int ( 
ifz n then 1 else n * f (n - 1) 
) 
) 
in (fac 3) 
type rules 
Var(x) : t 
where definition of x : t 
Param(x, t) : t 
Fun(p, e) : FunType(tp, te) 
where p : tp and e : te 
App(e1, e2) : tr 
where e1 : FunType(tf, tr) and e2 : ta 
and tf == ta 
else error "type mismatch" on e2 
e@Sub(e1, e2) : IntType() 
where e1 : IntType() 
else error "Int type expected" on e 
and e2 : IntType() 
else error "Int type expected" on e 
TS: Type analysiS
let fac : int -> int = 
fix f : int -> int ( 
fun n : int ( 
ifz n then 1 else n * f (n - 1) 
) 
) 
in (fac 3) 
type rules 
Var(x) : t 
where definition of x : t 
Param(x, t) : t 
Fun(p, e) : FunType(tp, te) 
where p : tp and e : te 
App(e1, e2) : tr 
where e1 : FunType(tf, tr) and e2 : ta 
and tf == ta 
else error "type mismatch" on e2 
e@Sub(e1, e2) 
where e1 : IntType() 
else error "Int type expected" on e 
and e2 : IntType() 
else error "Int type expected" on e 
TS: Type analysiS
type rules 
Var(x) : t 
where definition of x : t 
Param(x, t) : t 
Fun(p, e) : FunType(tp, te) 
where p : tp and e : te 
App(e1, e2) : tr 
where e1 : FunType(tf, tr) and e2 : ta 
and tf == ta 
else error "type mismatch" on e2 
e@Sub(e1, e2) 
where e1 : IntType() 
else error "Int type expected" on e 
and e2 : IntType() 
else error "Int type expected" on e 
let fac : int -> int = 
fix f : int -> int ( 
fun n : int ( 
ifz n then 1 else n * f (n - 1) 
) 
) 
in (fac 3) 
TS: Type analysiS
let fac : int -> int = 
fix f : int -> int ( 
fun n : int ( 
ifz n then 1 else n * f (n - 1) 
) 
) 
in (fac 3) 
type rules 
Var(x) : t 
where definition of x : t 
Param(x, t) : t 
Fun(p, e) : FunType(tp, te) 
where p : tp and e : te 
App(e1, e2) : tr 
where e1 : FunType(tf, tr) and e2 : ta 
and tf == ta 
else error "type mismatch" on e2 
e@Sub(e1, e2) 
where e1 : IntType() 
else error "Int type expected" on e 
and e2 : IntType() 
else error "Int type expected" on e 
TS: Type analysiS
let fac : int -> int = 
fix f : int -> int ( 
fun n : int ( 
ifz n then 1 else n * f (n - 1) 
) 
) 
in (fac 3) 
type rules 
Var(x) : t 
where definition of x : t 
Param(x, t) : t 
Fun(p, e) : FunType(tp, te) 
where p : tp and e : te 
App(e1, e2) : tr 
where e1 : FunType(tf, tr) and e2 : ta 
and tf == ta 
else error "type mismatch" on e2 
e@Sub(e1, e2) 
where e1 : IntType() 
else error "Int type expected" on e 
and e2 : IntType() 
else error "Int type expected" on e 
TS: Type analysiS
let fac : int -> int = 
fix f : int -> int ( 
fun n : int ( 
ifz n then 1 else n * f (n - 1) 
) 
) 
in (fac 3) 
type rules 
Var(x) : t 
where definition of x : t 
Param(x, t) : t 
Fun(p, e) : FunType(tp, te) 
where p : tp and e : te 
App(e1, e2) : tr 
where e1 : FunType(tf, tr) and e2 : ta 
and tf == ta 
else error "type mismatch" on e2 
e@Sub(e1, e2) 
where e1 : IntType() 
else error "Int type expected" on e 
and e2 : IntType() 
else error "Int type expected" on e 
TS: Type analysiS
Multiple messages: 
- types not compatible 
- Unresolved reference
Multi-Purpose Type Constraints 
Inline type error reports 
Type annotations 
Interaction with name binding 
Semantic code completion 
Refactorings 
type rules 
Var(x) : t 
where definition of x : t 
Param(x, t) : t 
Fun(p, e) : FunType(tp, te) 
where p : tp and e : te 
App(e1, e2) : tr 
where e1 : FunType(tf, tr) and e2 : ta 
and tf == ta 
else error "type mismatch" on e2 
e@Sub(e1, e2) 
where e1 : IntType() 
else error "Int type expected" on e 
and e2 : IntType() 
else error "Int type expected" on e 
Incremental type analysis
Name Binding & Scope
let fac : int -> int = 
fix f : int -> int ( 
fun n : int ( 
ifz n then 1 else n * f (n - 1) 
) 
) 
in (fac 3) 
what does this variable refer to?
module names 
namespaces Variable 
binding rules 
Var(x) : 
refers to Variable x 
Param(x, t) : 
defines Variable x of type t 
Fun(p, e) : 
scopes Variable 
Fix(p, e) : 
scopes Variable 
Let(x, t, e1, e2) : 
defines Variable x of type t in e2 
let fac : int -> int = 
fix f : int -> int ( 
fun n : int ( 
ifz n then 1 else n * f (n - 1) 
) 
) 
in (fac 3) 
NaBL: Name Binding Language
module names 
namespaces Variable 
binding rules 
Var(x) : 
refers to Variable x 
Param(x, t) : 
defines Variable x of type t 
Fun(p, e) : 
scopes Variable 
Fix(p, e) : 
scopes Variable 
Let(x, t, e1, e2) : 
defines Variable x of type t in e2 
NaBL: Name Binding Language 
let fac : int -> int = 
fix f : int -> int ( 
fun n : int ( 
ifz n then 1 else n * f (n - 1) 
) 
) 
in (fac 3)
module names 
namespaces Variable 
binding rules 
Var(x) : 
refers to Variable x 
Param(x, t) : 
defines Variable x of type t 
Fun(p, e) : 
scopes Variable 
Fix(p, e) : 
scopes Variable 
Let(x, t, e1, e2) : 
defines Variable x of type t in e2 
NaBL: Name Binding Language 
let fac : int -> int = 
fix f : int -> int ( 
fun n : int ( 
ifz n then 1 else n * f (n - 1) 
) 
) 
in (fac 3)
module names 
namespaces Variable 
binding rules 
Var(x) : 
refers to Variable x 
Param(x, t) : 
defines Variable x of type t 
Fun(p, e) : 
scopes Variable 
Fix(p, e) : 
scopes Variable 
Let(x, t, e1, e2) : 
defines Variable x of type t in e2 
NaBL: Name Binding Language 
let fac : int -> int = 
fix f : int -> int ( 
fun n : int ( 
ifz n then 1 else n * f (n - 1) 
) 
) 
in (fac 3)
module names 
namespaces Variable 
binding rules 
Var(x) : 
refers to Variable x 
Param(x, t) : 
defines Variable x of type t 
Fun(p, e) : 
scopes Variable 
Fix(p, e) : 
scopes Variable 
Let(x, t, e1, e2) : 
defines Variable x of type t in e2 
let fac : int -> int = 
fix f : int -> int ( 
fun n : int ( 
ifz n then 1 else n * f (n - 1) 
) 
) 
in (fac 3) 
NaBL: Name Binding Language
module names 
namespaces Variable 
binding rules 
Var(x) : 
refers to Variable x 
Param(x, t) : 
defines Variable x of type t 
Fun(p, e) : 
scopes Variable 
Fix(p, e) : 
scopes Variable 
Let(x, t, e1, e2) : 
defines Variable x of type t in e2 
let fac : int -> int = 
fix f : int -> int ( 
fun n : int ( 
ifz n then 1 else n * f (n - 1) 
) 
) 
in (fac 3) 
NaBL: Name Binding Language
module names 
namespaces Variable 
binding rules 
Var(x) : 
refers to Variable x 
Param(x, t) : 
defines Variable x of type t 
Fun(p, e) : 
scopes Variable 
Fix(p, e) : 
scopes Variable 
Let(x, t, e1, e2) : 
defines Variable x of type t in e2 
let fac : int -> int = 
fix f : int -> int ( 
fun n : int ( 
ifz n then 1 else n * f (n - 1) 
) 
) 
in (fac 3) 
NaBL: Name Binding Language
module names 
namespaces Variable 
binding rules 
Var(x) : 
refers to Variable x 
Param(x, t) : 
defines Variable x of type t 
Fun(p, e) : 
scopes Variable 
Fix(p, e) : 
scopes Variable 
Let(x, t, e1, e2) : 
defines Variable x of type t in e2 
let fac : int -> int = 
fix f : int -> int ( 
fun n : int ( 
ifz n then 1 else n * f (n - 1) 
) 
) 
in (fac 3) 
NaBL: Name Binding Language
Multi-Purpose Name Binding Rules 
Incremental name resolution algorithm 
Name checks 
Reference resolution 
Semantic code completion 
module names 
namespaces Variable 
binding rules 
Var(x) : 
refers to Variable x 
Param(x, t) : 
defines Variable x of type t 
Fun(p, e) : 
scopes Variable 
Fix(p, e) : 
scopes Variable 
Let(x, t, e1, e2) : 
defines Variable x of type t in e2 
Refactorings
Dynamic Semantics
let fac : int -> int = 
fix f : int -> int ( 
fun n : int ( 
ifz n then 1 else n * f (n - 1) 
) 
) 
in (fac 3) 
What is the value of this expression?
let fac : int -> int = 
fix f : int -> int ( 
fun n : int ( 
ifz n then 1 else n * f (n - 1) 
) 
) 
in (fac 3) 
rules 
Num(i) --> I(i) 
Sub(e1, e2) --> I(subInt(i, j)) 
where e1 --> I(i), e2 --> I(j) 
Ifz(e1, e2, e3) --> v 
where e1 --> I(i), i = 0, e2 --> v 
Ifz(e1, e2, e3) --> v 
where e1 --> I(i), i != 0, e3 --> v 
DynSem: Dynamic Semantics
rules 
Num(i) --> I(i) 
Sub(e1, e2) --> I(subInt(i, j)) 
where e1 --> I(i), e2 --> I(j) 
Ifz(e1, e2, e3) --> v 
where e1 --> I(i), i = 0, e2 --> v 
Ifz(e1, e2, e3) --> v 
where e1 --> I(i), i != 0, e3 --> v 
let fac : int -> int = 
fix f : int -> int ( 
fun n : int ( 
ifz n then 1 else n * f (n - 1) 
) 
) 
in (fac 3) 
DynSem: Dynamic Semantics
rules 
E env |- Var(x) --> v 
where env[x] => T(e, env'), 
E env' |- e --> v 
E env |- Fun(Param(x, t), e) --> C(x, e, env) 
E env |- App(e1, e2) --> v 
where E env |- e1 --> C(x, e, env'), 
E {x |--> T(e2, env), env'} |- e --> v 
let fac : int -> int = 
fix f : int -> int ( 
fun n : int ( 
ifz n then 1 else n * f (n - 1) 
) 
) 
in (fac 3) 
DynSem: Dynamic Semantics
let fac : int -> int = 
fix f : int -> int ( 
fun n : int ( 
ifz n then 1 else n * f (n - 1) 
) 
) 
in (fac 3) 
rules 
E env |- Var(x) --> v 
where env[x] => T(e, env'), 
E env' |- e --> v 
E env |- Fun(Param(x, t), e) --> C(x, e, env) 
E env |- App(e1, e2) --> v 
where E env |- e1 --> C(x, e, env'), 
E {x |--> T(e2, env), env'} |- e --> v 
DynSem: Dynamic Semantics
rules 
E env |- Var(x) --> v 
where env[x] => T(e, env'), 
E env' |- e --> v 
E env |- Fun(Param(x, t), e) --> C(x, e, env) 
E env |- App(e1, e2) --> v 
where E env |- e1 --> C(x, e, env'), 
E {x |--> T(e2, env), env'} |- e --> v 
let fac : int -> int = 
fix f : int -> int ( 
fun n : int ( 
ifz n then 1 else n * f (n - 1) 
) 
) 
in (fac 3) 
DynSem: Dynamic Semantics
Implicitly-Modular Structural Operational Semantics (I-MSOS)* 
rules 
E env |- Var(x) --> v 
where env[x] => T(e, env'), 
E env' |- e --> v 
Add(e1, e2) --> I(addInt(i, j)) 
where e1 --> I(i), 
e2 --> I(j) 
rules 
E env |- Var(x) --> v 
where env[x] => T(e, env'), 
E env' |- e --> v 
E env |- Add(e1, e2) --> I(addInt(i, j)) 
where E env |- e1 --> I(i), 
explicate E env |- e2 --> I(j) 
* P. D. Mosses. Modular structural operational semantics. JLP, 60-61:195–228, 2004. 
M. Churchill, P. D. Mosses, and P. Torrini. Reusable components of semantic specifications. In MODULARITY, April 2014.
Interpreter Generation 
rules 
Ifz(e1, e2, e3) --> v 
where e1 --> I(i), i = 0, e2 --> v 
Ifz(e1, e2, e3) --> v 
where e1 --> I(i), i != 0, e3 --> v 
explicate 
& merge 
rules 
E env |- Ifz(e1, e2, e3) --> v 
where E env |- e1 --> I(i), 
[i = 0, E env |- e2 --> v] + 
i != 0, E env |- e3 --> v]
Multi-Purpose Dynamic Semantics 
Generate interpreter 
Verification 
Type soundness 
rules 
E env |- Var(x) --> v 
where env[x] => T(e, env'), 
E env' |- e --> v 
E env |- Fun(Param(x, t), e) --> C(x, e, env) 
E env |- App(e1, e2) --> v 
where E env |- e1 --> C(x, e, env'), 
E {x |--> T(e2, env), env'} |- e --> v 
Semantics preservation
Verification
module PCF 
sorts Exp Param Type 
templates 
Exp.Var = [[ID]] 
Exp.App = [[Exp] [Exp]] {left} 
Exp.Fun = [ 
fun [Param] ( 
[Exp] 
) 
] 
Exp.Fix = [ 
fix [Param] ( 
[Exp] 
) 
] 
Exp.Let = [ 
let [ID] : [Type] = 
[Exp] 
in [Exp] 
] 
Exp.Num = [[INT]] 
Exp.Add = [[Exp] + [Exp]] {left} 
Exp.Sub = [[Exp] - [Exp]] {left} 
Exp.Mul = [[Exp] * [Exp]] {left} 
Exp = [([Exp])] {bracket} 
Exp.Ifz = [ 
ifz [Exp] then 
[Exp] 
else 
[Exp] 
] 
Type.IntType = [int] 
Type.FunType = [[Type] -> [Type]] 
Param.Param = [[ID] : [Type]] 
context-free priorities 
Exp.App > Exp.Mul > {left: Exp.Add Exp.Sub} 
> Exp.Ifz 
From PCF in Spoofax … 
module types 
type rules 
Var(x) : t 
where definition of x : t 
Param(x, t) : t 
Fun(p, e) : FunType(tp, te) 
where p : tp and e : te 
App(e1, e2) : tr 
where e1 : FunType(tf, tr) and e2 : ta 
and tf == ta 
else error "type mismatch" on e2 
Fix(p, e) : tp 
where p : tp and e : te 
and tp == te 
else error "type mismatch" on p 
Let(x, tx, e1, e2) : t2 
where e2 : t2 and e1 : t1 
and t1 == tx 
else error "type mismatch" on e1 
Num(i) : IntType() 
Ifz(e1, e2, e3) : t2 
where e1 : IntType() and e2 : t2 and e3 : t3 
and t2 == t3 
else error "types not compatible" on e3 
e@Add(e1, e2) + e@Sub(e1, e2) + e@Mul(e1, e2) : IntType() 
where e1 : IntType() 
else error "Int type expected" on e 
and e2 : IntType() 
else error "Int type expected" on e 
module semantics 
rules 
E env |- Var(x) --> v 
where env[x] => T(e, env'), 
E env' |- e --> v 
E env |- Fun(Param(x, t), e) --> C(x, e, env) 
E env |- App(e1, e2) --> v 
where E env |- e1 --> C(x, e, env'), 
E {x |--> T(e2, env), env'} |- e --> v 
E env |- Fix(Param(x, t), e) --> v 
where 
E {x |--> T(Fix(Param(x,t),e),env), env} |- e --> v 
E env |- Let(x, t, e1, e2) --> v 
where E {x |--> T(e1, env), env} |- e2 --> v 
rules 
Num(i) --> I(i) 
Ifz(e1, e2, e3) --> v 
where e1 --> I(i), i = 0, e2 --> v 
Ifz(e1, e2, e3) --> v 
where e1 --> I(i), i != 0, e3 --> v 
Add(e1, e2) --> I(addInt(i, j)) 
where e1 --> I(i), e2 --> I(j) 
Sub(e1, e2) --> I(subInt(i, j)) 
where e1 --> I(i), e2 --> I(j) 
Mul(e1, e2) --> I(mulInt(i, j)) 
where e1 --> I(i), e2 --> I(j) 
module names 
namespaces Variable 
binding rules 
Var(x) : 
refers to Variable x 
Param(x, t) : 
defines Variable x of type t 
Fun(p, e) : 
scopes Variable 
Fix(p, e) : 
scopes Variable 
Let(x, t, e1, e2) : 
defines Variable x of type t in e2 
SDF3 NaBL TS DynSem
else 
[Exp] 
] 
Type.IntType = [int] 
Type.FunType = [[Type] -> [Type]] 
Param.Param = [[ID] : [Type]] 
context-free priorities 
Exp.App > Exp.Mul > {left: Exp.Add Exp.Sub} 
> Exp.Ifz 
Ifz(e1, e2, e3) : t2 
where e1 : IntType() and e2 : t2 and e3 : t3 
and t2 == t3 
else error "types not compatible" on e3 
e@Add(e1, e2) + e@Sub(e1, e2) + e@Mul(e1, e2) : IntType() 
where e1 : IntType() 
else error "Int type expected" on e 
and e2 : IntType() 
else error "Int type expected" on e 
Ifz(e1, e2, e3) --> v 
where e1 --> I(i), i != 0, e3 --> v 
Add(e1, e2) --> I(addInt(i, j)) 
where e1 --> I(i), e2 --> I(j) 
Sub(e1, e2) --> I(subInt(i, j)) 
where e1 --> I(i), e2 --> I(j) 
Mul(e1, e2) --> I(mulInt(i, j)) 
where e1 --> I(i), e2 --> I(j) 
Param(x, t) : 
defines Variable x of type t 
Fun(p, e) : 
scopes Variable 
Fix(p, e) : 
scopes Variable 
Let(x, t, e1, e2) : 
defines Variable x of type t in e2 
Inductive has_type (C: Context) : term -> term -> Prop := 
| VarC_ht ns k0 t x k1 : lookup C x ns k0 t -> has_type C (Co VarC [Id x k0] k1) t 
| ParamC_ht x t k0 : has_type C (Co ParamC [x;t] k0) t 
| FunC_ht k0 t_p t_e p e k1 : has_type C p t_p -> has_type C e t_e -> has_type C (Co FunC [p;e] k1) (Co FunTypeC [t_p;t_e] k0) 
| FixC_ht t_p t_e p e k0 : has_type C p t_p -> has_type C e t_e -> (t_p = t_e) -> has_type C (Co FixC [p;e] k0) t_p 
| AppC_ht t_r k0 t_f t_a e1 e2 k1 : has_type C e1 (Co FunTypeC [t_f;t_r] k0) -> has_type C e2 t_a -> (t_f = t_a) -> has_type C (Co AppC [e1;e2] k1) t_r 
| LetC_ht t2 t1 x t_x e1 e2 k0 : has_type C e2 t2 -> has_type C e1 t1 -> (t1 = t_x) -> has_type C (Co LetC [x;t_x;e1;e2] k0) t2 
| NumC_ht k0 i k1 : has_type C (Co NumC [i] k1) (Co IntTypeC [] k0) 
| IfzC_ht k0 t2 t3 e1 e2 e3 k1 : has_type C e1 (Co IntTypeC [] k0) -> has_type C e2 t2 -> has_type C e3 t3 -> (t2 = t3) -> has_type C (Co IfzC [e1;e2;e3] k1) t2 
| AddC_ht k2 k0 k1 e1 e2 k3 : has_type C e1 (Co IntTypeC [] k0) -> has_type C e2 (Co IntTypeC [] k1) -> has_type C (Co AddC [e1;e2] k3) (Co IntTypeC [] k2) 
| SubC_ht k2 k0 k1 e1 e2 k3 : has_type C e1 (Co IntTypeC [] k0) -> has_type C e2 (Co IntTypeC [] k1) -> has_type C (Co SubC [e1;e2] k3) (Co IntTypeC [] k2) 
| MulC_ht k2 k0 k1 e1 e2 k3 : has_type C e1 (Co IntTypeC [] k0) -> has_type C e2 (Co IntTypeC [] k1) -> has_type C (Co MulC [e1;e2] k3) (Co IntTypeC [] k2) 
| HT_eq e ty1 ty2 (hty1: has_type C e ty1) (tyeq: term_eq ty1 ty2) : has_type C e ty2 
. 
Inductive semantics_cbn : Env -> term -> value -> Prop := 
| Var0C_sem env' e env x k0 v : get_env x env e env' -> semantics_cbn env' e v -> semantics_cbn env (Co VarC [x] k0) v 
| Fun0C_sem t k1 k0 x e env : semantics_cbn env (Co FunC [Co ParamC [x;t] k1;e] k0) (Clos x e env) 
| Fix0C_sem k1 k0 env x t k3 e k2 v : semantics_cbn { x |--> (Co FixC [Co ParamC [x;t] k1;e] k0,env), env } e v -> semantics_cbn env (Co FixC [Co ParamC [x;t] k3;e] k2) v 
| App0C_sem env' x e env e1 e2 k0 v : semantics_cbn env e1 (Clos x e env') -> semantics_cbn { x |--> (e2,env), env' } e v -> semantics_cbn env (Co AppC [e1;e2] k0) v 
| Let0C_sem env x t e1 e2 k0 v : semantics_cbn { x |--> (e1,env), env } e2 v -> semantics_cbn env (Co LetC [x;t;e1;e2] k0) v 
| Num0C_sem env k0 i : semantics_cbn env (Co NumC [i] k0) (Natval i) 
| Ifz0C_sem i env e1 e2 e3 k0 v : semantics_cbn env e1 (Natval i) -> (i = 0) -> semantics_cbn env e2 v -> semantics_cbn env (Co IfzC [e1;e2;e3] k0) v 
| Ifz1C_sem i env e1 e2 e3 k0 v : semantics_cbn env e1 (Natval i) -> (i <> 0) -> semantics_cbn env e3 v -> semantics_cbn env (Co IfzC [e1;e2;e3] k0) v 
| Add0C_sem env e1 e2 k0 i j : semantics_cbn env e1 (Natval i) -> semantics_cbn env e2 (Natval j) -> semantics_cbn env (Co AddC [e1;e2] k0) (plus i j) 
| Sub0C_sem env e1 e2 k0 i j : semantics_cbn env e1 (Natval i) -> semantics_cbn env e2 (Natval j) -> semantics_cbn env (Co SubC [e1;e2] k0) (minus i j) 
| Mul0C_sem env e1 e2 k0 i j : semantics_cbn env e1 (Natval i) -> semantics_cbn env e2 (Natval j) -> semantics_cbn env (Co MulC [e1;e2] k0) (mult i j) 
. 
Inductive ID_NS : Set := 
| VariableNS 
. 
Definition NS := 
ID_NS 
. 
Inductive scopesR : term -> NS -> Prop := 
| Fun_scopes_Variable p e k0 : scopesR (Co FunC [p;e] k0) VariableNS 
| Fix_scopes_Variable p e k0 : scopesR (Co FixC [p;e] k0) VariableNS 
. 
Definition scopes_R := 
scopesR 
. 
Inductive definesR : term -> Ident -> NS -> key -> Prop := 
| Param_defines_Variable x k1 t k0 : definesR (Co ParamC [Id x k1;t] k0) x VariableNS k1 
. 
Definition defines_R := 
definesR 
. 
Inductive refers_toR : term -> Ident -> NS -> key -> Prop := 
| Var_refers_to_Variable x k1 k0 : refers_toR (Co VarC [Id x k1] k0) x VariableNS k1 
. 
Definition refers_to_R := 
refers_toR 
. 
Inductive typed_definesR : term -> Ident -> NS -> term -> key -> Prop := 
| Param_typed_defines_Variable x t k1 t k0 : typed_definesR (Co ParamC [Id x k1;t] k0) x VariableNS t k1 
. 
Definition typed_defines_R := 
typed_definesR 
. 
Inductive sorts : Set := 
| Param_S 
| ID_S 
| INT_S 
| Exp_S 
| Type_S 
. 
Parameter Ident : Set. 
Definition sort := 
sorts 
. 
Definition Ident_Sort := 
ID_S 
. 
Inductive Constructors := 
| INTC (n: nat) 
| VarC 
| FunC 
| FixC 
| AppC 
| LetC 
| ParamC 
| NumC 
| AddC 
| SubC 
| MulC 
| DivC 
| IfzC 
| IntTypeC 
| FunTypeC 
. 
Definition constructors := 
Constructors 
. 
Fixpoint 
get_sig (x: constructors) : list sort * sort := 
match x with 
| INTC n => ([],INT_S) 
| VarC => ([ID_S],Exp_S) 
| FunC => ([Param_S;Exp_S],Exp_S) 
| FixC => ([Param_S;Exp_S],Exp_S) 
| AppC => ([Exp_S;Exp_S],Exp_S) 
| LetC => ([ID_S;Type_S;Exp_S;Exp_S],Exp_S) 
| ParamC => ([ID_S;Type_S],Param_S) 
| NumC => ([INT_S],Exp_S) 
| AddC => ([Exp_S;Exp_S],Exp_S) 
| SubC => ([Exp_S;Exp_S],Exp_S) 
| MulC => ([Exp_S;Exp_S],Exp_S) 
| DivC => ([Exp_S;Exp_S],Exp_S) 
| IfzC => ([Exp_S;Exp_S;Exp_S],Exp_S) 
| IntTypeC => ([],Type_S) 
| FunTypeC => ([Type_S;Type_S],Type_S) 
end. … to PCF in Coq (+ manual proof of type preservation)
A few things left to do …
spoofax.org

More Related Content

What's hot

Declare Your Language: Syntactic (Editor) Services
Declare Your Language: Syntactic (Editor) ServicesDeclare Your Language: Syntactic (Editor) Services
Declare Your Language: Syntactic (Editor) ServicesEelco Visser
 
07. Java Array, Set and Maps
07.  Java Array, Set and Maps07.  Java Array, Set and Maps
07. Java Array, Set and MapsIntro C# Book
 
Compiler Construction | Lecture 14 | Interpreters
Compiler Construction | Lecture 14 | InterpretersCompiler Construction | Lecture 14 | Interpreters
Compiler Construction | Lecture 14 | InterpretersEelco Visser
 
Static name resolution
Static name resolutionStatic name resolution
Static name resolutionEelco Visser
 
02. Data Types and variables
02. Data Types and variables02. Data Types and variables
02. Data Types and variablesIntro C# Book
 
03 and 04 .Operators, Expressions, working with the console and conditional s...
03 and 04 .Operators, Expressions, working with the console and conditional s...03 and 04 .Operators, Expressions, working with the console and conditional s...
03 and 04 .Operators, Expressions, working with the console and conditional s...Intro C# Book
 
13 Strings and Text Processing
13 Strings and Text Processing13 Strings and Text Processing
13 Strings and Text ProcessingIntro C# Book
 
Python quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung FuPython quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung Fuclimatewarrior
 
Compiler Construction | Lecture 2 | Declarative Syntax Definition
Compiler Construction | Lecture 2 | Declarative Syntax DefinitionCompiler Construction | Lecture 2 | Declarative Syntax Definition
Compiler Construction | Lecture 2 | Declarative Syntax DefinitionEelco Visser
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to pythonMarian Marinov
 
04. Console Input Output
04. Console Input Output 04. Console Input Output
04. Console Input Output Intro C# Book
 
05. Java Loops Methods and Classes
05. Java Loops Methods and Classes05. Java Loops Methods and Classes
05. Java Loops Methods and ClassesIntro C# Book
 
Declarative Thinking, Declarative Practice
Declarative Thinking, Declarative PracticeDeclarative Thinking, Declarative Practice
Declarative Thinking, Declarative PracticeKevlin Henney
 
FUNCTIONS IN PYTHON. CBSE +2 COMPUTER SCIENCE
FUNCTIONS IN PYTHON. CBSE +2 COMPUTER SCIENCEFUNCTIONS IN PYTHON. CBSE +2 COMPUTER SCIENCE
FUNCTIONS IN PYTHON. CBSE +2 COMPUTER SCIENCEVenugopalavarma Raja
 
19. Data Structures and Algorithm Complexity
19. Data Structures and Algorithm Complexity19. Data Structures and Algorithm Complexity
19. Data Structures and Algorithm ComplexityIntro C# Book
 

What's hot (20)

09. Java Methods
09. Java Methods09. Java Methods
09. Java Methods
 
Declare Your Language: Syntactic (Editor) Services
Declare Your Language: Syntactic (Editor) ServicesDeclare Your Language: Syntactic (Editor) Services
Declare Your Language: Syntactic (Editor) Services
 
07. Java Array, Set and Maps
07.  Java Array, Set and Maps07.  Java Array, Set and Maps
07. Java Array, Set and Maps
 
Compiler Construction | Lecture 14 | Interpreters
Compiler Construction | Lecture 14 | InterpretersCompiler Construction | Lecture 14 | Interpreters
Compiler Construction | Lecture 14 | Interpreters
 
Static name resolution
Static name resolutionStatic name resolution
Static name resolution
 
02. Data Types and variables
02. Data Types and variables02. Data Types and variables
02. Data Types and variables
 
03 and 04 .Operators, Expressions, working with the console and conditional s...
03 and 04 .Operators, Expressions, working with the console and conditional s...03 and 04 .Operators, Expressions, working with the console and conditional s...
03 and 04 .Operators, Expressions, working with the console and conditional s...
 
13 Strings and Text Processing
13 Strings and Text Processing13 Strings and Text Processing
13 Strings and Text Processing
 
Python quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung FuPython quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung Fu
 
Compiler Construction | Lecture 2 | Declarative Syntax Definition
Compiler Construction | Lecture 2 | Declarative Syntax DefinitionCompiler Construction | Lecture 2 | Declarative Syntax Definition
Compiler Construction | Lecture 2 | Declarative Syntax Definition
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
04. Console Input Output
04. Console Input Output 04. Console Input Output
04. Console Input Output
 
Python : Data Types
Python : Data TypesPython : Data Types
Python : Data Types
 
Python
PythonPython
Python
 
Arduino
ArduinoArduino
Arduino
 
05. Java Loops Methods and Classes
05. Java Loops Methods and Classes05. Java Loops Methods and Classes
05. Java Loops Methods and Classes
 
Arduino reference
Arduino referenceArduino reference
Arduino reference
 
Declarative Thinking, Declarative Practice
Declarative Thinking, Declarative PracticeDeclarative Thinking, Declarative Practice
Declarative Thinking, Declarative Practice
 
FUNCTIONS IN PYTHON. CBSE +2 COMPUTER SCIENCE
FUNCTIONS IN PYTHON. CBSE +2 COMPUTER SCIENCEFUNCTIONS IN PYTHON. CBSE +2 COMPUTER SCIENCE
FUNCTIONS IN PYTHON. CBSE +2 COMPUTER SCIENCE
 
19. Data Structures and Algorithm Complexity
19. Data Structures and Algorithm Complexity19. Data Structures and Algorithm Complexity
19. Data Structures and Algorithm Complexity
 

Viewers also liked

A(n abridged) tour of the Rust compiler [PDX-Rust March 2014]
A(n abridged) tour of the Rust compiler [PDX-Rust March 2014]A(n abridged) tour of the Rust compiler [PDX-Rust March 2014]
A(n abridged) tour of the Rust compiler [PDX-Rust March 2014]Tom Lee
 
Open Source in Big Business [LCA2011 Miniconf]
Open Source in Big Business [LCA2011 Miniconf]Open Source in Big Business [LCA2011 Miniconf]
Open Source in Big Business [LCA2011 Miniconf]Tom Lee
 
Inside Python [OSCON 2012]
Inside Python [OSCON 2012]Inside Python [OSCON 2012]
Inside Python [OSCON 2012]Tom Lee
 
Open Source Compiler Construction for the JVM [LCA2011 Miniconf]
Open Source Compiler Construction for the JVM [LCA2011 Miniconf]Open Source Compiler Construction for the JVM [LCA2011 Miniconf]
Open Source Compiler Construction for the JVM [LCA2011 Miniconf]Tom Lee
 
Open Source Compiler Construction for the JVM
Open Source Compiler Construction for the JVMOpen Source Compiler Construction for the JVM
Open Source Compiler Construction for the JVMTom Lee
 
Inside PHP [OSCON 2012]
Inside PHP [OSCON 2012]Inside PHP [OSCON 2012]
Inside PHP [OSCON 2012]Tom Lee
 

Viewers also liked (7)

A(n abridged) tour of the Rust compiler [PDX-Rust March 2014]
A(n abridged) tour of the Rust compiler [PDX-Rust March 2014]A(n abridged) tour of the Rust compiler [PDX-Rust March 2014]
A(n abridged) tour of the Rust compiler [PDX-Rust March 2014]
 
Open Source in Big Business [LCA2011 Miniconf]
Open Source in Big Business [LCA2011 Miniconf]Open Source in Big Business [LCA2011 Miniconf]
Open Source in Big Business [LCA2011 Miniconf]
 
Eva5
Eva5Eva5
Eva5
 
Inside Python [OSCON 2012]
Inside Python [OSCON 2012]Inside Python [OSCON 2012]
Inside Python [OSCON 2012]
 
Open Source Compiler Construction for the JVM [LCA2011 Miniconf]
Open Source Compiler Construction for the JVM [LCA2011 Miniconf]Open Source Compiler Construction for the JVM [LCA2011 Miniconf]
Open Source Compiler Construction for the JVM [LCA2011 Miniconf]
 
Open Source Compiler Construction for the JVM
Open Source Compiler Construction for the JVMOpen Source Compiler Construction for the JVM
Open Source Compiler Construction for the JVM
 
Inside PHP [OSCON 2012]
Inside PHP [OSCON 2012]Inside PHP [OSCON 2012]
Inside PHP [OSCON 2012]
 

Similar to A Language Designer’s Workbench. A one-stop shop for implementation and verification of language designs

Scala - where objects and functions meet
Scala - where objects and functions meetScala - where objects and functions meet
Scala - where objects and functions meetMario Fusco
 
Build a compiler in 2hrs - NCrafts Paris 2015
Build a compiler in 2hrs -  NCrafts Paris 2015Build a compiler in 2hrs -  NCrafts Paris 2015
Build a compiler in 2hrs - NCrafts Paris 2015Phillip Trelford
 
TI1220 Lecture 9: Parsing & interpretation
TI1220 Lecture 9: Parsing & interpretationTI1220 Lecture 9: Parsing & interpretation
TI1220 Lecture 9: Parsing & interpretationEelco Visser
 
Top down and botttom up 2 LATEST.
Top down     and botttom up 2 LATEST.Top down     and botttom up 2 LATEST.
Top down and botttom up 2 LATEST.Gerwin Ocsena
 
Model-Driven Software Development - Static Analysis & Error Checking
Model-Driven Software Development - Static Analysis & Error CheckingModel-Driven Software Development - Static Analysis & Error Checking
Model-Driven Software Development - Static Analysis & Error CheckingEelco Visser
 
Top down and botttom up Parsing
Top down     and botttom up ParsingTop down     and botttom up Parsing
Top down and botttom up ParsingGerwin Ocsena
 
Compiler Construction | Lecture 4 | Parsing
Compiler Construction | Lecture 4 | Parsing Compiler Construction | Lecture 4 | Parsing
Compiler Construction | Lecture 4 | Parsing Eelco Visser
 
Top down parsing(sid) (1)
Top down parsing(sid) (1)Top down parsing(sid) (1)
Top down parsing(sid) (1)Siddhesh Pange
 
Declare Your Language: Name Resolution
Declare Your Language: Name ResolutionDeclare Your Language: Name Resolution
Declare Your Language: Name ResolutionEelco Visser
 
仕事で使うF#
仕事で使うF#仕事で使うF#
仕事で使うF#bleis tift
 
Swift Rocks #2: Going functional
Swift Rocks #2: Going functionalSwift Rocks #2: Going functional
Swift Rocks #2: Going functionalHackraft
 
ANSI C REFERENCE CARD
ANSI C REFERENCE CARDANSI C REFERENCE CARD
ANSI C REFERENCE CARDTia Ricci
 
chap09alg.ppt for string matching algorithm
chap09alg.ppt for string matching algorithmchap09alg.ppt for string matching algorithm
chap09alg.ppt for string matching algorithmSadiaSharmin40
 

Similar to A Language Designer’s Workbench. A one-stop shop for implementation and verification of language designs (20)

Scala - where objects and functions meet
Scala - where objects and functions meetScala - where objects and functions meet
Scala - where objects and functions meet
 
Build a compiler in 2hrs - NCrafts Paris 2015
Build a compiler in 2hrs -  NCrafts Paris 2015Build a compiler in 2hrs -  NCrafts Paris 2015
Build a compiler in 2hrs - NCrafts Paris 2015
 
TI1220 Lecture 9: Parsing & interpretation
TI1220 Lecture 9: Parsing & interpretationTI1220 Lecture 9: Parsing & interpretation
TI1220 Lecture 9: Parsing & interpretation
 
Top down and botttom up 2 LATEST.
Top down     and botttom up 2 LATEST.Top down     and botttom up 2 LATEST.
Top down and botttom up 2 LATEST.
 
Model-Driven Software Development - Static Analysis & Error Checking
Model-Driven Software Development - Static Analysis & Error CheckingModel-Driven Software Development - Static Analysis & Error Checking
Model-Driven Software Development - Static Analysis & Error Checking
 
Top down and botttom up Parsing
Top down     and botttom up ParsingTop down     and botttom up Parsing
Top down and botttom up Parsing
 
Compiler Construction | Lecture 4 | Parsing
Compiler Construction | Lecture 4 | Parsing Compiler Construction | Lecture 4 | Parsing
Compiler Construction | Lecture 4 | Parsing
 
Top down parsing(sid) (1)
Top down parsing(sid) (1)Top down parsing(sid) (1)
Top down parsing(sid) (1)
 
Python Lecture 11
Python Lecture 11Python Lecture 11
Python Lecture 11
 
Ch5b
Ch5bCh5b
Ch5b
 
Declare Your Language: Name Resolution
Declare Your Language: Name ResolutionDeclare Your Language: Name Resolution
Declare Your Language: Name Resolution
 
仕事で使うF#
仕事で使うF#仕事で使うF#
仕事で使うF#
 
Term Rewriting
Term RewritingTerm Rewriting
Term Rewriting
 
Swift Rocks #2: Going functional
Swift Rocks #2: Going functionalSwift Rocks #2: Going functional
Swift Rocks #2: Going functional
 
Ch6
Ch6Ch6
Ch6
 
Chap09alg
Chap09algChap09alg
Chap09alg
 
Chap09alg
Chap09algChap09alg
Chap09alg
 
ANSI C REFERENCE CARD
ANSI C REFERENCE CARDANSI C REFERENCE CARD
ANSI C REFERENCE CARD
 
Ch6.ppt
Ch6.pptCh6.ppt
Ch6.ppt
 
chap09alg.ppt for string matching algorithm
chap09alg.ppt for string matching algorithmchap09alg.ppt for string matching algorithm
chap09alg.ppt for string matching algorithm
 

More from Eelco Visser

CS4200 2019 | Lecture 5 | Transformation by Term Rewriting
CS4200 2019 | Lecture 5 | Transformation by Term RewritingCS4200 2019 | Lecture 5 | Transformation by Term Rewriting
CS4200 2019 | Lecture 5 | Transformation by Term RewritingEelco Visser
 
CS4200 2019 | Lecture 4 | Syntactic Services
CS4200 2019 | Lecture 4 | Syntactic ServicesCS4200 2019 | Lecture 4 | Syntactic Services
CS4200 2019 | Lecture 4 | Syntactic ServicesEelco Visser
 
CS4200 2019 | Lecture 3 | Parsing
CS4200 2019 | Lecture 3 | ParsingCS4200 2019 | Lecture 3 | Parsing
CS4200 2019 | Lecture 3 | ParsingEelco Visser
 
CS4200 2019 | Lecture 2 | syntax-definition
CS4200 2019 | Lecture 2 | syntax-definitionCS4200 2019 | Lecture 2 | syntax-definition
CS4200 2019 | Lecture 2 | syntax-definitionEelco Visser
 
CS4200 2019 Lecture 1: Introduction
CS4200 2019 Lecture 1: IntroductionCS4200 2019 Lecture 1: Introduction
CS4200 2019 Lecture 1: IntroductionEelco Visser
 
A Direct Semantics of Declarative Disambiguation Rules
A Direct Semantics of Declarative Disambiguation RulesA Direct Semantics of Declarative Disambiguation Rules
A Direct Semantics of Declarative Disambiguation RulesEelco Visser
 
Declarative Type System Specification with Statix
Declarative Type System Specification with StatixDeclarative Type System Specification with Statix
Declarative Type System Specification with StatixEelco Visser
 
Compiler Construction | Lecture 17 | Beyond Compiler Construction
Compiler Construction | Lecture 17 | Beyond Compiler ConstructionCompiler Construction | Lecture 17 | Beyond Compiler Construction
Compiler Construction | Lecture 17 | Beyond Compiler ConstructionEelco Visser
 
Domain Specific Languages for Parallel Graph AnalytiX (PGX)
Domain Specific Languages for Parallel Graph AnalytiX (PGX)Domain Specific Languages for Parallel Graph AnalytiX (PGX)
Domain Specific Languages for Parallel Graph AnalytiX (PGX)Eelco Visser
 
Compiler Construction | Lecture 15 | Memory Management
Compiler Construction | Lecture 15 | Memory ManagementCompiler Construction | Lecture 15 | Memory Management
Compiler Construction | Lecture 15 | Memory ManagementEelco Visser
 
Compiler Construction | Lecture 13 | Code Generation
Compiler Construction | Lecture 13 | Code GenerationCompiler Construction | Lecture 13 | Code Generation
Compiler Construction | Lecture 13 | Code GenerationEelco Visser
 
Compiler Construction | Lecture 12 | Virtual Machines
Compiler Construction | Lecture 12 | Virtual MachinesCompiler Construction | Lecture 12 | Virtual Machines
Compiler Construction | Lecture 12 | Virtual MachinesEelco Visser
 
Compiler Construction | Lecture 11 | Monotone Frameworks
Compiler Construction | Lecture 11 | Monotone FrameworksCompiler Construction | Lecture 11 | Monotone Frameworks
Compiler Construction | Lecture 11 | Monotone FrameworksEelco Visser
 
Compiler Construction | Lecture 10 | Data-Flow Analysis
Compiler Construction | Lecture 10 | Data-Flow AnalysisCompiler Construction | Lecture 10 | Data-Flow Analysis
Compiler Construction | Lecture 10 | Data-Flow AnalysisEelco Visser
 
Compiler Construction | Lecture 9 | Constraint Resolution
Compiler Construction | Lecture 9 | Constraint ResolutionCompiler Construction | Lecture 9 | Constraint Resolution
Compiler Construction | Lecture 9 | Constraint ResolutionEelco Visser
 
Compiler Construction | Lecture 8 | Type Constraints
Compiler Construction | Lecture 8 | Type ConstraintsCompiler Construction | Lecture 8 | Type Constraints
Compiler Construction | Lecture 8 | Type ConstraintsEelco Visser
 
Compiler Construction | Lecture 7 | Type Checking
Compiler Construction | Lecture 7 | Type CheckingCompiler Construction | Lecture 7 | Type Checking
Compiler Construction | Lecture 7 | Type CheckingEelco Visser
 
Compiler Construction | Lecture 6 | Introduction to Static Analysis
Compiler Construction | Lecture 6 | Introduction to Static AnalysisCompiler Construction | Lecture 6 | Introduction to Static Analysis
Compiler Construction | Lecture 6 | Introduction to Static AnalysisEelco Visser
 
Compiler Construction | Lecture 5 | Transformation by Term Rewriting
Compiler Construction | Lecture 5 | Transformation by Term RewritingCompiler Construction | Lecture 5 | Transformation by Term Rewriting
Compiler Construction | Lecture 5 | Transformation by Term RewritingEelco Visser
 
Compiler Construction | Lecture 3 | Syntactic Editor Services
Compiler Construction | Lecture 3 | Syntactic Editor ServicesCompiler Construction | Lecture 3 | Syntactic Editor Services
Compiler Construction | Lecture 3 | Syntactic Editor ServicesEelco Visser
 

More from Eelco Visser (20)

CS4200 2019 | Lecture 5 | Transformation by Term Rewriting
CS4200 2019 | Lecture 5 | Transformation by Term RewritingCS4200 2019 | Lecture 5 | Transformation by Term Rewriting
CS4200 2019 | Lecture 5 | Transformation by Term Rewriting
 
CS4200 2019 | Lecture 4 | Syntactic Services
CS4200 2019 | Lecture 4 | Syntactic ServicesCS4200 2019 | Lecture 4 | Syntactic Services
CS4200 2019 | Lecture 4 | Syntactic Services
 
CS4200 2019 | Lecture 3 | Parsing
CS4200 2019 | Lecture 3 | ParsingCS4200 2019 | Lecture 3 | Parsing
CS4200 2019 | Lecture 3 | Parsing
 
CS4200 2019 | Lecture 2 | syntax-definition
CS4200 2019 | Lecture 2 | syntax-definitionCS4200 2019 | Lecture 2 | syntax-definition
CS4200 2019 | Lecture 2 | syntax-definition
 
CS4200 2019 Lecture 1: Introduction
CS4200 2019 Lecture 1: IntroductionCS4200 2019 Lecture 1: Introduction
CS4200 2019 Lecture 1: Introduction
 
A Direct Semantics of Declarative Disambiguation Rules
A Direct Semantics of Declarative Disambiguation RulesA Direct Semantics of Declarative Disambiguation Rules
A Direct Semantics of Declarative Disambiguation Rules
 
Declarative Type System Specification with Statix
Declarative Type System Specification with StatixDeclarative Type System Specification with Statix
Declarative Type System Specification with Statix
 
Compiler Construction | Lecture 17 | Beyond Compiler Construction
Compiler Construction | Lecture 17 | Beyond Compiler ConstructionCompiler Construction | Lecture 17 | Beyond Compiler Construction
Compiler Construction | Lecture 17 | Beyond Compiler Construction
 
Domain Specific Languages for Parallel Graph AnalytiX (PGX)
Domain Specific Languages for Parallel Graph AnalytiX (PGX)Domain Specific Languages for Parallel Graph AnalytiX (PGX)
Domain Specific Languages for Parallel Graph AnalytiX (PGX)
 
Compiler Construction | Lecture 15 | Memory Management
Compiler Construction | Lecture 15 | Memory ManagementCompiler Construction | Lecture 15 | Memory Management
Compiler Construction | Lecture 15 | Memory Management
 
Compiler Construction | Lecture 13 | Code Generation
Compiler Construction | Lecture 13 | Code GenerationCompiler Construction | Lecture 13 | Code Generation
Compiler Construction | Lecture 13 | Code Generation
 
Compiler Construction | Lecture 12 | Virtual Machines
Compiler Construction | Lecture 12 | Virtual MachinesCompiler Construction | Lecture 12 | Virtual Machines
Compiler Construction | Lecture 12 | Virtual Machines
 
Compiler Construction | Lecture 11 | Monotone Frameworks
Compiler Construction | Lecture 11 | Monotone FrameworksCompiler Construction | Lecture 11 | Monotone Frameworks
Compiler Construction | Lecture 11 | Monotone Frameworks
 
Compiler Construction | Lecture 10 | Data-Flow Analysis
Compiler Construction | Lecture 10 | Data-Flow AnalysisCompiler Construction | Lecture 10 | Data-Flow Analysis
Compiler Construction | Lecture 10 | Data-Flow Analysis
 
Compiler Construction | Lecture 9 | Constraint Resolution
Compiler Construction | Lecture 9 | Constraint ResolutionCompiler Construction | Lecture 9 | Constraint Resolution
Compiler Construction | Lecture 9 | Constraint Resolution
 
Compiler Construction | Lecture 8 | Type Constraints
Compiler Construction | Lecture 8 | Type ConstraintsCompiler Construction | Lecture 8 | Type Constraints
Compiler Construction | Lecture 8 | Type Constraints
 
Compiler Construction | Lecture 7 | Type Checking
Compiler Construction | Lecture 7 | Type CheckingCompiler Construction | Lecture 7 | Type Checking
Compiler Construction | Lecture 7 | Type Checking
 
Compiler Construction | Lecture 6 | Introduction to Static Analysis
Compiler Construction | Lecture 6 | Introduction to Static AnalysisCompiler Construction | Lecture 6 | Introduction to Static Analysis
Compiler Construction | Lecture 6 | Introduction to Static Analysis
 
Compiler Construction | Lecture 5 | Transformation by Term Rewriting
Compiler Construction | Lecture 5 | Transformation by Term RewritingCompiler Construction | Lecture 5 | Transformation by Term Rewriting
Compiler Construction | Lecture 5 | Transformation by Term Rewriting
 
Compiler Construction | Lecture 3 | Syntactic Editor Services
Compiler Construction | Lecture 3 | Syntactic Editor ServicesCompiler Construction | Lecture 3 | Syntactic Editor Services
Compiler Construction | Lecture 3 | Syntactic Editor Services
 

Recently uploaded

BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxfenichawla
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college projectTonystark477637
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 

Recently uploaded (20)

BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 

A Language Designer’s Workbench. A one-stop shop for implementation and verification of language designs

  • 1. A Language Designer’s Workbench A one-stop shop for implementation and verification of language designs Eelco Visser, Guido Wachsmuth, Andrew Tolmach Pierre Neron, Vlad Vergu, Augusto Passalaqua, Gabriël Konat
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8. parser type checker code generator interpreter parser error recovery syntax highlighting outline code completion navigation type checker debugger syntax definition static semantics dynamic semantics abstract syntax type system operational semantics type soundness proof
  • 10. Language Engineering Syntax Checker Name Resolver Type Checker Code Generator
  • 11. Semantics Engineering Abstract Syntax Type System Dynamic Semantics Transform
  • 12. Language Design Syntax Definition Name Binding Type Constraints Dynamic Semantics Transform Language Designer’s Workbench
  • 13. Language Design Syntax Name Type Dynamic Languages Transform Definition Binding Constraints Semantics Declarative Meta-Multi-purpose Language Designer’s Workbench
  • 14. Language Design SDF3 NaBL TS DynSem Stratego Language Designer’s Workbench: First Prototype
  • 15. module PCF sorts Exp Param Type templates Exp.Var = [[ID]] Exp.App = [[Exp] [Exp]] {left} Exp.Fun = [ fun [Param] ( [Exp] ) ] Exp.Fix = [ fix [Param] ( [Exp] ) ] Exp.Let = [ let [ID] : [Type] = [Exp] in [Exp] ] Exp.Num = [[INT]] Exp.Add = [[Exp] + [Exp]] {left} Exp.Sub = [[Exp] - [Exp]] {left} Exp.Mul = [[Exp] * [Exp]] {left} Exp = [([Exp])] {bracket} Exp.Ifz = [ ifz [Exp] then [Exp] else [Exp] ] Type.IntType = [int] Type.FunType = [[Type] -> [Type]] Param.Param = [[ID] : [Type]] context-free priorities Exp.App > Exp.Mul > {left: Exp.Add Exp.Sub} > Exp.Ifz First Little (Big) Step: PCF in Spoofax module types type rules Var(x) : t where definition of x : t Param(x, t) : t Fun(p, e) : FunType(tp, te) where p : tp and e : te App(e1, e2) : tr where e1 : FunType(tf, tr) and e2 : ta and tf == ta else error "type mismatch" on e2 Fix(p, e) : tp where p : tp and e : te and tp == te else error "type mismatch" on p Let(x, tx, e1, e2) : t2 where e2 : t2 and e1 : t1 and t1 == tx else error "type mismatch" on e1 Num(i) : IntType() Ifz(e1, e2, e3) : t2 where e1 : IntType() and e2 : t2 and e3 : t3 and t2 == t3 else error "types not compatible" on e3 e@Add(e1, e2) + e@Sub(e1, e2) + e@Mul(e1, e2) : IntType() where e1 : IntType() else error "Int type expected" on e and e2 : IntType() else error "Int type expected" on e module semantics rules E env |- Var(x) --> v where env[x] => T(e, env'), E env' |- e --> v E env |- Fun(Param(x, t), e) --> C(x, e, env) E env |- App(e1, e2) --> v where E env |- e1 --> C(x, e, env'), E {x |--> T(e2, env), env'} |- e --> v E env |- Fix(Param(x, t), e) --> v where E {x |--> T(Fix(Param(x,t),e),env), env} |- e --> v E env |- Let(x, t, e1, e2) --> v where E {x |--> T(e1, env), env} |- e2 --> v rules Num(i) --> I(i) Ifz(e1, e2, e3) --> v where e1 --> I(i), i = 0, e2 --> v Ifz(e1, e2, e3) --> v where e1 --> I(i), i != 0, e3 --> v Add(e1, e2) --> I(addInt(i, j)) where e1 --> I(i), e2 --> I(j) Sub(e1, e2) --> I(subInt(i, j)) where e1 --> I(i), e2 --> I(j) Mul(e1, e2) --> I(mulInt(i, j)) where e1 --> I(i), e2 --> I(j) module names namespaces Variable binding rules Var(x) : refers to Variable x Param(x, t) : defines Variable x of type t Fun(p, e) : scopes Variable Fix(p, e) : scopes Variable Let(x, t, e1, e2) : defines Variable x of type t in e2 SDF3 NaBL TS DynSem
  • 17. Syntax = Tree Structure parse(prettyprint(t)) = t No need to understand how parse works! Exp.Fun Param ( Exp ) Exp.App Exp Exp.Ifz ifz Exp then Exp else Exp Exp.Add Exp + Exp Exp.Var ID fun Exp
  • 18. Exp.Fun Param ( Exp ) Exp.App Exp Exp.Ifz ifz Exp then Exp else Exp Exp.Add Exp + Exp context-free syntax Exp.Fun = [ fun [Param] ( [Exp] ) ] Exp.Ifz = [ ifz [Exp] then [Exp] else [Exp] ] Exp.App = [[Exp] [Exp]] {left} Exp.Add = <<Exp> + <Exp>> Exp.Var = <<ID>> Exp.Var ID fun Exp SDF3 : Syntax Definition Formalism
  • 19.
  • 20. Multi-Purpose Declarative Syntax Definition Exp.Ifz = [ ifz [Exp] then [Exp] else [Exp] ] Parser Error recovery rules Pretty-Printer Abstract syntax tree schema Syntactic coloring Syntactic completion templates Folding rules Outline rules Syntax Definition
  • 22. let fac : int -> int = fix f : int -> int ( fun n : int ( ifz n then 1 else n * f (n - 1) ) ) in (fac 3) is this expression well-typed?
  • 23. let fac : int -> int = fix f : int -> int ( fun n : int ( ifz n then 1 else n * f (n - 1) ) ) in (fac 3) type rules Var(x) : t where definition of x : t Param(x, t) : t Fun(p, e) : FunType(tp, te) where p : tp and e : te App(e1, e2) : tr where e1 : FunType(tf, tr) and e2 : ta and tf == ta else error "type mismatch" on e2 e@Sub(e1, e2) : IntType() where e1 : IntType() else error "Int type expected" on e and e2 : IntType() else error "Int type expected" on e TS: Type analysiS
  • 24. let fac : int -> int = fix f : int -> int ( fun n : int ( ifz n then 1 else n * f (n - 1) ) ) in (fac 3) type rules Var(x) : t where definition of x : t Param(x, t) : t Fun(p, e) : FunType(tp, te) where p : tp and e : te App(e1, e2) : tr where e1 : FunType(tf, tr) and e2 : ta and tf == ta else error "type mismatch" on e2 e@Sub(e1, e2) where e1 : IntType() else error "Int type expected" on e and e2 : IntType() else error "Int type expected" on e TS: Type analysiS
  • 25. type rules Var(x) : t where definition of x : t Param(x, t) : t Fun(p, e) : FunType(tp, te) where p : tp and e : te App(e1, e2) : tr where e1 : FunType(tf, tr) and e2 : ta and tf == ta else error "type mismatch" on e2 e@Sub(e1, e2) where e1 : IntType() else error "Int type expected" on e and e2 : IntType() else error "Int type expected" on e let fac : int -> int = fix f : int -> int ( fun n : int ( ifz n then 1 else n * f (n - 1) ) ) in (fac 3) TS: Type analysiS
  • 26. let fac : int -> int = fix f : int -> int ( fun n : int ( ifz n then 1 else n * f (n - 1) ) ) in (fac 3) type rules Var(x) : t where definition of x : t Param(x, t) : t Fun(p, e) : FunType(tp, te) where p : tp and e : te App(e1, e2) : tr where e1 : FunType(tf, tr) and e2 : ta and tf == ta else error "type mismatch" on e2 e@Sub(e1, e2) where e1 : IntType() else error "Int type expected" on e and e2 : IntType() else error "Int type expected" on e TS: Type analysiS
  • 27. let fac : int -> int = fix f : int -> int ( fun n : int ( ifz n then 1 else n * f (n - 1) ) ) in (fac 3) type rules Var(x) : t where definition of x : t Param(x, t) : t Fun(p, e) : FunType(tp, te) where p : tp and e : te App(e1, e2) : tr where e1 : FunType(tf, tr) and e2 : ta and tf == ta else error "type mismatch" on e2 e@Sub(e1, e2) where e1 : IntType() else error "Int type expected" on e and e2 : IntType() else error "Int type expected" on e TS: Type analysiS
  • 28. let fac : int -> int = fix f : int -> int ( fun n : int ( ifz n then 1 else n * f (n - 1) ) ) in (fac 3) type rules Var(x) : t where definition of x : t Param(x, t) : t Fun(p, e) : FunType(tp, te) where p : tp and e : te App(e1, e2) : tr where e1 : FunType(tf, tr) and e2 : ta and tf == ta else error "type mismatch" on e2 e@Sub(e1, e2) where e1 : IntType() else error "Int type expected" on e and e2 : IntType() else error "Int type expected" on e TS: Type analysiS
  • 29. Multiple messages: - types not compatible - Unresolved reference
  • 30. Multi-Purpose Type Constraints Inline type error reports Type annotations Interaction with name binding Semantic code completion Refactorings type rules Var(x) : t where definition of x : t Param(x, t) : t Fun(p, e) : FunType(tp, te) where p : tp and e : te App(e1, e2) : tr where e1 : FunType(tf, tr) and e2 : ta and tf == ta else error "type mismatch" on e2 e@Sub(e1, e2) where e1 : IntType() else error "Int type expected" on e and e2 : IntType() else error "Int type expected" on e Incremental type analysis
  • 31. Name Binding & Scope
  • 32. let fac : int -> int = fix f : int -> int ( fun n : int ( ifz n then 1 else n * f (n - 1) ) ) in (fac 3) what does this variable refer to?
  • 33. module names namespaces Variable binding rules Var(x) : refers to Variable x Param(x, t) : defines Variable x of type t Fun(p, e) : scopes Variable Fix(p, e) : scopes Variable Let(x, t, e1, e2) : defines Variable x of type t in e2 let fac : int -> int = fix f : int -> int ( fun n : int ( ifz n then 1 else n * f (n - 1) ) ) in (fac 3) NaBL: Name Binding Language
  • 34. module names namespaces Variable binding rules Var(x) : refers to Variable x Param(x, t) : defines Variable x of type t Fun(p, e) : scopes Variable Fix(p, e) : scopes Variable Let(x, t, e1, e2) : defines Variable x of type t in e2 NaBL: Name Binding Language let fac : int -> int = fix f : int -> int ( fun n : int ( ifz n then 1 else n * f (n - 1) ) ) in (fac 3)
  • 35. module names namespaces Variable binding rules Var(x) : refers to Variable x Param(x, t) : defines Variable x of type t Fun(p, e) : scopes Variable Fix(p, e) : scopes Variable Let(x, t, e1, e2) : defines Variable x of type t in e2 NaBL: Name Binding Language let fac : int -> int = fix f : int -> int ( fun n : int ( ifz n then 1 else n * f (n - 1) ) ) in (fac 3)
  • 36. module names namespaces Variable binding rules Var(x) : refers to Variable x Param(x, t) : defines Variable x of type t Fun(p, e) : scopes Variable Fix(p, e) : scopes Variable Let(x, t, e1, e2) : defines Variable x of type t in e2 NaBL: Name Binding Language let fac : int -> int = fix f : int -> int ( fun n : int ( ifz n then 1 else n * f (n - 1) ) ) in (fac 3)
  • 37. module names namespaces Variable binding rules Var(x) : refers to Variable x Param(x, t) : defines Variable x of type t Fun(p, e) : scopes Variable Fix(p, e) : scopes Variable Let(x, t, e1, e2) : defines Variable x of type t in e2 let fac : int -> int = fix f : int -> int ( fun n : int ( ifz n then 1 else n * f (n - 1) ) ) in (fac 3) NaBL: Name Binding Language
  • 38. module names namespaces Variable binding rules Var(x) : refers to Variable x Param(x, t) : defines Variable x of type t Fun(p, e) : scopes Variable Fix(p, e) : scopes Variable Let(x, t, e1, e2) : defines Variable x of type t in e2 let fac : int -> int = fix f : int -> int ( fun n : int ( ifz n then 1 else n * f (n - 1) ) ) in (fac 3) NaBL: Name Binding Language
  • 39. module names namespaces Variable binding rules Var(x) : refers to Variable x Param(x, t) : defines Variable x of type t Fun(p, e) : scopes Variable Fix(p, e) : scopes Variable Let(x, t, e1, e2) : defines Variable x of type t in e2 let fac : int -> int = fix f : int -> int ( fun n : int ( ifz n then 1 else n * f (n - 1) ) ) in (fac 3) NaBL: Name Binding Language
  • 40. module names namespaces Variable binding rules Var(x) : refers to Variable x Param(x, t) : defines Variable x of type t Fun(p, e) : scopes Variable Fix(p, e) : scopes Variable Let(x, t, e1, e2) : defines Variable x of type t in e2 let fac : int -> int = fix f : int -> int ( fun n : int ( ifz n then 1 else n * f (n - 1) ) ) in (fac 3) NaBL: Name Binding Language
  • 41. Multi-Purpose Name Binding Rules Incremental name resolution algorithm Name checks Reference resolution Semantic code completion module names namespaces Variable binding rules Var(x) : refers to Variable x Param(x, t) : defines Variable x of type t Fun(p, e) : scopes Variable Fix(p, e) : scopes Variable Let(x, t, e1, e2) : defines Variable x of type t in e2 Refactorings
  • 43. let fac : int -> int = fix f : int -> int ( fun n : int ( ifz n then 1 else n * f (n - 1) ) ) in (fac 3) What is the value of this expression?
  • 44. let fac : int -> int = fix f : int -> int ( fun n : int ( ifz n then 1 else n * f (n - 1) ) ) in (fac 3) rules Num(i) --> I(i) Sub(e1, e2) --> I(subInt(i, j)) where e1 --> I(i), e2 --> I(j) Ifz(e1, e2, e3) --> v where e1 --> I(i), i = 0, e2 --> v Ifz(e1, e2, e3) --> v where e1 --> I(i), i != 0, e3 --> v DynSem: Dynamic Semantics
  • 45. rules Num(i) --> I(i) Sub(e1, e2) --> I(subInt(i, j)) where e1 --> I(i), e2 --> I(j) Ifz(e1, e2, e3) --> v where e1 --> I(i), i = 0, e2 --> v Ifz(e1, e2, e3) --> v where e1 --> I(i), i != 0, e3 --> v let fac : int -> int = fix f : int -> int ( fun n : int ( ifz n then 1 else n * f (n - 1) ) ) in (fac 3) DynSem: Dynamic Semantics
  • 46. rules E env |- Var(x) --> v where env[x] => T(e, env'), E env' |- e --> v E env |- Fun(Param(x, t), e) --> C(x, e, env) E env |- App(e1, e2) --> v where E env |- e1 --> C(x, e, env'), E {x |--> T(e2, env), env'} |- e --> v let fac : int -> int = fix f : int -> int ( fun n : int ( ifz n then 1 else n * f (n - 1) ) ) in (fac 3) DynSem: Dynamic Semantics
  • 47. let fac : int -> int = fix f : int -> int ( fun n : int ( ifz n then 1 else n * f (n - 1) ) ) in (fac 3) rules E env |- Var(x) --> v where env[x] => T(e, env'), E env' |- e --> v E env |- Fun(Param(x, t), e) --> C(x, e, env) E env |- App(e1, e2) --> v where E env |- e1 --> C(x, e, env'), E {x |--> T(e2, env), env'} |- e --> v DynSem: Dynamic Semantics
  • 48. rules E env |- Var(x) --> v where env[x] => T(e, env'), E env' |- e --> v E env |- Fun(Param(x, t), e) --> C(x, e, env) E env |- App(e1, e2) --> v where E env |- e1 --> C(x, e, env'), E {x |--> T(e2, env), env'} |- e --> v let fac : int -> int = fix f : int -> int ( fun n : int ( ifz n then 1 else n * f (n - 1) ) ) in (fac 3) DynSem: Dynamic Semantics
  • 49. Implicitly-Modular Structural Operational Semantics (I-MSOS)* rules E env |- Var(x) --> v where env[x] => T(e, env'), E env' |- e --> v Add(e1, e2) --> I(addInt(i, j)) where e1 --> I(i), e2 --> I(j) rules E env |- Var(x) --> v where env[x] => T(e, env'), E env' |- e --> v E env |- Add(e1, e2) --> I(addInt(i, j)) where E env |- e1 --> I(i), explicate E env |- e2 --> I(j) * P. D. Mosses. Modular structural operational semantics. JLP, 60-61:195–228, 2004. M. Churchill, P. D. Mosses, and P. Torrini. Reusable components of semantic specifications. In MODULARITY, April 2014.
  • 50. Interpreter Generation rules Ifz(e1, e2, e3) --> v where e1 --> I(i), i = 0, e2 --> v Ifz(e1, e2, e3) --> v where e1 --> I(i), i != 0, e3 --> v explicate & merge rules E env |- Ifz(e1, e2, e3) --> v where E env |- e1 --> I(i), [i = 0, E env |- e2 --> v] + i != 0, E env |- e3 --> v]
  • 51. Multi-Purpose Dynamic Semantics Generate interpreter Verification Type soundness rules E env |- Var(x) --> v where env[x] => T(e, env'), E env' |- e --> v E env |- Fun(Param(x, t), e) --> C(x, e, env) E env |- App(e1, e2) --> v where E env |- e1 --> C(x, e, env'), E {x |--> T(e2, env), env'} |- e --> v Semantics preservation
  • 53. module PCF sorts Exp Param Type templates Exp.Var = [[ID]] Exp.App = [[Exp] [Exp]] {left} Exp.Fun = [ fun [Param] ( [Exp] ) ] Exp.Fix = [ fix [Param] ( [Exp] ) ] Exp.Let = [ let [ID] : [Type] = [Exp] in [Exp] ] Exp.Num = [[INT]] Exp.Add = [[Exp] + [Exp]] {left} Exp.Sub = [[Exp] - [Exp]] {left} Exp.Mul = [[Exp] * [Exp]] {left} Exp = [([Exp])] {bracket} Exp.Ifz = [ ifz [Exp] then [Exp] else [Exp] ] Type.IntType = [int] Type.FunType = [[Type] -> [Type]] Param.Param = [[ID] : [Type]] context-free priorities Exp.App > Exp.Mul > {left: Exp.Add Exp.Sub} > Exp.Ifz From PCF in Spoofax … module types type rules Var(x) : t where definition of x : t Param(x, t) : t Fun(p, e) : FunType(tp, te) where p : tp and e : te App(e1, e2) : tr where e1 : FunType(tf, tr) and e2 : ta and tf == ta else error "type mismatch" on e2 Fix(p, e) : tp where p : tp and e : te and tp == te else error "type mismatch" on p Let(x, tx, e1, e2) : t2 where e2 : t2 and e1 : t1 and t1 == tx else error "type mismatch" on e1 Num(i) : IntType() Ifz(e1, e2, e3) : t2 where e1 : IntType() and e2 : t2 and e3 : t3 and t2 == t3 else error "types not compatible" on e3 e@Add(e1, e2) + e@Sub(e1, e2) + e@Mul(e1, e2) : IntType() where e1 : IntType() else error "Int type expected" on e and e2 : IntType() else error "Int type expected" on e module semantics rules E env |- Var(x) --> v where env[x] => T(e, env'), E env' |- e --> v E env |- Fun(Param(x, t), e) --> C(x, e, env) E env |- App(e1, e2) --> v where E env |- e1 --> C(x, e, env'), E {x |--> T(e2, env), env'} |- e --> v E env |- Fix(Param(x, t), e) --> v where E {x |--> T(Fix(Param(x,t),e),env), env} |- e --> v E env |- Let(x, t, e1, e2) --> v where E {x |--> T(e1, env), env} |- e2 --> v rules Num(i) --> I(i) Ifz(e1, e2, e3) --> v where e1 --> I(i), i = 0, e2 --> v Ifz(e1, e2, e3) --> v where e1 --> I(i), i != 0, e3 --> v Add(e1, e2) --> I(addInt(i, j)) where e1 --> I(i), e2 --> I(j) Sub(e1, e2) --> I(subInt(i, j)) where e1 --> I(i), e2 --> I(j) Mul(e1, e2) --> I(mulInt(i, j)) where e1 --> I(i), e2 --> I(j) module names namespaces Variable binding rules Var(x) : refers to Variable x Param(x, t) : defines Variable x of type t Fun(p, e) : scopes Variable Fix(p, e) : scopes Variable Let(x, t, e1, e2) : defines Variable x of type t in e2 SDF3 NaBL TS DynSem
  • 54. else [Exp] ] Type.IntType = [int] Type.FunType = [[Type] -> [Type]] Param.Param = [[ID] : [Type]] context-free priorities Exp.App > Exp.Mul > {left: Exp.Add Exp.Sub} > Exp.Ifz Ifz(e1, e2, e3) : t2 where e1 : IntType() and e2 : t2 and e3 : t3 and t2 == t3 else error "types not compatible" on e3 e@Add(e1, e2) + e@Sub(e1, e2) + e@Mul(e1, e2) : IntType() where e1 : IntType() else error "Int type expected" on e and e2 : IntType() else error "Int type expected" on e Ifz(e1, e2, e3) --> v where e1 --> I(i), i != 0, e3 --> v Add(e1, e2) --> I(addInt(i, j)) where e1 --> I(i), e2 --> I(j) Sub(e1, e2) --> I(subInt(i, j)) where e1 --> I(i), e2 --> I(j) Mul(e1, e2) --> I(mulInt(i, j)) where e1 --> I(i), e2 --> I(j) Param(x, t) : defines Variable x of type t Fun(p, e) : scopes Variable Fix(p, e) : scopes Variable Let(x, t, e1, e2) : defines Variable x of type t in e2 Inductive has_type (C: Context) : term -> term -> Prop := | VarC_ht ns k0 t x k1 : lookup C x ns k0 t -> has_type C (Co VarC [Id x k0] k1) t | ParamC_ht x t k0 : has_type C (Co ParamC [x;t] k0) t | FunC_ht k0 t_p t_e p e k1 : has_type C p t_p -> has_type C e t_e -> has_type C (Co FunC [p;e] k1) (Co FunTypeC [t_p;t_e] k0) | FixC_ht t_p t_e p e k0 : has_type C p t_p -> has_type C e t_e -> (t_p = t_e) -> has_type C (Co FixC [p;e] k0) t_p | AppC_ht t_r k0 t_f t_a e1 e2 k1 : has_type C e1 (Co FunTypeC [t_f;t_r] k0) -> has_type C e2 t_a -> (t_f = t_a) -> has_type C (Co AppC [e1;e2] k1) t_r | LetC_ht t2 t1 x t_x e1 e2 k0 : has_type C e2 t2 -> has_type C e1 t1 -> (t1 = t_x) -> has_type C (Co LetC [x;t_x;e1;e2] k0) t2 | NumC_ht k0 i k1 : has_type C (Co NumC [i] k1) (Co IntTypeC [] k0) | IfzC_ht k0 t2 t3 e1 e2 e3 k1 : has_type C e1 (Co IntTypeC [] k0) -> has_type C e2 t2 -> has_type C e3 t3 -> (t2 = t3) -> has_type C (Co IfzC [e1;e2;e3] k1) t2 | AddC_ht k2 k0 k1 e1 e2 k3 : has_type C e1 (Co IntTypeC [] k0) -> has_type C e2 (Co IntTypeC [] k1) -> has_type C (Co AddC [e1;e2] k3) (Co IntTypeC [] k2) | SubC_ht k2 k0 k1 e1 e2 k3 : has_type C e1 (Co IntTypeC [] k0) -> has_type C e2 (Co IntTypeC [] k1) -> has_type C (Co SubC [e1;e2] k3) (Co IntTypeC [] k2) | MulC_ht k2 k0 k1 e1 e2 k3 : has_type C e1 (Co IntTypeC [] k0) -> has_type C e2 (Co IntTypeC [] k1) -> has_type C (Co MulC [e1;e2] k3) (Co IntTypeC [] k2) | HT_eq e ty1 ty2 (hty1: has_type C e ty1) (tyeq: term_eq ty1 ty2) : has_type C e ty2 . Inductive semantics_cbn : Env -> term -> value -> Prop := | Var0C_sem env' e env x k0 v : get_env x env e env' -> semantics_cbn env' e v -> semantics_cbn env (Co VarC [x] k0) v | Fun0C_sem t k1 k0 x e env : semantics_cbn env (Co FunC [Co ParamC [x;t] k1;e] k0) (Clos x e env) | Fix0C_sem k1 k0 env x t k3 e k2 v : semantics_cbn { x |--> (Co FixC [Co ParamC [x;t] k1;e] k0,env), env } e v -> semantics_cbn env (Co FixC [Co ParamC [x;t] k3;e] k2) v | App0C_sem env' x e env e1 e2 k0 v : semantics_cbn env e1 (Clos x e env') -> semantics_cbn { x |--> (e2,env), env' } e v -> semantics_cbn env (Co AppC [e1;e2] k0) v | Let0C_sem env x t e1 e2 k0 v : semantics_cbn { x |--> (e1,env), env } e2 v -> semantics_cbn env (Co LetC [x;t;e1;e2] k0) v | Num0C_sem env k0 i : semantics_cbn env (Co NumC [i] k0) (Natval i) | Ifz0C_sem i env e1 e2 e3 k0 v : semantics_cbn env e1 (Natval i) -> (i = 0) -> semantics_cbn env e2 v -> semantics_cbn env (Co IfzC [e1;e2;e3] k0) v | Ifz1C_sem i env e1 e2 e3 k0 v : semantics_cbn env e1 (Natval i) -> (i <> 0) -> semantics_cbn env e3 v -> semantics_cbn env (Co IfzC [e1;e2;e3] k0) v | Add0C_sem env e1 e2 k0 i j : semantics_cbn env e1 (Natval i) -> semantics_cbn env e2 (Natval j) -> semantics_cbn env (Co AddC [e1;e2] k0) (plus i j) | Sub0C_sem env e1 e2 k0 i j : semantics_cbn env e1 (Natval i) -> semantics_cbn env e2 (Natval j) -> semantics_cbn env (Co SubC [e1;e2] k0) (minus i j) | Mul0C_sem env e1 e2 k0 i j : semantics_cbn env e1 (Natval i) -> semantics_cbn env e2 (Natval j) -> semantics_cbn env (Co MulC [e1;e2] k0) (mult i j) . Inductive ID_NS : Set := | VariableNS . Definition NS := ID_NS . Inductive scopesR : term -> NS -> Prop := | Fun_scopes_Variable p e k0 : scopesR (Co FunC [p;e] k0) VariableNS | Fix_scopes_Variable p e k0 : scopesR (Co FixC [p;e] k0) VariableNS . Definition scopes_R := scopesR . Inductive definesR : term -> Ident -> NS -> key -> Prop := | Param_defines_Variable x k1 t k0 : definesR (Co ParamC [Id x k1;t] k0) x VariableNS k1 . Definition defines_R := definesR . Inductive refers_toR : term -> Ident -> NS -> key -> Prop := | Var_refers_to_Variable x k1 k0 : refers_toR (Co VarC [Id x k1] k0) x VariableNS k1 . Definition refers_to_R := refers_toR . Inductive typed_definesR : term -> Ident -> NS -> term -> key -> Prop := | Param_typed_defines_Variable x t k1 t k0 : typed_definesR (Co ParamC [Id x k1;t] k0) x VariableNS t k1 . Definition typed_defines_R := typed_definesR . Inductive sorts : Set := | Param_S | ID_S | INT_S | Exp_S | Type_S . Parameter Ident : Set. Definition sort := sorts . Definition Ident_Sort := ID_S . Inductive Constructors := | INTC (n: nat) | VarC | FunC | FixC | AppC | LetC | ParamC | NumC | AddC | SubC | MulC | DivC | IfzC | IntTypeC | FunTypeC . Definition constructors := Constructors . Fixpoint get_sig (x: constructors) : list sort * sort := match x with | INTC n => ([],INT_S) | VarC => ([ID_S],Exp_S) | FunC => ([Param_S;Exp_S],Exp_S) | FixC => ([Param_S;Exp_S],Exp_S) | AppC => ([Exp_S;Exp_S],Exp_S) | LetC => ([ID_S;Type_S;Exp_S;Exp_S],Exp_S) | ParamC => ([ID_S;Type_S],Param_S) | NumC => ([INT_S],Exp_S) | AddC => ([Exp_S;Exp_S],Exp_S) | SubC => ([Exp_S;Exp_S],Exp_S) | MulC => ([Exp_S;Exp_S],Exp_S) | DivC => ([Exp_S;Exp_S],Exp_S) | IfzC => ([Exp_S;Exp_S;Exp_S],Exp_S) | IntTypeC => ([],Type_S) | FunTypeC => ([Type_S;Type_S],Type_S) end. … to PCF in Coq (+ manual proof of type preservation)
  • 55. A few things left to do …
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.