SlideShare a Scribd company logo
Challenge the future
Delft
University of
Technology
Course IN4303, 2013/14
Compiler Construction
Guido Wachsmuth
Imperative and
Object-Oriented Languages
last lecture
Imperative and Object-Oriented Languages
Assessment
Explain the properties of language using the examples of English
and MiniJava.
• arbitrary
• symbolic
• systematic
• productive
• non-instinctive
• conventional
• modifiable
2
last lecture
Imperative and Object-Oriented Languages
Assessment
What is a software language?
• computer-processable artificial language used to engineer software
• piece of software
Why is MiniJava a software language?
• computer-processable artificial language
• programming language, can be used to engineer software
• MiniJava compiler = piece of software
Why is English not a software language?
• not computer-processable, not artificial
3
Imperative and Object-Oriented Languages
Recap: Compilers
4
compiler
software
language
machine
language
today’s lecture
Imperative and Object-Oriented Languages
Overview
5
I
imperative languages
II
object-oriented languages
Term Rewriting
imperative languages
I
6
Imperative and Object-Oriented Languages 7
machine code
registers
Imperative and Object-Oriented Languages
x86 family
general purpose registers
• accumulator AX - arithmetic operations
• counter CX - shift/rotate instructions, loops
• data DX - arithmetic operations, I/O
• base BX - pointer to data
• stack pointer SP, base pointer BP - top and base of stack
• source SI, destination DI - stream operations
special purpose registers
• segments SS, CS, DS, ES, FS, GS
• flags EFLAGS
8
read memorymov AX [1]
mov CX AX
L: dec CX
mul CX
cmp CX 1
ja L
mov [2] AX
basic concepts
Imperative and Object-Oriented Languages
Example: x86 Assembler
9
write memory
calculation
jump
.method static public m(I)I
iload 1
ifne else
iconst_1
ireturn
else: iload 1
dup
iconst_1
isub
invokestatic Math/m(I)I
imul
ireturn
basic concepts
Imperative and Object-Oriented Languages
Example: Java Bytecode
10
read memory
calculation
jump
states & statements
Imperative and Object-Oriented Languages
Example: C
	 int f = 1
	 int x = 5
	 int s = f + x
	 while (x > 1) {
	 	 f = x * f ;
	 	 x = x - 1
	 }
11
variable
expression
assignment
control flow
states & statements
Imperative and Object-Oriented Languages
Example: Tiger
/* factorial function */
let
	 var f := 1
	 var x := 5
	 var s := f + x
in
	 while x > 1 do (
	 	 f := x * f ;
	 	 x := x - 1
	 )
end
12
variable
expression
assignment
control flow
push 21
push 42
call _f
add SP 8
push BP
mov BP SP
mov AX [BP + 8]
mov DX [BP + 12]
add AX DX
pop BP
ret
pass parameter
Imperative and Object-Oriented Languages
Example: x86 Assembler
13
access parameter
new stack frame
modularity
old stack frame
free parameters
procedures
Imperative and Object-Oriented Languages
Example: C
#include <stio.h>
/* factorial function */
int fac( int num ) {
	 if (num < 1)
	 	 return 1;
	 else
	 	 return num * fac(num - 1) ;
}
int main() {
	 int x = 10 ;
	 int f = fac( x ) ;
	 int x printf(“%d! = %dn”, x, f);
	 return 0;
}
14
formal parameter
actual parameter
local variable
recursive call
procedures
Imperative and Object-Oriented Languages
Example: Tiger
/* factorial function */
let
	 function fac( n: int ) : int =
	 let
	 	 var f := 1
	 in
	 	 if n < 1 then
	 	 	 f := 1
	 	 else
	 	 	 f := (n * fac(n - 1) );
	 	 f
	 end
var f := 0
var x := 5
in
	 f := fac( x )
end
15
formal parameter
actual parameter
local variable
recursive call
call by value vs. call by reference
Imperative and Object-Oriented Languages
Example: Tiger
let
	 type vector = array of int
	 function init(v: vector) =
	 	 v := vector[5] of 0
	 	
	 function upto(v: vector, l: int) =
	 	 for i := 0 to l do
	 	 	 v[i] := i
	 	 	
	 var v : vector := vector[5] of 1
in
	 init(v) ;
	 upto(v, 5)
end
16
dynamic & static typing
Imperative and Object-Oriented Languages
Type Systems
machine code
• memory: no type information
• instructions: assume values of certain types
dynamically typed languages
• typed values
• run-time checking & run-time errors
statically typed languages
• typed expressions
• compile-time checking & compile-time errors
17
compatibility
Imperative and Object-Oriented Languages
Type Systems
type compatibility
• value/expression: actual type
• context: expected type
type equivalence
• structural type systems
• nominative type systems
subtyping
• relation between types
• value/expression: multiple types
18
type compatibility
Imperative and Object-Oriented Languages
Example: Tiger
let
	 type A = int
	 type B = int
	 type V = array of A
	 type W = V
	 type X = array of A
	 type Y = array of B
	
	 var a: A := 42
	 var b: B := a
	 var v: V := V[42] of b
	 var w: W := v
	 var x: X := w
	 var y: Y := x
in
	 y
