Bottom-up parsing (Shift-Reduce, LR parsers, SLR, LALR)(MCQs)

What is the primary goal of bottom-up parsing?

a) To construct a parse tree from the input string to the start symbol
b) To convert a grammar to Chomsky Normal Form
c) To check if a string is regular
d) To minimize the number of states in a finite automaton
Answer: a) To construct a parse tree from the input string to the start symbol
Which of the following is a characteristic of Shift-Reduce parsing?

a) It uses a stack to manage the parse state
b) It constructs parse trees from top to bottom
c) It uses recursive procedures to handle parsing
d) It uses multiple lookahead tokens
Answer: a) It uses a stack to manage the parse state
Which type of grammar is suitable for LR parsing?

a) Context-free grammar
b) Regular grammar
c) Unambiguous grammar
d) Context-sensitive grammar
Answer: a) Context-free grammar
What does the ‘LR’ in LR parsing stand for?

a) Left-to-right scan of the input and Rightmost derivation in reverse
b) Left-to-right scan of the input and Rightmost derivation in direct
c) Left-to-right scan of the input and Leftmost derivation in reverse
d) Left-to-right scan of the input and Leftmost derivation in direct
Answer: a) Left-to-right scan of the input and Rightmost derivation in reverse
What is the main advantage of LR parsing over LL parsing?

a) It can handle a broader range of grammars, including those with left recursion
b) It avoids using a stack for managing the parse state
c) It uses multiple lookahead tokens
d) It constructs parse trees from top to bottom
Answer: a) It can handle a broader range of grammars, including those with left recursion
In Shift-Reduce parsing, what action does ‘shift’ perform?

a) It moves the next input symbol onto the parsing stack
b) It reduces a sequence of symbols on the stack to a non-terminal symbol
c) It removes the top symbol from the stack
d) It replaces a non-terminal symbol with a sequence of production rules
Answer: a) It moves the next input symbol onto the parsing stack
What is the purpose of ‘reduce’ action in Shift-Reduce parsing?

a) To apply a production rule in reverse and replace symbols on the stack with a non-terminal
b) To add a new symbol to the stack
c) To remove symbols from the stack
d) To examine multiple production rules simultaneously
Answer: a) To apply a production rule in reverse and replace symbols on the stack with a non-terminal
Which type of parser is an example of an LR parser?

a) LALR parser
b) LL(1) parser
c) Recursive Descent parser
d) SLR parser
Answer: a) LALR parser
In SLR parsing, what does ‘SLR’ stand for?

a) Simple LR
b) Shift-Left-Reduce
c) Standard LR
d) Shift-Reduce-Lookahead
Answer: a) Simple LR
What is the main difference between SLR and LR parsing?

a) SLR uses a simpler parsing table than LR parsing
b) LR parsing handles left recursion directly, while SLR parsing does not
c) SLR parsing can handle more complex grammars than LR parsing
d) LR parsing uses a single lookahead token, while SLR uses multiple tokens
Answer: a) SLR uses a simpler parsing table than LR parsing
Which parsing technique is used to handle grammars with ambiguities by adding lookahead tokens to resolve conflicts?

a) LALR parsing
b) LL(1) parsing
c) Recursive Descent parsing
d) SLR parsing
Answer: a) LALR parsing
In LR parsing, what does ‘shift’ operation do?

a) Moves the next input symbol onto the parsing stack and transitions to a new state
b) Applies a production rule to replace symbols on the stack
c) Pops symbols off the stack
d) Replaces non-terminal symbols with terminal symbols
Answer: a) Moves the next input symbol onto the parsing stack and transitions to a new state
Which type of parser uses a canonical collection of LR(0) items to construct its parsing table?

a) LR parser
b) SLR parser
c) LALR parser
d) LL(1) parser
Answer: a) LR parser
What is the main advantage of LALR parsing over SLR parsing?

a) LALR parsing can handle more complex grammars with better accuracy
b) LALR parsing is simpler to implement than SLR parsing
c) LALR parsing avoids the use of lookahead tokens
d) LALR parsing does not require a parsing table
Answer: a) LALR parsing can handle more complex grammars with better accuracy
In Shift-Reduce parsing, what does the ‘shift’ operation typically involve?

a) Moving the next symbol from the input onto the stack
b) Replacing a sequence of symbols on the stack with a non-terminal
c) Removing the top symbol from the stack
d) Adding new symbols to the parsing table
Answer: a) Moving the next symbol from the input onto the stack
Which of the following actions is NOT typically part of a Shift-Reduce parser?

a) Shift
b) Reduce
c) Accept
d) Backtrack
Answer: d) Backtrack
What does ‘accept’ operation indicate in a Shift-Reduce parser?

