Q.1 Which phase of a compiler is primarily responsible for detecting syntax errors?
Lexical Analysis
Syntax Analysis
Semantic Analysis
Code Generation
Explanation - Syntax analysis, also called parsing, checks whether the sequence of tokens follows the grammatical rules of the language, thus detecting syntax errors.
Correct answer is: Syntax Analysis
Q.2 Which of the following is NOT a common error recovery technique in compilers?
Panic Mode
Phrase-Level Recovery
Error Productions
Loop Unrolling
Explanation - Loop unrolling is an optimization technique, not an error recovery method. Panic mode, phrase-level recovery, and error productions are all used to handle errors.
Correct answer is: Loop Unrolling
Q.3 In panic-mode error recovery, what does the compiler do after encountering an error?
Deletes the program
Skips tokens until a synchronizing token is found
Generates assembly code
Restarts the compiler
Explanation - Panic-mode recovery skips input tokens until it finds a token that is likely to allow the parser to continue without cascading errors.
Correct answer is: Skips tokens until a synchronizing token is found
Q.4 Error productions in a grammar are used to:
Optimize the compiler
Define common mistakes for error detection
Generate machine code
Minimize memory usage
Explanation - Error productions extend the grammar to include common mistakes, helping the parser detect and report errors more effectively.
Correct answer is: Define common mistakes for error detection
Q.5 Which error recovery strategy is the simplest and most widely used in compilers?
Panic Mode
Phrase-Level Recovery
Global Correction
Backtracking
Explanation - Panic mode is simple, widely used, and ensures that parsing can continue after encountering an error, though it may skip some valid input.
Correct answer is: Panic Mode
Q.6 What is the main drawback of panic-mode error recovery?
It stops compilation immediately
It may skip valid code along with errors
It cannot detect syntax errors
It requires rewriting the entire grammar
Explanation - Panic mode skips tokens to find a synchronizing token, which can cause some valid statements to be ignored.
Correct answer is: It may skip valid code along with errors
Q.7 Which of the following best describes phrase-level recovery?
It modifies the input to correct the error locally
It skips the entire program
It ignores semantic errors
It only works for lexical errors
Explanation - Phrase-level recovery attempts to make minimal changes, such as inserting or deleting tokens, to continue parsing.
Correct answer is: It modifies the input to correct the error locally
Q.8 In the context of error detection, what are 'synchronizing tokens'?
Tokens that are never valid
Tokens used to resume parsing after an error
Reserved keywords
Tokens that generate machine code
Explanation - Synchronizing tokens are tokens that the parser can safely use to resume parsing after skipping erroneous input.
Correct answer is: Tokens used to resume parsing after an error
Q.9 Global correction error recovery tries to:
Skip tokens until parsing can continue
Minimally change the entire input to produce a correct program
Generate error messages only
Optimize code execution
Explanation - Global correction aims to find the smallest set of changes to the input so that it conforms to the grammar, but it is computationally expensive.
Correct answer is: Minimally change the entire input to produce a correct program
Q.10 Which type of errors can semantic analysis detect that syntax analysis cannot?
Missing semicolons
Type mismatches
Unbalanced parentheses
Invalid tokens
Explanation - Semantic analysis checks for meaning-related errors, such as type mismatches or undeclared variables, which syntax analysis alone cannot detect.
Correct answer is: Type mismatches
Q.11 Which error detection approach is most suitable for interactive development environments?
Panic Mode
Incremental Parsing
Global Correction
Loop Optimization
Explanation - Incremental parsing allows compilers or IDEs to detect errors continuously as the programmer types, providing faster feedback.
Correct answer is: Incremental Parsing
Q.12 Which of the following is true about error recovery in lexical analysis?
It uses panic mode to skip characters
It replaces invalid tokens with valid ones or discards them
It cannot detect errors
It only detects semantic errors
Explanation - Lexical error recovery typically involves deleting illegal characters or replacing them with valid tokens to allow scanning to continue.
Correct answer is: It replaces invalid tokens with valid ones or discards them
Q.13 Which of the following errors is easiest to detect at compile time?
Runtime errors
Syntax errors
Logic errors
Performance errors
Explanation - Syntax errors violate grammatical rules and are detected immediately during compilation.
Correct answer is: Syntax errors
Q.14 Backtracking as an error recovery technique is:
Fast but may skip errors
Computationally expensive and tries alternatives
Only used in lexical analysis
A method for code optimization
Explanation - Backtracking attempts multiple parse paths to find one that succeeds, which is accurate but can be very costly in terms of time.
Correct answer is: Computationally expensive and tries alternatives
Q.15 Which of the following is a limitation of phrase-level recovery?
It cannot detect errors
It may fail to recover from complex errors
It stops compilation
It only works for semantic errors
Explanation - Phrase-level recovery works well for small, localized errors but can struggle with errors affecting large portions of input.
Correct answer is: It may fail to recover from complex errors
Q.16 Inserting missing tokens during parsing is an example of:
Panic-mode recovery
Phrase-level recovery
Global correction
Lexical analysis
Explanation - Phrase-level recovery may insert missing tokens or delete extra tokens to fix local errors and continue parsing.
Correct answer is: Phrase-level recovery
Q.17 Which of the following errors is a semantic error?
Using an undeclared variable
Missing a closing brace
Misspelling a keyword
Exceeding array bounds at runtime
Explanation - Semantic errors relate to meaning in the program; using a variable before declaration violates semantic rules.
Correct answer is: Using an undeclared variable
Q.18 Which error recovery technique may result in cascading errors?
Panic Mode
Phrase-Level Recovery
Error Productions
Global Correction
Explanation - If the local fixes are incorrect, phrase-level recovery can introduce new errors in subsequent parsing, leading to cascading errors.
Correct answer is: Phrase-Level Recovery
Q.19 What is the main goal of error detection in a compiler?
To generate optimized code
To find and report errors to the programmer
To execute the program
To reduce memory usage
Explanation - The primary purpose of error detection is to identify errors in the source code and provide meaningful feedback to the programmer.
Correct answer is: To find and report errors to the programmer
Q.20 Which phase of compilation is least likely to perform error recovery?
Lexical Analysis
Syntax Analysis
Semantic Analysis
Code Generation
Explanation - Code generation focuses on translating intermediate representation to machine code and generally does not attempt to recover from errors.
Correct answer is: Code Generation
Q.21 What is a common disadvantage of global correction?
Cannot detect errors
Requires extensive computation
Skips all input tokens
Only works for syntax errors
Explanation - Global correction finds minimal changes to make the input correct, but this is computationally expensive and impractical for large programs.
Correct answer is: Requires extensive computation
Q.22 Error productions are particularly useful when:
The grammar has no errors
Certain errors occur frequently
Optimizing code
Reducing compilation time
Explanation - Error productions explicitly define likely mistakes in the grammar, allowing the parser to detect and report them efficiently.
Correct answer is: Certain errors occur frequently
Q.23 Which error recovery method is preferred in real-time systems due to its simplicity?
Global Correction
Panic Mode
Phrase-Level Recovery
Backtracking
Explanation - Panic mode is simple, fast, and predictable, making it suitable for real-time or embedded systems where immediate error handling is required.
Correct answer is: Panic Mode
Q.24 Which of the following is true about lexical errors?
They are never reported
They are related to token patterns
They occur only in semantic analysis
They are handled by code optimization
Explanation - Lexical errors occur when the input sequence cannot be matched to any valid token pattern.
Correct answer is: They are related to token patterns
