Professional Documents
Culture Documents
declarative statements
imperative statements
- static scoping:
Syntax
- the syntax was greatly improved when compared with that of
the first generation languages
pass by value
pass by name
x = 5;
Sub(ref y : Y)
CALL BY RESULT
- used in ADA to implement out mode parameters
- formal paramater acts as an un-initialised local variable
which is given a value during the execution of the procedure
- on leaving the procedure, the value of the formal parameter is
assigned to the actual parameter which must be a variable
Read_Negative(amount);
Update(currentaccount);
a:begin integer m;
procedure P;
m := 1;
b:begin integer m;
P; -> call 1;
end;
P; -> call 2;
end
Static Scoping Example
m (a)
P
SL DL (b)
m Call P - call one
SL DL (P)
m := 1
m (a)
P Call P - call two
SL DL (P)
m := 1
m (a)
P
m (b)
Call P - call one
SL DL
P
m := 1
pointer-variable =
Address-of(variable-name)
pointer-variable =
Address-of(function-name)
Pointers
<Dereference(pointer-variable)>
memory allocated
A := B
but not accessible
B
Example of a Dangling Pointer
memory allocated
but not accessible
B
memory allocated
delete A
but not accessible
B
memory
deallocated
Pointers vs References
6
Pointer Pointer Variable
Variable 12
Variable
function2
Reference
Reference Variable
Constant M
Variable
Pointers vs References
10
Pointer
Pointer Variable
Variable 20
Variable
Reference function1
Reference Variable
Constant H
Variable
Strong and Weak Typing
R1 | R2 | R3 | X | Y | Z Register Store
Sub 1
Sub 2
Sub 3
Sub 4
Sub 5 Sub 1
AR #1
Dynamic Chain - Example
Sub 1
Sub 2
Sub 3
Sub 4
Sub 2
AR #2
Sub 5 Sub 1
AR #1
Dynamic Chain - Example
Sub 1
Sub 2
Sub 3 Sub 3
AR #3
Sub 4
Sub 2
AR #2
Sub 5 Sub 1
AR #1
Dynamic Chain - Example
Sub 1
Sub 2
Sub 4
AR #4
Sub 3 Sub 3
AR #3
Sub 4
Sub 2
AR #2
Sub 5 Sub 1
AR #1
Dynamic Chain - Example
Sub 1
Sub 4
Sub 2 AR #5
Sub 4
AR #4
Sub 3 Sub 3
AR #3
Sub 4
Sub 2
AR #2
Sub 5 Sub 1
AR #1
Dynamic Chain - Example
Sub 2
Sub 1 AR #6
Sub 4
Sub 2 AR #5
Sub 4
AR #4
Sub 3 Sub 3
AR #3
Sub 4
Sub 2
AR #2
Sub 5 Sub 1
AR #1
Static Chain - Example
Sub 1 [0]
Sub 2 [1]
Sub 3 [1]
Sub 4 [2]
Sub 1 [0]
Sub 2 [1]
Sub 1 [0]
Sub 2 [1]
Sub 1 [0]
Sub 2 [1]
Sub 4 @ 2 Sub 4 [2]
AR #4
Sub 3 [1] Sub 3 @ 1 Sub 3 [1]
AR #3
Sub 4 [2] Therefore
assign this Sub 2 [1]
AR to the AR #2
Sub 5 [2] static link Sub 1 [0]
AR #1
Static Chain - Example
Sub 1 [0]
Sub 4 @ 2 Sub 4 [2]
Sub 2 [1] AR #5
Sub 4 @ 2
Sub 4 [2]
Therefore AR #4
Sub 3 [1] assign same Sub 3 [1]
AR to this AR #3
Sub 4 [2] static link
Sub 2 [1]
AR #2
Sub 5 [2] Sub 1 [0]
AR #1
Static Chain - Example