1 Using the C programming language indicate the binding time

1. Using the C++ programming language, indicate the binding time (language design, language implementation, compilation, program writing time, link, run, etc.) for each of the following attributes. Justify your answer.

a. The variable declaration that corresponds to a certain variable reference (use)

b. The range of possible values for integer numbers

c. The meaning of char

d. The address of a local variable

e. The address of a library function

f. The referencing environment of a function passed as a parameter

g. The total amount of memory needed by the data in a program

2. Can a language that uses dynamic scoping do type checking at compile time? Why? Can a language that uses static scoping do type checking at run time? Why?

3. Does Scheme use static or dynamic scoping? Write a short Scheme program that proves your answer.

4. Consider the following pseudo-code:

x : integer; -- global

procedure set_x (n : integer)

            x := n;

procedure print_x

           write_integer (x);

procedure foo (S, P : procedure; n : integer)

           x : integer;

           if n in {1,3}

                  set_x(n);

           else

                  S(n);

           if n in {1,2}

                 print_x;

           else

                 P;

-- main program

set_x(0); foo (set_x, print_x, 1); print_x;

set_x(0); foo (set_x, print_x, 2); print_x;

set_x(0); foo (set_x, print_x, 3); print_x;

set_x(0); foo (set_x, print_x, 4); print_x;

Assume that the language uses dynamic scoping. What does this program print if the language uses shallow binding? Why? What does it print with deep binding? Why? Note: At exactly one point during execution in the deep binding case, the program will attempt to print an uninitialized variable. Simply write a “?” for the value printed at that point.

Solution

Binding time in C++ programming language:

a) The variable declaration that corresponds to a certain variable reference (use)

The declaration of variables is done at compile time. The names are assigned with the type and name at the time of program compilation.

b) The range of possible values for integer numbers

The range of integers that the C++ language are language is implementation time binding. The range that the C++ handles is predefined and fixed.

c)The meaning of char

The meaning of char is a design time binding. The meaning of the key words will be fixed at the time of designing the language.

d) The address of a local variable

The address of a local variable is a run time binding. The address to the local variables is assigned at run time.

e) The address of a library function

The address of a library function is a run time binding. The library functions will be stored in the memory at the run time.

f) The referencing environment of a function passed as a parameter

The referring environment of a function passed as a parameter is a run time binding.

g) The total amount of memory needed by the data in a program

The total amount of memory needed by the data in a program is a run time binding. While running the program, if the object is created, memory will be allocated.

1. Using the C++ programming language, indicate the binding time (language design, language implementation, compilation, program writing time, link, run, etc.)
1. Using the C++ programming language, indicate the binding time (language design, language implementation, compilation, program writing time, link, run, etc.)

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site