1. What is the primary goal of error detection in parsing?
A) To identify the lexical errors in the code
B) To detect syntax errors in the input code
C) To optimize the performance of the parser
D) To generate machine code from the parsed input
Answer: B) To detect syntax errors in the input code
2. Which of the following is a common method for error recovery in parsing?
A) Halting the parsing process on the first error
B) Ignoring the error and continuing parsing
C) Skipping the rest of the input
D) Inserting or deleting tokens to recover from errors
Answer: D) Inserting or deleting tokens to recover from errors
3. Which of the following strategies is used in top-down parsing for error recovery?
A) Panic mode recovery
B) Backtracking
C) Error productions in grammar rules
D) Predictive error handling
Answer: C) Error productions in grammar rules
4. In bottom-up parsing, which of the following is a common recovery method when encountering a syntax error?
A) Error rule expansion
B) Panic mode recovery
C) Backtracking
D) Adding extra tokens to the input stream
Answer: B) Panic mode recovery
5. Which of the following is true about panic mode error recovery?
A) It continues parsing from the last valid state
B) It skips input until a synchronizing token is found
C) It backtracks to the previous correct state
D) It tries to correct errors automatically
Answer: B) It skips input until a synchronizing token is found
6. Which of the following is a syntax error in a source program?
A) Missing semicolon at the end of a statement
B) Incorrect use of a variable
C) Mismatched parentheses
D) Division by zero
Answer: C) Mismatched parentheses
7. Which of the following error recovery techniques can be implemented in both top-down and bottom-up parsers?
A) Panic mode recovery
B) Backtracking
C) Lookahead parsing
D) Semantic error handling
Answer: A) Panic mode recovery
8. In top-down parsing, if an error occurs, the parser may use which of the following recovery methods?
A) Skipping symbols until a valid rule can be applied
B) Deleting the erroneous tokens from the input
C) Backtracking to the previous valid state
D) Switching to another parsing strategy
Answer: A) Skipping symbols until a valid rule can be applied
9. Which of the following is an advantage of error productions in grammar for error recovery?
A) It reduces the time complexity of parsing
B) It allows for immediate correction of errors
C) It enables parsing to continue despite syntax errors
D) It prevents the parser from encountering errors
Answer: C) It enables parsing to continue despite syntax errors
10. What is the key challenge in error recovery during parsing?
A) Finding a valid token after an error
B) Detecting semantic errors in the code
C) Reducing the number of grammar rules
D) Ensuring that the parser does not backtrack too much
Answer: A) Finding a valid token after an error
11. Which of the following is a technique where the parser discards input until a token is found that can continue parsing?
A) Panic mode
B) Error production
C) Backtracking
D) Lookahead
Answer: A) Panic mode
12. Which of the following recovery techniques involves inserting a missing token to fix a syntax error?
A) Panic mode recovery
B) Error productions
C) Token insertion
D) Backtracking
Answer: C) Token insertion
13. Which of the following is NOT typically a part of error recovery in parsers?
A) Error detection
B) Token insertion or deletion
C) Semantic error reporting
D) Syntax error recovery
Answer: C) Semantic error reporting
14. In bottom-up parsing, when an error is detected, what is one potential recovery method?
A) Skip to the next function definition
B) Backtrack and try a different rule
C) Remove the entire syntax tree
D) Insert a default production rule
Answer: B) Backtrack and try a different rule
15. Which of the following is a typical synchronizing token used in error recovery?
A) Keywords like if
, else
, or for
B) Delimiters such as parentheses, braces, or semicolons
C) Arithmetic operators like +
, -
, or *
D) Function names and identifiers
Answer: B) Delimiters such as parentheses, braces, or semicolons