SlideShare a Scribd company logo
IN4303 2016-2017
Compiler Construction
Programming Languages
imperative & object-oriented
Guido Wachsmuth, Eelco Visser
Imperative and Object-Oriented Languages 2
Imperative and Object-Oriented Languages 3
interpreter
software
language
compiler
software
language
machine
language
Imperative and Object-Oriented Languages
natural
language
natural
language
translator
4
compiler
software
language
machine
language
Imperative and Object-Oriented Languages 5
Traditional compilers
architecture
source
code
errors
parse generate
check
machine
code
Imperative and Object-Oriented Languages 6
Modern compilers in IDEs
architecture
source
code
parse generate
machine
code
check
Imperative and Object-Oriented Languages 7
Compilers are inverted abstractions
architecture
source
code
machine
code
abstract
Imperative and Object-Oriented Languages
Compilers Invert Abstractions
Computers speak machine language
• basic instructions to move around and combine small things
Humans do not speak machine language very well
• “mov; loadi; jump” anyone?
Programming languages abstract from machine language
• capture common programming patterns in language constructs
• abstract from uninteresting variation in machines
Compilers invert the abstractions of programming languages
8
Imperative and Object-Oriented Languages 9
Portability: Platform Independence
architecture
source
code
parse
generate
GPU
code
check
generate
x86
code
Imperative and Object-Oriented Languages
Understanding Compilers Requires …
Understanding machine languages
• machine architecture, instruction sets
Understanding programming language (abstraction)s
• memory, control-flow, procedures, modules, …
• safety mechanisms: type systems & other static analyses
Understanding how to define mapping from PL to ML
• semantics of such mappings
• techniques to implement such mappings
10
Imperative and Object-Oriented Languages 11
Imperative Languages
state & statements
procedures
types
Object-Oriented Languages
objects & messages
types
Imperative and Object-Oriented Languages 12
Imperative Languages
state & statements
Imperative and Object-Oriented Languages 13
machine code
basic concepts
Imperative and Object-Oriented Languages
State
Machine state
• a pile of data stored in memory
• memory hierarchy: registers, RAM, disk, network, …
Imperative program
• computation is series of changes to memory
• basic operations on memory (increment register)
• controlling such operations (jump, return address, …)
• control represented by state (program counter, stack, …)
14
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
15
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
15
mov 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
16
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
16
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
16
write memory
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
16
write memory
calculation
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
16
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
17
.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
17
read memory
.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
17
read memory
calculation
.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
17
read memory
calculation
jump
basic concepts
Imperative and Object-Oriented Languages
Memory & Control Abstractions
Memory abstractions
• variables: abstract over data storage
• expressions: combine data into new data
• assignment: abstract over storage operations
Control-flow abstractions
• structured control-flow: abstract over unstructured jumps
• ‘go to statement considered harmful’ Edgser Dijkstra, 1968
18
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
}
19
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
}
19
variable
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
}
19
variable
expression
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
}
19
variable
expression
assignment
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
}
19
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
20
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
20
variable
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
20
variable
expression
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
20
variable
expression
assignment
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
20
variable
expression
assignment
control flow
Imperative and Object-Oriented Languages 21
Imperative Languages
procedures
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
Imperative and Object-Oriented Languages
Example: x86 Assembler
22
modularity
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
22
modularity
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
22
new stack frame
modularity
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
22
access parameter
new stack frame
modularity
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
22
access parameter
new stack frame
modularity
old stack frame
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
22
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;
}
23
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;
}
23
formal parameter
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;
}
23
formal parameter
actual parameter
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;
}
23
formal parameter
actual parameter
local variable
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;
}
23
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
24
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
24
formal parameter
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
24
formal parameter
actual parameter
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
24
formal parameter
actual parameter
local variable
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
24
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
25
Imperative and Object-Oriented Languages 26
Imperative Languages
types
Subtitle Text
Imperative and Object-Oriented Languages
Types & Type Checking
Type
• type is category of values
• operation can be applied to all values in some category
Type checking
• safety: ensure that operation is applied to right input values
• static: check during compile time
• dynamic: check during execution
27
dynamic & static typing
Imperative and Object-Oriented Languages
Type Systems
Machine code
• memory: no type information
• instructions: assume values of certain types
28
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
28
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
28
compatibility
Imperative and Object-Oriented Languages
Type Systems
Type compatibility
• value/expression: actual type
• context: expected type
29
compatibility
Imperative and Object-Oriented Languages
Type Systems
Type compatibility
• value/expression: actual type
• context: expected type
Type equivalence
• structural type systems
• nominal type systems
29
compatibility
Imperative and Object-Oriented Languages
Type Systems
Type compatibility
• value/expression: actual type
• context: expected type
Type equivalence
• structural type systems
• nominal type systems
Subtyping
• relation between types
• value/expression: multiple types
29
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
30
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
31
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
32
biology
Imperative and Object-Oriented Languages
Polymorphism
32
biology
Imperative and Object-Oriented Languages
Polymorphism
32
biology
Imperative and Object-Oriented Languages
Polymorphism
32
the occurrence of more than one form
biology
Imperative and Object-Oriented Languages
Polymorphism
33
biology
Imperative and Object-Oriented Languages
Polymorphism
34
can give blood to can give plasma to
programming languages
Imperative and Object-Oriented Languages
Polymorphism
35
programming languages
Imperative and Object-Oriented Languages
Polymorphism
21 + 21
35
programming languages
Imperative and Object-Oriented Languages
Polymorphism
21 + 21
21.0 + 21.0
35
programming languages
Imperative and Object-Oriented Languages
Polymorphism
21 + 21
21.0 + 21.0
"foo" + "bar"
35
programming languages
Imperative and Object-Oriented Languages
Polymorphism
print(42)
print(42.0)
print("foo")
36
programming languages
Imperative and Object-Oriented Languages
Polymorphism
21 + 21
21.0 + 21.0
21 + 21.0
21 + "bar"
37
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
38
21 + 21
21.0 + 21.0
print(42)
print(42.0)
"foo" + "bar"
21 + "bar"
Imperative and Object-Oriented Languages 39
Object-Oriented Languages
objects & messages
objects & messages
Imperative and Object-Oriented Languages
Modularity
Objects
• generalization of records
• identity
• state
• behavior
40
objects & messages
Imperative and Object-Oriented Languages
Modularity
Objects
• generalization of records
• identity
• state
• behavior
Messages
• objects send and receive messages
• trigger behavior
• imperative realization: method calls
40
Imperative and Object-Oriented Languages 41
Object-Oriented Languages
types
classes
Imperative and Object-Oriented Languages
Modularity
Classes
• generalization of record types
• characteristics of objects: attributes, fields, properties
• behavior of objects: methods, operations, features
42
public class C {
public int f1;
private int f2;
public void m1() { return; }
private C m2(C c) { return c; }
}
classes
Imperative and Object-Oriented Languages
Modularity
Classes
• generalization of record types
• characteristics of objects: attributes, fields, properties
• behavior of objects: methods, operations, features
Encapsulation
• interface exposure
• hide attributes & methods
• hide implementation
42
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 behavior
• nominal subtyping
43
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’() {…}
}
inheritance vs. interfaces
Imperative and Object-Oriented Languages
Modularity
Inheritance
• inherit attributes & methods
• additional attributes & methods
• override behavior
• nominal subtyping
Interfaces
• avoid multiple inheritance
• interface: contract for attributes & methods
• class: provides attributes & methods
• nominal subtyping
43
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
44
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
44
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
44
static vs. dynamic dispatch
Imperative and Object-Oriented Languages
Type Systems
Dispatch
• link method call to method
45
static vs. dynamic dispatch
Imperative and Object-Oriented Languages
Type Systems
Dispatch
• link method call to method
Static dispatch
• type information at compile-time
45
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
45
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; }
}
46
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);
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 G {
public B m(B b) { System.out.println("H.m(B b)"); return b; }
}
47
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);
Imperative and Object-Oriented Languages 48
Except where otherwise noted, this work is licensed under
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
49

