SlideShare a Scribd company logo
Eelco Visser
Curry On 2017
Barcelona
June 2017
Scope Graphs
A fresh look at name binding 

in programming languages
/* A program to solve the 8-queens problem */
let
var N := 8
type intArray = array of int
var row := intArray [ N ] of 0
var col := intArray [ N ] of 0
var diag1 := intArray [N+N-1] of 0
var diag2 := intArray [N+N-1] of 0
function printboard() =
(for i := 0 to N-1
do (for j := 0 to N-1
do print(if col[i]=j then " O" else " .");
print("n"));
print("n"))
function try(c:int) =
( if c=N
then printboard()
else for r := 0 to N-1
do if row[r]=0 & diag1[r+c]=0 & diag2[r+7-c]=0
then (row[r]:=1; diag1[r+c]:=1; diag2[r+7-c]:=1;
col[c]:=r;
try(c+1);
row[r]:=0; diag1[r+c]:=0; diag2[r+7-c]:=0)
)
in try(0)
end
let function fact(n : int) : int =
if n < 1 then 1 else (n * fact(n -
1))
in fact(10)
end
/* define valid recursive types */
let
/* define a list */
type intlist = {hd: int, tl: intlist}
/* define a tree */
type tree ={key: int, children: treelist}
type treelist = {hd: tree, tl: treelist}
var lis:intlist := intlist { hd=0, tl=
nil }
in
lis
end
A Language Design
Tiger by Andrew Appel, 1996
Want: An Implementation
Type Checker
Compiler
Interpreter
Parser
module Functions
imports Identifiers
imports Types
context-free syntax
Dec.FunDecs = <<{FunDec "n"}+>> {longest-match}
FunDec.ProcDec = <
function <Id>(<{FArg ", "}*>) =
<Exp>
>
FunDec.FunDec = <
function <Id>(<{FArg ", "}*>) : <Type> =
<Exp>
>
FArg.FArg = <<Id> : <Type>>
Exp.Call = <<Id>(<{Exp ", "}*>)>
let function fact(n : int) : int =
if n < 1 then 1 else (n * fact(n - 1))
in fact(10)
end
Mod(
Let(
[ FunDecs(
[ FunDec(
"fact"
, [FArg("n", Tid("int"))]
, Tid("int")
, If(
Lt(Var("n"), Int("1"))
, Int("1")
, Seq(
[ Times(
Var("n")
, Call("fact", [Minus(Var("n"), Int("1"))])
)
]
)
)
)
]
)
]
, [Call("fact", [Int("10")])]
)
)
Context-Free Grammar Abstract Syntax
Parser
Start: Syntax
Syntax CheckingSyntactic Completion
Representation
• Parse Trees / Abstract Syntax Trees

Declarative Rules
• Context-free grammar + disambiguation

Language-Independent Tooling
• Parser generation

• Syntax aware editor

• Syntactic completion

• Formatter

