General Concepts of Error Recovery
What is the primary purpose of error recovery strategies in compilers?
A) To correct syntax errors automatically
B) To allow the compiler to continue processing after detecting an error
C) To detect semantic errors
D) To optimize code
Answer: B) To allow the compiler to continue processing after detecting an error
Which of the following is NOT a common error recovery strategy in compilers?
A) Panic mode
B) Phrase level
C) Backtracking
D) Syntax-directed translation
Answer: D) Syntax-directed translation
Which of the following is an error recovery strategy that attempts to delete a portion of input until a synchronizing token is found?
A) Panic mode recovery
B) Phrase level recovery
C) Global correction
D) Error reporting
Answer: A) Panic mode recovery
What is the main advantage of panic mode error recovery?
A) It provides meaningful error messages
B) It is simple and guarantees that the parser will not get stuck
C) It corrects all syntax errors
D) It produces the most optimal parse tree
Answer: B) It is simple and guarantees that the parser will not get stuck
Which error recovery strategy involves making local corrections to the program at the point of the error?
A) Phrase level recovery
B) Panic mode recovery
C) Backpatching
D) Intermediate code generation
Answer: A) Phrase level recovery
In phrase level recovery, the parser:
A) Makes immediate corrections to allow parsing to continue
B) Stops parsing after an error is found
C) Skips the remainder of the line after an error
D) Ignores all input until a synchronizing token is found
Answer: A) Makes immediate corrections to allow parsing to continue
What is a drawback of phrase level recovery?
A) It can result in multiple errors being detected
B) It may result in an infinite loop
C) The parser may fail to recover properly, causing additional errors
D) It requires a lot of memory
Answer: C) The parser may fail to recover properly, causing additional errors
Which of the following is an error recovery strategy that makes the least number of changes to the source program?
A) Global correction
B) Panic mode
C) Backpatching
D) Incremental recovery
Answer: A) Global correction
In panic mode recovery, the parser attempts to recover by:
A) Removing erroneous tokens until a synchronizing token is found
B) Correcting the source program locally
C) Reversing the sequence of operations
D) Optimizing the code to prevent future errors
Answer: A) Removing erroneous tokens until a synchronizing token is found
Which of the following is typically used as a synchronizing token in panic mode recovery?
A) Delimiters such as semicolons
B) Variables
C) Function calls
D) Pointers
Answer: A) Delimiters such as semicolons
Panic Mode Error Recovery
In panic mode error recovery, how does the parser synchronize?
A) By deleting input symbols until a predefined set of synchronizing tokens is found
B) By restarting the parser from the beginning of the program
C) By entering an infinite loop
D) By skipping the remaining input
Answer: A) By deleting input symbols until a predefined set of synchronizing tokens is found
What is a significant advantage of panic mode error recovery?
A) The parser never gets stuck in an infinite loop
B) It provides accurate corrections for errors
C) It optimizes the generated code
D) It guarantees semantic correctness
Answer: A) The parser never gets stuck in an infinite loop
Panic mode recovery is most appropriate when:
A) The goal is to quickly resume parsing after an error
B) The goal is to correct every error accurately
C) The goal is to minimize memory usage
D) The goal is to detect semantic errors
Answer: A) The goal is to quickly resume parsing after an error
Which of the following errors is most easily handled by panic mode error recovery?
A) A missing semicolon
B) A mismatched data type
C) A semantic error
D) A logic error
Answer: A) A missing semicolon
One limitation of panic mode error recovery is:
A) It may cause the parser to skip over large portions of the input
B) It provides detailed error reports
C) It can only detect lexical errors
D) It uses excessive memory
Answer: A) It may cause the parser to skip over large portions of the input
Phrase Level Error Recovery
Which of the following describes phrase level recovery?
A) Making local corrections to the code at the point of error detection
B) Discarding input until a synchronizing token is found
C) Exiting the program immediately upon error detection
D) Optimizing the source code before error checking
Answer: A) Making local corrections to the code at the point of error detection
Phrase level error recovery is often used in:
A) Syntax analysis
B) Semantic analysis
C) Lexical analysis
D) Code generation
Answer: A) Syntax analysis
What is a common technique used in phrase level recovery?
A) Inserting or deleting symbols to allow parsing to continue
B) Skipping all remaining input
C) Entering an infinite loop until the error is resolved
D) Removing all errors before continuing
Answer: A) Inserting or deleting symbols to allow parsing to continue
One drawback of phrase level error recovery is:
A) It can introduce new errors during recovery
B) It requires a lot of memory
C) It is difficult to implement
D) It optimizes code prematurely
Answer: A) It can introduce new errors during recovery
Which of the following recovery strategies is likely to introduce the fewest changes to the source code?
A) Phrase level recovery
B) Panic mode recovery
C) Global correction
D) Incremental recovery
Answer: C) Global correction
Global Correction
Global correction attempts to:
A) Make the minimum number of changes necessary to fix the source code
B) Skip large portions of the input after an error
C) Enter a debugging mode upon error detection
D) Provide suggestions for fixing runtime errors
Answer: A) Make the minimum number of changes necessary to fix the source code
Which of the following is a limitation of global correction as an error recovery strategy?
A) It can be computationally expensive
B) It fails to correct semantic errors
C) It requires no memory
D) It cannot handle lexical errors
Answer: A) It can be computationally expensive
Global correction is most effective in handling:
A) Syntax errors
B) Lexical errors
C) Runtime errors
D) Logical errors
Answer: A) Syntax errors
Global correction typically requires:
A) Finding an optimal sequence of changes to fix the input
B) Skipping input symbols until a delimiter is found
C) Providing a set of predefined fixes for common errors
D) No changes to the input
Answer: A) Finding an optimal sequence of changes to fix the input
A major disadvantage of global correction is that:
A) It can be time-consuming to compute the best correction
B) It skips large portions of the input, leading to missed errors
C) It causes infinite loops in the parser
D) It fails to detect syntactic errors
Answer: A) It can be time-consuming to compute the best correction
Error Productions
Error productions in grammar are used to:
A) Define how the parser should handle certain common errors
B) Skip all errors in the input
C) Detect lexical errors in a program
D) Report semantic errors
Answer: A) Define how the parser should handle certain common errors
Which of the following error recovery strategies can use error productions?
A) Syntax-directed error recovery
B) Panic mode error recovery
C) Global correction
D) Semantic analysis
Answer: A) Syntax-directed error recovery
Error productions are most useful for:
A) Handling predictable and common errors in input
B) Skipping large portions of the input after an error
C) Correcting semantic mistakes
D) Code optimization
Answer: A) Handling predictable and common errors in input