More Related Content

What's hot

Lex (lexical analyzer)
Lex (lexical analyzer)Lex (lexical analyzer)
Lex (lexical analyzer)
Sami Said
 
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
 
Declarative Semantics Definition - Term Rewriting
Declarative Semantics Definition - Term RewritingDeclarative Semantics Definition - Term Rewriting
Declarative Semantics Definition - Term Rewriting
Guido Wachsmuth
 
Introduction of flex
Introduction of flexIntroduction of flex
Introduction of flexvip_du
 
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
 
Introduction of bison
Introduction of bisonIntroduction of bison
Introduction of bisonvip_du
 
Writing Parsers and Compilers with PLY
Writing Parsers and Compilers with PLYWriting Parsers and Compilers with PLY
Writing Parsers and Compilers with PLY
David Beazley (Dabeaz LLC)
 
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
 
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
 
regular expressions (Regex)
regular expressions (Regex)regular expressions (Regex)
regular expressions (Regex)
Rebaz Najeeb
 
More on Lex
More on LexMore on Lex
More on LexTech_MX
 
Chapter Eight(3)
Chapter Eight(3)Chapter Eight(3)
Chapter Eight(3)bolovv
 
Logic Programming and Prolog
Logic Programming and PrologLogic Programming and Prolog
Logic Programming and Prolog
Sadegh Dorri N.
 
