0
0
Compiler Designknowledge~5 mins

Left factoring in Compiler Design - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is left factoring in compiler design?
Left factoring is a grammar transformation technique used to remove common prefixes from alternatives in a production rule to make the grammar suitable for top-down parsing.
Click to reveal answer
beginner
Why is left factoring important in parsing?
Left factoring helps eliminate ambiguity caused by common prefixes in grammar rules, enabling predictive parsers to decide which production to use by looking at the next input symbol.
Click to reveal answer
intermediate
Given the grammar rule: <br> A → αβ | αγ<br> How would left factoring transform this rule?
The rule is transformed to:<br> A → αA'<br> A' → β | γ<br> This removes the common prefix α from the alternatives.
Click to reveal answer
intermediate
What problem does left recursion cause that left factoring helps to avoid?
Left recursion causes infinite recursion in top-down parsers. Left factoring does not remove left recursion but helps by making choices clear when alternatives share prefixes.
Click to reveal answer
advanced
Can left factoring be applied multiple times on the same grammar? Why?
Yes, left factoring can be applied repeatedly until no two alternatives in a production share a common prefix, ensuring the grammar is fully factored for predictive parsing.
Click to reveal answer
What is the main goal of left factoring in grammar rules?
ATo add more production rules
BTo remove common prefixes from alternatives
CTo eliminate left recursion
DTo convert grammar to Chomsky Normal Form
Which type of parser benefits most from left factoring?
ALR parsers
BBottom-up parsers
CTop-down predictive parsers
DShift-reduce parsers
Given the rule: S → if E then S else S | if E then S, what transformation does left factoring perform?
AS → if E then S S'<br>S' → else S | ε
BS → if E then S else S | if E then S
CS → if E then S else S
DNo transformation needed
Does left factoring remove left recursion from a grammar?
AOnly for immediate left recursion
BYes, always
COnly for indirect left recursion
DNo, it only removes common prefixes
What symbol is commonly introduced during left factoring to represent the factored part?
AA prime (A')
BA star (*)
CA plus (+)
DA question mark (?)
Explain what left factoring is and why it is used in compiler design.
Think about how parsers decide which rule to apply when alternatives start the same way.
You got /3 concepts.
    Describe the steps to left factor the grammar rule: A → αβ | αγ | δ.
    Focus on extracting the shared beginning part of the alternatives.
    You got /4 concepts.