Questions: LR Parsing Fundamentals

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

A grammar includes the rule: Expr → Expr + Term. A recursive descent (LL) parser encounters this rule and fails to parse. An LR parser handles it correctly. Why?

ARecursive descent parsers cannot handle the + operator; LR parsers have built-in support for arithmetic
BRecursive descent parsers guess the rule before reading input, so Expr → Expr + Term causes infinite recursion trying to expand Expr; LR parsers work bottom-up and have already parsed the left operand before deciding about the rule
CLR parsers use a larger lookahead window than recursive descent parsers, which is why they resolve left recursion
DRecursive descent parsers use a stack, which cannot represent left-recursive derivations
Question 2 Multiple Choice

During LR parsing of an expression, the parser has the state stack [..., Expr, +] and the next input token is a number. What does the parser do?

AReduce immediately — Expr + is enough to recognize a pattern
BShift the number token onto the stack, because more input is needed before a reduction is possible
CReport an error — a number cannot follow the + operator in this grammar
DReduce Expr + to a partial expression using a default rule
Question 3 True / False

LR parsers, like recursive descent parsers, predict which grammar rule to apply by examining the next token before any input has been consumed.

TTrue
FFalse
Question 4 True / False

LR parsers can handle left-recursive grammar rules (like Expr → Expr + Term) without requiring any rewriting of the grammar.

TTrue
FFalse
Question 5 Short Answer

What does 'bottom-up' mean in the context of LR parsing, and why does this allow LR parsers to handle left-recursive grammars that top-down parsers cannot?

Think about your answer, then reveal below.