C programming_MSBTE_Diploma_Pranoti Doke
C programming_MSBTE_Diploma_Pranoti DokeC programming_MSBTE_Diploma_Pranoti Doke
C programming_MSBTE_Diploma_Pranoti Doke
Pranoti Doke
 
Compiler Components and their Generators - Traditional Parsing Algorithms
Compiler Components and their Generators - Traditional Parsing AlgorithmsCompiler Components and their Generators - Traditional Parsing Algorithms
Compiler Components and their Generators - Traditional Parsing Algorithms
Guido Wachsmuth
 
Lecture 3 RE NFA DFA
Lecture 3   RE NFA DFA Lecture 3   RE NFA DFA
Lecture 3 RE NFA DFA
Rebaz Najeeb
 
LISP: Introduction to lisp
LISP: Introduction to lispLISP: Introduction to lisp
LISP: Introduction to lisp
DataminingTools Inc
 
Static name resolution
Static name resolutionStatic name resolution
Static name resolution
Eelco Visser
 
System Programming Unit IV
System Programming Unit IVSystem Programming Unit IV
System Programming Unit IVManoj Patil
 

What's hot (20)

Lex (lexical analyzer)
Lex (lexical analyzer)Lex (lexical analyzer)
Lex (lexical analyzer)
 
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
 
Declarative Semantics Definition - Term Rewriting
Declarative Semantics Definition - Term RewritingDeclarative Semantics Definition - Term Rewriting
Declarative Semantics Definition - Term Rewriting
 
Introduction of flex
Introduction of flexIntroduction of flex
Introduction of flex
 
Compiler Construction | Lecture 9 | Constraint Resolution
Compiler Construction | Lecture 9 | Constraint ResolutionCompiler Construction | Lecture 9 | Constraint Resolution
Compiler Construction | Lecture 9 | Constraint Resolution
 
Introduction of bison
Introduction of bisonIntroduction of bison
Introduction of bison
 
Writing Parsers and Compilers with PLY
Writing Parsers and Compilers with PLYWriting Parsers and Compilers with PLY
Writing Parsers and Compilers with PLY
 
Compiler Construction | Lecture 13 | Code Generation
Compiler Construction | Lecture 13 | Code GenerationCompiler Construction | Lecture 13 | Code Generation
Compiler Construction | Lecture 13 | Code Generation
 
CS4200 2019 | Lecture 2 | syntax-definition
CS4200 2019 | Lecture 2 | syntax-definitionCS4200 2019 | Lecture 2 | syntax-definition
CS4200 2019 | Lecture 2 | syntax-definition
 