end
19
record types
Imperative and Object-Oriented Languages
Type Systems
record
• consecutively stored values
• fields accessible via different offsets
record type
• fields by name, type, position in record
• structural subtyping: width vs. depth
20
type R1 = {f1 : int, f2 : int}
type R2 = {f1 : int, f2 : int, f3 : int}
type R3 = {f1 : byte, f2 : byte}
biology
Imperative and Object-Oriented Languages
Polymorphism
21
the occurrence of more than one form
biology
Imperative and Object-Oriented Languages
Polymorphism
22
biology
Imperative and Object-Oriented Languages
Polymorphism
23
programming languages
Imperative and Object-Oriented Languages
Polymorphism
21 + 21
21.0 + 21.0
"foo" + "bar"
24
programming languages
Imperative and Object-Oriented Languages
Polymorphism
print(42)
print(42.0)
print("foo")
25
programming languages
Imperative and Object-Oriented Languages
Polymorphism
21 + 21
21.0 + 21.0
21 + 21.0
21 + "bar"
26
polymorphism
Imperative and Object-Oriented Languages
Type Systems
ad-hoc polymorphism
overloading
• same name, different types, same operation
• same name, different types, different operations
type coercion
• implicit conversion
universal polymorphism
subtype polymorphism
• substitution principle
parametric polymorphism
27
21 + 21
21.0 + 21.0
print(42)
print(42.0)
"foo" + "bar"
21 + "bar"
Imperative and Object-Oriented Languages 28
coffee break
Term Rewriting
object-oriented languages
II
29
objects & messages
Imperative and Object-Oriented Languages
Modularity
objects
• generalisation of records
• identity
• state
• behaviour
messages
• objects send and receive messages
• trigger behaviour
• imperative realisation: method calls
30
classes
Imperative and Object-Oriented Languages
Modularity
classes
• generalisation of record types
• characteristics of objects: attributes, fields, properties
• behaviour of objects: methods, operations, features
encapsulation
• interface exposure
• hide attributes & methods
• hide implementation
31
public class C {
public int f1;
private int f2;
public void m1() { return; }
private C m2(C c) { return c; }
}
inheritance vs. interfaces
Imperative and Object-Oriented Languages
Modularity
inheritance
• inherit attributes & methods
• additional attributes & methods
• override behaviour
• nominative subtyping
interfaces
• avoid multiple inheritance
• interface: contract for attributes & methods
• class: provide attributes & methods
• nominative subtyping
32
public class C {
public int f1;
public void m1() {…}
public void m2() {…}
}
public class D extends C {
public int f2;
public void m2() {…}
public void m3() {…}
}
public interface I {
public int f;
public void m();
}
public class E implements I {
public int f;
public void m() {…}
public void m’() {…}
}
polymorphism
Imperative and Object-Oriented Languages
Type Systems
ad-hoc polymorphism
overloading
• same method name, independent classes
• same method name, same class, different parameter types
overriding
• same method name, subclass, compatible types
universal polymorphism
subtype polymorphism
• inheritance, interfaces
parametric polymorphism
33
static vs. dynamic dispatch
Imperative and Object-Oriented Languages
Type Systems
dispatch
• link method call to method
static dispatch
• type information at compile-time
dynamic dispatch
• type information at run-time
• single dispatch: one parameter
• multiple dispatch: more parameters
34
single dispatch
Imperative and Object-Oriented Languages
Example: Java
public class A {} public class B extends A {} public class C extends B {}
public class D {
public A m(A a) { System.out.println("D.m(A a)"); return a; }
public A m(B b) { System.out.println("D.m(B b)"); return b; }
}
public class E extends D {
public A m(A a) { System.out.println("E.m(A a)"); return a; }
public B m(B b) { System.out.println("E.m(B b)"); return b; }
}
35
A a = new A(); B b = new B(); C c = new C(); D d = new D(); E e = new E();
A ab = b; A ac = c; D de = e;
d. m(a); d. m(b); d. m(ab); d. m(c); d. m(ac);
e. m(a); e. m(b); e. m(ab); e. m(c); e. m(ac);
de.m(a); de.m(b); de.m(ab); de.m(c); de.m(ac);
variance
Imperative and Object-Oriented Languages
Type Systems
A <: B
C ? D
36
covariance
Imperative and Object-Oriented Languages
Type Systems
A <: B
C <: D
37
contravariance
Imperative and Object-Oriented Languages
Type Systems
A <: B
C :> D
38
invariance
Imperative and Object-Oriented Languages
Type Systems
A <: B
C = D
39
overriding
Imperative and Object-Oriented Languages
Type Systems
methods
• parameter types
• return type
covariance
• method in subclass
• return type: subtype of original return type
contravariance
• method in subclass
• parameter types: supertypes of original parameter types
40
overloading vs. overriding
Imperative and Object-Oriented Languages
Example: Java
public class F {
public A m(B b) { System.out.println("F.m(B b)"); return b; }
}
public class G extends F {
public A m(A a) { System.out.println("G.m(A a)"); return a; }
}
public class H extends F {
public B m(B b) { System.out.println("H.m(B b)"); return b; }
}
41
A a = new A(); B b = new B(); F f = new F(); G g = new G(); H h = new H();
A ab = b;
f.m(b);
g.m(a); g.m(b); g.m(ab);
h.m(a); h.m(b); h.m(ab);
invariance
Imperative and Object-Oriented Languages
Example: Java
public class X {
public A a;
public A getA() { return a ; }	
public void setA(A a) { this.a = a ; }
}
public class Y extends X {
public B a;
public B getA() { return a ; }	
public void setA(B a) { this.a = a ; }
}
42
A a = new A(); B b = new B(); X y = new Y();
y.getA(); y.setA(b); y.setA(a);
String[] s = new String[3] ; Object[] o = s ; o[1] = new A();
Term Rewriting
summary
III
43
lessons learned
Imperative and Object-Oriented Languages
Summary
imperative languages
• state & statements
• abstraction over machine code
• control flow & procedures
• types
object-oriented languages
• objects & messages
• classes
• inheritance
• types
44
learn more
Imperative and Object-Oriented Languages
Literature
Imperative Languages
Carl A. Gunter: Semantics of Programming Languages: Structures and
Techniques. MIT Press, 1992
Kenneth C. Louden: Programming Languages: Principles and Practice.
Course Technology, 2002
Object-Oriented Languages
Martin Abadi, Luca Cardelli: A Theory of Objects. Springer, 1996.
Kim B. Bruce: Foundations of Object-Oriented Programming Languages:
Types and Semantics. MIT Press, 2002.
Timothy Budd: An Introduction to Object-Oriented Programming.
Addison-Wesley, 2002.
45
coming next
Imperative and Object-Oriented Languages
Outlook
declarative language definition
• Lecture 1: Grammars and Trees
• Lecture 2: SDF and ATerms
• Lecture 3: Name Binding and Type Systems
• Lecture 4: Term Rewriting
• Lecture 5: Static Analysis and Error Checking
• Lecture 6: Code Generation
Lab Sep 12
• get used to Eclipse, Spoofax, and MiniJava
46
Imperative and Object-Oriented Languages 47
copyrights
Imperative and Object-Oriented Languages
Pictures
Slide 1: Popular C++ by Itkovian, some rights reserved
Slide 4: PICOL icons by Melih Bilgil, some rights reserved
Slides 7, 9, 13: Dual Processor Module by roobarb!, some rights reserved
Slides 11, 14: The C Programming Language by Bill Bradford, some rights reserved
Slides 12, 15, 16, 19: Tiger by Bernard Landgraf, some rights reserved
Slide 21: Adam and Eva by Albrecht Dürer, public domain
Slide 22: ABO blood type by InvictaHOG, public domain
Slide 23: Blood Compability and Plasma donation compatibility path by InvictaHOG, public domain
Slide 28: Delice de France by Dominica Williamson, some rights reserved
Slide 46: Nieuwe Kerk by Arne Kuilman, some rights reserved
48
Ad

