Program 4
Program 4
Program no -4
• A → αβ1 / αβ2 / αβ3
• This kind of grammar creates a problematic
situation for Top down parsers.
• Top down parsers can not decide which
production must be chosen to parse the string
in hand.
• To remove this confusion, we use left
factoring.
Example-
Problem-01:
– S -> i E t S | i E t S e S | a
– E -> b
α α β2
After applying Left Factoring grammar have following
production
S -> iEtSS’ | a A -> αA’
S’ -> eS | ɛ A’ -> β1 | β2
E-> b
Problem-02:
Do left factoring in the following grammar-
• A → aAB / aBc / aAc
A->αβ1 | αβ2
• β1 =AB, β2=Bc, β3=Ac, α=a
•
• Step-01: A → aA’
• A’ → AB / Bc / Ac 1) A -> αA’
• 2) A’ -> β1 | β2
Again, this is a grammar with common prefixes.
•
• Step-02: A’ → AB / Bc / Ac
• A → aA’
• A’ → AA’’/ Bc
• A’’ → B / c
• This is a left factored grammar.
Problem-03:
• Step-01:
•
• S → bSS’ / a
• S’ → SaaS / SaSb / b
• Again, this is a grammar with common prefixes.
• Step-02:S’ → SaaS / SaSb / b
• Β1=As, β2=Sb α=Sa
• 1) A -> αA’
• 2) A’ -> β1 | β2
• S → bSS’ / a
• S’ → SaS’’ / b
• S’’ → aS / Sb
• This is a left factored grammar.
Problem-04: