Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For the rest of the questions, we will use the following programming language. Let s call it PL 3 0 5 . PL 3 0

For the rest of the questions, we will use the following programming language. Lets call it PL305. PL305 has the following syntax for the declaration and call of the procedures:
####################################################
# This is how we write a line comment.
def foo1(): #This line assigns the value of the parameter z to the variable y.Whatever integer foo2 is called with, y will hold that value,
int x # this is how we declare a variable (no initialization possible)
def foo2(z): # Here, within the body of foo1, we define a nested procedure called foo2 that takes one parameter, z. Procedures or functions within other functions are often used for encapsulation or to create closures.
int y #Within the body of foo2, this declares another integer variable named y.
y = z # his line assigns the value of the parameter z to the variable y. Whatever integer foo2 is called with, y will hold that value.
print(y) # we can print the value of a variable
end foo2 # end of foo2
x =1 # assign 1 to the variable x
call foo2(x) # The foo1 procedure then calls foo2, passing x as an argument. Since x is 1, foo2 will print 1.
end foo1 # end of foo1
Question 3)Suppose that you just started to learn PL305 and you would like to find out whether the dynamic scoping or the lexical scoping is used in PL305. To find this out, you design the following PL305 program:
####################################################
def foo1():
......... # LINE 1
def foo2(): # foo2 is defined in foo1
........... # LINE 2
........... # LINE 3
call foo3() # foo2 calls foo3
end foo2
def foo3(): # foo3 is also defined in foo1
........... # LINE 4
end foo3
............. # LINE 5
call foo2() # foo1 calls foo2
print(x) # this print will tell
end foo1
####################################################
Complete the dotted lines (i.e. LINE 1, LINE 2, LINE 3, LINE 4, LINE 5 above) in such a way that, when foo1 is called, the print statement at the end of foo1 prints 1 if PL305 uses dynamic scoping, and it prints 2 if PL305 uses lexical scoping.

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

Records And Database Management

Authors: Jeffrey R Stewart Ed D, Judith S Greene, Judith A Hickey

4th Edition

0070614741, 9780070614741

More Books

Students also viewed these Databases questions

Question

Describe the financing synergies of M&A.

Answered: 1 week ago