More Related Content

What's hot (20)

Declarative Syntax Definition - Grammars and Trees
Declarative Syntax Definition - Grammars and TreesDeclarative Syntax Definition - Grammars and Trees
Declarative Syntax Definition - Grammars and Trees
Guido Wachsmuth
 
Programming languages
Programming languagesProgramming languages
Programming languages
Eelco Visser
 
Static Analysis
Static AnalysisStatic Analysis
Static Analysis
Eelco Visser
 
Declare Your Language: Syntax Definition
Declare Your Language: Syntax DefinitionDeclare Your Language: Syntax Definition
Declare Your Language: Syntax Definition
Eelco Visser
 
Type analysis
Type analysisType analysis
Type analysis
Eelco Visser
 
Formal Grammars
Formal GrammarsFormal Grammars
Formal Grammars
Eelco Visser
 
LL Parsing
LL ParsingLL Parsing
LL Parsing
Eelco Visser
 
Pure and Declarative Syntax Definition: Paradise Lost and Regained
Pure and Declarative Syntax Definition: Paradise Lost and RegainedPure and Declarative Syntax Definition: Paradise Lost and Regained
Pure and Declarative Syntax Definition: Paradise Lost and Regained
Guido Wachsmuth
 
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
 
Declare Your Language: Name Resolution
Declare Your Language: Name ResolutionDeclare Your Language: Name Resolution
Declare Your Language: Name Resolution
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
 
Declare Your Language (at DLS)
Declare Your Language (at DLS)Declare Your Language (at DLS)
Declare Your Language (at DLS)
Eelco Visser
 
Syntax Definition
Syntax DefinitionSyntax Definition
Syntax Definition
Eelco Visser
 
Declare Your Language: Syntactic (Editor) Services
Declare Your Language: Syntactic (Editor) ServicesDeclare Your Language: Syntactic (Editor) Services
Declare Your Language: Syntactic (Editor) Services
Eelco Visser
 
Syntax Definition
Syntax DefinitionSyntax Definition
Syntax Definition
Guido Wachsmuth
 
Declare Your Language: Transformation by Strategic Term Rewriting
Declare Your Language: Transformation by Strategic Term RewritingDeclare Your Language: Transformation by Strategic Term Rewriting
Declare Your Language: Transformation by Strategic Term Rewriting
Eelco Visser
 
Declare Your Language: Type Checking
Declare Your Language: Type CheckingDeclare Your Language: Type Checking
Declare Your Language: Type Checking
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
 
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
 
Ch04
Ch04Ch04
Ch04
Hankyo
 
Declarative Syntax Definition - Grammars and Trees
Declarative Syntax Definition - Grammars and TreesDeclarative Syntax Definition - Grammars and Trees
Declarative Syntax Definition - Grammars and Trees
Guido Wachsmuth
 
Programming languages
Programming languagesProgramming languages
Programming languages
Eelco Visser
 
Declare Your Language: Syntax Definition
Declare Your Language: Syntax DefinitionDeclare Your Language: Syntax Definition
Declare Your Language: Syntax Definition
Eelco Visser
 
Pure and Declarative Syntax Definition: Paradise Lost and Regained
Pure and Declarative Syntax Definition: Paradise Lost and RegainedPure and Declarative Syntax Definition: Paradise Lost and Regained
Pure and Declarative Syntax Definition: Paradise Lost and Regained
Guido Wachsmuth
 
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
 
Declare Your Language: Name Resolution
Declare Your Language: Name ResolutionDeclare Your Language: Name Resolution
Declare Your Language: Name Resolution
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
 
Declare Your Language (at DLS)
Declare Your Language (at DLS)Declare Your Language (at DLS)
Declare Your Language (at DLS)
Eelco Visser
 
Declare Your Language: Syntactic (Editor) Services
Declare Your Language: Syntactic (Editor) ServicesDeclare Your Language: Syntactic (Editor) Services
Declare Your Language: Syntactic (Editor) Services
Eelco Visser
 
Declare Your Language: Transformation by Strategic Term Rewriting
Declare Your Language: Transformation by Strategic Term RewritingDeclare Your Language: Transformation by Strategic Term Rewriting
Declare Your Language: Transformation by Strategic Term Rewriting
Eelco Visser
 
Declare Your Language: Type Checking
Declare Your Language: Type CheckingDeclare Your Language: Type Checking
Declare Your Language: Type Checking
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
 
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
 

Viewers also liked (20)

SSRP Self Learning Guide Maths Class 10 - In Hindi
SSRP Self Learning Guide Maths Class 10 - In HindiSSRP Self Learning Guide Maths Class 10 - In Hindi
SSRP Self Learning Guide Maths Class 10 - In Hindi
kusumafoundation
 
Labsheet_3
Labsheet_3Labsheet_3
Labsheet_3
rohassanie
 
Oops
OopsOops
Oops
Maheswarikrishnasamy
 
Labsheet2
Labsheet2Labsheet2
Labsheet2
rohassanie
 
Unit i
Unit iUnit i
Unit i
vijay gupta
 
Oops Concepts
Oops ConceptsOops Concepts
Oops Concepts
guest1aac43
 
Introduction to object oriented language
Introduction to object oriented languageIntroduction to object oriented language
Introduction to object oriented language
farhan amjad
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
Haris Bin Zahid
 
Cbse class 10 hindi course b model answers by candidates 2015
Cbse class 10 hindi course b model answers by candidates 2015Cbse class 10 hindi course b model answers by candidates 2015
Cbse class 10 hindi course b model answers by candidates 2015
Saurabh Singh Negi
 
Object Oriented Language
Object Oriented LanguageObject Oriented Language
Object Oriented Language
dheva B
 
Labsheet1stud
Labsheet1studLabsheet1stud
Labsheet1stud
rohassanie
 
