Deep binding binds the environment at the time a procedure is passed as an argument.
Shallow binding binds the environment at the time a procedure is actually called.
When deep binding;
Sequence of execution is
So 5,21 will be printed
When shallow binding
Sequence of execution is
So 15,7 will be printed
Consider the following pseudocode which uses dynamic scoping. What does the program print if the language...
Consider the following pseudocode Xinteger procedure set x(n global integer) Xin procedure print x write integer(x) procedure first set x(1) print x procedure second xinteger set x(2) print x set x(e) first() print x second print x What does this program print if the language uses static scoping? What does it print with dynamic scoping? Why?
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?
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?
Question 7 (1 point) Suppose the program below outputs 10 30. The language uses int vari int var2 = 10 40 def bar() : print varl var2 def foo (f): int var2 = 30 f() def qux(): int varl = 20 foo (bar) # execution starts here qux () # execution starts here qux ( ) dynamic scoping with shallow binding lexical scoping dynamic scoping with deep binding None of these options
Which of the following are the two ways dynamic scoping can be implemented? (May contain more than one possible answer) A.) Shallow access B.) Shallow binding C.) Deep access D.) Deep binding
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()...
For the given program determine what is printed after each write statement assuming static scoping, deep binding and parameters are passed-by-value-result. program main; var X: integer; procedure Q(var I: integer; function R(J: integer):integer); var X: integer; begin X:=4; write(“In Q, before call of R, I=”, I, “X=”, X); I=R(I); write(“In Q, after call of R, I=”, I, “X=”, X); end; procedure P; var I: integer; ...
1. Which of the following is a problem with dynamic scoping? Readability Access to nonlocal variables takes longer Static type checking may not be possible 2.Languages with dynamic type binding are usually implemented using: Compilers Interpreters Hybrid implementations JIT 3.Which variables are created using operator new? Static Stack-dynamic Explicit heap-dynamic Implicit heap-dynamic 4.Which variables are bound to memory cells before program execution and remain bound to the same memory cell during program execution? Static Stack-dynamic Explicit heap-dynamic Implicit heap-dynamic
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 JavaScript skeletal program: //the main program var x: function sub1 () { var x: function sub2 () { } } function sub3 () { } Assume the execution of this program is in the following unit order: main calls sub1 sub1 calls sub2 sub2 calls sub3 a. Assuming static scoping, which declaration of x is the correct one for a reference to x in: i. sub1 ii. sub2 iii. sub3 b. Repeat part a, but assume dynamic...