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

1 answer below »
Please finish before the deadline


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 incorrect 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; b = 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 brandybuck(int a, int b, int c) start b := b + 5; b := a + c + 4; print a, b, c; end procedure main start int j := 10; ink k := 15; brandybuck(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 subroutine call stack is the responsibility of the caller. 2. Modern machines typically pass subroutine parameters in stacks 3. Subroutine 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 subroutine 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:Integer 5 begin -- of Sub1 6 .... 7 end; -- of Sub1 8 procedure Sub2 (E:Integer) is 9 procedure Sub3 (F:Integer) is 10 B,D: Integer 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 5 ( 12 points) Read about call-by-sharing from the textbook. (Section 9.3 or 8.3 depending on the edition.) Explain call- by-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 6 (6+7+7 = 20 points) Consider the following program from a made up language “gameG” that uses pass-by-name parameter passing: 1 function exchange (a, b) 2 var t = a 3 start 4 a = b 5 b = t 6 end a) (6pt) What scoping (dynamic or static) should “gameG” use? Why? In whose environment (caller or callee) who would we want the arguments to be evaluated? b) (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 array. 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 DayFeb 28, 2023

Answer To: Assignment 3CMSPC 461: Programming Language ConceptsProf. Suman Saha, Spring 2023Due: 11:59...

Sumit Kumar answered on Mar 01 2023
37 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