Names, Bindings and Scopes: CSE 325/CSE 425: Concepts of Programming Language
Names, Bindings and Scopes: CSE 325/CSE 425: Concepts of Programming Language
function addSquares(a, b) {
function square(x) {
return x * x;
}
return square(a) + square(b);
}
a = addSquares(2, 3); // returns 13
b = addSquares(3, 4); // returns 25
c = addSquares(4, 5); // returns 41
print (a);
print (b);
print (c);
SCOPES
• We already know the scopes in C, Java!!!
• In Ada, the block structured language-
• A block is formed by a begin-end pair-
declare x: integer;
y: boolean;
begin
x := 2;
y := true;
z := x + 1;
….
end;
EXAMPLE (RUN IT)
with Ada.Text_IO; use Ada.Text_IO;
procedure Hello is
begin
declare x: integer;
y: boolean;
begin
x := 2;
y := true;
x := x + 1;
declare x: integer;
y: boolean;
begin
x := 3;
y := false;
x := x + 6;
end;
end;
end Hello;
C
PRO
GRA
M
IF ELSE (ADA)
SYMBOL TABLE(IMP)
SYMBOL TABLE(IMP)
SYMBOL TABLE(IMP)
SYMBOL TABLE(IMP)
$day = "Monday";
$Month = "January";
function calendar(){
$day = "Tuesday";
global $Month;
print "local day is $day <br />";
$gday = $GLOBALS['day'];
print "global day is $gday <br />";
print "global month is $Month <br />";
}
calendar();
?>
ALIASES
DANGLING
REFERENCES
A Dangling References
occurs if an object can be
accessed beyond its lifetime
in the environment.
THANKS