Left Recursion and Left Factoring
Left Recursion and Left Factoring
S0 f
Path labeled ambn
Left Recursion – Why is it bad
• Example:
(a) (b)
Left Recursion Removal
Immediate Left Recursion Elimination: example
• Grammar
EE+T|T
TT *F|F
F ( E ) | id
• Grammar
EE+T|T
TT *F|F
F ( E ) | id
• Grammar
EE+T|T
TT *F|F
F ( E ) | id
Next Form
Left Recursion in More Than One Step
Algorithm for Eliminating Left Recursion
Left Factoring
Remember that a parser has limited look ahead symbols (1 look ahead
usually)
Left Factoring