Symbol Table Management MCQs

1. What is the primary purpose of a symbol table in a compiler?

A) To store syntax tree nodes B) To store variables and their attributes C) To perform semantic analysis D) To optimize the code Answer: B) To store variables and their attributes

2. Which of the following is typically stored in a symbol table?

A) Function calls B) Tokens and keywords C) Variable names and their data types D) Code generation instructions Answer: C) Variable names and their data types

3. What does a symbol table entry typically contain?

A) The source code of the program B) The variable’s name and its type, scope, and memory location C) The address of the code that uses the variable D) A list of all keywords used in the program Answer: B) The variable’s name and its type, scope, and memory location

4. When is a symbol table created during the compilation process?

A) During lexical analysis B) During syntax analysis C) During semantic analysis D) During code generation Answer: C) During semantic analysis

5. Which of the following operations is NOT performed by the symbol table manager?

A) Insertion of new symbols B) Lookup of symbol information C) Deletion of used symbols D) Parsing of source code Answer: D) Parsing of source code

6. What happens when a symbol with the same name is declared in a different scope?

A) The new symbol overwrites the previous one B) The compiler throws a syntax error C) The new symbol is ignored D) A new entry is added for the new scope Answer: D) A new entry is added for the new scope

7. Which of the following is true about the scope of a symbol in a symbol table?

A) A symbol’s scope determines its visibility throughout the program B) A symbol’s scope is determined by its data type C) A symbol’s scope is independent of its declaration D) Symbols in the same scope must have unique names Answer: A) A symbol’s scope determines its visibility throughout the program

8. What is one way to manage nested scopes in a symbol table?

A) Use a linked list to store symbols in different scopes B) Use a single array to store all symbols C) Use a stack to push and pop symbols as scope changes D) Use a queue to store the symbols Answer: C) Use a stack to push and pop symbols as scope changes

9. How does the symbol table help in type checking?

A) It stores the types of variables, which can be checked against each other during semantic analysis B) It automatically corrects type errors C) It stores the source code with type annotations D) It performs type inference during compilation Answer: A) It stores the types of variables, which can be checked against each other during semantic analysis

10. Which of the following is NOT typically a component of a symbol table entry?

A) The symbol’s name B) The symbol’s type C) The memory location of the symbol D) The symbol’s value at runtime Answer: D) The symbol’s value at runtime

11. What is a hash table commonly used for in a symbol table?

A) To optimize memory allocation B) To speed up the lookup of symbols C) To store the symbol’s data D) To maintain the order of symbol declarations Answer: B) To speed up the lookup of symbols

12. How is the scope of a variable typically determined in a symbol table?

A) By the block of code in which the variable is declared B) By the variable’s data type C) By the function in which the variable is used D) By the number of times the variable is referenced Answer: A) By the block of code in which the variable is declared

13. What is the role of the symbol table during the code generation phase?

A) To assist in syntax checking B) To provide information about variables, functions, and their locations for code generation C) To check for type errors D) To optimize the generated machine code Answer: B) To provide information about variables, functions, and their locations for code generation

14. In which phase of compilation is the symbol table most actively used?

A) Lexical analysis B) Syntax analysis C) Semantic analysis D) Code optimization Answer: C) Semantic analysis

15. What is the main advantage of using a symbol table in the context of code generation?

A) It reduces the size of the code B) It allows for faster execution of the program C) It provides essential information for generating correct and optimized code D) It helps in detecting runtime errors Answer: C) It provides essential information for generating correct and optimized code

Leave a Comment

All copyrights Reserved by MCQsAnswers.com - Powered By T4Tutorials