Non Local Names
Non Local Names
Names
1
Scope :
Scope is the textual region of a
program in which a binding is
active.
Programming languages implement
3
Closely Nested Rule
1.The scope of a declaration in a block B
includes B.
2.If a name x is not declared in a block
B,then an occurrence of x in B is in the
scope of a declaration of x in an
enclosing block B1 such that
iii.B1 has a declaration of x
iv.B1 is more closely nested around B
than any other block with a
declaration of x.
4
Non Local Names
5
Non-local names in
PASCAL
procedure A
real a;
procedure B
real b;
reference a; ->non local
name
end B
end A;
6
main () {
int a = 0, b=0; {
int b = 1; {
B2 int a = 2;
print(a,b); } 2, 1
B0 B1 {
B3 int b = 3;
print(a,b); } 0, 3
0, 1
print(a,b);}
print(a,b); } 0, 0
7
Block-level and Procedure-
level ARs
1. Each block can be considered as an in-line
procedure without parameters. So we could
create a new AR for each block. This is block-
level AR and is very inefficient.
2. In procedure-level AR method, AR is only
used for a true procedure. The relative
location of variables in individual blocks
within a procedure can be computed and
fixed at compile time.
a0
b0
b1
a2 ,
Storage for
names b1
8
Lexical scope without nested procedures
(1)int a[11];
(2)readarray() {….a….}
(3)int partition(y,z) int y,z; {….
a….}
(4)quicksort(m,n) int m,n; {…..}
(5)main() {….a….}
9
Lexical scope with nested procedures