Question 1 Consider the following program in a dynamic-scoped language. void sub3() { int x, z; x = u + v;

Question 1 Consider the following program in a dynamic-scoped language. void sub3() { int x, z; x = u + v;


Assignment 8 Due Dec 6 Question 1 Consider the following program in a dynamic-scoped language. void sub3() { int x, z; x = u + v; . . . } void sub2() { int w, x; . . . } void sub1() { int v, w; . . . } void main() { int v, u; . . . } 1. Show the run-time stack during the execution of function sub3 after the following calling sequence (all the details must be included). main calls sub1 sub1 calls sub1 sub1 calls sub2 sub2 calls sub3 1 2. Consider the reference to variable u in function sub3. (a) Write the sequence of activation record instances that must be searched in order to find u. (b) How many dynamic links must be followed? 3. Consider the reference to variable v in function sub3. (a) Write the sequence of activation record instances that must be searched in order to find v. (b) How many dynamic links must be followed? 2 Question 2 Consider the following program in a static-scoped language. program P; bool a,b; procedure A; bool a; begin a := true; if a != b then B <-------- point="" 1="" end="" a;="" procedure="" b;="" begin="" if="" a="" then="" a=""><-------- point="" 2="" end="" b;="" begin="" a="" :="b" :="false;" a="" end="" p.="" 1.="" calculate="" the="" static="" depth="" of="" the="" following="" subprograms:="" p="" a="" b="" 2.="" calculate="" chain="" offset="" of="" the="" following="" variables:="" (a)="" variable="" a="" at="" point="" 1="" (b)="" variable="" b="" at="" point="" 1="" (c)="" variable="" a="" at="" point="" 2="" 3.="" show="" the="" run-time="" stack="" during="" the="" execution="" of="" b="" (all="" the="" details="" must="" be="" included).="" 3="" assignment="" 8="" due="" dec="" 6="" question="" 1="" consider="" the="" following="" program="" in="" a="" dynamic-scoped="" language.="" void="" sub3()="" {="" int="" x,="" z;="" x="u" +="" v;="" .="" .="" .="" }="" void="" sub2()="" {="" int="" w,="" x;="" .="" .="" .="" }="" void="" sub1()="" {="" int="" v,="" w;="" .="" .="" .="" }="" void="" main()="" {="" int="" v,="" u;="" .="" .="" .="" }="" 1.="" show="" the="" run-time="" stack="" during="" the="" execution="" of="" function="" sub3="" after="" the="" following="" calling="" sequence="" (all="" the="" details="" must="" be="" included).="" main="" calls="" sub1="" sub1="" calls="" sub1="" sub1="" calls="" sub2="" sub2="" calls="" sub3="" 1="" 2.="" consider="" the="" reference="" to="" variable="" u="" in="" function="" sub3.="" (a)="" write="" the="" sequence="" of="" activation="" record="" instances="" that="" must="" be="" searched="" in="" order="" to="" find="" u.="" (b)="" how="" many="" dynamic="" links="" must="" be="" followed?="" 3.="" consider="" the="" reference="" to="" variable="" v="" in="" function="" sub3.="" (a)="" write="" the="" sequence="" of="" activation="" record="" instances="" that="" must="" be="" searched="" in="" order="" to="" find="" v.="" (b)="" how="" many="" dynamic="" links="" must="" be="" followed?="" 2="" question="" 2="" consider="" the="" following="" program="" in="" a="" static-scoped="" language.="" program="" p;="" bool="" a,b;="" procedure="" a;="" bool="" a;="" begin="" a="" :="true;" if="" a="" !="b" then="" b=""><-------- point="" 1="" end="" a;="" procedure="" b;="" begin="" if="" a="" then="" a=""><-------- point 2 end b; begin a := b := false; a end p. 1. calculate the static depth of the following subprograms: p a b 2. calculate chain offset of the following variables: (a) variable a at point 1 (b) variable b at point 1 (c) variable a at point 2 3. show the run-time stack during the execution of b (all the details must be included). 3 point="" 2="" end="" b;="" begin="" a="" :="b" :="false;" a="" end="" p.="" 1.="" calculate="" the="" static="" depth="" of="" the="" following="" subprograms:="" p="" a="" b="" 2.="" calculate="" chain="" offset="" of="" the="" following="" variables:="" (a)="" variable="" a="" at="" point="" 1="" (b)="" variable="" b="" at="" point="" 1="" (c)="" variable="" a="" at="" point="" 2="" 3.="" show="" the="" run-time="" stack="" during="" the="" execution="" of="" b="" (all="" the="" details="" must="" be="" included).="">
May 18, 2022
SOLUTION.PDF

Get Answer To This Question

Submit New Assignment

Copy and Paste Your Assignment Here