Recall & Review
beginner
What is left recursion in grammar rules?
Left recursion occurs when a grammar rule refers to itself as the first symbol on the right side, causing potential infinite loops in parsers.
Click to reveal answer
beginner
Why must left recursion be eliminated in top-down parsers?
Because top-down parsers like recursive descent can get stuck in infinite loops when processing left-recursive rules.
Click to reveal answer
intermediate
What is the general approach to eliminate immediate left recursion?
Rewrite the rule A → Aα | β as A → βA' and A' → αA' | ε, where A' is a new rule and ε means empty string.
Click to reveal answer
beginner
What does ε represent in grammar rules after left recursion elimination?
ε represents the empty string, meaning the rule can end without producing any symbol.
Click to reveal answer
intermediate
How is indirect left recursion different from immediate left recursion?
Indirect left recursion happens when a rule refers to another rule that eventually refers back to the first rule on the left side, unlike immediate left recursion which is direct self-reference.
Click to reveal answer
What problem does left recursion cause in top-down parsers?
✗ Incorrect
Left recursion causes the parser to call itself repeatedly without progress, leading to infinite loops.
Which of the following is a correct way to eliminate immediate left recursion from A → Aα | β?
✗ Incorrect
The standard method introduces a new rule A' to remove left recursion by factoring out the recursive part.
In left recursion elimination, what does the new rule A' typically represent?
✗ Incorrect
A' is a new rule that helps rewrite the grammar to avoid left recursion by handling repetitions.
What does ε stand for in grammar rules?
✗ Incorrect
ε means the rule can produce nothing, allowing the parser to stop recursion.
Indirect left recursion involves:
✗ Incorrect
Indirect left recursion happens when recursion occurs through a chain of rules, not directly.
Explain why left recursion must be eliminated for top-down parsers and describe the general method to remove immediate left recursion.
Think about how recursive calls behave in top-down parsing.
You got /3 concepts.
Describe the difference between immediate and indirect left recursion and why indirect left recursion is more complex to eliminate.
Consider how rules refer to each other in a grammar.
You got /3 concepts.