Unit 3 TAFL
Unit 3 TAFL
Unit 3
Unit: 3
TAFL
Course Details
(B Tech 4th Sem)
• Introduction
• Grammars
• Types of Grammars
• Context-Free Languages
• Context-Free Languages: Example
• Left Most ad Right Most derivations
• Parse Tree
• Ambiguous grammar
• Regular Grammar
• Removal of Unit Productions
• Removal of ɛ Productions
• Chomsky Normal Form
• Greibach Normal Form
Prerequisite:
• Basic concept of rules of grammars of various languages, concept of
tree.
Recap:
• Regular expressions are the way of representation of the FA.
• RE can be converted into FA.
• FA can be converted into regular expressions.
• Any language can be regular or not which will be proved by
Pumping Lemma.
A grammar consists of :
α→β,
Palindrome is a string which will be same while reading from LHS or RHS
example 101, 010…..
• S → 0S0/1S1
• S → 0/1/ɛ
Generate 0101010
• S → 0S0 [S → 0S0 ]
• S → 01S10 [S → 1S1 ]
• S → 010S010 [S → 0S0 ]
• S → 0101010[S → 1]
• r = 0*1(0+1)*
• 0* 1 (0+1)*
• A B
• S →A1B
• A →0A/ɛ
• B →0B/1B/ɛ
• S →AaaA
• A →aA/ɛ
• A →bA/ɛ
• R=(a+b)(a+b)
• S →AA
• A →a/b
Solution
Leftmost derivation of 1001:
S →A1B
S →1B *A →ɛ+
→10B *B →0B+
→100B *B →0B+
→1001B *B →1B+
→1001 *B →ɛ+
KCS - 402 TAFL Unit Number: 3
6/12/2023 20
Left Most ad Right Most derivations
[Example] (Continued)
Rightmost derivation of 1001:
S →A1B
S →A10B *B →0B+
→A100B *B →0B+
→A1001B *B →1B+
→A1001 *A →ɛ+
→1001 *B →ɛ]
• Recursion
• Grouping of symbols
S S →0S1
0 S 1 S →0S1
1 S →01
0 S
0 1
Recap: We have studied about Grammar and its type and Parse Tree.
Definition:
G = (V,T,P,S) is a CFG is said to be ambiguous if and only if there exist a
string in T* that has more than on parse tree.
• S
S
S S S S
S S b S S
b
a a
a a
Recap: We have studied about Grammar and its type, Parse Tree and
Ambiguity of grammar.
• Given a DFA:
a
q0 q1
b b b
b
a
q2 q3
S A
b b b
b
a
B C
S A
b b b
b
a
B C
a
• S → aA|bB
• A → aS|bC|b
• B → bs|aC|a
• C → aB|bA KCS - 402 TAFL Unit Number: 3
6/12/2023 34
Right Linear Grammar to DFA
Convert the given Right Linear Grammar to DFA :
• S →bB
• B →bC|b
• B →aB
• C →a
• Interchange the starting state and the final state and reverse the
direction of transactions, we get the transaction graph as following:
Removal Procedure −
• Step 1 − To remove A → B, add production A → x to the grammar
rule whenever B → x occurs in the grammar. [x ∈ Terminal, x can be
Null]
• Step 2 − Delete A → B from the grammar.
• Step 3 − Repeat from step 1 until all unit productions are removed.
Given Grammar:
• S→aA
• A →b|ɛ
Solution:
• Substitute ɛ on production S→aA
• S→a*ɛ+
• S→a
Problem
Solution
(1) Since S appears in R.H.S, we add a new state S0 and S0→S is added
to the production set and it becomes −
• B → ∈ and A → ∈
• S0→S, S→ ASA | aB | a, A → B | S | ∈, B → b
• S0→S, S→ ASA | aB | a | AS | SA | S, A → B | S, B → b
(4) Now we will find out more than two variables in the R.H.S
Hence we will apply step 4 and step 5 to get the following final
production set which is in CNF −
• S0→ AX | aB | a | AS | SA
• S→ AX | aB | a | AS | SA
• A → b |AX | aB | a | AS | SA
• B→b
• X → SA
• S0→ AX | YB | a | AS | SA
• S→ AX | YB | a | AS | SA
• A → b A → b |AX | YB | a | AS | SA
• B→b
• X → SA
• Y→a
• A→b
• A → bD1…Dn
• S→ε
Question:
• S → mXY | mY | mXC | mC | p
• X → mX | m
• Y → mXD | mD | o
• O→o
• P→p
a. S→a
b. aA→b
c. S→aA
d. S→Sb
a. {ab}
b. {ba}
c. {a,b}
d. {a}
10. in case of a CFG in regular form the productions should be in which form:
a. A→aB|a
b. A→Ba
c. A→a
d. A→CV
6/12/2023 KCS - 402 TAFL Unit Number: 3 71
Expected Questions for University Exam