Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

Assignment 3 CMSPC 461: Programming Language Concepts Prof. Suman Saha, Spring 2023 Due: 11:59 PM, 3rdMarch, 2023 Instructions: You need to submit your homework to Gradescope. Do every problem on...

1 answer below »
Assignment 3
CMSPC 461: Programming Language Concepts
Prof. Suman Saha, Spring 2023
Due: 11:59 PM, 3rdMarch, 2023
Instructions:
You need to submit your homework to Gradescope. Do every problem on a separate page and mark
them before submitting. If the questions are not marked or are submitted with inco
ect page-to-question
mapping, the question will not be graded. Make sure your name and PSU ID is legible on the first page of
your assignment. Add page numbers to your submission.
We highly recommend you follow the latex/doc template (which can be found on canvas) for the homework
submissions; however, if you are writing and scanning, make sure you maintain proper handwriting and use
stationary of high contrast.
**(Kindly refer syllabus for late submission and academic integration policies.)
Question 1 (4*5 = 20 pt)
Consider the following code and print the output if:
procedure took(int a, int b, int c)
start
a = b + c;
= c + 1;
print (a, b, c);
end
function main
start
int i = 5;
int j = 10;
ink k = 15;
took(i, j, j + k);
print (i, j, k);
end
1. All parameters are call by value (CBV)
2. Call a,b by reference, and c by value
3. Call a, b by value-result and c by value
4. All parameters are call by name.
1/7
Question 2 (4*5 = 20 pt)
Consider the following code and print the output if:
procedure
andybuck(int a, int b, int c)
start
:= b + 5;
:= a + c + 4;
print a, b, c;
end
procedure main
start
int j := 10;
ink k := 15;
andybuck(j, j, j + k);
print j, k;
end
1. All parameters are call by value (CBV)
2. Call a,b by reference, and c by value
3. Call a, b by value-result and c by value
4. All parameters are call by name.
2/7
Question 3 (8*2 = 16 points)
Answer the following with True or False with a short justification.
1. Maintenance of the su
outine call stack is the responsibility of the caller.
2. Modern machines typically pass su
outine parameters in stacks
3. Su
outine calling convention gives the caller the responsibility to save all the registers.
4. Parameter-passing in C is call-by-value as well as call-by-reference (when using pointers)
5. For calling sequence convention compiler uses callee-saves registers for local variables and caller-
saves registers for address.
6. It is the caller’s responsibility to maintain static chain during a su
outine call.
7. Pascal is call by value but can do call by reference with the help of the keyword ‘var’
8. For C++ function header “void f1(int p1, float& p2);” p1, is passed by reference and p2 is passed by
value.
3/7
Question 4 (12 points)
Consider the Ada program given below.
1 procedure Main is
2 A,B: Integer;
3 procedure Sub1(C: Integer) is
4 D:Intege
5 begin -- of Sub1
6 ....
7 end; -- of Sub1
8 procedure Sub2 (E:Integer) is
9 procedure Sub3 (F:Integer) is
10 B,D: Intege
11 begin -- of Sub3
12 Sub1(100);
13 end; -- of Sub3
14 begin -- of Sub2
15 Sub3(E);
16 end; -- of SUb2
17 begin -- of Main
18 Sub2(10);
19 end; -- of Main
Ada is a statically scoped language. In the above program, the Main function invokes Sub2; Sub2 invokes
Sub3; and Sub3 invokes Sub1. Draw the stack of activation records that shows the calling sequence when
the program’s execution reaches before line 12 and before line 6. For each activation record, include local
variables, parameters, the dynamic link, the static link, and the return address. Identify the caller and callee.
4/7
Question XXXXXXXXXXpoints)
Read about call-by-sharing from the textbook. (Section 9.3 or 8.3 depending on the edition.) Explain call-
y-sharing in your own words. How is different from call by value or call by reference (in terms of the
mechanics of these parameter passing modes and in terms of the degree to which the called function can
alter the contents of the caller’s variables)?
5/7
Question XXXXXXXXXX = 20 points)
Consider the following program from a made up language “gameG” that uses pass-by-name paramete
passing:
1 function exchange (a, b)
2 var t = a
3 start
4 a =
5 b = t
6 end
a) (6pt) What scoping (dynamic or static) should “gameG” use? Why? In whose environment (caller o
callee) who would we want the arguments to be evaluated?
) (7pt) A programmer wants to use the call exchange on existing variables s and t. Will they face any
problems when calling exchange(s,t), if yes, how to solve it?
c) (7pt) The same programmer tries to call exchange(i, o[i]), where o is an a
ay. Will that be a problem? If
yes, how to solve it? Will a call to exchange(o[i], i) have the same problem?
6/7
7/7
Answered Same Day Feb 28, 2023

Solution

Sumit Kumar answered on Mar 01 2023
34 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here