1. Which of the following is a common method used for error detection in a compiler?
A) Lexical analysis
B) Syntax analysis
C) Semantic analysis
D) All of the above
Answer: D) All of the above
2. What is the primary goal of error recovery in a compiler?
A) To terminate the compilation process when an error is detected
B) To correct the error in the source code automatically
C) To allow the compiler to continue processing the source code after detecting an error
D) To display detailed error messages to the programmer
Answer: C) To allow the compiler to continue processing the source code after detecting an error
3. Which of the following is an example of a panic mode error recovery strategy?
A) Skipping tokens until a synchronized point (such as a semicolon) is found
B) Automatically correcting minor syntax errors
C) Attempting to restore the program to a valid state
D) Providing suggestions for fixing the error
Answer: A) Skipping tokens until a synchronized point (such as a semicolon) is found
4. In panic mode recovery, what does the compiler do after skipping tokens to recover from an error?
A) Attempts to correct the error
B) Resumes parsing at a known synchronization point
C) Halts the compilation process
D) Tries to produce a more meaningful error message
Answer: B) Resumes parsing at a known synchronization point
5. Which of the following error detection mechanisms is used to handle syntax errors in a compiler?
A) Backtracking
B) Error productions
C) Panic mode recovery
D) All of the above
Answer: D) All of the above
6. Which of the following describes an error production mechanism in error recovery?
A) Using special grammar rules to detect and recover from errors
B) Skipping the erroneous token and continuing to parse the next one
C) Providing a list of potential corrections for the errors found
D) Making the compiler stop immediately when an error is detected
Answer: A) Using special grammar rules to detect and recover from errors
7. What is the main advantage of the panic mode recovery strategy?
A) It guarantees to fix errors automatically
B) It is simple to implement and allows the compiler to continue processing after encountering errors
C) It provides detailed feedback on the errors
D) It requires no error handling code
Answer: B) It is simple to implement and allows the compiler to continue processing after encountering errors
8. Which of the following strategies is used to recover from semantic errors?
A) Panic mode recovery
B) Backtracking
C) Error productions
D) No specific recovery strategy (semantic errors are usually reported and halted)
Answer: D) No specific recovery strategy (semantic errors are usually reported and halted)
9. What does backtracking involve in error recovery?
A) Skipping over erroneous tokens
B) Searching for another possible parse tree that might resolve the error
C) Continuing to parse from the next known synchronization point
D) Automatically correcting the errors and continuing the compilation
Answer: B) Searching for another possible parse tree that might resolve the error
10. Which of the following is the most common strategy for syntax error recovery in a compiler?
A) Panic mode recovery
B) Backtracking
C) Error productions
D) Syntax-directed translation
Answer: A) Panic mode recovery
11. What is the primary disadvantage of panic mode error recovery?
A) It can lead to the loss of important error information
B) It is computationally expensive
C) It causes the compiler to crash after detecting the first error
D) It cannot handle semantic errors
Answer: A) It can lead to the loss of important error information
12. Which of the following best describes global error recovery?
A) An error recovery technique that works by finding the best possible fix for the entire source code
B) A strategy that handles errors across multiple phases of compilation
C) A recovery method where the parser tries to repair multiple errors simultaneously
D) A mechanism that only focuses on local errors within a specific part of the program
Answer: B) A strategy that handles errors across multiple phases of compilation
13. What is the goal of error recovery in semantic analysis?
A) To produce correct intermediate code
B) To fix syntax errors automatically
C) To ensure that the source code adheres to the meaning and rules of the programming language
D) To optimize the code for better execution performance
Answer: C) To ensure that the source code adheres to the meaning and rules of the programming language
14. Which of the following error recovery techniques involves providing special grammar rules that can handle errors during parsing?
A) Panic mode recovery
B) Error productions
C) Backtracking
D) Error-directed parsing
Answer: B) Error productions
15. Which of the following is the most suitable recovery strategy when an error is detected in a complex program with no clear synchronization points?
A) Panic mode recovery
B) Backtracking
C) Error productions
D) Global error recovery
Answer: D) Global error recovery
16. Which phase of the compiler typically handles semantic errors and their detection?
A) Lexical analysis
B) Syntax analysis
C) Semantic analysis
D) Code generation
Answer: C) Semantic analysis
17. What is one disadvantage of backtracking as an error recovery mechanism?
A) It requires a large amount of memory and processing time
B) It can lead to an incorrect parse tree
C) It produces misleading error messages
D) It cannot recover from semantic errors
Answer: A) It requires a large amount of memory and processing time
18. What is the primary role of an error handler in a compiler?
A) To generate machine code
B) To detect errors in the code and recover from them
C) To optimize the program’s execution
D) To manage the compiler’s internal data structures
Answer: B) To detect errors in the code and recover from them
19. In which situation would error productions be most useful for error recovery?
A) When the syntax of the program is incorrect
B) When the program fails to meet semantic rules
C) When the compiler encounters runtime errors
D) When the program contains invalid variable declarations
Answer: A) When the syntax of the program is incorrect
20. Which of the following error recovery mechanisms helps a compiler continue parsing after encountering an error by skipping invalid tokens until it reaches a valid synchronization point?
A) Panic mode recovery
B) Backtracking
C) Error productions
D) Error-directed parsing
Answer: A) Panic mode recovery