Question: Consider the following pseudocode, assuming dynamic scoping rules: 1 procedure main ( ) { 2 x : int : = 2 3 y : int

Consider the following pseudocode, assuming dynamic scoping rules:
1 procedure main (){
2 x : int :=2
3 y : int :=4
4
5 procedure increment ( n : int ){
6 if n >0{
7 x := x +10
8 y := y +5
9 increment ( n -1)
10}
11}
12
13 procedure decrement ( n : int ){
14 if n >0{
15 x := x -5
16 y := y -2
17 decrement ( n -1)
18}
19}
20
21 procedure two (){
22 y : int :=3
23 one ( decrement , increment ,2)
24}
25
26 procedure one ( f1 : procedure , f2 : procedure , m : int ){
27 x : int :=10
28 f1( m )
29 f2( m )
30}
31
32 two ()
33 print ( x )
34 print ( y )
35}
1. If the language uses deep binding, what will the output be? Explain your answer.
2. If the language uses shallow binding, what will the output be? Explain your answer.

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 Programming Questions!