regular expressions (Regex)
regular expressions (Regex)regular expressions (Regex)
regular expressions (Regex)
 
Lexyacc
LexyaccLexyacc
Lexyacc
 
More on Lex
More on LexMore on Lex
More on Lex
 
Chapter Eight(3)
Chapter Eight(3)Chapter Eight(3)
Chapter Eight(3)
 
Logic Programming and Prolog
Logic Programming and PrologLogic Programming and Prolog
Logic Programming and Prolog
 
C programming_MSBTE_Diploma_Pranoti Doke
C programming_MSBTE_Diploma_Pranoti DokeC programming_MSBTE_Diploma_Pranoti Doke
C programming_MSBTE_Diploma_Pranoti Doke
 
Compiler Components and their Generators - Traditional Parsing Algorithms
Compiler Components and their Generators - Traditional Parsing AlgorithmsCompiler Components and their Generators - Traditional Parsing Algorithms
Compiler Components and their Generators - Traditional Parsing Algorithms
 
Lecture 3 RE NFA DFA
Lecture 3   RE NFA DFA Lecture 3   RE NFA DFA
Lecture 3 RE NFA DFA
 
LISP: Introduction to lisp
LISP: Introduction to lispLISP: Introduction to lisp
LISP: Introduction to lisp
 
Static name resolution
Static name resolutionStatic name resolution
Static name resolution
 
System Programming Unit IV
System Programming Unit IVSystem Programming Unit IV
System Programming Unit IV
 

Viewers also liked

Lexical Analysis
Lexical AnalysisLexical Analysis
Lexical Analysis
Eelco Visser
 
Syntax Definition
Syntax DefinitionSyntax Definition
Syntax Definition
Eelco Visser
 
Language
LanguageLanguage
Language
Guido Wachsmuth
 
Register Allocation
Register AllocationRegister Allocation
Register Allocation
Eelco Visser
 
Dynamic Semantics
Dynamic SemanticsDynamic Semantics
Dynamic Semantics
Eelco Visser
 
Software languages
Software languagesSoftware languages
Software languages
Eelco Visser
 
LR Parsing
LR ParsingLR Parsing
LR Parsing
Eelco Visser
 
LL Parsing
LL ParsingLL Parsing
LL Parsing
Eelco Visser
 
Type analysis
Type analysisType analysis
Type analysis
Eelco Visser
 
Garbage Collection
Garbage CollectionGarbage Collection
Garbage Collection
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
 

Viewers also liked (11)

Lexical Analysis
Lexical AnalysisLexical Analysis
Lexical Analysis
 
Syntax Definition
Syntax DefinitionSyntax Definition
Syntax Definition
 
Language
LanguageLanguage
Language
 
Register Allocation
Register AllocationRegister Allocation
Register Allocation
 
Dynamic Semantics
Dynamic SemanticsDynamic Semantics
Dynamic Semantics
 
Software languages
Software languagesSoftware languages
Software languages
 
LR Parsing
LR ParsingLR Parsing
LR Parsing
 
LL Parsing
LL ParsingLL Parsing
LL Parsing
 
Type analysis
Type analysisType analysis
Type analysis
 
Garbage Collection
Garbage CollectionGarbage Collection
Garbage Collection
 
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
 

Similar to Programming languages

AVR_Course_Day3 c programming
AVR_Course_Day3 c programmingAVR_Course_Day3 c programming
AVR_Course_Day3 c programming
Mohamed Ali
 
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
 
Return of c++
Return of c++Return of c++
Return of c++
Yongwei Wu
 
C language introduction
C language introduction C language introduction
C language introduction
musrath mohammad
 
TI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific LanguagesTI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific LanguagesEelco Visser
 
Clanguage
ClanguageClanguage
Clanguage
Vidyacenter
 
c programming L-1.pdf43333333544444444444444444444
c programming L-1.pdf43333333544444444444444444444c programming L-1.pdf43333333544444444444444444444
c programming L-1.pdf43333333544444444444444444444
PurvaShyama
 
C language
C languageC language
C language
spatidar0
 
Lex tool manual
Lex tool manualLex tool manual
Lex tool manualSami Said
 
Reduce course notes class xii
Reduce course notes class xiiReduce course notes class xii
Reduce course notes class xii
Syed Zaid Irshad
 
Exploring SharePoint with F#
Exploring SharePoint with F#Exploring SharePoint with F#
Exploring SharePoint with F#Talbott Crowell
 
Fundamentals of Data Structures Unit 1.pptx
Fundamentals of Data Structures Unit 1.pptxFundamentals of Data Structures Unit 1.pptx
Fundamentals of Data Structures Unit 1.pptx
Vigneshkumar Ponnusamy
 
C
CC
A Replay Approach to Software Validation
A Replay Approach to Software ValidationA Replay Approach to Software Validation
A Replay Approach to Software ValidationJames Pascoe
 
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
 
Compiler Engineering Lab#5 : Symbol Table, Flex Tool
Compiler Engineering Lab#5 : Symbol Table, Flex ToolCompiler Engineering Lab#5 : Symbol Table, Flex Tool
Compiler Engineering Lab#5 : Symbol Table, Flex Tool
MashaelQ
 
Combinators, DSLs, HTML and F#
Combinators, DSLs, HTML and F#Combinators, DSLs, HTML and F#
Combinators, DSLs, HTML and F#Robert Pickering
 

Similar to Programming languages (20)

AVR_Course_Day3 c programming
AVR_Course_Day3 c programmingAVR_Course_Day3 c programming
AVR_Course_Day3 c programming
 
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
 
Return of c++
Return of c++Return of c++
Return of c++
 
C language introduction
C language introduction C language introduction
C language introduction
 
TI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific LanguagesTI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific Languages
 
Clanguage
ClanguageClanguage
Clanguage
 
c programming L-1.pdf43333333544444444444444444444
c programming L-1.pdf43333333544444444444444444444c programming L-1.pdf43333333544444444444444444444
c programming L-1.pdf43333333544444444444444444444
 
C language
C languageC language
C language
 
C language
C languageC language
C language
 
Lex tool manual
Lex tool manualLex tool manual
Lex tool manual
 
Interm codegen
Interm codegenInterm codegen
Interm codegen
 
L4 functions
L4 functionsL4 functions
L4 functions
 
Reduce course notes class xii
Reduce course notes class xiiReduce course notes class xii
Reduce course notes class xii
 
Exploring SharePoint with F#
Exploring SharePoint with F#Exploring SharePoint with F#
Exploring SharePoint with F#
 
Fundamentals of Data Structures Unit 1.pptx
Fundamentals of Data Structures Unit 1.pptxFundamentals of Data Structures Unit 1.pptx
Fundamentals of Data Structures Unit 1.pptx
 
C
CC
C
 
A Replay Approach to Software Validation
A Replay Approach to Software ValidationA Replay Approach to Software Validation
A Replay Approach to Software Validation
 
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
 
Compiler Engineering Lab#5 : Symbol Table, Flex Tool
Compiler Engineering Lab#5 : Symbol Table, Flex ToolCompiler Engineering Lab#5 : Symbol Table, Flex Tool
Compiler Engineering Lab#5 : Symbol Table, Flex Tool
 
Combinators, DSLs, HTML and F#
Combinators, DSLs, HTML and F#Combinators, DSLs, HTML and F#
Combinators, DSLs, HTML and F#
 

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 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 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 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 4 | Parsing
Compiler Construction | Lecture 4 | Parsing Compiler Construction | Lecture 4 | Parsing
Compiler Construction | Lecture 4 | Parsing
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
 
Compiler Construction | Lecture 1 | What is a compiler?
Compiler Construction | Lecture 1 | What is a compiler?Compiler Construction | Lecture 1 | What is a compiler?
Compiler Construction | Lecture 1 | What is a compiler?
Eelco Visser
 
Declare Your Language: Dynamic Semantics
Declare Your Language: Dynamic SemanticsDeclare Your Language: Dynamic Semantics
Declare Your Language: Dynamic Semantics
Eelco Visser
 