Basics of c++
Basics of c++Basics of c++
Basics of c++
Madhavendra Dutt
 
हिन्दी व्याकरण
हिन्दी व्याकरणहिन्दी व्याकरण
हिन्दी व्याकरण
Chintan Patel
 
OOPs concept and implementation
OOPs concept and implementationOOPs concept and implementation
OOPs concept and implementation
Sandeep Kumar P K
 
Chapter3: fundamental programming
Chapter3: fundamental programmingChapter3: fundamental programming
Chapter3: fundamental programming
Ngeam Soly
 
4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT
Ajay Chimmani
 
कारक
कारककारक
कारक
guddijangir
 
Jedi slides 2.1 object-oriented concepts
Jedi slides 2.1 object-oriented conceptsJedi slides 2.1 object-oriented concepts
Jedi slides 2.1 object-oriented concepts
Maryo Manjaruni
 
02a fundamental c++ types, arithmetic
02a   fundamental c++ types, arithmetic 02a   fundamental c++ types, arithmetic
02a fundamental c++ types, arithmetic
Manzoor ALam
 
Advance oops concepts
Advance oops conceptsAdvance oops concepts
Advance oops concepts
Sangharsh agarwal
 
SSRP Self Learning Guide Maths Class 10 - In Hindi
SSRP Self Learning Guide Maths Class 10 - In HindiSSRP Self Learning Guide Maths Class 10 - In Hindi
SSRP Self Learning Guide Maths Class 10 - In Hindi
kusumafoundation
 
Introduction to object oriented language
Introduction to object oriented languageIntroduction to object oriented language
Introduction to object oriented language
farhan amjad
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
Haris Bin Zahid
 
Cbse class 10 hindi course b model answers by candidates 2015
Cbse class 10 hindi course b model answers by candidates 2015Cbse class 10 hindi course b model answers by candidates 2015
Cbse class 10 hindi course b model answers by candidates 2015
Saurabh Singh Negi
 
Object Oriented Language
Object Oriented LanguageObject Oriented Language
Object Oriented Language
dheva B
 
हिन्दी व्याकरण
हिन्दी व्याकरणहिन्दी व्याकरण
हिन्दी व्याकरण
Chintan Patel
 
OOPs concept and implementation
OOPs concept and implementationOOPs concept and implementation
OOPs concept and implementation
Sandeep Kumar P K
 
Chapter3: fundamental programming
Chapter3: fundamental programmingChapter3: fundamental programming
Chapter3: fundamental programming
Ngeam Soly
 
4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT
Ajay Chimmani
 
Jedi slides 2.1 object-oriented concepts
Jedi slides 2.1 object-oriented conceptsJedi slides 2.1 object-oriented concepts
Jedi slides 2.1 object-oriented concepts
Maryo Manjaruni
 
02a fundamental c++ types, arithmetic
02a   fundamental c++ types, arithmetic 02a   fundamental c++ types, arithmetic
02a fundamental c++ types, arithmetic
Manzoor ALam
 
Ad

Similar to Introduction - Imperative and Object-Oriented Languages (20)

Clanguage
ClanguageClanguage
Clanguage
Vidyacenter
 
TI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific LanguagesTI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific Languages
Eelco Visser
 
Declare Your Language: Virtual Machines & Code Generation
Declare Your Language: Virtual Machines & Code GenerationDeclare Your Language: Virtual Machines & Code Generation
Declare Your Language: Virtual Machines & Code Generation
Eelco Visser
 
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
 
Introduction to D programming language at Weka.IO
Introduction to D programming language at Weka.IOIntroduction to D programming language at Weka.IO
Introduction to D programming language at Weka.IO
Liran Zvibel
 
C language introduction
C language introduction C language introduction
C language introduction
musrath mohammad
 
Reduce course notes class xii
Reduce course notes class xiiReduce course notes class xii
Reduce course notes class xii
Syed Zaid Irshad
 
PERTEMUAN 1 - MENGENAL ENVIRONTMENT PROGRAM VISUAL C#.pptx
PERTEMUAN 1 - MENGENAL ENVIRONTMENT PROGRAM VISUAL C#.pptxPERTEMUAN 1 - MENGENAL ENVIRONTMENT PROGRAM VISUAL C#.pptx
PERTEMUAN 1 - MENGENAL ENVIRONTMENT PROGRAM VISUAL C#.pptx
TriSandhikaJaya
 
AVR_Course_Day3 c programming
AVR_Course_Day3 c programmingAVR_Course_Day3 c programming
AVR_Course_Day3 c programming
Mohamed Ali
 
C language
C languageC language
C language
spatidar0
 
L4 functions
L4 functionsL4 functions
L4 functions
mondalakash2012
 
C language
C languageC language
C language
VAIRA MUTHU
 
JSLounge - TypeScript 소개
JSLounge - TypeScript 소개JSLounge - TypeScript 소개
JSLounge - TypeScript 소개
Reagan Hwang
 
Introduction to C programming
Introduction to C programmingIntroduction to C programming
Introduction to C programming
Kathmandu University
 
Programming Languages: some news for the last N years
Programming Languages: some news for the last N yearsProgramming Languages: some news for the last N years
Programming Languages: some news for the last N years
Ruslan Shevchenko
 
Using Language Oriented Programming to Execute Computations on the GPU
Using Language Oriented Programming to Execute Computations on the GPUUsing Language Oriented Programming to Execute Computations on the GPU
Using Language Oriented Programming to Execute Computations on the GPU
Skills Matter
 
PDC Video on C# 4.0 Futures
PDC Video on C# 4.0 FuturesPDC Video on C# 4.0 Futures
PDC Video on C# 4.0 Futures
nithinmohantk
 
C_Intro.ppt
C_Intro.pptC_Intro.ppt
C_Intro.ppt
gitesh_nagar
 
Compiler Design Tutorial
Compiler Design Tutorial Compiler Design Tutorial
Compiler Design Tutorial
Sarit Chakraborty
 
Dr archana dhawan bajaj - c# dot net
Dr archana dhawan bajaj - c# dot netDr archana dhawan bajaj - c# dot net
Dr archana dhawan bajaj - c# dot net
Dr-archana-dhawan-bajaj
 
TI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific LanguagesTI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific Languages
Eelco Visser
 
