Answered step by step
Verified Expert Solution
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 setxn: integer
x: n
procedure printx
writeintegerx
procedure firstn: integer
setx
x: n
printx
procedure second
x: integer
setx
firstx
printx
setx
firstx
printx
second
printx
What does this program print if the language uses static scoping? What does it print with dynamic scoping? Explain why.
Answer:
marks Consider the following code written in a language that implements nested subroutines and static scoping rules:
procedure main
a : integer :
b: integer :
procedure middle
a: integer : b
b: integer :
a : a b
print a b
procedure inner
b: integer : a
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:
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 Explain why or why not.
a baba
b abab
c cbaba
d bbbcba
Answer:
Consider the following program written in generic pseudocode:
int h ;
int a;
void fooint u int v
v u;
h ;
a ah;
h ;
u ;
print u;
print v;
print h;
int main
int h ;
fooa ah;
print h;
print a;
print a;
print a;
print a;
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started