Professional Documents
Culture Documents
◦ Killing Λ-Productions
◦ Killing unit-productions
◦ Removing Useless Variables
Symbols & Productions
◦ Augmented Grammar
2
Λ-Productions:
In a given CFG, we call a non-terminal N nullable
if there is a production N Λ, or
there is a derivation that starts at N and lead to a
Λ.
N ……… Λ
Λ-Productions are undesirable.
We can replace Λ-production with appropriate
non-Λ productions.
3
If L is CFL generated by a CFG having Λ-productions, then there is a different
CFG that has no Λ-production and still generates either the whole language L
(if L does not include Λ) or else generate the language of all the words in L
other than Λ.
Replacement Rule.
1.Deleteall Λ-Productions.
2.Add the following productions:
For every production of the X old string
Add new production(s) of the form X .., where right
side will account for every modification of the old string
that can be formed by deleting all possible subsets of
null-able Non-Terminals, except that we do not allow X
Λ, to be formed if all the character in old string are
null-able
4
Consider the CFG
S a | Xb | aYa
XY|Λ X is nullable
Yb|X Y is nullable
5
Consider the CFG
S Xa
X aX | bX | Λ
X is nullable
X aX Xa
X bX Xb
6
S XY
X Zb
• Null-able Non-terminals are?
Y bW
Z AB • A, B, Z and W
WZ
A aA | bA | Λ
B Ba | Bb | Λ
7
S XY
X Zb
Y bW
Z AB
WZ
A aA | bA | Λ
B Ba | Bb | Λ
11
This is another proof by constructive algorithm.
Algorithm: For every pair of non-terminals A and
B, if the CFG has a unit production A B, or if
there is a chain
A X1 X2 … B
where X1, X2, ... are non-terminals, create new
productions as follows:
If the non-unit productions from B are
B s1 | s2| …
where s1, s2, ... are strings, we create the
productions
A s1| s2| …
12
Consider the CFG
S A| bb
AB|b
BS|a
The non-unit productions are
S bb Ab Ba
And unit productions are
SA
AB
BS
13
Let’s list all unit productions and their sequences and create new
productions:
SA gives Sb
SAB gives Sa
AB gives Aa
ABS gives A bb
BS gives B bb
BSA gives Bb
Eliminating all unit productions, the new CFG is
S bb | b | a
A b | a | bb
B a | bb | b
This CFG generates a finite language since there are no non-
terminals in any strings produced from S.
S A| bb
AB|b 14
Remove S A
Values of A are B and b
S A| bb Put A = b in above
SAb
AB|b Put A = B in above
SAB
BS|a
UNIT PRODUCTIONS Values OF B are S and a
SA Put B =a
S A B a
AB Put B = S
BS S A B S
Updated grammar
S bb | b |a
AB|b
B
S|a
Theory of Automata Oct 5, 2016
S bb | b |a
AB| Updated grammar
b S bb | b |a
BS|a A b |a |
Remove A B bb
Vlues of B are S and a BS|a
Put B=a
ABa
Put B= S
ABS
PUT values of S in above
A B S bb | b |a
Remove B S bb | b | a
Updated grammar
S bb | b | a
A bb| b |a
B a |bb | b
19
PART1-Remove non generating
Identify variables that derive terminal strings
Remove non-terminals that do not derive
terminal strings.
e.g. following grammar G = S aS | A | C
Aa
B aa
C CB
20
S aS | A | C
Aa
B aa
C CB
S aS | A
Aa
B aa
21
PART – II- Unreachable Production
S A B
As B is unreachable so delete it and the final grammar will be G V=
S aS | A
Aa
22
Useless Productions
S aSb
S
SA
A aA Non Generating
Production
aAS
24
In general:
if S xAy w
and w contains only terminals
w L(G )
25
Example Grammar:
S aS | A | C
Aa
B aa
C aCb
26
First: find all variables that can produce
strings with only terminals
S aS | A | C Round 1: { A, B}
Aa SA
B aa
C aCb Round 2: { A, B, S }
27
Keep only the variables
that produce terminal symbols: { A, B, S }
(the rest variables are useless)
S aS | A | C
Aa S aS | A
B aa Aa
C aCb B aa
Remove useless productions
28
Second: Find all variables
reachable from S
S aS | A
Aa S A B
B aa not
reachable
29
Keep only the variables
reachable from S
(the rest variables are useless)
Final Grammar
S aS | A
S aS | A
Aa
Aa
B aa
30
Consider following CFG • Remove Non generating
G: S AC | BS | B G T:
A aA | aF S BS | B
B CF | b A aA | aF
C cC | D Bb
D aD | BD | C E aA | BSA
E aA | BSA F bB | b
F bB | b Remove Un reachable
G’T:
S BS | B
Bb
31
Step 1: Remove Nullable Variables
32
S AS | BS | B
33