Declare Your Language: Virtual Machines & Code Generation
Declare Your Language: Virtual Machines & Code GenerationDeclare Your Language: Virtual Machines & Code Generation
Declare Your Language: Virtual Machines & Code Generation
Eelco Visser
 
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
 
Introduction to D programming language at Weka.IO
Introduction to D programming language at Weka.IOIntroduction to D programming language at Weka.IO
Introduction to D programming language at Weka.IO
Liran Zvibel
 
Reduce course notes class xii
Reduce course notes class xiiReduce course notes class xii
Reduce course notes class xii
Syed Zaid Irshad
 
PERTEMUAN 1 - MENGENAL ENVIRONTMENT PROGRAM VISUAL C#.pptx
PERTEMUAN 1 - MENGENAL ENVIRONTMENT PROGRAM VISUAL C#.pptxPERTEMUAN 1 - MENGENAL ENVIRONTMENT PROGRAM VISUAL C#.pptx
PERTEMUAN 1 - MENGENAL ENVIRONTMENT PROGRAM VISUAL C#.pptx
TriSandhikaJaya
 
AVR_Course_Day3 c programming
AVR_Course_Day3 c programmingAVR_Course_Day3 c programming
AVR_Course_Day3 c programming
Mohamed Ali
 
JSLounge - TypeScript 소개
JSLounge - TypeScript 소개JSLounge - TypeScript 소개
JSLounge - TypeScript 소개
Reagan Hwang
 
Programming Languages: some news for the last N years
Programming Languages: some news for the last N yearsProgramming Languages: some news for the last N years
Programming Languages: some news for the last N years
Ruslan Shevchenko
 
Using Language Oriented Programming to Execute Computations on the GPU
Using Language Oriented Programming to Execute Computations on the GPUUsing Language Oriented Programming to Execute Computations on the GPU
Using Language Oriented Programming to Execute Computations on the GPU
Skills Matter
 
PDC Video on C# 4.0 Futures
PDC Video on C# 4.0 FuturesPDC Video on C# 4.0 Futures
PDC Video on C# 4.0 Futures
nithinmohantk
 
Ad

More from Guido Wachsmuth (10)

Language
LanguageLanguage
Language
Guido Wachsmuth
 
Domain-Specific Type Systems
Domain-Specific Type SystemsDomain-Specific Type Systems
Domain-Specific Type Systems
Guido Wachsmuth
 
Declarative Syntax Definition - Pretty Printing
Declarative Syntax Definition - Pretty PrintingDeclarative Syntax Definition - Pretty Printing
Declarative Syntax Definition - Pretty Printing
Guido Wachsmuth
 
Compiler Components and their Generators - LR Parsing
Compiler Components and their Generators - LR ParsingCompiler Components and their Generators - LR Parsing
Compiler Components and their Generators - LR Parsing
Guido Wachsmuth
 
Compiling Imperative and Object-Oriented Languages - Garbage Collection
Compiling Imperative and Object-Oriented Languages - Garbage CollectionCompiling Imperative and Object-Oriented Languages - Garbage Collection
Compiling Imperative and Object-Oriented Languages - Garbage Collection
Guido Wachsmuth
 
Compiling Imperative and Object-Oriented Languages - Register Allocation
Compiling Imperative and Object-Oriented Languages - Register AllocationCompiling Imperative and Object-Oriented Languages - Register Allocation
Compiling Imperative and Object-Oriented Languages - Register Allocation
Guido Wachsmuth
 
Compiling Imperative and Object-Oriented Languages - Dataflow Analysis
Compiling Imperative and Object-Oriented Languages - Dataflow AnalysisCompiling Imperative and Object-Oriented Languages - Dataflow Analysis
Compiling Imperative and Object-Oriented Languages - Dataflow Analysis
Guido Wachsmuth
 
Compiling Imperative and Object-Oriented Languages - Activation Records
Compiling Imperative and Object-Oriented Languages - Activation RecordsCompiling Imperative and Object-Oriented Languages - Activation Records
Compiling Imperative and Object-Oriented Languages - Activation Records
Guido Wachsmuth
 
Declarative Semantics Definition - Code Generation
Declarative Semantics Definition - Code Generation Declarative Semantics Definition - Code Generation
Declarative Semantics Definition - Code Generation
Guido Wachsmuth
 
Software Languages
Software LanguagesSoftware Languages
Software Languages
Guido Wachsmuth
 
Domain-Specific Type Systems
Domain-Specific Type SystemsDomain-Specific Type Systems
Domain-Specific Type Systems
Guido Wachsmuth
 
Declarative Syntax Definition - Pretty Printing
Declarative Syntax Definition - Pretty PrintingDeclarative Syntax Definition - Pretty Printing
Declarative Syntax Definition - Pretty Printing
Guido Wachsmuth
 
Compiler Components and their Generators - LR Parsing
Compiler Components and their Generators - LR ParsingCompiler Components and their Generators - LR Parsing
Compiler Components and their Generators - LR Parsing
Guido Wachsmuth
 
Compiling Imperative and Object-Oriented Languages - Garbage Collection
Compiling Imperative and Object-Oriented Languages - Garbage CollectionCompiling Imperative and Object-Oriented Languages - Garbage Collection
Compiling Imperative and Object-Oriented Languages - Garbage Collection
Guido Wachsmuth
 
Compiling Imperative and Object-Oriented Languages - Register Allocation
Compiling Imperative and Object-Oriented Languages - Register AllocationCompiling Imperative and Object-Oriented Languages - Register Allocation
Compiling Imperative and Object-Oriented Languages - Register Allocation
Guido Wachsmuth
 
Compiling Imperative and Object-Oriented Languages - Dataflow Analysis
Compiling Imperative and Object-Oriented Languages - Dataflow AnalysisCompiling Imperative and Object-Oriented Languages - Dataflow Analysis
Compiling Imperative and Object-Oriented Languages - Dataflow Analysis
Guido Wachsmuth
 
Compiling Imperative and Object-Oriented Languages - Activation Records
Compiling Imperative and Object-Oriented Languages - Activation RecordsCompiling Imperative and Object-Oriented Languages - Activation Records
Compiling Imperative and Object-Oriented Languages - Activation Records
Guido Wachsmuth
 
Declarative Semantics Definition - Code Generation
Declarative Semantics Definition - Code Generation Declarative Semantics Definition - Code Generation
Declarative Semantics Definition - Code Generation
Guido Wachsmuth
 