a) The input string is successfully parsed and accepted by the grammar
b) The parser needs to backtrack and try a different parsing path
c) A syntax error has occurred in the input string
d) The parser has reached a stopping point and needs to terminate
Answer: a) The input string is successfully parsed and accepted by the grammar
Which of the following is a common issue that can occur in Shift-Reduce parsing?

a) Shift-reduce conflicts
b) Left recursion
c) Multiple lookahead tokens
d) Unambiguous grammars
Answer: a) Shift-reduce conflicts
What does ‘LALR’ stand for in LALR parsing?

a) Look-Ahead LR
b) Look-Ahead Left-Right
c) Look-Ahead LR(1)
d) Look-Ahead Left Recursive
Answer: c) Look-Ahead LR(1)
Which type of parsing table is used in SLR parsing?

a) Simple LR table
b) Look-Ahead LR table
c) Canonical LR table
d) Regular Expression table
Answer: a) Simple LR table
What does the ‘reduce’ operation do in a Shift-Reduce parser?

a) It applies a production rule in reverse to replace symbols on the stack with a non-terminal
b) It adds new symbols to the stack
c) It removes symbols from the stack
d) It transitions to a new state based on the current input symbol
Answer: a) It applies a production rule in reverse to replace symbols on the stack with a non-terminal
Which parsing technique is best suited for handling context-free grammars with minimal lookahead tokens?

a) LR parsing
b) LL(1) parsing
c) Recursive Descent parsing
d) SLR parsing
Answer: b) LL(1) parsing
What does the ‘lookahead’ token refer to in bottom-up parsing techniques like LR parsing?

a) The next input symbol used to make parsing decisions
b) The entire input string
c) The previous symbols in the input
d) The final symbol in the input string
Answer: a) The next input symbol used to make parsing decisions
What is a key feature of LR parsing compared to SLR parsing?

a) LR parsing handles more complex grammars and has a more detailed parsing table
b) SLR parsing handles more complex grammars with fewer states
c) LR parsing is simpler to implement than SLR parsing
d) LR parsing uses multiple lookahead tokens
Answer: a) LR parsing handles more complex grammars and has a more detailed parsing table
What is the main advantage of SLR parsing?

a) It uses a simpler parsing table and is easier to implement compared to canonical LR parsing
b) It handles ambiguous grammars more effectively than other techniques
c) It does not require a parsing table
d) It uses multiple lookahead tokens for parsing
Answer: a) It uses a simpler parsing table and is easier to implement compared to canonical LR parsing
Which of the following is true about LALR parsing compared to LR parsing?

a) LALR parsing combines states in the LR parsing table to reduce the size of the table
b) LALR parsing handles more complex grammars than LR parsing
c) LALR parsing requires more lookahead tokens than LR parsing
d) LALR parsing does not use a parsing table
Answer: a) LALR parsing combines states in the LR parsing table to reduce the size of the table
What is a shift-reduce conflict in Shift-Reduce parsing?

a) A situation where the parser cannot decide whether to shift or reduce
b) A situation where the parser requires multiple lookahead tokens
c) A situation where the grammar is ambiguous
d) A situation where left recursion is present in the grammar
Answer: a) A situation where the parser cannot decide whether to shift or reduce
In which of the following parsers is the lookahead token used to resolve conflicts in parsing decisions?

a) LALR parser
b) SLR parser
c) Recursive Descent parser
d) LL(1) parser
Answer: a) LALR parser
What does ‘canonical’ in canonical LR parsing refer to?

a) The use of a comprehensive set of parsing states to handle all possible input scenarios
b) The use of a simplified parsing table to reduce the number of states
c) The use of regular expressions for parsing
d) The use of multiple lookahead tokens
Answer: a) The use of a comprehensive set of parsing states to handle all possible input scenarios
What is the primary function of the parser’s state stack in bottom-up parsing techniques?

a) To manage the current state of parsing and track symbols being processed
b) To store the entire input string
c) To hold the production rules of the grammar
d) To manage multiple lookahead tokens
Answer: a) To manage the current state of parsing and track symbols being processed
Which parsing technique is known for handling a broader range of grammars by using a larger parsing table?

a) LR parsing
b) LL(1) parsing
c) SLR parsing
d) Recursive Descent parsing
Answer: a) LR parsing
What is the main difference between LR(0) and LALR parsing?

a) LALR parsing combines states from LR(0) to reduce the size of the parsing table
b) LR(0) parsing handles more complex grammars than LALR parsing
c) LALR parsing uses multiple lookahead tokens, while LR(0) uses only one
d) LR(0) parsing is simpler to implement than LALR parsing
Answer: a) LALR parsing combines states from LR(0) to reduce the size of the parsing table
Which type of parser is generally more complex to implement but handles a wider range of grammars than SLR parsing?

a) LR parsing
b) LL(1) parsing
c) Recursive Descent parsing
d) LALR parsing
Answer: a) LR parsing
In which parsing technique are conflicts typically resolved by examining a detailed parsing table?

