REMOVING AMBIGUITY
FROM CFG
1
Group Members:
1. Muradul Islam Jamil (152-35-1203)
2. Mahadi Hasan Joy (152-35-1207)
3. Mazed Mourshed (152-35-1215)
Md. Anwar Hossen
Lecturer, Dept. of Software Engineering
Daffodil International University
2
AMBIGUITY IN CFG
If a context free grammar has more than one derivation tree
for some string, it is called an ambiguous grammar. There
exist multiple right-most or left-most derivations for some
string generated from
that grammar.
3
PROBLEM
Check whether the grammar G with production rules −
S → AB | aaB
A → a | Aa
B → b
4
SOLUTION
Let’s find out the derivation tree for the string “aab". It has two leftmost deriv
i) S → aaB → aab
ii) S → AB →AaB → aaB → aab
5
ANOTHER PROBLEM
Check whether the grammar G with
production rules −
S → S + S | S * S | a
6
SOLUTION
Let’s find out the derivation tree for the string “a+a+a". It has two leftmost d
i) S → S + S → S + S + S → a + a + S → a + a + a
ii) S → S + S → S + S + S → S + a + a → a + a + a
7
SOLUTION
Let’s find out the derivation tree for the string “a+a*a". It has two leftmost de
i) S → S + S → a + S → a + S * S → a + a * a
ii) S → S * S → S + S * S → a + a * S → a + a * a
8
THANK
YOU
9

Removing ambiguity-from-cfg

  • 1.
  • 2.
    Group Members: 1. MuradulIslam Jamil (152-35-1203) 2. Mahadi Hasan Joy (152-35-1207) 3. Mazed Mourshed (152-35-1215) Md. Anwar Hossen Lecturer, Dept. of Software Engineering Daffodil International University 2
  • 3.
    AMBIGUITY IN CFG Ifa context free grammar has more than one derivation tree for some string, it is called an ambiguous grammar. There exist multiple right-most or left-most derivations for some string generated from that grammar. 3
  • 4.
    PROBLEM Check whether thegrammar G with production rules − S → AB | aaB A → a | Aa B → b 4
  • 5.
    SOLUTION Let’s find outthe derivation tree for the string “aab". It has two leftmost deriv i) S → aaB → aab ii) S → AB →AaB → aaB → aab 5
  • 6.
    ANOTHER PROBLEM Check whetherthe grammar G with production rules − S → S + S | S * S | a 6
  • 7.
    SOLUTION Let’s find outthe derivation tree for the string “a+a+a". It has two leftmost d i) S → S + S → S + S + S → a + a + S → a + a + a ii) S → S + S → S + S + S → S + a + a → a + a + a 7
  • 8.
    SOLUTION Let’s find outthe derivation tree for the string “a+a*a". It has two leftmost de i) S → S + S → a + S → a + S * S → a + a * a ii) S → S * S → S + S * S → a + a * S → a + a * a 8
  • 9.