Recently uploaded (20)

Operations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdfOperations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdf
Arab Academy for Science, Technology and Maritime Transport
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
P-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 finalP-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 final
bs22n2s
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
Social Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsSocial Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy Students
DrNidhiAgarwal
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
How to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POSHow to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POS
Celine George
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdfBiophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
PKLI-Institute of Nursing and Allied Health Sciences Lahore , Pakistan.
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...
Sandeep Swamy
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
P-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 finalP-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 final
bs22n2s
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
Social Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsSocial Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy Students
DrNidhiAgarwal
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
How to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POSHow to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POS
Celine George
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...
Sandeep Swamy
 

Introduction - Imperative and Object-Oriented Languages

  • 1. Challenge the future Delft University of Technology Course IN4303, 2013/14 Compiler Construction Guido Wachsmuth Imperative and Object-Oriented Languages
  • 2. last lecture Imperative and Object-Oriented Languages Assessment Explain the properties of language using the examples of English and MiniJava. • arbitrary • symbolic • systematic • productive • non-instinctive • conventional • modifiable 2
  • 3. last lecture Imperative and Object-Oriented Languages Assessment What is a software language? • computer-processable artificial language used to engineer software • piece of software Why is MiniJava a software language? • computer-processable artificial language • programming language, can be used to engineer software • MiniJava compiler = piece of software Why is English not a software language? • not computer-processable, not artificial 3
  • 4. Imperative and Object-Oriented Languages Recap: Compilers 4 compiler software language machine language
  • 5. today’s lecture Imperative and Object-Oriented Languages Overview 5 I imperative languages II object-oriented languages
  • 7. Imperative and Object-Oriented Languages 7 machine code
  • 8. registers Imperative and Object-Oriented Languages x86 family general purpose registers • accumulator AX - arithmetic operations • counter CX - shift/rotate instructions, loops • data DX - arithmetic operations, I/O • base BX - pointer to data • stack pointer SP, base pointer BP - top and base of stack • source SI, destination DI - stream operations special purpose registers • segments SS, CS, DS, ES, FS, GS • flags EFLAGS 8
  • 9. read memorymov AX [1] mov CX AX L: dec CX mul CX cmp CX 1 ja L mov [2] AX basic concepts Imperative and Object-Oriented Languages Example: x86 Assembler 9 write memory calculation jump
  • 10. .method static public m(I)I iload 1 ifne else iconst_1 ireturn else: iload 1 dup iconst_1 isub invokestatic Math/m(I)I imul ireturn basic concepts Imperative and Object-Oriented Languages Example: Java Bytecode 10 read memory calculation jump
  • 11. states & statements Imperative and Object-Oriented Languages Example: C int f = 1 int x = 5 int s = f + x while (x > 1) { f = x * f ; x = x - 1 } 11 variable expression assignment control flow
  • 12. states & statements Imperative and Object-Oriented Languages Example: Tiger /* factorial function */ let var f := 1 var x := 5 var s := f + x in while x > 1 do ( f := x * f ; x := x - 1 ) end 12 variable expression assignment control flow
  • 13. push 21 push 42 call _f add SP 8 push BP mov BP SP mov AX [BP + 8] mov DX [BP + 12] add AX DX pop BP ret pass parameter Imperative and Object-Oriented Languages Example: x86 Assembler 13 access parameter new stack frame modularity old stack frame free parameters
  • 14. procedures Imperative and Object-Oriented Languages Example: C #include <stio.h> /* factorial function */ int fac( int num ) { if (num < 1) return 1; else return num * fac(num - 1) ; } int main() { int x = 10 ; int f = fac( x ) ; int x printf(“%d! = %dn”, x, f); return 0; } 14 formal parameter actual parameter local variable recursive call
  • 15. procedures Imperative and Object-Oriented Languages Example: Tiger /* factorial function */ let function fac( n: int ) : int = let var f := 1 in if n < 1 then f := 1 else f := (n * fac(n - 1) ); f end var f := 0 var x := 5 in f := fac( x ) end 15 formal parameter actual parameter local variable recursive call
  • 16. call by value vs. call by reference Imperative and Object-Oriented Languages Example: Tiger let type vector = array of int function init(v: vector) = v := vector[5] of 0 function upto(v: vector, l: int) = for i := 0 to l do v[i] := i var v : vector := vector[5] of 1 in init(v) ; upto(v, 5) end 16
  • 17. dynamic & static typing Imperative and Object-Oriented Languages Type Systems machine code • memory: no type information • instructions: assume values of certain types dynamically typed languages • typed values • run-time checking & run-time errors statically typed languages • typed expressions • compile-time checking & compile-time errors 17
  • 18. compatibility Imperative and Object-Oriented Languages Type Systems type compatibility • value/expression: actual type • context: expected type type equivalence • structural type systems • nominative type systems subtyping • relation between types • value/expression: multiple types 18
  • 19. type compatibility Imperative and Object-Oriented Languages Example: Tiger let type A = int type B = int type V = array of A type W = V type X = array of A type Y = array of B var a: A := 42 var b: B := a var v: V := V[42] of b var w: W := v var x: X := w var y: Y := x in y end 19
  • 20. record types Imperative and Object-Oriented Languages Type Systems record • consecutively stored values • fields accessible via different offsets record type • fields by name, type, position in record • structural subtyping: width vs. depth 20 type R1 = {f1 : int, f2 : int} type R2 = {f1 : int, f2 : int, f3 : int} type R3 = {f1 : byte, f2 : byte}
  • 21. biology Imperative and Object-Oriented Languages Polymorphism 21 the occurrence of more than one form
  • 22. biology Imperative and Object-Oriented Languages Polymorphism 22
  • 23. biology Imperative and Object-Oriented Languages Polymorphism 23
  • 24. programming languages Imperative and Object-Oriented Languages Polymorphism 21 + 21 21.0 + 21.0 "foo" + "bar" 24
  • 25. programming languages Imperative and Object-Oriented Languages Polymorphism print(42) print(42.0) print("foo") 25
  • 26. programming languages Imperative and Object-Oriented Languages Polymorphism 21 + 21 21.0 + 21.0 21 + 21.0 21 + "bar" 26
  • 27. polymorphism Imperative and Object-Oriented Languages Type Systems ad-hoc polymorphism overloading • same name, different types, same operation • same name, different types, different operations type coercion • implicit conversion universal polymorphism subtype polymorphism • substitution principle parametric polymorphism 27 21 + 21 21.0 + 21.0 print(42) print(42.0) "foo" + "bar" 21 + "bar"
  • 28. Imperative and Object-Oriented Languages 28 coffee break
  • 30. objects & messages Imperative and Object-Oriented Languages Modularity objects • generalisation of records • identity • state • behaviour messages • objects send and receive messages • trigger behaviour • imperative realisation: method calls 30
  • 31. classes Imperative and Object-Oriented Languages Modularity classes • generalisation of record types • characteristics of objects: attributes, fields, properties • behaviour of objects: methods, operations, features encapsulation • interface exposure • hide attributes & methods • hide implementation 31 public class C { public int f1; private int f2; public void m1() { return; } private C m2(C c) { return c; } }
  • 32. inheritance vs. interfaces Imperative and Object-Oriented Languages Modularity inheritance • inherit attributes & methods • additional attributes & methods • override behaviour • nominative subtyping interfaces • avoid multiple inheritance • interface: contract for attributes & methods • class: provide attributes & methods • nominative subtyping 32 public class C { public int f1; public void m1() {…} public void m2() {…} } public class D extends C { public int f2; public void m2() {…} public void m3() {…} } public interface I { public int f; public void m(); } public class E implements I { public int f; public void m() {…} public void m’() {…} }
  • 33. polymorphism Imperative and Object-Oriented Languages Type Systems ad-hoc polymorphism overloading • same method name, independent classes • same method name, same class, different parameter types overriding • same method name, subclass, compatible types universal polymorphism subtype polymorphism • inheritance, interfaces parametric polymorphism 33
  • 34. static vs. dynamic dispatch Imperative and Object-Oriented Languages Type Systems dispatch • link method call to method static dispatch • type information at compile-time dynamic dispatch • type information at run-time • single dispatch: one parameter • multiple dispatch: more parameters 34
  • 35. single dispatch Imperative and Object-Oriented Languages Example: Java public class A {} public class B extends A {} public class C extends B {} public class D { public A m(A a) { System.out.println("D.m(A a)"); return a; } public A m(B b) { System.out.println("D.m(B b)"); return b; } } public class E extends D { public A m(A a) { System.out.println("E.m(A a)"); return a; } public B m(B b) { System.out.println("E.m(B b)"); return b; } } 35 A a = new A(); B b = new B(); C c = new C(); D d = new D(); E e = new E(); A ab = b; A ac = c; D de = e; d. m(a); d. m(b); d. m(ab); d. m(c); d. m(ac); e. m(a); e. m(b); e. m(ab); e. m(c); e. m(ac); de.m(a); de.m(b); de.m(ab); de.m(c); de.m(ac);
  • 36. variance Imperative and Object-Oriented Languages Type Systems A <: B C ? D 36
  • 37. covariance Imperative and Object-Oriented Languages Type Systems A <: B C <: D 37
  • 38. contravariance Imperative and Object-Oriented Languages Type Systems A <: B C :> D 38
  • 39. invariance Imperative and Object-Oriented Languages Type Systems A <: B C = D 39
  • 40. overriding Imperative and Object-Oriented Languages Type Systems methods • parameter types • return type covariance • method in subclass • return type: subtype of original return type contravariance • method in subclass • parameter types: supertypes of original parameter types 40
  • 41. overloading vs. overriding Imperative and Object-Oriented Languages Example: Java public class F { public A m(B b) { System.out.println("F.m(B b)"); return b; } } public class G extends F { public A m(A a) { System.out.println("G.m(A a)"); return a; } } public class H extends F { public B m(B b) { System.out.println("H.m(B b)"); return b; } } 41 A a = new A(); B b = new B(); F f = new F(); G g = new G(); H h = new H(); A ab = b; f.m(b); g.m(a); g.m(b); g.m(ab); h.m(a); h.m(b); h.m(ab);
  • 42. invariance Imperative and Object-Oriented Languages Example: Java public class X { public A a; public A getA() { return a ; } public void setA(A a) { this.a = a ; } } public class Y extends X { public B a; public B getA() { return a ; } public void setA(B a) { this.a = a ; } } 42 A a = new A(); B b = new B(); X y = new Y(); y.getA(); y.setA(b); y.setA(a); String[] s = new String[3] ; Object[] o = s ; o[1] = new A();
  • 44. lessons learned Imperative and Object-Oriented Languages Summary imperative languages • state & statements • abstraction over machine code • control flow & procedures • types object-oriented languages • objects & messages • classes • inheritance • types 44
  • 45. learn more Imperative and Object-Oriented Languages Literature Imperative Languages Carl A. Gunter: Semantics of Programming Languages: Structures and Techniques. MIT Press, 1992 Kenneth C. Louden: Programming Languages: Principles and Practice. Course Technology, 2002 Object-Oriented Languages Martin Abadi, Luca Cardelli: A Theory of Objects. Springer, 1996. Kim B. Bruce: Foundations of Object-Oriented Programming Languages: Types and Semantics. MIT Press, 2002. Timothy Budd: An Introduction to Object-Oriented Programming. Addison-Wesley, 2002. 45
  • 46. coming next Imperative and Object-Oriented Languages Outlook declarative language definition • Lecture 1: Grammars and Trees • Lecture 2: SDF and ATerms • Lecture 3: Name Binding and Type Systems • Lecture 4: Term Rewriting • Lecture 5: Static Analysis and Error Checking • Lecture 6: Code Generation Lab Sep 12 • get used to Eclipse, Spoofax, and MiniJava 46
  • 48. copyrights Imperative and Object-Oriented Languages Pictures Slide 1: Popular C++ by Itkovian, some rights reserved Slide 4: PICOL icons by Melih Bilgil, some rights reserved Slides 7, 9, 13: Dual Processor Module by roobarb!, some rights reserved Slides 11, 14: The C Programming Language by Bill Bradford, some rights reserved Slides 12, 15, 16, 19: Tiger by Bernard Landgraf, some rights reserved Slide 21: Adam and Eva by Albrecht Dürer, public domain Slide 22: ABO blood type by InvictaHOG, public domain Slide 23: Blood Compability and Plasma donation compatibility path by InvictaHOG, public domain Slide 28: Delice de France by Dominica Williamson, some rights reserved Slide 46: Nieuwe Kerk by Arne Kuilman, some rights reserved 48