a) LALR parsing
b) SLR parsing
c) LL(1) parsing
d) Recursive Descent parsing
Answer: a) LALR parsing
What is the purpose of a parsing table in Shift-Reduce parsing?

a) To determine the actions (shift or reduce) based on the current state and lookahead token
b) To handle left recursion in the grammar
c) To convert the grammar to regular expressions
d) To manage multiple lookahead tokens
Answer: a) To determine the actions (shift or reduce) based on the current state and lookahead token
Which of the following is a key feature of SLR parsing?

a) It uses a simple parsing table and handles a broad range of grammars
b) It handles ambiguous grammars with multiple lookahead tokens
c) It requires complex backtracking to resolve conflicts
d) It eliminates the need for a parsing table
Answer: a) It uses a simple parsing table and handles a broad range of grammars
In which parser is a lookahead token used to decide between shifting and reducing actions?

a) LR parser
b) SLR parser
c) LALR parser
d) Both a and b
Answer: d) Both a and b
Which parsing technique is commonly used in compiler implementations for parsing programming languages?

a) LR parsing
b) LL(1) parsing
c) SLR parsing
d) Recursive Descent parsing
Answer: a) LR parsing
What does the ‘shift’ operation involve in Shift-Reduce parsing?

a) Pushing the next input symbol onto the stack
b) Applying a production rule to reduce the stack’s contents
c) Removing the top symbol from the stack
d) Replacing non-terminal symbols with terminals
Answer: a) Pushing the next input symbol onto the stack
Which of the following statements is true about LR parsing compared to SLR parsing?

a) LR parsing can handle more complex grammars with more detailed parsing tables
b) SLR parsing handles more complex grammars than LR parsing
c) LR parsing uses fewer states than SLR parsing
d) SLR parsing is simpler to implement than LR parsing
Answer: a) LR parsing can handle more complex grammars with more detailed parsing tables
Which type of parsing technique is best suited for parsing programming languages with complex syntax?

a) LR parsing
b) LL(1) parsing
c) SLR parsing
d) Recursive Descent parsing
Answer: a) LR parsing
What is a key advantage of LALR parsing over LR parsing?

a) LALR parsing reduces the size of the parsing table while maintaining the ability to handle complex grammars
b) LALR parsing is simpler to implement than LR parsing
c) LALR parsing handles left recursion automatically
d) LALR parsing avoids using a parsing table
Answer: a) LALR parsing reduces the size of the parsing table while maintaining the ability to handle complex grammars
What is a characteristic of SLR parsing that distinguishes it from canonical LR parsing?

a) SLR parsing uses a simpler set of parsing states
b) Canonical LR parsing is simpler to implement
c) SLR parsing handles more complex grammars
d) Canonical LR parsing avoids using lookahead tokens
Answer: a) SLR parsing uses a simpler set of parsing states
What does the ‘reduce’ operation typically involve in Shift-Reduce parsing?

a) Replacing a sequence of symbols on the stack with a non-terminal symbol based on a production rule
b) Shifting the next input symbol onto the stack
c) Removing the top symbol from the stack
d) Adding new symbols to the parsing table
Answer: a) Replacing a sequence of symbols on the stack with a non-terminal symbol based on a production rule
Which type of parser uses lookahead tokens to resolve ambiguities in parsing decisions?

a) LALR parser
b) SLR parser
c) LL(1) parser
d) Recursive Descent parser
Answer: a) LALR parser
What is a primary challenge of implementing LR parsers compared to simpler parsers like LL(1)?

a) LR parsers require more complex parsing tables and state management
b) LR parsers cannot handle context-free grammars
c) LR parsers are simpler to implement than LL(1) parsers
d) LR parsers do not use lookahead tokens
Answer: a) LR parsers require more complex parsing tables and state management
What is a key feature of the LALR parsing technique?

a) It combines states from LR(0) to simplify the parsing table
b) It uses multiple lookahead tokens for parsing decisions
c) It handles left recursion directly
d) It does not require a parsing table
Answer: a) It combines states from LR(0) to simplify the parsing table
Which parsing technique is best suited for handling grammars with a large number of states?

a) LALR parsing
b) SLR parsing
c) LL(1) parsing
d) Recursive Descent parsing
Answer: a) LALR parsing
In Shift-Reduce parsing, which action is taken when the parser encounters a reduce action?

a) The parser replaces a sequence of symbols on the stack with a non-terminal symbol
b) The parser pushes the next input symbol onto the stack
c) The parser removes the top symbol from the stack
d) The parser transitions to a new state based on the input symbol
Answer: a) The parser replaces a sequence of symbols on the stack with a non-terminal symbol
Which parsing technique requires the construction of a canonical collection of LR(0) items for its parsing table?

a) LR parsing
b) SLR parsing
c) LALR parsing
d) LL(1) parsing
Answer: a) LR parsing