Question: Consider the following skeletal Ada program: procedure Main is X: Integer; procedure Sub3; -- This is a declaration of Sub3 -- It allows Sub1 to

 Consider the following skeletal Ada program: procedure Main is X: Integer;procedure Sub3; -- This is a declaration of Sub3 -- It allows

Consider the following skeletal Ada program: procedure Main is X: Integer; procedure Sub3; -- This is a declaration of Sub3 -- It allows Sub1 to call it procedure Sub1 is X : Integer; procedure Sub2 is begin -- of Sub2 end; -- of Sub2 begin -- of Sub1 end; -- of Sub1 procedure Sub3 is begin -- of Sub3 end; -- of Sub3 begin -- of main end; -- of main Assume that the execution of this program is in the following unit order: Main calls Sub1 Sub1 calls Sub2 Sub2 calls Sub3 Assuming static scoping in the following, which declaration of X is the correct one for a refer- ence to X in each of the following subprograms? [3 points] a. Sub1 (which declaration of X does Sub1 refer to?) b. Sub2 (which declaration of X does Sub2 refer to?) C. Sub3 (which declaration of X does Sub3 refer to?) Explain your answers. Repeat the above (a, b, c), but assume dynamic scoping. Consider the following skeletal Ada program: procedure Main is X: Integer; procedure Sub3; -- This is a declaration of Sub3 -- It allows Sub1 to call it procedure Sub1 is X : Integer; procedure Sub2 is begin -- of Sub2 end; -- of Sub2 begin -- of Sub1 end; -- of Sub1 procedure Sub3 is begin -- of Sub3 end; -- of Sub3 begin -- of main end; -- of main Assume that the execution of this program is in the following unit order: Main calls Sub1 Sub1 calls Sub2 Sub2 calls Sub3 Assuming static scoping in the following, which declaration of X is the correct one for a refer- ence to X in each of the following subprograms? [3 points] a. Sub1 (which declaration of X does Sub1 refer to?) b. Sub2 (which declaration of X does Sub2 refer to?) C. Sub3 (which declaration of X does Sub3 refer to?) Explain your answers. Repeat the above (a, b, c), but assume dynamic scoping

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!