Error Detection and Recovery Mechanisms MCQs December 19, 2025December 14, 2024 by u930973931_answers 30 min Score: 0 Attempted: 0/30 Subscribe 1. What is the main goal of error detection in compilers? (A) To identify and report errors in the source code (B) To stop compilation immediately (C) To optimize code performance (D) To execute the program 2. Which phase of compilation primarily detects syntax errors? (A) Lexical analysis (B) Semantic analysis (C) Syntax analysis (parsing) (D) Code generation 3. Which type of errors is typically detected during lexical analysis? (A) Missing semicolons (B) Invalid identifiers or tokens (C) Type mismatches (D) Memory allocation errors 4. What is the purpose of semantic error detection? (A) To check for spelling mistakes in code (B) To enforce indentation rules (C) To optimize loops (D) To ensure statements are meaningful and consistent in context 5. Which error recovery technique discards input symbols until a designated token is found? (A) Phrase-level recovery (B) Lexical correction (C) Semantic recovery (D) Panic mode recovery 6. Which method attempts to make minimal local changes to continue parsing after an error? (A) Panic mode recovery (B) Code optimization (C) Lexical scanning (D) Phrase-level recovery 7. What is a synchronizing token in error recovery? (A) A token used to pause compilation (B) A variable name (C) A reserved keyword (D) A token that signals where parsing can safely resume 8. Which type of error is a “semantic error”? (A) Misspelled keyword (B) Missing semicolon (C) Type mismatch or undeclared variable (D) Runtime crash 9. What is a “lexical error”? (A) Invalid or unrecognized token during scanning (B) An incorrect use of operators (C) Type mismatch (D) Memory violation at runtime 10. Which recovery strategy is easiest to implement? (A) Semantic recovery (B) Phrase-level recovery (C) Panic mode recovery (D) Runtime exception handling 11. What is a cascading error? (A) A syntax error that occurs multiple times in different files (B) Runtime exceptions caused by memory leaks (C) Errors that occur due to an incorrect earlier error recovery (D) Warnings that do not affect compilation 12. What is the main disadvantage of panic mode recovery? (A) It cannot detect any errors (B) It is prone to runtime crashes (C) It is too slow to implement (D) It may skip large portions of code, causing loss of context 13. Which recovery method is safer for preserving parse structure? (A) Phrase-level recovery (B) Panic mode recovery (C) Lexical scanning (D) Code optimization 14. In phrase-level recovery, which operations are commonly used? (A) Semantic rewriting (B) Discarding the entire input (C) Restarting the compiler (D) Token insertion, deletion, or replacement 15. What is the primary goal of error recovery? (A) To prevent any error messages (B) To allow compilation to continue and detect multiple errors (C) To optimize generated code (D) To stop parsing at the first error 16. Which error detection mechanism checks for undefined variables and type mismatches? (A) Lexical analysis (B) Syntax analysis (C) Semantic analysis (D) Code generation 17. What is the function of an error handler in a compiler? (A) To generate optimized code (B) To manage error reporting and recovery strategies (C) To allocate memory (D) To execute the program 18. Which type of error is detected at runtime rather than compile-time? (A) Syntax error (B) Runtime error (C) Semantic error (D) Lexical error 19. In error recovery, what is the term “local repair”? (A) Restarting compilation (B) Making minimal changes near the error to continue parsing (C) Ignoring the error (D) Logging the error without any correction 20. Which phase is most responsible for detecting missing semicolons? (A) Lexical analysis (B) Code optimization (C) Semantic analysis (D) Syntax analysis 21. Which type of error does a type checker primarily detect? (A) Lexical error (B) Syntax error (C) Runtime error (D) Semantic error 22. Why is error recovery important in large programs? (A) To reduce compilation time (B) To generate runtime exceptions (C) To report multiple errors in one compilation instead of stopping at the first error (D) To optimize memory usage 23. Which of the following is a common panic mode recovery approach? (A) Restarting the compiler (B) Inserting random tokens (C) Skipping input symbols until a semicolon or brace is found (D) Performing runtime checks 24. Phrase-level recovery is most effective for: (A) Multiple nested syntax errors (B) Runtime errors (C) Single, isolated syntax errors (D) Lexical errors 25. Which recovery method may introduce cascading errors if used incorrectly? (A) Phrase-level recovery (B) Panic mode recovery (C) Lexical analysis (D) Runtime error handling 26. Which error recovery strategy is typically combined with semantic analysis? (A) Local repair and phrase-level recovery (B) Panic mode recovery (C) Token skipping (D) Runtime exception handling 27. In panic mode recovery, how does the parser decide where to resume? (A) By generating a new parse tree (B) By asking the user for input (C) By restarting compilation (D) By finding a pre-defined synchronizing token 28. Which is a key feature of error detection in compilers? (A) Optimizing runtime performance (B) Identifying and reporting errors as early as possible (C) Skipping input to save memory (D) Executing the program faster 29. Which phase might detect division by zero as a compile-time error? (A) Lexical analysis (B) Syntax analysis (C) Semantic analysis (D) Code generation 30. What is the relationship between error detection and error recovery? (A) They are unrelated (B) Error detection identifies the problem, and error recovery attempts to continue compilation (C) Error recovery replaces error detection (D) Error detection occurs only at runtime