Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the following pseudocode: x: integer - - global procedure set _ x ( n: integer ) x: = n procedure print _ x (

Consider the following pseudocode:
x: integer -- global
procedure set_x(n: integer)
x:= n
procedure print_x()
write_integer(x)
procedure first(n: integer)
set_x(1)
x:= n
print_x()
procedure second()
x: integer
set_x(2)
first(x)
print_x()
set_x(0)
first(x)
print_x()
second()
print_x()
What does this program print if the language uses static scoping? What does it print with dynamic scoping? Explain why.
Answer:
---------------------------------------------------------
5.(2 marks) Consider the following code written in a language that implements nested subroutines and static scoping rules:
procedure main()
a : integer :=5
b: integer :=10
procedure middle()
a: integer := b -1
b: integer :=1
a := a + b
print a, b
procedure inner()
b: integer := a -1
middle()
print a, b
--body of main
inner()
print a, b
What does the program print (or will the compiler identify static semantic errors) if we assume that names can be declared in any order and their scope is the entire block in which they are declared?
Answer:
----------------------------------------------------------------------------------------
3.(5 marks) Consider the following grammar given in BNF notation:
::=
::= a
: a | b | b
::= c b | b
Which of the following sentences are in the language generated by this grammar? For sentences in the language, draw the corresponding parse tree. Otherwise, explain why the sentence cannot be generated using the rules of the grammar.
Is the grammar LL(1)? Explain why or why not.
a) baba
b) abab
c) cbaba
d) bbbcba
Answer:
----------------------------------------------------------------------------------
Consider the following program written in generic pseudocode:
int h =1;
int a[4]={-4,-6,0,-3};
void foo(int u, int v){
v = u;
h =0;
a[1]= a[h];
h =2;
u =0;
print u;
print v;
print h;
}
int main(){
int h =3;
foo(a[3], a[h]);
print h;
print a[0];
print a[1];
print a[2];
print a[3];
}
What is the output produced by the above program if we assume call by name as the underlying mechanism for passing parameters. Explain your answer.
Answer:

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

More Books

Students also viewed these Databases questions

Question

=+ Do you see any potential problems with the analysis?

Answered: 1 week ago

Question

Will it ever be executed?

Answered: 1 week ago

Question

Does it make clear how measurements are defined?

Answered: 1 week ago

Question

How will your strategy receive approval?

Answered: 1 week ago