6. (30%) Given the following Ada program: (a) For each of the four marked points
ID: 3907760 • Letter: 6
Question
6. (30%) Given the following Ada program: (a) For each of the four marked points, list each visible variable if the static scoping is used (b) Show the stack with all activation record instances, including static and dynamic chains, when execution reaches point 2 (c) What are the purposes of using static and dynamic links in activation records? procedure Main is X, Y: Integer, procedure Sub1 is Y, Z: Integer Sub2; procedure Sub2 is begin -of Sub1 K- point 1 d of Sub1 W: Integer, procedure Sub3(B: Integer) is A: Integer begin of Sub3 point 2 end; -- of Sub3 begin - of Sub2 point 3 Sub3(VW); dof Sub2 begin -of Main point 4 Sub1; end; --of MalnExplanation / Answer
a)at Point 1 X,Y of Main Procedure and Y,Z of Sub1 will be visible
at Point 2:X,Y of Main Procedure,W of Sub2,B and A of Sub3 will be visible.
at Point 3 X,Y of Main Procedure and W of Sub 2 will be Visible.
at Point 4:X,Y of Main Procedure will be visible.
Here the concept is like the variables declared in the Main procedure will be global to all the subprocedures defined inside Main Procedure.
b) Static chain can be represented as a tree pointing to the callee function in this case Main.
It will be from Main to SubProcedure while dynamic lnking will be from SubProcedure to Main.
Main->Sub1->Sub2->Sub3.
dynamic Linking involves while the program executes and it in this order
Call Stack
Sub3
Sub2
Sub1
Main
c)Static Links is used to know the overall structure of the program which can be determined during compilation time.
While Dynamic links is used to determine the calling sequence of a particular subprocedure from main or to trace back the execution steps.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.