Machine-translated by Google. Questions are authored in English.
Top

Symbol Table Management Questions and Answers

21.

Arrange the actions taken when a compiler enters and leaves a nested block.
1. resolve uses within the block against the scope chain
2. create or push a new scope on entering the block
3. discard or pop the scope on leaving the block
4. install the declarations found in the block into that scope

Answer: C

Correct answer: 2 - 4 - 1 - 3

The scope must exist before anything can be installed in it, and the declarations must be installed before uses can be resolved against them. Discarding comes last, when the block ends and its names go out of scope. Resolving before installing would fail on any name declared in the block itself.

Please log in or register to report this question.

Answer: D

Shadowing is temporary and lexical: the outer declaration becomes visible again on leaving the block. Overloading and aliasing are quite different relationships between names. Confusing the three is one of the commonest terminological errors in this area.

Please log in or register to report this question.

23.

State whether the following is true or false.
A name declared in an inner block permanently removes the outer declaration from the symbol table.

Answer: A

The outer entry is hidden rather than deleted, and becomes visible again when the inner block ends. A stacked or chained table implements this restoration naturally. Deleting the outer entry would make the enclosing code fail to compile.

Please log in or register to report this question.

Answer: B

Correct answer: the most recent binding in the call chain at run time

Dynamic scoping looks outward through the chain of active calls rather than outward through the enclosing text, so which declaration a name refers to depends on who called the procedure. It cannot be resolved at compile time, which is why static scoping is almost universal in modern languages.

Please log in or register to report this question.

25.

Assertion (A): A compiler for a statically scoped language can resolve every name at compile time.
Reason (R): Visibility depends only on the nesting of blocks in the program text, which the compiler can see in full.

Answer: C

Both are true and the reason gives the mechanism, and it explains why static scoping is universal. A dynamically scoped language would have to search a chain of bindings at run time, costing both speed and predictability.

Please log in or register to report this question.

Answer: D

The same spelling may be a struct tag and a variable simultaneously without conflict. The compiler keeps separate tables or tags each entry with the space it belongs to. Languages differ considerably in how many such spaces they define.

Please log in or register to report this question.

Answer: A

Overload resolution selects among the candidates using the argument types at the call. The symbol table must therefore be able to hold several entries under one name. A chain of candidates under one key is the usual arrangement.

Please log in or register to report this question.

Answer: B

Every visible candidate must be available so the best match can be chosen. Discarding all but one at declaration time would make correct resolution impossible. Some languages also permit the return type to participate in the choice.

Please log in or register to report this question.

Answer: C

Correct answer: appears in the text before the declaration of that name

A forward reference forces the compiler either to make two passes, or to record the use and patch it when the declaration arrives. Languages requiring declaration before use avoid the difficulty; those permitting mutual recursion between procedures must deal with it somehow.

Please log in or register to report this question.

Answer: D

Correct answer: the attributes of every name are known when the use is compiled

With the declaration guaranteed to have been seen already, the type, the scope and the storage are all in the symbol table when the use is compiled, so code and checks can be generated on the spot. Without that guarantee the compiler must defer, and a second pass or a patching mechanism becomes necessary.

Please log in or register to report this question.

Loading…

Other Subjects

Tags: Symbol Table Management Questions and Answers || Symbol Table Management MCQ Questions and Answers || Symbol Table Management GK Questions and Answers || Symbol Table Management GK MCQ Questions || Symbol Table Management Multiple Choice Questions and Answers || Symbol Table Management GK || GK on Symbol Table Management || Compiler Design Questions and Answers || Compiler Design MCQ Questions and Answers || Compiler Design GK Questions and Answers || GK on Compiler Design