• …
Separation of Concerns in Syntax Definition
More in ECOOP
Summer School lecture
on Thursday afternoon
A language
for talking
about syntax
}
Type Checker
Compiler
Interpreter
Parser
Type Checker
Compiler
Interpreter
Parser
Name Binding
{
Name Binding
?
let function fact(n : int) : int =
if n < 1 then
1
else
n * fact(n - 1)
in
fact(10)
end
Variables
let function fact(n : int) : int =
if n < 1 then
1
else
n * fact(n - 1)
in
fact(10)
end
Function Calls
function prettyprint(tree: tree) : string =
let
var output := ""
function write(s: string) =
output := concat(output, s)
function show(n: int, t: tree) =
let function indent(s: string) =
(write("n");
for i := 1 to n
do write(" ");
output := concat(output, s))
in if t = nil then indent(".")
else (indent(t.key);
show(n+1, t.left);
show(n+1, t.right))
end
in show(0, tree);
output
end
Nested Scopes
(Shadowing)
let
type point = {
x : int,
y : int
}
var origin := point {
x = 1,
y = 2
}
in
origin.x := 10;
origin := nil
end
Type References
let
type point = {
x : int,
y : int
}
var origin := point {
x = 1,
y = 2
}
in
origin.x := 10;
origin := nil
end
Record Fields
let
type point = {
x : int,
y : int
}
var origin := point {
x = 1,
y = 2
}
in
origin.x := 10;
origin := nil
end
Type Dependent
Name Resolution
name binding
?
How to define the
rules of a language
name binding
?
What is the BNF of
Representation
• To conduct and represent the results of name resolution 

Declarative Rules
• To define name binding rules of a language

Language-Independent Tooling
• Name resolution

• Code completion 

• Refactoring

• …
Separation of Concerns in Name Binding
Representation
• ?

Declarative Rules
• To define name binding rules of a language

Language-Independent Tooling
• Name resolution

• Code completion 

• Refactoring

• …
Separation of Concerns in Name Binding
Scope Graphs
let function fact(n : int) : int =
if n < 1 then
1
else
n * fact(n - 1)
in
fact(10)
end
fact S1 fact
S2n
n
fact
nn
Scope GraphProgram
Name Resolution
A Calculus for Name Resolution
S R1 R2 SR
SRS
I(R1
)
S’S
S’S P
Sx
Sx R
xS
xS D
Path in scope graph connects reference to declaration
Scopes, References, Declarations, Parents, Imports
Neron, Tolmach, Visser, Wachsmuth
A Theory of Name Resolution
ESOP 2015
Simple Scopes
Reference
Declaration
Scope
Reference Step Declaration Step
def y1 = x2 + 1
def x1 = 5
S0
def y1 = x2 + 1
def x1 = 5
Sx
Sx R
xS
xS D
S0
y1
x1S0
y1
x1S0x2
R
y1
x1S0x2
R D
y1
x1S0x2
S
x
x
Lexical Scoping
S1
S0
Parent
def x1 = z2 5
def z1 =
fun y1 {
x2 + y2
}
S’S
S’S P
z1
x1S0z2
S1
y1y2 x2
z1
x1S0z2
S1
y1y2 x2
z1
x1S0z2
S1
y1y2 x2
z1
x1S0z2
R
S1
y1y2 x2
z1
x1S0z2
R
D
S1
y1y2 x2
z1
x1S0z2
R
S1
y1y2 x2
z1
x1S0z2
R
P
S1
y1y2 x2
z1
x1S0z2
R
P
D
S’S
Parent Step
Imports
Associated scope
Import
S0
SB
SA
module A1 {
def z1 = 5
}
module B1 {
import A2
def x1 = 1 + z2
}
A1
SA
z1
B1
SB
z2
S0
A2
x1
S R1
R2 SR
A1
SA
z1
B1
SB
z2
S0
A2
x1
A1
SA
z1
B1
SB
z2
S0
A2
x1
A1
SA
z1
B1
SB
z2
S0
A2
x1
R
A1
SA
z1
B1
SB
z2
S0
A2
x1
R
R
A1
SA
z1
B1
SB
z2
S0
A2
x1
R
R
P
A1
SA
z1
B1
SB
z2
S0
A2
x1
R
R
P
D
A1
SA
z1
B1
SB
z2
S0
A2
x1
I(A2
)R
R
P
D
A1
SA
z1
B1
SB
z2
S0
A2
x1
I(A2
)R
R
D
P
D
S R1 R2 SR
SRS
I(R1
)
Import Step
Qualified Names
module N1 {
def s1 = 5
}
module M1 {
def x1 = 1 + N2.s2
}
S0
N1
SN
s2
S0
N2
R
D
R
I(N2) D
X1
s1
N1
SN
s2
S0
N2
R
D
X1
s1
N1
SN
s2
S0
N2 X1
s1
A Calculus for Name Resolution
S R1 R2 SR
SRS
I(R1
)
S’S
S’S P
Sx
Sx R
xS
xS D
Reachability of declarations from
references through scope graph edges
How about ambiguities?
References with multiple paths
A Calculus for Name Resolution
S R1 R2 SR
SRS
I(R1
)
S’S
S’S P
Sx
Sx R
xS
xS D
I(_).p’ < P.p
D < I(_).p’
D < P.p
s.p < s.p’
p < p’
Visibility
Well formed path: R.P*.I(_)*.D
Reachability
Ambiguous Resolutions
match t with
| A x | B x => …
z1 x2
x1S0x3
z1 x2
x1S0x3
R
z1 x2
x1S0x3
R D
z1 x2
x1S0x3
R
D
z1 x2
x1S0x3
R D
D
S0def x1 = 5
def x2 = 3
def z1 = x3 + 1
Shadowing
S0
S1
S2
D < P.p
s.p < s.p’
p < p’
S1
S2
x1
y1
y2 x2
z1
x3S0z2
def x3 = z2 5 7
def z1 =
fun x1 {
fun y1 {
x2 + y2
}
}
S1
S2
x1
y1
y2 x2
z1
x3S0z2
R
P
P
D
S1
S2
x1
y1
y2 x2
z1
x3S0z2
D
P
R
R
P
P
D
R.P.D < R.P.P.D
Imports shadow Parents
I(_).p’ < P.p R.I(A2).D < R.P.D
A1
SA
z1
B1
SB
z2
S0
A2
x1
z3
A1
SA
z1
B1
SB
z2
S0
A2
x1
I(A2)R D
z3
A1
SA
z1
B1
SB
z2
S0
A2
x1
I(A2)R D
P
D
z3
R
S0def z3 = 2
module A1 {
def z1 = 5
}
module B1 {
import A2
def x1 = 1 + z2
}
SA
SB
Imports vs. Includes
S0def z3 = 2
module A1 {
def z1 = 5
}
import A2
def x1 = 1 + z2
SA A1
SA
z1
z2
S0
A2
x1
I(A2)
R
D
z3
R
D
D < I(_).p’
R.D < R.I(A2).D
A1
SA
z1
z2
S0
A2
x1
R
z3
D
A1
SA
z1
z2
S0
A2
x1z3
S0def z3 = 2
module A1 {
def z1 = 5
}
include A2
def x1 = 1 + z2
SA
X
Import Parents
def s1 = 5
module N1 {
}
def x1 = 1 + N2.s2
S0
SN
def s1 = 5
module N1 {
}
def x1 = 1 + N2.s2
S0
SN
Well formed path: R.P*.I(_)*.D
N1
SN
s2
S0
N2
X1
s1
R
I(N2
)
D
P
N1
SN
s2
S0
N2
X1
s1
Transitive vs. Non-Transitive
With transitive imports, a well formed path is R.P*.I(_)*.D
With non-transitive imports, a well formed path is R.P*.I(_)?.D
A1
SA
z1
B1
SB
S0
A2
C1
SCz2
x1 B2
A1
SA
z1
B1
SB
S0
A2
I(A2
)
D
C1
SCz2
I(B2
)
R
x1 B2
??
module A1 {
def z1 = 5
}
module B1 {
import A2
}
module C1 {
import B2
def x1 = 1 + z2
}
SA
SB
SC
A Calculus for Name Resolution
S R1 R2 SR
SRS
I(R1
)
S’S
S’S P
Sx
Sx R
xS
xS D
I(_).p’ < P.p
D < I(_).p’
D < P.p
s.p < s.p’
p < p’
Visibility
Well formed path: R.P*.I(_)*.D
Reachability
Representation
• To conduct and represent the results of name resolution 

Declarative Rules
• To define name binding rules of a language

Language-Independent Tooling
• Name resolution

• Code completion 

• Refactoring

• …
Separation of Concerns in Name Binding
Representation
• ?

Declarative Rules
• To define name binding rules of a language

Language-Independent Tooling
• Name resolution

• Code completion 

• Refactoring

• …
Separation of Concerns in Name Binding
Scope Graphs
Representation
• ?

Declarative Rules
• ?

Language-Independent Tooling
• Name resolution

• Code completion 

• Refactoring

• …
Separation of Concerns in Name Binding
Scope (& Type) Constraint Rules [PEPM16]
Scope Graphs
Architecture
Program AST
Parse
Constraints
Generate
Constraints
Solution
Resolve
Constraints
Language
Specific
Language
Independent
Scope Graph Constraints
new s // new scope
s1 -L-> s2 // labeled edge from scope s1 to scope s2
N{x} <- s // x is a declaration in scope s for namespace N
N{x} -> s // x is a reference in scope s for namespace N
N{x} |-> d // x resolves to declaration d
[[ e ^ (s) ]] // constraints for expression e in scope s
let
var x : int := x + 1
in
x + 1
end
s
s_bodyx
x
Let(
[VarDec(
"x"
, Tid("int")
, Plus(Var("x"), Int("1"))
)]
, [Plus(Var("x"), Int("1"))]
)
[[ Let([VarDec(x, t, e)], [e_body]) ^ (s) ]] :=
new s_body, // new scope
s_body -P-> s, // parent edge to enclosing scope
Var{x} <- s_body, // x is a declaration in s_body
[[ e ^ (s) ]], // init expression
[[ e_body ^ (s_body) ]]. // body expression
[[ Var(x) ^ (s') ]] :=
Var{x} -> s', // x is a reference in s'
Var{x} |-> d, // check that x resolves to a declaration
s’
x
?
P
How about types?
Type Constraints
d : ty // declaration has type
t1 == ty2 // type equality
ty1 <! ty2 // declare sub-type
ty1 <? ty2 // query sub-type
. . . // extensions
[[ e ^ (s) : ty ]] // type of expression in scope
s
s_bodyx
x
[[ Let([VarDec(x, t, e)], [e_body]) ^ (s) : ty' ]] :=
new s_body, // new scope
s_body -P-> s, // parent edge to enclosing scope
Var{x} <- s_body, // x is a declaration in s_body
Var{x} : ty, // associate type
[[ t ^ (s) : ty ]], // type of type
[[ e ^ (s) : ty ]], // type of expression
[[ e_body ^ (s_body) : ty' ]]. // constraints for body
[[ Var(x) ^ (s') : ty ]] :=
Var{x} -> s', // x is a reference in s'
Var{x} |-> d, // check that x resolves to a declaration
d : ty. // type of declaration is type of reference
s’
x
let
var x : int := x + 1
in
x + 1
end
Let(
[VarDec(
"x"
, Tid("int")
, Plus(Var("x"), Int("1"))
)]
, [Plus(Var("x"), Int("1"))]
)
let
type point = {x : int, y : int}
var origin : point := …
in origin.x
end
S2
S3
x
x
point
[[ FieldVar(e, f) ^ (s) : ty ]] :=
[[ e ^ (s) : ty_e ]],
new s_use,
Field{f} -> s_use,
s_use -I-> s_rec,
ty_e == RECORD(s_rec),
Field{f} |-> d,
d : ty.
[[ RecordTy(fields) ^ (s) : ty ]] :=
ty == RECORD(s_rec),
new s_rec,
Map2[[ fields ^ (s_rec, s) ]].
[[ Field(x, t) ^ (s_rec, s_outer) ]] :=
Field{x} <- s_rec,
Field{x} : ty !,
[[ t ^ (s_outer) : ty ]].
S1 point
s_rec
y
RECORD
INT
origin
origin
s_use
s_recty_e
Type Dependent Name Resolution
Representation
• ?

Declarative Rules
• ?

Language-Independent Tooling
• Name resolution

• Code completion 

• Refactoring

• …
Separation of Concerns in Name Binding
Scope Graphs
Scope & Type Constraint Rules
A language
for talking
about name
binding}
NaBL2 in Spoofax Language Workbench
http://spoofax.org
Languages
• IceDust2 [ECOOP17]

• Education

‣ Mini-Java, Tiger, Calc

• Programming languages

‣ Pascal, TypeScript, F# 

‣ (student projects in progress)

• Bootstrapping language workbench

‣ NaBL2, …
Applications
Scopes Describe Frames [ECOOP16]
S
x
y
l’l
: T
: T
S’ S’’
xx
S
y
l l’
x
S’
x
S’’
A Uniform Model for Memory Layout
in Dynamic Semantics
Theory
• Resolution calculus

• Name binding and type constraints

• Resolution algorithm sound wrt calculus

• Mapping to run-time memory layout

Declarative specification
• NaBL2: generation of name and type constraints

Tooling
• Solver (second version)

• Integrated in Spoofax Language Workbench

‣ editors with name and type checking

‣ navigation
Scope Graphs for Name Binding: Status
A domain-specific (= restricted) model
• Cannot describe all name resolution algorithms
implemented in Turing complete languages 

Normative model
• ‘this is name binding’

Claim/hypothesis
• Describes all sane models of name binding
Scope Graphs for Name Binding: Limitations
Theory
• Scopes = structural types?

‣ operations for scope / type comparison

• Generics

‣ DOT-style?

• Type soundness of interpreters — automatically

Tooling
• Tune name binding language (notation)

• Incremental analysis (in progress)

• Code completion

• Refactoring (renaming)
Scope Graphs for Name Binding: Future Work
A common (cross-language)
understanding of name
binding?
A foundation for formalization
and implementation of
programming languages?
Scope Graphs for Name Binding: The Future
A1
SA
z1
B1
SB
z2
S0
A2
x1
A1
SA
z1
B1
SB
z2
S0
A2
x1
A1
SA
z1
B1
SB
z2
S0
A2
x1
A1
SA
z1
B1
SB
z2
S0
A2
x1
R
A1
SA
z1
B1
SB
z2
S0
A2
x1
R
R
A1
SA
z1
B1
SB
z2
S0
A2
x1
R
R
P
A1
SA
z1
B1
SB
z2
S0
A2
x1
R
R
P
D
A1
SA
z1
B1
SB
z2
S0
A2
x1
I(A2
)R
R
P
D
A1
SA
z1
B1
SB
z2
S0
A2
x1
I(A2
)R
R
D
P
D

More Related Content

What's hot

JBUG 11 - Scala For Java Programmers
JBUG 11 - Scala For Java ProgrammersJBUG 11 - Scala For Java Programmers
JBUG 11 - Scala For Java Programmers
Tikal Knowledge
 
Introduction to join calculus
Introduction to join calculusIntroduction to join calculus
Introduction to join calculus
Sergei Winitzki
 
Ch03
Ch03Ch03
Ch03
Hankyo
 
Introduction to Functional Programming in JavaScript
Introduction to Functional Programming in JavaScriptIntroduction to Functional Programming in JavaScript
Introduction to Functional Programming in JavaScript
tmont
 
CS4200 2019 | Lecture 2 | syntax-definition
CS4200 2019 | Lecture 2 | syntax-definitionCS4200 2019 | Lecture 2 | syntax-definition
CS4200 2019 | Lecture 2 | syntax-definition
Eelco Visser
 
.NET 2015: Будущее рядом
.NET 2015: Будущее рядом.NET 2015: Будущее рядом
.NET 2015: Будущее рядом
Andrey Akinshin
 
Ch06
Ch06Ch06
Ch06
Hankyo
 
Advanced Tagless Final - Saying Farewell to Free
Advanced Tagless Final - Saying Farewell to FreeAdvanced Tagless Final - Saying Farewell to Free
Advanced Tagless Final - Saying Farewell to Free
Luka Jacobowitz
 
Programming Paradigms Which One Is The Best?
Programming Paradigms Which One Is The Best?Programming Paradigms Which One Is The Best?
Programming Paradigms Which One Is The Best?
Netguru
 
The Death of Final Tagless
The Death of Final TaglessThe Death of Final Tagless
The Death of Final Tagless
John De Goes
 
Compiler Construction | Lecture 12 | Virtual Machines
Compiler Construction | Lecture 12 | Virtual MachinesCompiler Construction | Lecture 12 | Virtual Machines
Compiler Construction | Lecture 12 | Virtual Machines
Eelco Visser
 
1.4 the basic language of functions
1.4 the basic language of functions1.4 the basic language of functions
1.4 the basic language of functions
math123c
 
Library functions in c++
Library functions in c++Library functions in c++
Library functions in c++
Neeru Mittal
 
Basic c++ programs
Basic c++ programsBasic c++ programs
Basic c++ programs
harman kaur
 
Functional programming in JavaScript
Functional programming in JavaScriptFunctional programming in JavaScript
Functional programming in JavaScript
Joseph Smith
 
Python programming workshop session 1
Python programming workshop session 1Python programming workshop session 1
Python programming workshop session 1
Abdul Haseeb
 
Practical scalaz
Practical scalazPractical scalaz
Practical scalaz
oxbow_lakes
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets
kinan keshkeh
 
Testing in the World of Functional Programming
Testing in the World of Functional ProgrammingTesting in the World of Functional Programming
Testing in the World of Functional Programming
Luka Jacobowitz
 
Scalaz
ScalazScalaz
Scalaz
mpilquist
 

What's hot (20)

JBUG 11 - Scala For Java Programmers
JBUG 11 - Scala For Java ProgrammersJBUG 11 - Scala For Java Programmers
JBUG 11 - Scala For Java Programmers
 
Introduction to join calculus
Introduction to join calculusIntroduction to join calculus
Introduction to join calculus
 
Ch03
Ch03Ch03
Ch03
 
Introduction to Functional Programming in JavaScript
Introduction to Functional Programming in JavaScriptIntroduction to Functional Programming in JavaScript
Introduction to Functional Programming in JavaScript
 
CS4200 2019 | Lecture 2 | syntax-definition
CS4200 2019 | Lecture 2 | syntax-definitionCS4200 2019 | Lecture 2 | syntax-definition
CS4200 2019 | Lecture 2 | syntax-definition
 
.NET 2015: Будущее рядом
.NET 2015: Будущее рядом.NET 2015: Будущее рядом
.NET 2015: Будущее рядом
 
Ch06
Ch06Ch06
Ch06
 
Advanced Tagless Final - Saying Farewell to Free
Advanced Tagless Final - Saying Farewell to FreeAdvanced Tagless Final - Saying Farewell to Free
Advanced Tagless Final - Saying Farewell to Free
 
Programming Paradigms Which One Is The Best?
Programming Paradigms Which One Is The Best?Programming Paradigms Which One Is The Best?
Programming Paradigms Which One Is The Best?
 
The Death of Final Tagless
The Death of Final TaglessThe Death of Final Tagless
The Death of Final Tagless
 
Compiler Construction | Lecture 12 | Virtual Machines
Compiler Construction | Lecture 12 | Virtual MachinesCompiler Construction | Lecture 12 | Virtual Machines
Compiler Construction | Lecture 12 | Virtual Machines
 
1.4 the basic language of functions
1.4 the basic language of functions1.4 the basic language of functions
1.4 the basic language of functions
 
Library functions in c++
Library functions in c++Library functions in c++
Library functions in c++
 
Basic c++ programs
Basic c++ programsBasic c++ programs
Basic c++ programs
 
Functional programming in JavaScript
Functional programming in JavaScriptFunctional programming in JavaScript
Functional programming in JavaScript
 
Python programming workshop session 1
Python programming workshop session 1Python programming workshop session 1
Python programming workshop session 1
 
Practical scalaz
Practical scalazPractical scalaz
Practical scalaz
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets
 
Testing in the World of Functional Programming
Testing in the World of Functional ProgrammingTesting in the World of Functional Programming
Testing in the World of Functional Programming
 
Scalaz
ScalazScalaz
Scalaz
 

Similar to Scope Graphs: A fresh look at name binding in programming languages

The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
Philip Schwarz
 
Five Languages in a Moment
Five Languages in a MomentFive Languages in a Moment
Five Languages in a Moment
Sergio Gil
 
Term Rewriting
Term RewritingTerm Rewriting
Term Rewriting
Eelco Visser
 
Scala as a Declarative Language
Scala as a Declarative LanguageScala as a Declarative Language
Scala as a Declarative Language
vsssuresh
 
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
Philip Schwarz
 
Ch3
Ch3Ch3
6-Nfa & equivalence with RE.pdf
6-Nfa & equivalence with RE.pdf6-Nfa & equivalence with RE.pdf
6-Nfa & equivalence with RE.pdf
shruti533256
 
Compiling fµn language
Compiling fµn languageCompiling fµn language
Compiling fµn language
Didier Plaindoux
 
Sequences
SequencesSequences
Sequences
Abdur Rehman
 
Ch5b.ppt
Ch5b.pptCh5b.ppt
Ch5b.ppt
MDSayem35
 
Ch8a
Ch8aCh8a
Disjoint sets
Disjoint setsDisjoint sets
Disjoint sets
Core Condor
 
Struct examples
Struct examplesStruct examples
Struct examples
mondalakash2012
 
Monadologie
MonadologieMonadologie
Monadologie
league
 
Declare Your Language: Dynamic Semantics
Declare Your Language: Dynamic SemanticsDeclare Your Language: Dynamic Semantics
Declare Your Language: Dynamic Semantics
Eelco Visser
 
Dynamic Semantics
Dynamic SemanticsDynamic Semantics
Dynamic Semantics
Eelco 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 Rewriting
Eelco Visser
 
Introduction to R programming
Introduction to R programmingIntroduction to R programming
Introduction to R programming
Alberto Labarga
 
Scala - where objects and functions meet
Scala - where objects and functions meetScala - where objects and functions meet
Scala - where objects and functions meet
Mario Fusco
 
Goldie chapter 4 function
Goldie chapter 4 functionGoldie chapter 4 function
Goldie chapter 4 function
Sarah Sue Calbio
 

Similar to Scope Graphs: A fresh look at name binding in programming languages (20)

The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
 
Five Languages in a Moment
Five Languages in a MomentFive Languages in a Moment
Five Languages in a Moment
 
Term Rewriting
Term RewritingTerm Rewriting
Term Rewriting
 
Scala as a Declarative Language
Scala as a Declarative LanguageScala as a Declarative Language
Scala as a Declarative Language
 
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
 
Ch3
Ch3Ch3
Ch3
 
6-Nfa & equivalence with RE.pdf
6-Nfa & equivalence with RE.pdf6-Nfa & equivalence with RE.pdf
6-Nfa & equivalence with RE.pdf
 
Compiling fµn language
Compiling fµn languageCompiling fµn language
Compiling fµn language
 
Sequences
SequencesSequences
Sequences
 
Ch5b.ppt
Ch5b.pptCh5b.ppt
Ch5b.ppt
 
Ch8a
Ch8aCh8a
Ch8a
 
Disjoint sets
Disjoint setsDisjoint sets
Disjoint sets
 
Struct examples
Struct examplesStruct examples
Struct examples
 
Monadologie
MonadologieMonadologie
Monadologie
 
Declare Your Language: Dynamic Semantics
Declare Your Language: Dynamic SemanticsDeclare Your Language: Dynamic Semantics
Declare Your Language: Dynamic Semantics
 
Dynamic Semantics
Dynamic SemanticsDynamic Semantics
Dynamic Semantics
 
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
 
Introduction to R programming
Introduction to R programmingIntroduction to R programming
Introduction to R programming
 
Scala - where objects and functions meet
Scala - where objects and functions meetScala - where objects and functions meet
Scala - where objects and functions meet
 
Goldie chapter 4 function
Goldie chapter 4 functionGoldie chapter 4 function
Goldie chapter 4 function
 

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 Rewriting
Eelco Visser
 
CS4200 2019 | Lecture 4 | Syntactic Services
CS4200 2019 | Lecture 4 | Syntactic ServicesCS4200 2019 | Lecture 4 | Syntactic Services
CS4200 2019 | Lecture 4 | Syntactic Services
Eelco Visser
 
CS4200 2019 | Lecture 3 | Parsing
CS4200 2019 | Lecture 3 | ParsingCS4200 2019 | Lecture 3 | Parsing
CS4200 2019 | Lecture 3 | Parsing
Eelco Visser
 
CS4200 2019 Lecture 1: Introduction
CS4200 2019 Lecture 1: IntroductionCS4200 2019 Lecture 1: Introduction
CS4200 2019 Lecture 1: Introduction
Eelco 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 Rules
Eelco Visser
 
Declarative Type System Specification with Statix
Declarative Type System Specification with StatixDeclarative Type System Specification with Statix
Declarative Type System Specification with Statix
Eelco 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 Construction
Eelco 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 Management
Eelco Visser
 
Compiler Construction | Lecture 14 | Interpreters
Compiler Construction | Lecture 14 | InterpretersCompiler Construction | Lecture 14 | Interpreters
Compiler Construction | Lecture 14 | Interpreters
Eelco Visser
 
Compiler Construction | Lecture 13 | Code Generation
Compiler Construction | Lecture 13 | Code GenerationCompiler Construction | Lecture 13 | Code Generation
Compiler Construction | Lecture 13 | Code Generation
Eelco Visser
 
Compiler Construction | Lecture 11 | Monotone Frameworks
Compiler Construction | Lecture 11 | Monotone FrameworksCompiler Construction | Lecture 11 | Monotone Frameworks
Compiler Construction | Lecture 11 | Monotone Frameworks
Eelco 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 Analysis
Eelco Visser
 
Compiler Construction | Lecture 9 | Constraint Resolution
Compiler Construction | Lecture 9 | Constraint ResolutionCompiler Construction | Lecture 9 | Constraint Resolution
Compiler Construction | Lecture 9 | Constraint Resolution
Eelco Visser
 
Compiler Construction | Lecture 8 | Type Constraints
Compiler Construction | Lecture 8 | Type ConstraintsCompiler Construction | Lecture 8 | Type Constraints
Compiler Construction | Lecture 8 | Type Constraints
Eelco Visser
 
Compiler Construction | Lecture 7 | Type Checking
Compiler Construction | Lecture 7 | Type CheckingCompiler Construction | Lecture 7 | Type Checking
Compiler Construction | Lecture 7 | Type Checking
Eelco 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 Analysis
Eelco Visser
 
Compiler Construction | Lecture 4 | Parsing
Compiler Construction | Lecture 4 | Parsing Compiler Construction | Lecture 4 | Parsing
Compiler Construction | Lecture 4 | Parsing
Eelco 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 Services
Eelco Visser
 
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
Eelco 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 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 14 | Interpreters
Compiler Construction | Lecture 14 | InterpretersCompiler Construction | Lecture 14 | Interpreters
Compiler Construction | Lecture 14 | Interpreters
 
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 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 4 | Parsing
Compiler Construction | Lecture 4 | Parsing Compiler Construction | Lecture 4 | Parsing
Compiler Construction | Lecture 4 | Parsing
 
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
 
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
 

Recently uploaded

Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
safelyiotech
 
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
widenerjobeyrl638
 
ACE - Team 24 Wrapup event at ahmedabad.
ACE - Team 24 Wrapup event at ahmedabad.ACE - Team 24 Wrapup event at ahmedabad.
ACE - Team 24 Wrapup event at ahmedabad.
Maitrey Patel
 
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSISDECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
Tier1 app
 
The Role of DevOps in Digital Transformation.pdf
The Role of DevOps in Digital Transformation.pdfThe Role of DevOps in Digital Transformation.pdf
The Role of DevOps in Digital Transformation.pdf
mohitd6
 
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
kgyxske
 
The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
kalichargn70th171
 
14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision
ShulagnaSarkar2
 
Voxxed Days Trieste 2024 - Unleashing the Power of Vector Search and Semantic...
Voxxed Days Trieste 2024 - Unleashing the Power of Vector Search and Semantic...Voxxed Days Trieste 2024 - Unleashing the Power of Vector Search and Semantic...
Voxxed Days Trieste 2024 - Unleashing the Power of Vector Search and Semantic...
Luigi Fugaro
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Manyata Tech Park Bangalore_ Infrastructure, Facilities and More
Manyata Tech Park Bangalore_ Infrastructure, Facilities and MoreManyata Tech Park Bangalore_ Infrastructure, Facilities and More
Manyata Tech Park Bangalore_ Infrastructure, Facilities and More
narinav14
 
What is Continuous Testing in DevOps - A Definitive Guide.pdf
What is Continuous Testing in DevOps - A Definitive Guide.pdfWhat is Continuous Testing in DevOps - A Definitive Guide.pdf
What is Continuous Testing in DevOps - A Definitive Guide.pdf
kalichargn70th171
 
Optimizing Your E-commerce with WooCommerce.pptx
Optimizing Your E-commerce with WooCommerce.pptxOptimizing Your E-commerce with WooCommerce.pptx
Optimizing Your E-commerce with WooCommerce.pptx
WebConnect Pvt Ltd
 
Enhanced Screen Flows UI/UX using SLDS with Tom Kitt
Enhanced Screen Flows UI/UX using SLDS with Tom KittEnhanced Screen Flows UI/UX using SLDS with Tom Kitt
Enhanced Screen Flows UI/UX using SLDS with Tom Kitt
Peter Caitens
 
Upturn India Technologies - Web development company in Nashik
Upturn India Technologies - Web development company in NashikUpturn India Technologies - Web development company in Nashik
Upturn India Technologies - Web development company in Nashik
Upturn India Technologies
 
WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...
WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...
WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...
Luigi Fugaro
 
Building API data products on top of your real-time data infrastructure
Building API data products on top of your real-time data infrastructureBuilding API data products on top of your real-time data infrastructure
Building API data products on top of your real-time data infrastructure
confluent
 
The Comprehensive Guide to Validating Audio-Visual Performances.pdf
The Comprehensive Guide to Validating Audio-Visual Performances.pdfThe Comprehensive Guide to Validating Audio-Visual Performances.pdf
The Comprehensive Guide to Validating Audio-Visual Performances.pdf
kalichargn70th171
 
Modelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - AmsterdamModelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - Amsterdam
Alberto Brandolini
 

Recently uploaded (20)

Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
 
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
 
ACE - Team 24 Wrapup event at ahmedabad.
ACE - Team 24 Wrapup event at ahmedabad.ACE - Team 24 Wrapup event at ahmedabad.
ACE - Team 24 Wrapup event at ahmedabad.
 
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSISDECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
 
The Role of DevOps in Digital Transformation.pdf
The Role of DevOps in Digital Transformation.pdfThe Role of DevOps in Digital Transformation.pdf
The Role of DevOps in Digital Transformation.pdf
 
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
 
The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
 
14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision
 
Voxxed Days Trieste 2024 - Unleashing the Power of Vector Search and Semantic...
Voxxed Days Trieste 2024 - Unleashing the Power of Vector Search and Semantic...Voxxed Days Trieste 2024 - Unleashing the Power of Vector Search and Semantic...
Voxxed Days Trieste 2024 - Unleashing the Power of Vector Search and Semantic...
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
 
Manyata Tech Park Bangalore_ Infrastructure, Facilities and More
Manyata Tech Park Bangalore_ Infrastructure, Facilities and MoreManyata Tech Park Bangalore_ Infrastructure, Facilities and More
Manyata Tech Park Bangalore_ Infrastructure, Facilities and More
 
bgiolcb
bgiolcbbgiolcb
bgiolcb
 
What is Continuous Testing in DevOps - A Definitive Guide.pdf
What is Continuous Testing in DevOps - A Definitive Guide.pdfWhat is Continuous Testing in DevOps - A Definitive Guide.pdf
What is Continuous Testing in DevOps - A Definitive Guide.pdf
 
Optimizing Your E-commerce with WooCommerce.pptx
Optimizing Your E-commerce with WooCommerce.pptxOptimizing Your E-commerce with WooCommerce.pptx
Optimizing Your E-commerce with WooCommerce.pptx
 
Enhanced Screen Flows UI/UX using SLDS with Tom Kitt
Enhanced Screen Flows UI/UX using SLDS with Tom KittEnhanced Screen Flows UI/UX using SLDS with Tom Kitt
Enhanced Screen Flows UI/UX using SLDS with Tom Kitt
 
Upturn India Technologies - Web development company in Nashik
Upturn India Technologies - Web development company in NashikUpturn India Technologies - Web development company in Nashik
Upturn India Technologies - Web development company in Nashik
 
WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...
WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...
WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...
 
Building API data products on top of your real-time data infrastructure
Building API data products on top of your real-time data infrastructureBuilding API data products on top of your real-time data infrastructure
Building API data products on top of your real-time data infrastructure
 
The Comprehensive Guide to Validating Audio-Visual Performances.pdf
The Comprehensive Guide to Validating Audio-Visual Performances.pdfThe Comprehensive Guide to Validating Audio-Visual Performances.pdf
The Comprehensive Guide to Validating Audio-Visual Performances.pdf
 
Modelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - AmsterdamModelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - Amsterdam
 

Scope Graphs: A fresh look at name binding in programming languages

  • 1. Eelco Visser Curry On 2017 Barcelona June 2017 Scope Graphs A fresh look at name binding in programming languages
  • 2. /* A program to solve the 8-queens problem */ let var N := 8 type intArray = array of int var row := intArray [ N ] of 0 var col := intArray [ N ] of 0 var diag1 := intArray [N+N-1] of 0 var diag2 := intArray [N+N-1] of 0 function printboard() = (for i := 0 to N-1 do (for j := 0 to N-1 do print(if col[i]=j then " O" else " ."); print("n")); print("n")) function try(c:int) = ( if c=N then printboard() else for r := 0 to N-1 do if row[r]=0 & diag1[r+c]=0 & diag2[r+7-c]=0 then (row[r]:=1; diag1[r+c]:=1; diag2[r+7-c]:=1; col[c]:=r; try(c+1); row[r]:=0; diag1[r+c]:=0; diag2[r+7-c]:=0) ) in try(0) end let function fact(n : int) : int = if n < 1 then 1 else (n * fact(n - 1)) in fact(10) end /* define valid recursive types */ let /* define a list */ type intlist = {hd: int, tl: intlist} /* define a tree */ type tree ={key: int, children: treelist} type treelist = {hd: tree, tl: treelist} var lis:intlist := intlist { hd=0, tl= nil } in lis end A Language Design Tiger by Andrew Appel, 1996
  • 5. module Functions imports Identifiers imports Types context-free syntax Dec.FunDecs = <<{FunDec "n"}+>> {longest-match} FunDec.ProcDec = < function <Id>(<{FArg ", "}*>) = <Exp> > FunDec.FunDec = < function <Id>(<{FArg ", "}*>) : <Type> = <Exp> > FArg.FArg = <<Id> : <Type>> Exp.Call = <<Id>(<{Exp ", "}*>)> let function fact(n : int) : int = if n < 1 then 1 else (n * fact(n - 1)) in fact(10) end Mod( Let( [ FunDecs( [ FunDec( "fact" , [FArg("n", Tid("int"))] , Tid("int") , If( Lt(Var("n"), Int("1")) , Int("1") , Seq( [ Times( Var("n") , Call("fact", [Minus(Var("n"), Int("1"))]) ) ] ) ) ) ] ) ] , [Call("fact", [Int("10")])] ) ) Context-Free Grammar Abstract Syntax Parser Start: Syntax
  • 6.
  • 8. Representation • Parse Trees / Abstract Syntax Trees Declarative Rules • Context-free grammar + disambiguation Language-Independent Tooling • Parser generation • Syntax aware editor • Syntactic completion • Formatter • … Separation of Concerns in Syntax Definition More in ECOOP Summer School lecture on Thursday afternoon A language for talking about syntax }
  • 12. let function fact(n : int) : int = if n < 1 then 1 else n * fact(n - 1) in fact(10) end Variables
  • 13. let function fact(n : int) : int = if n < 1 then 1 else n * fact(n - 1) in fact(10) end Function Calls
  • 14. function prettyprint(tree: tree) : string = let var output := "" function write(s: string) = output := concat(output, s) function show(n: int, t: tree) = let function indent(s: string) = (write("n"); for i := 1 to n do write(" "); output := concat(output, s)) in if t = nil then indent(".") else (indent(t.key); show(n+1, t.left); show(n+1, t.right)) end in show(0, tree); output end Nested Scopes (Shadowing)
  • 15. let type point = { x : int, y : int } var origin := point { x = 1, y = 2 } in origin.x := 10; origin := nil end Type References
  • 16. let type point = { x : int, y : int } var origin := point { x = 1, y = 2 } in origin.x := 10; origin := nil end Record Fields
  • 17. let type point = { x : int, y : int } var origin := point { x = 1, y = 2 } in origin.x := 10; origin := nil end Type Dependent Name Resolution
  • 18.
  • 19. name binding ? How to define the rules of a language
  • 21. Representation • To conduct and represent the results of name resolution Declarative Rules • To define name binding rules of a language Language-Independent Tooling • Name resolution • Code completion • Refactoring • … Separation of Concerns in Name Binding
  • 22. Representation • ? Declarative Rules • To define name binding rules of a language Language-Independent Tooling • Name resolution • Code completion • Refactoring • … Separation of Concerns in Name Binding Scope Graphs
  • 23. let function fact(n : int) : int = if n < 1 then 1 else n * fact(n - 1) in fact(10) end fact S1 fact S2n n fact nn Scope GraphProgram Name Resolution
  • 24. A Calculus for Name Resolution S R1 R2 SR SRS I(R1 ) S’S S’S P Sx Sx R xS xS D Path in scope graph connects reference to declaration Scopes, References, Declarations, Parents, Imports Neron, Tolmach, Visser, Wachsmuth A Theory of Name Resolution ESOP 2015
  • 25. Simple Scopes Reference Declaration Scope Reference Step Declaration Step def y1 = x2 + 1 def x1 = 5 S0 def y1 = x2 + 1 def x1 = 5 Sx Sx R xS xS D S0 y1 x1S0 y1 x1S0x2 R y1 x1S0x2 R D y1 x1S0x2 S x x
  • 26. Lexical Scoping S1 S0 Parent def x1 = z2 5 def z1 = fun y1 { x2 + y2 } S’S S’S P z1 x1S0z2 S1 y1y2 x2 z1 x1S0z2 S1 y1y2 x2 z1 x1S0z2 S1 y1y2 x2 z1 x1S0z2 R S1 y1y2 x2 z1 x1S0z2 R D S1 y1y2 x2 z1 x1S0z2 R S1 y1y2 x2 z1 x1S0z2 R P S1 y1y2 x2 z1 x1S0z2 R P D S’S Parent Step
  • 27. Imports Associated scope Import S0 SB SA module A1 { def z1 = 5 } module B1 { import A2 def x1 = 1 + z2 } A1 SA z1 B1 SB z2 S0 A2 x1 S R1 R2 SR A1 SA z1 B1 SB z2 S0 A2 x1 A1 SA z1 B1 SB z2 S0 A2 x1 A1 SA z1 B1 SB z2 S0 A2 x1 R A1 SA z1 B1 SB z2 S0 A2 x1 R R A1 SA z1 B1 SB z2 S0 A2 x1 R R P A1 SA z1 B1 SB z2 S0 A2 x1 R R P D A1 SA z1 B1 SB z2 S0 A2 x1 I(A2 )R R P D A1 SA z1 B1 SB z2 S0 A2 x1 I(A2 )R R D P D S R1 R2 SR SRS I(R1 ) Import Step
  • 28. Qualified Names module N1 { def s1 = 5 } module M1 { def x1 = 1 + N2.s2 } S0 N1 SN s2 S0 N2 R D R I(N2) D X1 s1 N1 SN s2 S0 N2 R D X1 s1 N1 SN s2 S0 N2 X1 s1
  • 29. A Calculus for Name Resolution S R1 R2 SR SRS I(R1 ) S’S S’S P Sx Sx R xS xS D Reachability of declarations from references through scope graph edges How about ambiguities? References with multiple paths
  • 30. A Calculus for Name Resolution S R1 R2 SR SRS I(R1 ) S’S S’S P Sx Sx R xS xS D I(_).p’ < P.p D < I(_).p’ D < P.p s.p < s.p’ p < p’ Visibility Well formed path: R.P*.I(_)*.D Reachability
  • 31. Ambiguous Resolutions match t with | A x | B x => … z1 x2 x1S0x3 z1 x2 x1S0x3 R z1 x2 x1S0x3 R D z1 x2 x1S0x3 R D z1 x2 x1S0x3 R D D S0def x1 = 5 def x2 = 3 def z1 = x3 + 1
  • 32. Shadowing S0 S1 S2 D < P.p s.p < s.p’ p < p’ S1 S2 x1 y1 y2 x2 z1 x3S0z2 def x3 = z2 5 7 def z1 = fun x1 { fun y1 { x2 + y2 } } S1 S2 x1 y1 y2 x2 z1 x3S0z2 R P P D S1 S2 x1 y1 y2 x2 z1 x3S0z2 D P R R P P D R.P.D < R.P.P.D
  • 33. Imports shadow Parents I(_).p’ < P.p R.I(A2).D < R.P.D A1 SA z1 B1 SB z2 S0 A2 x1 z3 A1 SA z1 B1 SB z2 S0 A2 x1 I(A2)R D z3 A1 SA z1 B1 SB z2 S0 A2 x1 I(A2)R D P D z3 R S0def z3 = 2 module A1 { def z1 = 5 } module B1 { import A2 def x1 = 1 + z2 } SA SB
  • 34. Imports vs. Includes S0def z3 = 2 module A1 { def z1 = 5 } import A2 def x1 = 1 + z2 SA A1 SA z1 z2 S0 A2 x1 I(A2) R D z3 R D D < I(_).p’ R.D < R.I(A2).D A1 SA z1 z2 S0 A2 x1 R z3 D A1 SA z1 z2 S0 A2 x1z3 S0def z3 = 2 module A1 { def z1 = 5 } include A2 def x1 = 1 + z2 SA X
  • 35. Import Parents def s1 = 5 module N1 { } def x1 = 1 + N2.s2 S0 SN def s1 = 5 module N1 { } def x1 = 1 + N2.s2 S0 SN Well formed path: R.P*.I(_)*.D N1 SN s2 S0 N2 X1 s1 R I(N2 ) D P N1 SN s2 S0 N2 X1 s1
  • 36. Transitive vs. Non-Transitive With transitive imports, a well formed path is R.P*.I(_)*.D With non-transitive imports, a well formed path is R.P*.I(_)?.D A1 SA z1 B1 SB S0 A2 C1 SCz2 x1 B2 A1 SA z1 B1 SB S0 A2 I(A2 ) D C1 SCz2 I(B2 ) R x1 B2 ?? module A1 { def z1 = 5 } module B1 { import A2 } module C1 { import B2 def x1 = 1 + z2 } SA SB SC
  • 37. A Calculus for Name Resolution S R1 R2 SR SRS I(R1 ) S’S S’S P Sx Sx R xS xS D I(_).p’ < P.p D < I(_).p’ D < P.p s.p < s.p’ p < p’ Visibility Well formed path: R.P*.I(_)*.D Reachability
  • 38. Representation • To conduct and represent the results of name resolution Declarative Rules • To define name binding rules of a language Language-Independent Tooling • Name resolution • Code completion • Refactoring • … Separation of Concerns in Name Binding
  • 39. Representation • ? Declarative Rules • To define name binding rules of a language Language-Independent Tooling • Name resolution • Code completion • Refactoring • … Separation of Concerns in Name Binding Scope Graphs
  • 40. Representation • ? Declarative Rules • ? Language-Independent Tooling • Name resolution • Code completion • Refactoring • … Separation of Concerns in Name Binding Scope (& Type) Constraint Rules [PEPM16] Scope Graphs
  • 42. Scope Graph Constraints new s // new scope s1 -L-> s2 // labeled edge from scope s1 to scope s2 N{x} <- s // x is a declaration in scope s for namespace N N{x} -> s // x is a reference in scope s for namespace N N{x} |-> d // x resolves to declaration d [[ e ^ (s) ]] // constraints for expression e in scope s
  • 43. let var x : int := x + 1 in x + 1 end s s_bodyx x Let( [VarDec( "x" , Tid("int") , Plus(Var("x"), Int("1")) )] , [Plus(Var("x"), Int("1"))] ) [[ Let([VarDec(x, t, e)], [e_body]) ^ (s) ]] := new s_body, // new scope s_body -P-> s, // parent edge to enclosing scope Var{x} <- s_body, // x is a declaration in s_body [[ e ^ (s) ]], // init expression [[ e_body ^ (s_body) ]]. // body expression [[ Var(x) ^ (s') ]] := Var{x} -> s', // x is a reference in s' Var{x} |-> d, // check that x resolves to a declaration s’ x ? P
  • 45. Type Constraints d : ty // declaration has type t1 == ty2 // type equality ty1 <! ty2 // declare sub-type ty1 <? ty2 // query sub-type . . . // extensions [[ e ^ (s) : ty ]] // type of expression in scope
  • 46. s s_bodyx x [[ Let([VarDec(x, t, e)], [e_body]) ^ (s) : ty' ]] := new s_body, // new scope s_body -P-> s, // parent edge to enclosing scope Var{x} <- s_body, // x is a declaration in s_body Var{x} : ty, // associate type [[ t ^ (s) : ty ]], // type of type [[ e ^ (s) : ty ]], // type of expression [[ e_body ^ (s_body) : ty' ]]. // constraints for body [[ Var(x) ^ (s') : ty ]] := Var{x} -> s', // x is a reference in s' Var{x} |-> d, // check that x resolves to a declaration d : ty. // type of declaration is type of reference s’ x let var x : int := x + 1 in x + 1 end Let( [VarDec( "x" , Tid("int") , Plus(Var("x"), Int("1")) )] , [Plus(Var("x"), Int("1"))] )
  • 47. let type point = {x : int, y : int} var origin : point := … in origin.x end S2 S3 x x point [[ FieldVar(e, f) ^ (s) : ty ]] := [[ e ^ (s) : ty_e ]], new s_use, Field{f} -> s_use, s_use -I-> s_rec, ty_e == RECORD(s_rec), Field{f} |-> d, d : ty. [[ RecordTy(fields) ^ (s) : ty ]] := ty == RECORD(s_rec), new s_rec, Map2[[ fields ^ (s_rec, s) ]]. [[ Field(x, t) ^ (s_rec, s_outer) ]] := Field{x} <- s_rec, Field{x} : ty !, [[ t ^ (s_outer) : ty ]]. S1 point s_rec y RECORD INT origin origin s_use s_recty_e Type Dependent Name Resolution
  • 48. Representation • ? Declarative Rules • ? Language-Independent Tooling • Name resolution • Code completion • Refactoring • … Separation of Concerns in Name Binding Scope Graphs Scope & Type Constraint Rules A language for talking about name binding}
  • 49. NaBL2 in Spoofax Language Workbench http://spoofax.org
  • 50. Languages • IceDust2 [ECOOP17] • Education ‣ Mini-Java, Tiger, Calc • Programming languages ‣ Pascal, TypeScript, F# ‣ (student projects in progress) • Bootstrapping language workbench ‣ NaBL2, … Applications
  • 51. Scopes Describe Frames [ECOOP16] S x y l’l : T : T S’ S’’ xx S y l l’ x S’ x S’’ A Uniform Model for Memory Layout in Dynamic Semantics
  • 52. Theory • Resolution calculus • Name binding and type constraints • Resolution algorithm sound wrt calculus • Mapping to run-time memory layout Declarative specification • NaBL2: generation of name and type constraints Tooling • Solver (second version) • Integrated in Spoofax Language Workbench ‣ editors with name and type checking ‣ navigation Scope Graphs for Name Binding: Status
  • 53. A domain-specific (= restricted) model • Cannot describe all name resolution algorithms implemented in Turing complete languages Normative model • ‘this is name binding’ Claim/hypothesis • Describes all sane models of name binding Scope Graphs for Name Binding: Limitations
  • 54. Theory • Scopes = structural types? ‣ operations for scope / type comparison • Generics ‣ DOT-style? • Type soundness of interpreters — automatically Tooling • Tune name binding language (notation) • Incremental analysis (in progress) • Code completion • Refactoring (renaming) Scope Graphs for Name Binding: Future Work
  • 55. A common (cross-language) understanding of name binding? A foundation for formalization and implementation of programming languages? Scope Graphs for Name Binding: The Future A1 SA z1 B1 SB z2 S0 A2 x1 A1 SA z1 B1 SB z2 S0 A2 x1 A1 SA z1 B1 SB z2 S0 A2 x1 A1 SA z1 B1 SB z2 S0 A2 x1 R A1 SA z1 B1 SB z2 S0 A2 x1 R R A1 SA z1 B1 SB z2 S0 A2 x1 R R P A1 SA z1 B1 SB z2 S0 A2 x1 R R P D A1 SA z1 B1 SB z2 S0 A2 x1 I(A2 )R R P D A1 SA z1 B1 SB z2 S0 A2 x1 I(A2 )R R D P D