بنك اسئلة4

advertisement
1. A binding is a fixed association between an identifier and an entity such as a value,
variable, or procedure.
2. An environment or name space is a set of bindings.
3. The scope of a declaration (or of a binding) is the portion of the program text over
which it has effect.
4. In some early PLs (such as Cobol), the scope of each declaration is the whole
program.
5. In modern PLs, the scope of each declaration is controlled by the program’s block
structure.
6. What is the environment (set of bindings) at each numbered point in the following C
(or C++) program?
int n;
void zero () {
(1)
n = 0;
}
void inc (int d) {
(2)
(3)
n += d;
}
void main (int argc, char* argv) {
...
}
Answer:
(1) {
n an integer variable,
zero a procedure with no parameter }
(2) {
n an integer variable,
zero a procedure with no parameter,
inc a procedure with an integer parameter,
d an integer parameter }
(3) {
n an integer variable,
zero a procedure with no parameter,
inc a procedure with an integer parameter,
main a procedure with an integer parameter
and a pointer-to-character parameter,
argc an integer parameter,
argv a pointer-to-character parameter }
7. What is the environment (set of bindings) at each numbered point in the following
Ada program?
procedure p is
z: constant Integer := 0;
c: Character;
procedure q (x: in Float) is
c: constant Float := 3.0e6;
b: Boolean;
begin
…
end q;
(1)
begin
(2)
…
end p;
(1)
(2)
Answer:
{b  a Boolean variable,
c  the floating-point number 3.0106,
p  a procedure with no parameter,
q  a procedure with a Float parameter,
x  a Float variable,
z  the integer 0 }
{c  a Character variable,
p  a procedure with no parameter,
q  a procedure with a Float parameter,
z  the integer 0 }
Download