0
0
Compiler Designknowledge~20 mins

Left factoring in Compiler Design - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Left Factoring Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding the purpose of left factoring

Why is left factoring applied to a grammar in compiler design?

ATo remove ambiguity by eliminating common prefixes in productions
BTo convert a grammar into Chomsky Normal Form
CTo increase the number of productions for better parsing
DTo remove left recursion from the grammar
Attempts:
2 left
💡 Hint

Think about what problem left factoring solves in top-down parsers.

🚀 Application
intermediate
2:00remaining
Applying left factoring to a grammar

Given the grammar:
S -> if E then S else S | if E then S | other
Which is the correct left factored form?

AS -> if E then S else S | other
BS -> if E then S S' | other<br>S' -> else S | ε
CS -> if E then S else S | if E then S | other
DS -> if E then S else S else S | other
Attempts:
2 left
💡 Hint

Look for the common prefix in the productions and factor it out.

🔍 Analysis
advanced
2:00remaining
Identifying when left factoring is necessary

Consider the grammar:
A -> a B | a C | d
Which problem does this grammar present for a predictive parser?

AIt has unreachable productions
BIt contains left recursion
CIt is ambiguous due to multiple start symbols
DIt has common prefixes causing parsing conflicts
Attempts:
2 left
💡 Hint

Check if productions start with the same symbol.

Comparison
advanced
2:00remaining
Comparing left factoring and left recursion removal

Which statement correctly distinguishes left factoring from left recursion removal?

ALeft factoring removes common prefixes; left recursion removal eliminates productions where a non-terminal calls itself on the left
BBoth techniques remove ambiguity by the same method
CLeft factoring eliminates left recursion; left recursion removal removes common prefixes
DLeft factoring and left recursion removal are identical processes
Attempts:
2 left
💡 Hint

Consider what each technique targets in grammar transformations.

Reasoning
expert
2:00remaining
Effect of left factoring on FIRST sets

After applying left factoring to a grammar, what is the effect on the FIRST sets of the affected non-terminals?

AThe FIRST sets become empty because productions are split
BThe FIRST sets always become larger due to added productions
CThe FIRST sets remain the same because left factoring only restructures productions without changing terminals
DThe FIRST sets become disjoint sets to avoid conflicts
Attempts:
2 left
💡 Hint

Think about whether left factoring changes the terminals that can appear first.