Declare Your Language: Constraint Resolution 2
Declare Your Language: Constraint Resolution 2Declare Your Language: Constraint Resolution 2
Declare Your Language: Constraint Resolution 2
Eelco Visser
 
Declare Your Language: Constraint Resolution 1
Declare Your Language: Constraint Resolution 1Declare Your Language: Constraint Resolution 1
Declare Your Language: Constraint Resolution 1
Eelco Visser
 
Declare Your Language: Type Checking
Declare Your Language: Type CheckingDeclare Your Language: Type Checking
Declare Your Language: Type Checking
Eelco Visser
 
Declare Your Language: Name Resolution
Declare Your Language: Name ResolutionDeclare Your Language: Name Resolution
Declare Your Language: Name Resolution
Eelco Visser
 

More from Eelco Visser (19)

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 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 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 7 | Type Checking
Compiler Construction | Lecture 7 | Type CheckingCompiler Construction | Lecture 7 | Type Checking
Compiler Construction | Lecture 7 | Type Checking
 
Compiler Construction | Lecture 4 | Parsing
Compiler Construction | Lecture 4 | Parsing Compiler Construction | Lecture 4 | Parsing
Compiler Construction | Lecture 4 | Parsing
 
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
 
Compiler Construction | Lecture 1 | What is a compiler?
Compiler Construction | Lecture 1 | What is a compiler?Compiler Construction | Lecture 1 | What is a compiler?
Compiler Construction | Lecture 1 | What is a compiler?
 
Declare Your Language: Dynamic Semantics
Declare Your Language: Dynamic SemanticsDeclare Your Language: Dynamic Semantics
Declare Your Language: Dynamic Semantics
 
Declare Your Language: Constraint Resolution 2
Declare Your Language: Constraint Resolution 2Declare Your Language: Constraint Resolution 2
Declare Your Language: Constraint Resolution 2
 
Declare Your Language: Constraint Resolution 1
Declare Your Language: Constraint Resolution 1Declare Your Language: Constraint Resolution 1
Declare Your Language: Constraint Resolution 1
 
Declare Your Language: Type Checking
Declare Your Language: Type CheckingDeclare Your Language: Type Checking
Declare Your Language: Type Checking
 
Declare Your Language: Name Resolution
Declare Your Language: Name ResolutionDeclare Your Language: Name Resolution
Declare Your Language: Name Resolution
 

Recently uploaded

2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
vrstrong314
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Jay Das
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Mind IT Systems
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Anthony Dahanne
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
Ortus Solutions, Corp
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
e20449
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 

Recently uploaded (20)

2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 

