0% found this document useful (0 votes)
131 views12 pages

Non Local Names

Static scoping means that bindings are determined at compile time based on the textual structure of the program, while dynamic scoping means bindings are determined at runtime based on execution flow. Non-local names are identifiers that are neither local nor global variables, but are accessible from inner scopes due to static/lexical scoping rules. In languages with nested procedures and static scoping, variables can be accessed by procedures within the same block scope even if they are not passed as parameters.

Uploaded by

VinayKumarSingh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT or read online on Scribd
0% found this document useful (0 votes)
131 views12 pages

Non Local Names

Static scoping means that bindings are determined at compile time based on the textual structure of the program, while dynamic scoping means bindings are determined at runtime based on execution flow. Non-local names are identifiers that are neither local nor global variables, but are accessible from inner scopes due to static/lexical scoping rules. In languages with nested procedures and static scoping, variables can be accessed by procedures within the same block scope even if they are not passed as parameters.

Uploaded by

VinayKumarSingh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT or read online on Scribd
You are on page 1/ 12

Access To Non Local

Names

1
Scope :
Scope is the textual region of a
program in which a binding is
active.
 Programming languages implement

◦ Static Scoping: active bindings are


determined using the text of the
program at compile time.
Most recent scan of the program from top to
bottom
Closest nested subroutine rule

◦ Dynamic Scoping: active bindings are


determined by the flow of execution at
run time. 2
Egs:
Lexical scope
Pascal
C
Ada
Dynamic scope
Lisp
Snobol
APL

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

In a language with nested


procedures (or blocks) and static
scope (lexical scope), some names
are neither local nor global, they
are 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

 (1) program sort (input , output);


 (2) var a : array [0..10] of integer;
 (3) x : integer;
 (4) procedure readarray;
 (5) var I : integer;
 (6) begin …a…end{ readarray };
 (7) procedure exchange ( i , j : integer );
 (8) begin
 (9) x := a[ i ] ; a[ i ] := a[ j ]; a[
j ] := x
 (10) end { exchange };
10
 (11) procedure quicksort( m , n :
integer);
 (12) var k , v : integer;
 (13) function partition(y ,z :
integer):integer;
 (14) var i , j : integer;
 (15) begin …a …
 (16) …v …
 (17) …exchange( i , j ); …
 (18) end { partition };
 (19) begin … end { quicksort };
 (20) begin … end { sort }
11
12

You might also like