Editor's Notes

  • #2: \n
  • #3: no relation between sign and meaning\nno arbitrary composition but systematic\nsay what never was said\nwalking = instinctive\nsocial agreement\nbecause of arbitrariness\n
  • #4: no relation between sign and meaning\nno arbitrary composition but systematic\nsay what never was said\nwalking = instinctive\nsocial agreement\nbecause of arbitrariness\n
  • #5: no relation between sign and meaning\nno arbitrary composition but systematic\nsay what never was said\nwalking = instinctive\nsocial agreement\nbecause of arbitrariness\n
  • #6: no relation between sign and meaning\nno arbitrary composition but systematic\nsay what never was said\nwalking = instinctive\nsocial agreement\nbecause of arbitrariness\n
  • #7: no relation between sign and meaning\nno arbitrary composition but systematic\nsay what never was said\nwalking = instinctive\nsocial agreement\nbecause of arbitrariness\n
  • #8: no relation between sign and meaning\nno arbitrary composition but systematic\nsay what never was said\nwalking = instinctive\nsocial agreement\nbecause of arbitrariness\n
  • #9: no relation between sign and meaning\nno arbitrary composition but systematic\nsay what never was said\nwalking = instinctive\nsocial agreement\nbecause of arbitrariness\n
  • #10: no relation between sign and meaning\nno arbitrary composition but systematic\nsay what never was said\nwalking = instinctive\nsocial agreement\nbecause of arbitrariness\n
  • #11: \n
  • #12: \n
  • #13: \n
  • #14: \n
  • #15: \n
  • #16: \n
  • #17: \n
  • #18: \n
  • #19: \n
  • #20: replace human by artificial language\nhelps for communicating algorithms, ideas, designs\n\nbut still no stated process on machine\ncompiler translates\nuse the machine to establish the process on the machine\n
  • #21: replace human by artificial language\nhelps for communicating algorithms, ideas, designs\n\nbut still no stated process on machine\ncompiler translates\nuse the machine to establish the process on the machine\n
  • #22: replace human by artificial language\nhelps for communicating algorithms, ideas, designs\n\nbut still no stated process on machine\ncompiler translates\nuse the machine to establish the process on the machine\n
  • #23: replace human by artificial language\nhelps for communicating algorithms, ideas, designs\n\nbut still no stated process on machine\ncompiler translates\nuse the machine to establish the process on the machine\n
  • #24: replace human by artificial language\nhelps for communicating algorithms, ideas, designs\n\nbut still no stated process on machine\ncompiler translates\nuse the machine to establish the process on the machine\n
  • #25: replace human by artificial language\nhelps for communicating algorithms, ideas, designs\n\nbut still no stated process on machine\ncompiler translates\nuse the machine to establish the process on the machine\n
  • #26: \n
  • #27: \n
  • #28: \n
  • #29: \n
  • #30: \n
  • #31: memory\n\nread &amp; write memory, calculations, jumps\n
  • #32: memory\n\nread &amp; write memory, calculations, jumps\n
  • #33: memory\n\nread &amp; write memory, calculations, jumps\n
  • #34: memory\n\nread &amp; write memory, calculations, jumps\n
  • #35: \n
  • #36: \n
  • #37: \n
  • #38: variables: abstract over memory\n\nexpression: calculations over information in memory\n\nassignment: write memory, store result in memory\n\ncontrol flow statements: conditionals, loops, blocks - abstract over jumps\n
  • #39: variables: abstract over memory\n\nexpression: calculations over information in memory\n\nassignment: write memory, store result in memory\n\ncontrol flow statements: conditionals, loops, blocks - abstract over jumps\n
  • #40: variables: abstract over memory\n\nexpression: calculations over information in memory\n\nassignment: write memory, store result in memory\n\ncontrol flow statements: conditionals, loops, blocks - abstract over jumps\n
  • #41: variables: abstract over memory\n\nexpression: calculations over information in memory\n\nassignment: write memory, store result in memory\n\ncontrol flow statements: conditionals, loops, blocks - abstract over jumps\n
  • #42: jumps: call and return\ncall stack: return address, parameters, private data\nprocedure prologue and epilogue\n
  • #43: jumps: call and return\ncall stack: return address, parameters, private data\nprocedure prologue and epilogue\n
  • #44: jumps: call and return\ncall stack: return address, parameters, private data\nprocedure prologue and epilogue\n
  • #45: jumps: call and return\ncall stack: return address, parameters, private data\nprocedure prologue and epilogue\n
  • #46: jumps: call and return\ncall stack: return address, parameters, private data\nprocedure prologue and epilogue\n
  • #47: subroutines, routines, procedures, functions, methods \n\nscoping: local variables\ndeclarations with parameters (formal parameters)\ncalls with arguments (actual parameters)\n
  • #48: subroutines, routines, procedures, functions, methods \n\nscoping: local variables\ndeclarations with parameters (formal parameters)\ncalls with arguments (actual parameters)\n
  • #49: subroutines, routines, procedures, functions, methods \n\nscoping: local variables\ndeclarations with parameters (formal parameters)\ncalls with arguments (actual parameters)\n
  • #50: subroutines, routines, procedures, functions, methods \n\nscoping: local variables\ndeclarations with parameters (formal parameters)\ncalls with arguments (actual parameters)\n
  • #51: \n
  • #52: \n
  • #53: \n
  • #54: \n
  • #55: \n
  • #56: \n
  • #57: \n
  • #58: \n
  • #59: \n
  • #60: \n
  • #61: \n
  • #62: \n
  • #63: \n
  • #64: \n
  • #65: \n
  • #66: \n
  • #67: \n
  • #68: \n
  • #69: \n
  • #70: \n
  • #71: \n
  • #72: \n
  • #73: \n
  • #74: \n
  • #75: \n
  • #76: \n
  • #77: \n
  • #78: \n
  • #79: \n
  • #80: \n
  • #81: \n
  • #82: \n
  • #83: \n
  • #84: \n
  • #85: \n
  • #86: round-up on every lecture\n\nwhat to take with you\n\ncheck yourself, pre- and post-paration\n
  • #87: \n
  • #88: \n