0% found this document useful (0 votes)
50 views5 pages

Develop Static Referencing Environments For The Following Programs

The document summarizes static referencing environments for different programming languages: 1. It shows the local, non-local, and global scopes for variables and procedures in two Pascal-like language programs. 2. It does the same for a C-like language program that includes nested blocks and procedures. 3. It presents a Pascal-like language program and identifies which nested procedure would be called for three different procedure calls.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views5 pages

Develop Static Referencing Environments For The Following Programs

The document summarizes static referencing environments for different programming languages: 1. It shows the local, non-local, and global scopes for variables and procedures in two Pascal-like language programs. 2. It does the same for a C-like language program that includes nested blocks and procedures. 3. It presents a Pascal-like language program and identifies which nested procedure would be called for three different procedure calls.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Develop static referencing environments for the following programs

Question 1. (Pascal-like language)

program main;
var A, B: real;
procedure Sub1 (Sub1,C: real);
var D: real;
procedure Sub2 (C: real);
var D: real;
begin
… C:= C+B; …
end;
begin
… Sub2(B); …
end;
begin
… Sub1(A); …
end.

Local Non-local Global


main Main, A, B, Sub1 Main, A, B, Sub1
Sub1 Sub1,C,D,Sub2 Main, A, B Main, A, B
Sub2 C,D Sub1 (Sub1),Sub2, Main, A, B,
Main, A, B
Question 2. (Pascal-like language)

program main;
var A, B: real;
procedure Sub1 (Sub1,C: real);
var D: real;
begin
… Sub2(B); …
end;
procedure Sub2 (Sub1: real);
var D: real;
begin
… C:= C+B; …
end;

begin
… Sub1(A); …
end.

Local Non-local Global


main Main,A,B,Sub1,Sub2 Main,A,B,Sub1,Sub2
Sub1 Sub1,C,D Main,A,B,Sub2 Main,A,B,Sub2
Sub2 Sub1, D Main,A,B, Sub2 Main,A,B, Sub2
Question 3 (C-like language)

Local Non-local Global


Main_program x, f, f2, main
f x f, f2, main
f2 x, f, f2, main
main X,i
Block 1 x,y I, f, f2, main
Block 2 X(main),i, f, f2, main
Block 3
Block 4 f X(main),i,f2, main

int x =1;

int f()
{
int x = 2;
cout << x;
}

int f2()
{
cout << x;
}

void main() {
int x = 3;
//int i;
//block 1
{
int x = 4;
cout << x;
int y;
}

//block 2

{
cout <<x;
cout << y;
while (...) //block 3
{
f();
cout << x;
}
}

int i;
for (i =1;i<=3;i++)
//block 4
{
//int i;
int f = 5;
f(); cout <<i;
cout << x;
}

}
Question 4.

program main;
var A, B, C: real;
procedure Sub ; //sub-1
var D: real;
procedure Sub; //sub-2
var D: real;
begin
… C:= C+B; …
... Sub; ... /*1*/
end;
begin
… Sub; … /*2*/
end;
begin
… Sub; … /*3*/
end.

Which Sub will be called?

/*1*/, /*2*/, /*3*/

Local Non-local Global


main Main, A,B,C,Sub (sub- Main, A,B,C,Sub (sub-
1) 1)
Sub (sub 1) D,Sub (sub-2) Main, A,B,C Main, A,B,C
Sub (sub 2) D Sub (sub-2), Main, Main, A,B,C,
A,B,C,

/*1*/ --> sub-2


/*2*/ --> sub-2
/*3*/--> sub-1

You might also like