What is the primary purpose of error handling in parsers?
a) To debug code
b) To optimize the code
c) To detect and recover from syntactical errors
d) To execute the code faster
Answer: c) To detect and recover from syntactical errors
What type of error occurs when a parser encounters an undefined variable?
a) Syntax Error
b) Semantic Error
c) Lexical Error
d) Runtime Error
Answer: b) Semantic Error
Which of the following is a common error-handling technique used in parsing?
a) Backtracking
b) Panic-mode recovery
c) Semantic analysis
d) Code optimization
Answer: b) Panic-mode recovery
Which of these errors can be detected by a lexical analyzer?
a) Division by zero
b) Unmatched parentheses
c) Invalid token
d) Type mismatch
Answer: c) Invalid token
In error recovery, what does “panic mode” imply?
a) Discarding input until a specific set of tokens is encountered
b) Halting the compilation
c) Debugging automatically
d) Issuing a warning without stopping the process
Answer: a) Discarding input until a specific set of tokens is encountered
Which error recovery technique replaces the erroneous input with a set of predefined tokens?
a) Phrase-level recovery
b) Error productions
c) Panic mode
d) Global correction
Answer: a) Phrase-level recovery
What is a semantic error?
a) Misspelled variable name
b) Invalid token format
c) Logical inconsistency in the program
d) Incorrect use of programming syntax
Answer: c) Logical inconsistency in the program
Which of the following errors is typically detected during code generation?
a) Type mismatch
b) Missing semicolon
c) Invalid variable name
d) Runtime error
Answer: a) Type mismatch
What kind of error is encountered when a function is called with the wrong number of arguments?
a) Syntax Error
b) Semantic Error
c) Lexical Error
d) Logical Error
Answer: b) Semantic Error
Which error detection technique involves maintaining a set of error productions in the grammar?
a) Global correction
b) Backtracking
c) Error productions
d) Panic mode
Answer: c) Error productions
How does backtracking help in error handling during parsing?
a) By automatically debugging the code
b) By rolling back to a previously valid state
c) By providing optimization suggestions
d) By speeding up the parsing process
Answer: b) By rolling back to a previously valid state
Which phase of the compiler typically reports the highest number of errors?
a) Lexical analysis
b) Semantic analysis
c) Code generation
d) Parsing
Answer: d) Parsing
What is a “semantic error” during parsing?
a) Misuse of an operator
b) Invalid variable name
c) Undefined variable usage
d) Missing semicolon
Answer: c) Undefined variable usage
What does “panic mode” error recovery do in LR parsing?
a) Recompiles the code
b) Deletes tokens until a synchronizing token is found
c) Automatically fixes the code
d) Reports error but continues the parsing
Answer: b) Deletes tokens until a synchronizing token is found
Which error recovery technique makes minimal changes to the source code to continue parsing?
a) Global correction
b) Panic mode
c) Phrase-level recovery
d) Backtracking
Answer: a) Global correction
Which of the following is true for syntax-directed translation?
a) It ignores semantic errors
b) It includes error detection during parsing
c) It is purely based on lexical tokens
d) It skips the code generation phase
Answer: b) It includes error detection during parsing
In bottom-up parsing, what error-handling mechanism is commonly used?
a) Top-down recovery
b) Error productions
c) Shift-reduce error correction
d) Panic mode recovery
Answer: d) Panic mode recovery
Which of the following cannot be detected at the lexical analysis phase?
a) Unmatched parentheses
b) Invalid identifier
c) Type mismatch
d) Unterminated string literal
Answer: c) Type mismatch
Which of the following is not a type of parsing error?
a) Semantic error
b) Syntactic error
c) Lexical error
d) Memory error
Answer: d) Memory error
What is a common way to handle errors during code generation?
a) Ignoring them
b) Using optimization techniques
c) Emitting code for error handling routines
d) Disabling the parser
Answer: c) Emitting code for error handling routines
When a parser detects an error, what is the next best step?
a) Stop the parsing process
b) Issue a message and attempt recovery
c) Skip the remaining input
d) Restart the entire parsing process
Answer: b) Issue a message and attempt recovery
Which technique allows skipping over erroneous tokens to resume parsing?
a) Error correction
b) Backtracking
c) Panic-mode recovery
d) Syntax tree modification
Answer: c) Panic-mode recovery
What is a lexical error?
a) Using a variable before declaration
b) Incorrectly formed tokens
c) Dividing by zero
d) Passing incorrect parameters to a function
Answer: b) Incorrectly formed tokens
A semantic analyzer checks for which type of error?
a) Syntactical errors
b) Logical errors
c) Type consistency errors
d) Token mismatch errors
Answer: c) Type consistency errors
What is “phrase-level recovery”?
a) Recovering from syntactical errors by inserting or deleting tokens
b) Ignoring certain blocks of code
c) Jumping to another part of the code
d) Rewriting the entire program
Answer: a) Recovering from syntactical errors by inserting or deleting tokens
Which error-handling technique uses a “synchronizing token” to recover from errors?
a) Error productions
b) Panic-mode recovery
c) Backtracking
d) Phrase-level recovery
Answer: b) Panic-mode recovery
In the context of parsing, what is meant by “context-free grammar”?
a) A grammar without rules
b) A grammar that defines syntax rules
c) A grammar that handles all errors automatically
d) A grammar without semantic checks
Answer: b) A grammar that defines syntax rules
Which of the following can a parser not recover from?
a) Missing semicolon
b) Syntax errors
c) Semantic errors
d) Infinite loops
Answer: d) Infinite loops
What is a syntax error?
a) Logical error in the code
b) Mismatch between expected and actual grammar tokens
c) Incorrect data types used
d) Runtime error caused by memory issues
Answer: b) Mismatch between expected and actual grammar tokens
What is the role of a “symbol table” in error detection?
a) Storing runtime errors
b) Keeping track of variables and types
c) Handling syntactical errors
d) Detecting lexical errors
Answer: b) Keeping track of variables and types
Which of the following can detect division by zero at runtime?
a) Lexical analyzer
b) Semantic analyzer
c) Code generation
d) Runtime environment
Answer: d) Runtime environment
Which phase of the compiler is responsible for detecting lexical errors?
a) Lexical analysis
b) Syntax analysis
c) Semantic analysis
d) Code generation
Answer: a) Lexical analysis
What is the purpose of error productions in a grammar?
a) To fix syntactical mistakes automatically
b) To recover from errors by adding erroneous rules to the grammar
c) To remove problematic tokens
d) To optimize the parsing process
Answer: b) To recover from errors by adding erroneous rules to the grammar
What happens when a parser encounters a token that does not belong to the grammar?
a) It halts execution
b) It skips the token
c) It reports an error and recovers
d) It replaces the token with a default one
Answer: c) It reports an error and recovers
Which of the following is an example of a recoverable error in parsing?
a) Missing closing parenthesis
b) Infinite loop
c) Segmentation fault
d) Memory leak
Answer: a) Missing closing parenthesis
Which type of error is checked during type checking?
a) Lexical error
b) Syntax error
c) Semantic error
d) Logical error
Answer: c) Semantic error
How is an “undeclared variable” error classified?
a) Syntax error
b) Lexical error
c) Semantic error
d) Logical error
Answer: c) Semantic error
Which phase comes after syntax analysis in a typical compiler pipeline?
a) Code generation
b) Lexical analysis
c) Semantic analysis
d) Error recovery
Answer: c) Semantic analysis
What kind of error does “type mismatch” fall under?
a) Lexical error
b) Syntax error
c) Semantic error
d) Logical error
Answer: c) Semantic error
Which phase detects “undeclared identifier” errors?
a) Lexical analysis
b) Semantic analysis
c) Syntax analysis
d) Code generation
Answer: b) Semantic analysis
Which of the following is used for error handling in predictive parsing?
a) Backtracking
b) Parsing table
c) Panic mode recovery
d) Code optimization
Answer: c) Panic mode recovery
Which of the following errors are detected at compile time?
a) Array out-of-bounds
b) Division by zero
c) Syntax errors
d) Null pointer dereferencing
Answer: c) Syntax errors
How does the parser handle missing semicolons in error recovery?
a) It issues a warning and continues
b) It backtracks to a safe point
c) It inserts the missing semicolon and continues parsing
d) It halts the compilation
Answer: c) It inserts the missing semicolon and continues parsing
What is “local error recovery” in parsing?
a) Automatically fixing the error at the point of detection
b) Recovering by skipping multiple tokens
c) Using predefined rules for error recovery
d) Using the closest valid phrase to recover
Answer: a) Automatically fixing the error at the point of detection
Which error recovery strategy is most commonly used in YACC?
a) Backtracking
b) Global correction
c) Panic mode recovery
d) Phrase-level recovery
Answer: c) Panic mode recovery
What type of error is caused by using a data type incorrectly in an expression?
a) Syntax error
b) Lexical error
c) Semantic error
d) Runtime error
Answer: c) Semantic error
Which of the following best defines “phrase-level error recovery”?
a) It stops parsing upon detecting the error
b) It tries to recover by inserting or deleting symbols
c) It requires human intervention to correct errors
d) It performs full code recompilation
Answer: b) It tries to recover by inserting or deleting symbols
When does a parser generate an error message?
a) When it detects a token mismatch
b) During code optimization
c) During lexical analysis
d) After successful parsing
Answer: a) When it detects a token mismatch
Which of these error-handling techniques attempts to minimize disruptions in parsing?
a) Error productions
b) Global correction
c) Backtracking
d) Panic mode
Answer: b) Global correction
What kind of errors do lexical analyzers not detect?
a) Misspelled keywords
b) Unclosed strings
c) Type mismatches
d) Invalid identifiers
Answer: c) Type mismatches