Consider a top-down parser trying to parse a grammar with left recursion. Why does left recursion cause issues?
Think about what happens when a parser tries to apply a rule that calls itself first.
Left recursion means a rule calls itself as the first step. A top-down parser tries to expand this rule repeatedly without moving forward in the input, causing an infinite loop.
Which of the following grammar rules is left-recursive?
Left recursion occurs when the rule's first symbol on the right side is the same as the left side.
Rule A → A α | β is left-recursive because the first symbol on the right side is the same as the left side non-terminal A.
Given the grammar rule: A → A α | β, which of the following is the correct equivalent grammar after eliminating left recursion?
Use the standard left recursion elimination formula: A → β A', A' → α A' | ε
To remove left recursion, we create a new non-terminal A' and rewrite the grammar as A → β A' and A' → α A' | ε, where ε means empty string.
Starting with the grammar rule S → S a | S b | c, how many productions will the grammar have after eliminating left recursion?
First identify the left recursion, then apply elimination creating a new non-terminal.
The original rule has three productions. After elimination, it becomes S → c S' and S' → a S' | b S' | ε, totaling 4 productions.
Consider the grammar:A → B a | bB → A c | d
Does this grammar contain left recursion? If yes, what kind?
Check if a non-terminal can eventually call itself as the first symbol on the right side through other rules.
Indirect left recursion occurs when a non-terminal calls another non-terminal which eventually calls the first non-terminal again as the first symbol. Here, A → B a and B → A c form indirect left recursion.