declarative semantics definition - static analysis and error checking
DESCRIPTION
Presentation slides of lecture 7 of course IN4303 on Compiler Construction at TU Delft.TRANSCRIPT
![Page 1: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/1.jpg)
IN4303 2014/15 Compiler Construction
Declarative Semantics Definition static analysis and error checking
Guido Wachsmuth
![Page 2: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/2.jpg)
Static Analysis and Error Checking 2
source code
![Page 3: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/3.jpg)
Static Analysis and Error Checking 2
source code
parse
![Page 4: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/4.jpg)
Static Analysis and Error Checking 2
source code
errors
parse
check
![Page 5: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/5.jpg)
Static Analysis and Error Checking 2
source code
errors
parse generate
check
machine code
![Page 6: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/6.jpg)
Static Analysis and Error Checking 3
source code
![Page 7: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/7.jpg)
Static Analysis and Error Checking 3
source code
parse
![Page 8: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/8.jpg)
Static Analysis and Error Checking 3
source code
parse
check
![Page 9: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/9.jpg)
Static Analysis and Error Checking 3
source code
parse
check
![Page 10: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/10.jpg)
Static Analysis and Error Checking 3
source code
parse generate
machine code
check
![Page 11: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/11.jpg)
Static Analysis and Error Checking 4
static checking
name analysis name binding and scope
![Page 12: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/12.jpg)
Static Analysis and Error Checking 4
static checking
editor services
name analysis name binding and scope
![Page 13: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/13.jpg)
Static Analysis and Error Checking 4
static checking
editor services
transformation
name analysis name binding and scope
![Page 14: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/14.jpg)
Static Analysis and Error Checking 4
static checking
editor services
transformation
refactoring
name analysis name binding and scope
![Page 15: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/15.jpg)
Static Analysis and Error Checking 4
static checking
editor services
transformation
refactoring
code generation
name analysis name binding and scope
![Page 16: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/16.jpg)
Static Analysis and Error Checking
Stratego
NaBL TS
SDF3
ESV editor
SPT tests
5
syntax definition
concrete syntax
abstract syntax
static semantics
name binding
type system
dynamic semantics
translation
interpretation
![Page 17: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/17.jpg)
Static Analysis and Error Checking
Stratego
NaBL TS
SDF3
ESV editor
SPT tests
6
syntax definition
concrete syntax
abstract syntax
static semantics
name binding
type system
dynamic semantics
translation
interpretation
![Page 18: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/18.jpg)
Static Analysis and Error Checking 7
formal semantics
type system
name binding
testing
name binding
type system
constraints
specification
name binding
type system
constraints
![Page 19: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/19.jpg)
Static Analysis and Error Checking 8
formal semantics static semantics
![Page 20: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/20.jpg)
Static Analysis and Error Checking 9
word problem χL: Σ*→ {0,1}
w → 1, if w∈L
w → 0, else
theoretical computer science decidability & complexity
![Page 21: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/21.jpg)
Static Analysis and Error Checking 9
word problem χL: Σ*→ {0,1}
w → 1, if w∈L
w → 0, else
decidability
type-0: semi-decidable
type-1, type-2, type-3: decidable
theoretical computer science decidability & complexity
![Page 22: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/22.jpg)
Static Analysis and Error Checking 9
word problem χL: Σ*→ {0,1}
w → 1, if w∈L
w → 0, else
decidability
type-0: semi-decidable
type-1, type-2, type-3: decidable
complexity
type-1: PSPACE-complete
type-2, type-3: P
theoretical computer science decidability & complexity
![Page 23: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/23.jpg)
Static Analysis and Error Checking 9
word problem χL: Σ*→ {0,1}
w → 1, if w∈L
w → 0, else
decidability
type-0: semi-decidable
type-1, type-2, type-3: decidable
complexity
type-1: PSPACE-complete
type-2, type-3: P
theoretical computer science decidability & complexity
PSPACE⊇NP⊇P
![Page 24: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/24.jpg)
Static Analysis and Error Checking 10
formal grammars
context-sensitive
context-free
regular
theoretical computer science decidability & complexity
![Page 25: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/25.jpg)
Static Analysis and Error Checking 10
formal grammars
context-sensitive
context-free
regular
theoretical computer science decidability & complexity
![Page 26: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/26.jpg)
Static Analysis and Error Checking 10
formal grammars
context-sensitive
context-free
regular
theoretical computer science decidability & complexity
![Page 27: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/27.jpg)
Static Analysis and Error Checking 11
/* factorial function */!let ! var x := 0! function fact(n : int) : int = if n < 1 then 1 else (n * fact(n - 1))!in ! for i := 1 to 3 do ( x := x + fact(i); printint(x); print(" ") )!end
![Page 28: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/28.jpg)
Static Analysis and Error Checking 12
#include <stio.h>!/* factorial function */!int fac(int num) { if (num < 1) return 1; else return num * fac(num - 1);}!int main() { printf(“%d! = %d\n”, 10, fac(10)); return 0;}
![Page 29: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/29.jpg)
Static Analysis and Error Checking 13
class Main {! public static void main(String[] args) { System.out.println(new Fac().fac(10)); }}!class Fac {! public int fac(int num) { int num_aux; if (num < 1) num_aux = 1; else num_aux = num * this.fac(num - 1); return num_aux; }}
![Page 30: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/30.jpg)
Static Analysis and Error Checking 14
static semantics restricting context-free languages
context-sensitive language
context-free grammar
L(G) = {w∈Σ* | S ⇒G* w}
![Page 31: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/31.jpg)
Static Analysis and Error Checking 14
context-free superset
static semantics restricting context-free languages
context-sensitive language
context-free grammar
L(G) = {w∈Σ* | S ⇒G* w}
![Page 32: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/32.jpg)
Static Analysis and Error Checking 14
context-free superset
static semantics restricting context-free languages
context-sensitive language
context-free grammar
L(G) = {w∈Σ* | S ⇒G* w}
![Page 33: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/33.jpg)
Static Analysis and Error Checking 14
context-free superset
static semantics restricting context-free languages
context-sensitive language
context-free grammar
L(G) = {w∈Σ* | S ⇒G* w}
static semantics
L = {w∈ L(G) | ⊢ w}
![Page 34: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/34.jpg)
Static Analysis and Error Checking 14
context-free superset
static semantics restricting context-free languages
context-sensitive language
context-free grammar
L(G) = {w∈Σ* | S ⇒G* w}
static semantics
L = {w∈ L(G) | ⊢ w}
judgements
well-formed ⊢ w
well-typed E ⊢ e : t
![Page 35: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/35.jpg)
Static Analysis and Error Checking 14
context-free superset
static semantics restricting context-free languages
context-sensitive language
context-free grammar
L(G) = {w∈Σ* | S ⇒G* w}
static semantics
L = {w∈ L(G) | ⊢ w}
judgements
well-formed ⊢ w
well-typed E ⊢ e : t
![Page 36: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/36.jpg)
Static Analysis and Error Checking 15
formal semantics type systems
![Page 37: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/37.jpg)
Static Analysis and Error Checking 16
Tiger type system
E ⊢ i : int
E ⊢ s : string
E ⊢ nil : ⊥
![Page 38: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/38.jpg)
Static Analysis and Error Checking 17
Tiger type system
E ⊢ () : ∅
E ⊢ e1 : t1 E ⊢ e2 : t2
E ⊢ e1 ; e2 : t2
![Page 39: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/39.jpg)
Static Analysis and Error Checking 18
Tiger type system
E ⊢ e1 : int E ⊢ e2 : int
E ⊢ e1 + e2 : int
E ⊢ e1 : int E ⊢ e2 : int
E ⊢ e1 < e2 : int
E ⊢ e1 : string E ⊢ e2 : string
E ⊢ e1 < e2 : int
E ⊢ e1 : array of t E ⊢ e2 : int
E ⊢ e1[e2] : t
![Page 40: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/40.jpg)
Static Analysis and Error Checking 19
Tiger type system
E ⊢ e1 : t1 E ⊢ e2 : t2 t1 ≅ t2
E ⊢ e1 = e2 : int
t1 <: t2
t1 ≅ t2
t2 <: t1
t1 ≅ t2
t ≠ ∅
t ≅ t
⊥<: {f1, …, fn}
⊥<: array of t
![Page 41: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/41.jpg)
Static Analysis and Error Checking 20
Tiger type system
E ⊢ e1 : t1 E ⊢ e2 : t2 t1 ≅ t2
E ⊢ e1 := e2 : ∅
E ⊢ e1 : int E ⊢ e2 : t1 E ⊢ e3 : t2
E ⊢ if e1 then e2 else e3: sup<: {t1, t2}
![Page 42: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/42.jpg)
Static Analysis and Error Checking 21
formal semantics name binding
![Page 43: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/43.jpg)
Static Analysis and Error Checking 22
Tiger scoping
let type t = u type u = int var x: u := 0in x := 42 ; let type u = t var y: u := 0 in y := 42 endend
![Page 44: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/44.jpg)
Static Analysis and Error Checking 22
Tiger scoping
let type t = u type u = int var x: u := 0in x := 42 ; let type u = t var y: u := 0 in y := 42 endend
![Page 45: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/45.jpg)
Static Analysis and Error Checking 22
Tiger scoping
let type t = u type u = int var x: u := 0in x := 42 ; let type u = t var y: u := 0 in y := 42 endend
![Page 46: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/46.jpg)
Static Analysis and Error Checking 22
Tiger scoping
let type t = u type u = int var x: u := 0in x := 42 ; let type u = t var y: u := 0 in y := 42 endend
![Page 47: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/47.jpg)
Static Analysis and Error Checking 22
Tiger scoping
let type t = u type u = int var x: u := 0in x := 42 ; let type u = t var y: u := 0 in y := 42 endend
![Page 48: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/48.jpg)
Static Analysis and Error Checking 23
Tiger variable names
E ⊢ e1 : t1 t ≅ t1 E ⊕ v ↦ t ⊢ e2 : t2
E ⊢ let var v : t = e1 in e2: t2
E(v) = t
E ⊢ v : t
![Page 49: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/49.jpg)
Static Analysis and Error Checking 24
Tiger function names
E ⊕ v1 ↦ t1 ,…, vn ↦ tn ⊢ e1 : tf E ⊕ f ↦ t1 × … × tn → tf ⊢ e2 : t
E ⊢ let function f (v1 : t1, …, vn : tn) = e1 in e2: t
E(f) = t1 × … × tn → tf e1 : t1 … en : tn
E ⊢ f (e1, …, en) : t
![Page 50: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/50.jpg)
Static Analysis and Error Checking 25
testing
![Page 51: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/51.jpg)
Static Analysis and Error Checking 26
test outer name [[ let type t = u type [[u]] = int var x: [[u]] := 0 in x := 42 ; let type u = t var y: u := 0 in y := 42 endend]] resolve #2 to #1
test inner name [[ let type t = u type u = int var x: u := 0 in x := 42 ; let type [[u]] = t var y: [[u]] := 0 in y := 42 endend]] resolve #2 to #1
Testing name binding
![Page 52: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/52.jpg)
Static Analysis and Error Checking 27
test integer constant [[ let type t = u type u = int var x: u := 0 in x := 42 ; let type u = t var y: u := 0 in y := [[42]] endend]] run get-type to IntTy()
test variable reference [[ let type t = u type u = int var x: u := 0 in x := 42 ; let type u = t var y: u := 0 in y := [[x]] endend]] run get-type to IntTy()
Testing type system
![Page 53: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/53.jpg)
Static Analysis and Error Checking 28
test undefined variable [[ let type t = u type u = int var x: u := 0 in x := 42 ; let type u = t var y: u := 0 in y := [[z]] endend]] 1 error
test type error [[ let type t = u type u = string var x: u := 0 in x := 42 ; let type u = t var y: u := 0 in y := [[x]] endend]] 1 error
Testing constraints
![Page 54: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/54.jpg)
Static Analysis and Error Checking 29
context-free superset
testing static semantics
language
![Page 55: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/55.jpg)
Static Analysis and Error Checking 30
specification name binding
![Page 56: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/56.jpg)
Static Analysis and Error Checking 31
defines !
refers!
namespaces!
scopes!
imports
Name Binding Language concepts
![Page 57: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/57.jpg)
Static Analysis and Error Checking 32
Name Binding Language definitions and references
TypeDec(t, _): defines Type t Tid(t) : refers to Type t
let type t = u type u = int var x: u := 0in x := 42 ; let type u = t var y: u := 0 in y := 42 endend
![Page 58: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/58.jpg)
Static Analysis and Error Checking 33
Name Binding Language unique definitions
TypeDec(t, _): defines unique Type t Tid(t) : refers to Type t
let type t = u type u = int var x: u := 0in x := 42 ; let type u = t var y: u := 0 in y := 42 endend
![Page 59: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/59.jpg)
Static Analysis and Error Checking 34
Name Binding Language namespaces
let type mt = int type rt = {f1: string, f2: int} type at = array of int! var x := 42 var y: int := 42! function p() = print("foo") function sqr(x: int): int = x*xin … end
namespaces Type Variable Function!TypeDec(t, _): defines unique Type t!FunDec(f, _, _): defines unique Function fFunDec(f, _, _, _): defines unique Function fCall(f, _) : refers to Function f!VarDec(v, _): defines unique Variable vFArg(a, _): defines unique Variable aVar(v): refers to Variable v
![Page 60: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/60.jpg)
Static Analysis and Error Checking 35
Name Binding Language scopes
FunDec(f, _, _): defines unique Function f scopes Variable!FunDec(f, _, _, _): defines unique Function f scopes Variable Let(_, _): scopes Type, Function, Variable
let type t = u type u = int var x: u := 0in x := 42 ; let type u = t var y: u := 0 in y := 42 endend
![Page 61: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/61.jpg)
Static Analysis and Error Checking 35
Name Binding Language scopes
FunDec(f, _, _): defines unique Function f scopes Variable!FunDec(f, _, _, _): defines unique Function f scopes Variable Let(_, _): scopes Type, Function, Variable
let type t = u type u = int var x: u := 0in x := 42 ; let type u = t var y: u := 0 in y := 42 endend
![Page 62: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/62.jpg)
Static Analysis and Error Checking 35
Name Binding Language scopes
FunDec(f, _, _): defines unique Function f scopes Variable!FunDec(f, _, _, _): defines unique Function f scopes Variable Let(_, _): scopes Type, Function, Variable
let type t = u type u = int var x: u := 0in x := 42 ; let type u = t var y: u := 0 in y := 42 endend
![Page 63: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/63.jpg)
Static Analysis and Error Checking 35
Name Binding Language scopes
FunDec(f, _, _): defines unique Function f scopes Variable!FunDec(f, _, _, _): defines unique Function f scopes Variable Let(_, _): scopes Type, Function, Variable
let type t = u type u = int var x: u := 0in x := 42 ; let type u = t var y: u := 0 in y := 42 endend
![Page 64: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/64.jpg)
Static Analysis and Error Checking 35
Name Binding Language scopes
FunDec(f, _, _): defines unique Function f scopes Variable!FunDec(f, _, _, _): defines unique Function f scopes Variable Let(_, _): scopes Type, Function, Variable
let type t = u type u = int var x: u := 0in x := 42 ; let type u = t var y: u := 0 in y := 42 endend
![Page 65: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/65.jpg)
Static Analysis and Error Checking 36
Name Binding Language definition scopes
for x := 0 to 42 do x;For(v, start, end, body): defines Variable v in body
![Page 66: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/66.jpg)
Static Analysis and Error Checking 37
Spoofax bound renaming
let type t = u type u = int var x: u := 0in x := 42 ; let type u = t var y: u := 0 in y := 42 endend
let type t0 = u0 type u0 = int var x: u0 := 0in x := 42 ; let type u1 = t0 var y: u1 := 0 in y := 42 endend
![Page 67: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/67.jpg)
Static Analysis and Error Checking 38
Spoofax annotated terms
t{t1, ..., tn}!!!
add additional information to a term but preserve its signature
![Page 68: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/68.jpg)
Static Analysis and Error Checking 39
specification type system
![Page 69: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/69.jpg)
Static Analysis and Error Checking 40
TS axioms
type rules! Int(_) : IntTy() String(_): StringTy()!signatures! NilTy: Type type rules! Nil(): NilTy()
E ⊢ i : int
E ⊢ s : string
E ⊢ nil : ⊥
![Page 70: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/70.jpg)
Static Analysis and Error Checking 41
TS inference rules
type rules! Add(e1,e2): IntTy() where e1: ty1 and ty1 == IntTy() and e2: ty2 and ty2 == IntTy()
E ⊢ e1 : int E ⊢ e2 : int
E ⊢ e1 + e2 : int
![Page 71: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/71.jpg)
Static Analysis and Error Checking 42
TS inference rules
type rules! Lt(e1,e2): IntTy() where e1: ty1 and e2: ty2 and ( ( ty1 == IntTy() and ty2 == IntTy() ) or ( ty1 == StringTy() and ty2 == StringTy() ) )
E ⊢ e1 : int E ⊢ e2 : int
E ⊢ e1 < e2 : int
E ⊢ e1 : string E ⊢ e2 : string
E ⊢ e1 < e2 : int
![Page 72: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/72.jpg)
Static Analysis and Error Checking 43
NaBL and TS interaction
type rules! Var(x): ty where definition of x: ty
binding rules! VarDec(x, ty): defines unique Variable x of type ty
![Page 73: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/73.jpg)
Static Analysis and Error Checking 44
NaBL and TS interaction
FArg(a, t): defines unique Variable a of type t!FunDec(f, a*, e): defines unique Function f of type (t*, t) where a* has type t* and e has type t!Call(f, a*) : refers to Function f of type (t*, _) where a* has type t*
![Page 74: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/74.jpg)
Static Analysis and Error Checking 45
specification constraints
![Page 75: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/75.jpg)
Static Analysis and Error Checking 46
TS type errors
type rules! Add(e1,e2): IntTy() where e1: ty1 and ty1 == IntTy() else error "…" on e1 and e2: ty2 and ty2 == IntTy() else error "…" on e2
E ⊢ e1 : int E ⊢ e2 : int
E ⊢ e1 + e2 : int
![Page 76: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/76.jpg)
Static Analysis and Error Checking 47
TS missing definitions
type rules! Var(x): ty where definition of x: ty else error "…" on x
![Page 77: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/77.jpg)
Static Analysis and Error Checking48 48
Spoofax origin tracking
let var x := 21 in y * 2 end
![Page 78: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/78.jpg)
Static Analysis and Error Checking48 48
Spoofax origin tracking
let var x := 21 in y * 2 end
Let([VarDec("x", Int("21"))], [Times(Var("y"), Int("2"))])
![Page 79: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/79.jpg)
Static Analysis and Error Checking48 48
Spoofax origin tracking
let var x := 21 in y * 2 end
Let([VarDec("x", Int("21"))], [Times(Var("y"), Int("2"))])
desugar: Times(e1, e2) -> Bop(MUL(), e1, e2)
![Page 80: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/80.jpg)
Static Analysis and Error Checking48 48
Spoofax origin tracking
let var x := 21 in y * 2 end
Let([VarDec("x", Int("21"))], [Times(Var("y"), Int("2"))])
desugar: Times(e1, e2) -> Bop(MUL(), e1, e2)
Let([VarDec("x", Int("21"))], [Bop(MUL(), Var("y"), Int("2"))])
![Page 81: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/81.jpg)
Static Analysis and Error Checking48 48
Spoofax origin tracking
let var x := 21 in y * 2 end
Let([VarDec("x", Int("21"))], [Times(Var("y"), Int("2"))])
desugar: Times(e1, e2) -> Bop(MUL(), e1, e2)
Let([VarDec("x", Int("21"))], [Bop(MUL(), Var("y"), Int("2"))])
Let([VarDec("x"{"…"}, Int("21"))], [Bop(MUL(), Var("y"), Int("2"))])
![Page 82: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/82.jpg)
Static Analysis and Error Checking48 48
Spoofax origin tracking
let var x := 21 in y * 2 end
Let([VarDec("x", Int("21"))], [Times(Var("y"), Int("2"))])
desugar: Times(e1, e2) -> Bop(MUL(), e1, e2)
Let([VarDec("x", Int("21"))], [Bop(MUL(), Var("y"), Int("2"))])
Let([VarDec("x"{"…"}, Int("21"))], [Bop(MUL(), Var("y"), Int("2"))])
Var(x): ty where definition of x: ty else error "…" on x
![Page 83: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/83.jpg)
Static Analysis and Error Checking48 48
Spoofax origin tracking
let var x := 21 in y * 2 end
Let([VarDec("x", Int("21"))], [Times(Var("y"), Int("2"))])
desugar: Times(e1, e2) -> Bop(MUL(), e1, e2)
Let([VarDec("x", Int("21"))], [Bop(MUL(), Var("y"), Int("2"))])
Let([VarDec("x"{"…"}, Int("21"))], [Bop(MUL(), Var("y"), Int("2"))])
Var(x): ty where definition of x: ty else error "…" on x
![Page 84: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/84.jpg)
Static Analysis and Error Checking48 48
Spoofax origin tracking
let var x := 21 in y * 2 end
Let([VarDec("x", Int("21"))], [Times(Var("y"), Int("2"))])
desugar: Times(e1, e2) -> Bop(MUL(), e1, e2)
Let([VarDec("x", Int("21"))], [Bop(MUL(), Var("y"), Int("2"))])
Let([VarDec("x"{"…"}, Int("21"))], [Bop(MUL(), Var("y"), Int("2"))])
Var(x): ty where definition of x: ty else error "…" on x
![Page 85: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/85.jpg)
Static Analysis and Error Checking48 48
Spoofax origin tracking
let var x := 21 in y * 2 end
Let([VarDec("x", Int("21"))], [Times(Var("y"), Int("2"))])
desugar: Times(e1, e2) -> Bop(MUL(), e1, e2)
Let([VarDec("x", Int("21"))], [Bop(MUL(), Var("y"), Int("2"))])
Let([VarDec("x"{"…"}, Int("21"))], [Bop(MUL(), Var("y"), Int("2"))])
Var(x): ty where definition of x: ty else error "…" on x
![Page 86: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/86.jpg)
Static Analysis and Error Checking48 48
Spoofax origin tracking
let var x := 21 in y * 2 end
Let([VarDec("x", Int("21"))], [Times(Var("y"), Int("2"))])
desugar: Times(e1, e2) -> Bop(MUL(), e1, e2)
Let([VarDec("x", Int("21"))], [Bop(MUL(), Var("y"), Int("2"))])
Let([VarDec("x"{"…"}, Int("21"))], [Bop(MUL(), Var("y"), Int("2"))])
Var(x): ty where definition of x: ty else error "…" on x
![Page 87: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/87.jpg)
Static Analysis and Error Checking48 48
Spoofax origin tracking
let var x := 21 in y * 2 end
Let([VarDec("x", Int("21"))], [Times(Var("y"), Int("2"))])
desugar: Times(e1, e2) -> Bop(MUL(), e1, e2)
Let([VarDec("x", Int("21"))], [Bop(MUL(), Var("y"), Int("2"))])
Let([VarDec("x"{"…"}, Int("21"))], [Bop(MUL(), Var("y"), Int("2"))])
Var(x): ty where definition of x: ty else error "…" on x
![Page 88: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/88.jpg)
Static Analysis and Error Checking48 48
Spoofax origin tracking
let var x := 21 in y * 2 end
Let([VarDec("x", Int("21"))], [Times(Var("y"), Int("2"))])
desugar: Times(e1, e2) -> Bop(MUL(), e1, e2)
Let([VarDec("x", Int("21"))], [Bop(MUL(), Var("y"), Int("2"))])
Let([VarDec("x"{"…"}, Int("21"))], [Bop(MUL(), Var("y"), Int("2"))])
Var(x): ty where definition of x: ty else error "…" on x
![Page 89: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/89.jpg)
Static Analysis and Error Checking48 48
Spoofax origin tracking
let var x := 21 in y * 2 end
Let([VarDec("x", Int("21"))], [Times(Var("y"), Int("2"))])
desugar: Times(e1, e2) -> Bop(MUL(), e1, e2)
Let([VarDec("x", Int("21"))], [Bop(MUL(), Var("y"), Int("2"))])
Let([VarDec("x"{"…"}, Int("21"))], [Bop(MUL(), Var("y"), Int("2"))])
Var(x): ty where definition of x: ty else error "…" on x
![Page 90: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/90.jpg)
Static Analysis and Error Checking48 48
Spoofax origin tracking
let var x := 21 in y * 2 end
Let([VarDec("x", Int("21"))], [Times(Var("y"), Int("2"))])
desugar: Times(e1, e2) -> Bop(MUL(), e1, e2)
Let([VarDec("x", Int("21"))], [Bop(MUL(), Var("y"), Int("2"))])
Let([VarDec("x"{"…"}, Int("21"))], [Bop(MUL(), Var("y"), Int("2"))])
Var(x): ty where definition of x: ty else error "…" on x
![Page 91: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/91.jpg)
Static Analysis and Error Checking 49
derivation of editor services
error checking
reference resolution
code completion
Spoofax static analysis
![Page 92: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/92.jpg)
Static Analysis and Error Checking 49
derivation of editor services
error checking
reference resolution
code completion
multi-file analysis
Spoofax static analysis
![Page 93: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/93.jpg)
Static Analysis and Error Checking 49
derivation of editor services
error checking
reference resolution
code completion
multi-file analysis
parallel analysis
Spoofax static analysis
![Page 94: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/94.jpg)
Static Analysis and Error Checking 49
derivation of editor services
error checking
reference resolution
code completion
multi-file analysis
parallel analysis
incremental analysis
Spoofax static analysis
![Page 95: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/95.jpg)
Static Analysis and Error Checking 50
Except where otherwise noted, this work is licensed under
![Page 96: Declarative Semantics Definition - Static Analysis and Error Checking](https://reader033.vdocuments.mx/reader033/viewer/2022051513/547d34a6b47959c5508b4885/html5/thumbnails/96.jpg)
Static Analysis and Error Checking 51
attribution
slide title author license
1 Inspection Kent Wien CC BY-NC 2.0
2, 3 PICOL icons Melih Bilgil CC BY 3.0
10 Noam Chomsky Maria Castelló Solbes CC BY-NC-SA 2.0
11, 16-20, 22-24 Tiger Bernard Landgraf CC BY-SA 3.0
12 The C Programming Language Bill Bradford CC BY 2.0
13 Italian Java book cover