Consider the following pseudocode Xinteger procedure set x(n global integer) Xin procedure print x write integer(x)...
x: integer -- global procedure second x: integer --local x:= 2 second --main program x:= 0 first write_integer (x) //What does this program print if the language uses static scoping? //What does it print if the language uses dynamic scoping?
Consider the following pseudocode which uses dynamic scoping. What does the program print if the language uses shallow binding? What does it print with deep binding? x: integer//global procedure print_x write_integer (x) procedure first x:= x * 3 procedure second (F: procedure) x: integer x: = 5 F () print_x () x: = 7 second (first) print_x ()
Given the following Ada program: procedure Main is X, Y: Integer; procedure Sub1 is Y, Z: Integer; begin -- of Sub1 point 1 Sub2; end; -- of Sub1 procedure Sub2 is X: Integer; procedure sub3 (B: Integer) is W: Integer; begin -- of Sub3 point 2 end; -- of Sub3 begin -- of Sub2 point 3 Sub3 (X); end; -- of Sub2 begin -- of Main point 4 Sub1; end; -- of Main For each of the four marked points,...
Consider the following code: int a:=10 //global int b:=12 //global proc F a:= a-b proc P (M:proc) int a:=2 M() proc K int b:=3 P(F) K() //main program print(a) //built in function a- what does this code print if it uses dynamic scoping and deep binding? b- what does this code print if it uses dynamic scoping and shallow binding?
Will rate, thank you. Consider the following pseudocode, assuming nested subroutines, lexical scope, and that local variables (including formal parameters) are stored in the stack. procedure main() g: integer procedure B(a: integer) x: integer procedure A(n: integer) g := n procedure R(m: integer) write_integer (x) x := x/2 -- integer division if x > 1 R(m + 1) else A (m) --body of B x := a * a R(1) --body of main B(3) write_integer(g) (a) What does this program...
Consider the following pseudocode. int a = 9; //global variable void go {a = a +2; print a; } main { int a = 4; 80: a = a +1; print a; } a. What is printed out if we are using static scope rules? Show runtime stack. b. What is printed out if we are using dynamic scope rules? Show calling tree.
Consider the following program written in C syntax int a , b , c ; // first declaration void g() { print(a,b,c); } int f(int a) // parameter declaration { int b; // second declaration b = a + 1; g(); // first call { int a; // third declaration int c; // fourth declaration c = b; a = b + c; g(); // second call } g(); // third call return a + b ; } int main()...
2. Consider the following programs (using C's syntax): #include <stdio.h> int a- 1, b-2; int foo (int x) 1 return (x+a); void ba r () { printf("%d, %d\n",a,b); void foobar) } printf("%d, %d\n", a, b) ; int a -4; bar bfoo (b); bar int main)( int b 8; foobar printf ("%d, %d\n", a, b) ; return 0; (a) What does the program print under static scoping? (b) What does the program print under dynamic scoping?
3- (3 pts) Consider the following Pascal program skeleton program main var a, b, c: integer; procedure Sl; var x, b, c: integer procedure S2; var n, m, k: integer; end; end; procedure S3; var x, a, l: integer; end; end; List all of the variables, along with the program units where they are declared, that are visible in the bodies of S1, S2, and S3, assuming static scoping.
12. 10 points) Use pseudocode to write out algorithms for the following problems. (a) Assume n is any integer with n 2 7. Write out an algorithm SumofCertainIntenger in pseudocode that uses n as input variable. Use a "for" loop to compute the sum (Gk +4) (b) Assume m is any integer with m 2 5. Write out an algorithm ProductOfCertainInte- gers in pseudocode that uses m as input variable. Use a "while" loop to compute the product IT (é+4)....