Programming languages

  • 1. IN4303 2016-2017 Compiler Construction Programming Languages imperative & object-oriented Guido Wachsmuth, Eelco Visser
  • 3. Imperative and Object-Oriented Languages 3 interpreter software language compiler software language machine language
  • 4. Imperative and Object-Oriented Languages natural language natural language translator 4 compiler software language machine language
  • 5. Imperative and Object-Oriented Languages 5 Traditional compilers architecture source code errors parse generate check machine code
  • 6. Imperative and Object-Oriented Languages 6 Modern compilers in IDEs architecture source code parse generate machine code check
  • 7. Imperative and Object-Oriented Languages 7 Compilers are inverted abstractions architecture source code machine code abstract
  • 8. Imperative and Object-Oriented Languages Compilers Invert Abstractions Computers speak machine language • basic instructions to move around and combine small things Humans do not speak machine language very well • “mov; loadi; jump” anyone? Programming languages abstract from machine language • capture common programming patterns in language constructs • abstract from uninteresting variation in machines Compilers invert the abstractions of programming languages 8
  • 9. Imperative and Object-Oriented Languages 9 Portability: Platform Independence architecture source code parse generate GPU code check generate x86 code
  • 10. Imperative and Object-Oriented Languages Understanding Compilers Requires … Understanding machine languages • machine architecture, instruction sets Understanding programming language (abstraction)s • memory, control-flow, procedures, modules, … • safety mechanisms: type systems & other static analyses Understanding how to define mapping from PL to ML • semantics of such mappings • techniques to implement such mappings 10
  • 11. Imperative and Object-Oriented Languages 11 Imperative Languages state & statements procedures types Object-Oriented Languages objects & messages types
  • 12. Imperative and Object-Oriented Languages 12 Imperative Languages state & statements
  • 13. Imperative and Object-Oriented Languages 13 machine code
  • 14. basic concepts Imperative and Object-Oriented Languages State Machine state • a pile of data stored in memory • memory hierarchy: registers, RAM, disk, network, … Imperative program • computation is series of changes to memory • basic operations on memory (increment register) • controlling such operations (jump, return address, …) • control represented by state (program counter, stack, …) 14
  • 15. 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 15
  • 16. 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 15
  • 17. mov 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 16
  • 18. 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 16
  • 19. 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 16 write memory
  • 20. 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 16 write memory calculation
  • 21. 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 16 write memory calculation jump
  • 22. .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 17
  • 23. .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 17 read memory
  • 24. .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 17 read memory calculation
  • 25. .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 17 read memory calculation jump
  • 26. basic concepts Imperative and Object-Oriented Languages Memory & Control Abstractions Memory abstractions • variables: abstract over data storage • expressions: combine data into new data • assignment: abstract over storage operations Control-flow abstractions • structured control-flow: abstract over unstructured jumps • ‘go to statement considered harmful’ Edgser Dijkstra, 1968 18
  • 27. 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 } 19
  • 28. 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 } 19 variable
  • 29. 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 } 19 variable expression
  • 30. 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 } 19 variable expression assignment
  • 31. 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 } 19 variable expression assignment control flow
  • 32. 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 20
  • 33. 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 20 variable
  • 34. 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 20 variable expression
  • 35. 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 20 variable expression assignment
  • 36. 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 20 variable expression assignment control flow
  • 37. Imperative and Object-Oriented Languages 21 Imperative Languages procedures
  • 38. 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 Imperative and Object-Oriented Languages Example: x86 Assembler 22 modularity
  • 39. 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 22 modularity
  • 40. 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 22 new stack frame modularity
  • 41. 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 22 access parameter new stack frame modularity
  • 42. 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 22 access parameter new stack frame modularity old stack frame
  • 43. 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 22 access parameter new stack frame modularity old stack frame free parameters
  • 44. 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; } 23
  • 45. 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; } 23 formal parameter
  • 46. 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; } 23 formal parameter actual parameter
  • 47. 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; } 23 formal parameter actual parameter local variable
  • 48. 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; } 23 formal parameter actual parameter local variable recursive call
  • 49. 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 24
  • 50. 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 24 formal parameter
  • 51. 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 24 formal parameter actual parameter
  • 52. 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 24 formal parameter actual parameter local variable
  • 53. 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 24 formal parameter actual parameter local variable recursive call
  • 54. 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 25
  • 55. Imperative and Object-Oriented Languages 26 Imperative Languages types
  • 56. Subtitle Text Imperative and Object-Oriented Languages Types & Type Checking Type • type is category of values • operation can be applied to all values in some category Type checking • safety: ensure that operation is applied to right input values • static: check during compile time • dynamic: check during execution 27
  • 57. dynamic & static typing Imperative and Object-Oriented Languages Type Systems Machine code • memory: no type information • instructions: assume values of certain types 28
  • 58. 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 28
  • 59. 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 28
  • 60. compatibility Imperative and Object-Oriented Languages Type Systems Type compatibility • value/expression: actual type • context: expected type 29
  • 61. compatibility Imperative and Object-Oriented Languages Type Systems Type compatibility • value/expression: actual type • context: expected type Type equivalence • structural type systems • nominal type systems 29
  • 62. compatibility Imperative and Object-Oriented Languages Type Systems Type compatibility • value/expression: actual type • context: expected type Type equivalence • structural type systems • nominal type systems Subtyping • relation between types • value/expression: multiple types 29
  • 63. 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 30
  • 64. 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 31 type R1 = {f1 : int, f2 : int} type R2 = {f1 : int, f2 : int, f3 : int} type R3 = {f1 : byte, f2 : byte}
  • 65. biology Imperative and Object-Oriented Languages Polymorphism 32
  • 66. biology Imperative and Object-Oriented Languages Polymorphism 32
  • 67. biology Imperative and Object-Oriented Languages Polymorphism 32
  • 68. biology Imperative and Object-Oriented Languages Polymorphism 32 the occurrence of more than one form
  • 69. biology Imperative and Object-Oriented Languages Polymorphism 33
  • 70. biology Imperative and Object-Oriented Languages Polymorphism 34 can give blood to can give plasma to
  • 71. programming languages Imperative and Object-Oriented Languages Polymorphism 35
  • 72. programming languages Imperative and Object-Oriented Languages Polymorphism 21 + 21 35
  • 73. programming languages Imperative and Object-Oriented Languages Polymorphism 21 + 21 21.0 + 21.0 35
  • 74. programming languages Imperative and Object-Oriented Languages Polymorphism 21 + 21 21.0 + 21.0 "foo" + "bar" 35
  • 75. programming languages Imperative and Object-Oriented Languages Polymorphism print(42) print(42.0) print("foo") 36
  • 76. programming languages Imperative and Object-Oriented Languages Polymorphism 21 + 21 21.0 + 21.0 21 + 21.0 21 + "bar" 37
  • 77. 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 38 21 + 21 21.0 + 21.0 print(42) print(42.0) "foo" + "bar" 21 + "bar"
  • 78. Imperative and Object-Oriented Languages 39 Object-Oriented Languages objects & messages
  • 79. objects & messages Imperative and Object-Oriented Languages Modularity Objects • generalization of records • identity • state • behavior 40
  • 80. objects & messages Imperative and Object-Oriented Languages Modularity Objects • generalization of records • identity • state • behavior Messages • objects send and receive messages • trigger behavior • imperative realization: method calls 40
  • 81. Imperative and Object-Oriented Languages 41 Object-Oriented Languages types
  • 82. classes Imperative and Object-Oriented Languages Modularity Classes • generalization of record types • characteristics of objects: attributes, fields, properties • behavior of objects: methods, operations, features 42 public class C { public int f1; private int f2; public void m1() { return; } private C m2(C c) { return c; } }
  • 83. classes Imperative and Object-Oriented Languages Modularity Classes • generalization of record types • characteristics of objects: attributes, fields, properties • behavior of objects: methods, operations, features Encapsulation • interface exposure • hide attributes & methods • hide implementation 42 public class C { public int f1; private int f2; public void m1() { return; } private C m2(C c) { return c; } }
  • 84. inheritance vs. interfaces Imperative and Object-Oriented Languages Modularity Inheritance • inherit attributes & methods • additional attributes & methods • override behavior • nominal subtyping 43 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’() {…} }
  • 85. inheritance vs. interfaces Imperative and Object-Oriented Languages Modularity Inheritance • inherit attributes & methods • additional attributes & methods • override behavior • nominal subtyping Interfaces • avoid multiple inheritance • interface: contract for attributes & methods • class: provides attributes & methods • nominal subtyping 43 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’() {…} }
  • 86. polymorphism Imperative and Object-Oriented Languages Type Systems 44
  • 87. 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 44
  • 88. 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 44
  • 89. static vs. dynamic dispatch Imperative and Object-Oriented Languages Type Systems Dispatch • link method call to method 45
  • 90. static vs. dynamic dispatch Imperative and Object-Oriented Languages Type Systems Dispatch • link method call to method Static dispatch • type information at compile-time 45
  • 91. 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 45
  • 92. 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; } } 46 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);
  • 93. 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 G { public B m(B b) { System.out.println("H.m(B b)"); return b; } } 47 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);
  • 94. Imperative and Object-Oriented Languages 48 Except where otherwise noted, this work is licensed under
  • 95. 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 49