0
0
Compiler Designknowledge~20 mins

Left recursion elimination in Compiler Design - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Left Recursion Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why is left recursion problematic in top-down parsers?

Consider a top-down parser trying to parse a grammar with left recursion. Why does left recursion cause issues?

AIt makes the parser run slower but does not affect correctness.
BIt makes the parser skip some input tokens, leading to incorrect parsing.
CIt causes the parser to reject all inputs, even valid ones.
DIt causes the parser to enter an infinite loop because it keeps expanding the same rule without consuming input.
Attempts:
2 left
💡 Hint

Think about what happens when a parser tries to apply a rule that calls itself first.

📋 Factual
intermediate
1:30remaining
Identify the left-recursive grammar rule

Which of the following grammar rules is left-recursive?

AA → A α | β
BA → β A | α
CA → α β | γ
DA → β | γ α
Attempts:
2 left
💡 Hint

Left recursion occurs when the rule's first symbol on the right side is the same as the left side.

🚀 Application
advanced
2:30remaining
Eliminate left recursion from the grammar

Given the grammar rule: A → A α | β, which of the following is the correct equivalent grammar after eliminating left recursion?

AA → β | α A
BA → β A'<br>A' → α A' | ε
CA → β α | A'
DA → α A' | β
Attempts:
2 left
💡 Hint

Use the standard left recursion elimination formula: A → β A', A' → α A' | ε

🔍 Analysis
advanced
2:00remaining
Determine the number of productions after elimination

Starting with the grammar rule S → S a | S b | c, how many productions will the grammar have after eliminating left recursion?

A4
B3
C2
D5
Attempts:
2 left
💡 Hint

First identify the left recursion, then apply elimination creating a new non-terminal.

Reasoning
expert
3:00remaining
Predict parser behavior with indirect left recursion

Consider the grammar:
A → B a | b
B → A c | d
Does this grammar contain left recursion? If yes, what kind?

AYes, it contains direct left recursion because A calls B and B calls A directly.
BNo, it does not contain left recursion because no rule starts with itself directly.
CYes, it contains indirect left recursion because A calls B and B calls A starting with A again.
DNo, it contains right recursion only.
Attempts:
2 left
💡 Hint

Check if a non-terminal can eventually call itself as the first symbol on the right side through other rules.