You are on page 1of 56

Context Free Grammar

By:
Dr. Archana Gupta
CFG
• Formal notation for expressing recursive
definition in language like palindrome.
• A->0
• A->1
• A->0A0
• A->1A1
• A->epsilon
Formal definition
• V
• T
• P
• S
• P consist of rules in the form A-> α
where α ∈ (VUT)* and A ∈ V,
CFG for Arithmetic Grammar
|i=j+k
|i<=2j
Strings of even length
Identify the language of the grammar
• S->aS/Sb/a/b
• Prove that “ba” is not substring
Equal number of a’s and b’s
Derivation
Leftmost and Rightmost Derivation
Parse Tree
CNF
• S → 1A / 0B
• A → 1AA / 0S / 0
• B → 0BB / 1S / 1
GNF
• S->aAbB
• A->aAa/a
• B->bBb/b
GNF
• S → aB | AA
• A → a | aBA | AAA
• B→b
• X→a
GNF
• S→ABb|a
• A→aaA|B
• B→bAb
GNF
• S→AA | 1,
• A→SS |0
• S -> CA
• S -> BB
• B -> b
• B -> SB
• A -> a
GNF
• S→aAa | bBb |€
• A→C|a
• B→C|b
• C→CDE | €
• D→A|B|ab

You might also like