Question: 5.Define what binding time is. List five different binding times and give an example of each. 6. Consider the following Java assignment statement with one
5.Define what binding time is. List five different
binding times and give an example of each.
6. Consider the following Java assignment statement with one
arithmetic operator:
x = y + 1.0;
For each component of the statement (e.g., variable, operators,
and constant), list the various bindings that are required to
determine the semantics (meaning) when the statement is
executed. For each binding, indicate the binding time used.
8.Java does not support a history sensitive variable in a
method. Explain how you can simulate or implement a history
sensitive variable in Java, and describe the advantages of
supporting a history sensitive variable as a built-in language
feature (e.g., in PHP).
9. There are several different approaches for determining
the type of a variable, including type inference (e.g., Haskell),
explicit type declarations (e.g., Java), and dynamic typing
(e.g., PHP). Compare type inference and the other two approaches
and describe its advantages and disadvantages.
10. Consider the following Java-like program that uses
static scoping.
void fun() { int a, b, c; /* definition 1 */
...
while (...) { int a, c, d; /* definition 2 */
... <------------------------- 1
while (...) { int d, e, f; /* definition 3 */
... <----------------------- 2
}
... <------------------------- 3
}
... <--------------------------- 4
}
For each of the four statements labeled 1-4 in this function, list
all visible variables along with the definition statements (1-3)
that define them.
11. Consider the following Java-like program:
void main() { int a, b, c;
...
}
void fun1() { int b, c, d;
...
}
void fun2() { int c, d, e;
...
}
void fun3() { int d, e, f;
...
}
Given the following calling sequences and assuming that dynamic
scoping is used, what variables are visible during execution of the
last function called? Include with each visible variable the name
of the function in which it was defined.
(a) main calls fun1; fun1 calls fun2; fun2 calls fun3.
(b) main calls fun1; fun1 calls fun3.
(c) main calls fun2; fun2 calls fun3; fun3 calls fun1.
(d) main calls fun3; fun3 calls fun1.
(e) main calls fun1; fun1 calls fun3; fun3 calls fun2.
(f) main calls fun3; fun3 calls fun2; fun2 calls fun1.
12. Write test programs in Java and PHP to determine
the scopes of variables declared in a "for" statement and a "do"
statement; include loop variables, e.g., x from "for (int x = 0;
...". Specifically, your code should tell whether such variables
are visible in the code following the body of the "for" or "do"
statement. Summarize your findings.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
