Chomsky and Greibach Normal Form
Chomsky and Greibach Normal Form
A CFG is in Chomsky Normal Form if the Productions are in the following forms –
A→a
A → BC
S→ε
Step 1 − If the start symbol S occurs on some right side, create a new start symbol S’ and a new
production S’→ S.
Step 2 − Remove Null productions. (Using the Null production removal algorithm discussed earlier)
Step 3 − Remove unit productions. (Using the Unit production removal algorithm discussed earlier)
Step 4 − Replace each production A → B1…Bn where n > 2 with A → B1C where C → B2 …Bn. Repeat this
step for all productions having two or more symbols in the right side.
Step 5 − If the right side of any production is in the form A → aB where a is a terminal and A, B are
non-terminal, then the production is replaced by A → XB and X → a. Repeat this step for every
production which is in the form A → aB.
Problem
Convert the following CFG into CNF
S → ASA | aB, A → B | S, B → b | ε
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 → ∈
1 NIST (auto)
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
2 NIST (auto)
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
3 NIST (auto)
Greibach Normal Form
A CFG is in Greibach Normal Form if the Productions are in the following forms −
A→b
A → bD1…Dn
S→ε
Step 1 − If the start symbol S occurs on some right side, create a new start symbol S’ and a new
production S’ → S.
Step 2 − Remove Null productions. (Using the Null production removal algorithm discussed
earlier)
Step 3 − Remove unit productions. (Using the Unit production removal algorithm discussed
earlier)
Step 5 − Do proper substitutions of productions to convert it into the proper form of GNF.
Problem
Problem
S → XY | Xn | p
X → mX | m
Y → Xn | o
Solution
Here, S does not appear on the right side of any production and there are no unit or null productions in
the production rule set. So, we can skip Step 1 to Step 3.
Step 4
we obtain Y → mXn | mn | o.
Two new productions O → o and P → p are added to the production set and then we came to the final GNF as
the following −
S → mXY | mY | mXC | mC | p
X → mX | m
Y → mXD | mD | o
O→o
P→p
5 NIST (auto)
Pushdown Automata Introduction
Basic Structure of PDA
A pushdown automaton is a way to implement a context-free grammar in a similar way we design DFA for a
regular grammar. A DFA can remember a finite amount of information, but a PDA can remember an infinite
amount of information.
an input tape,
a control unit, and
a stack with infinite size.
This means at state q1, if we encounter an input string ‘a’ and top symbol of the stack is ‘b’, then we pop ‘b’,
push ‘c’ on top of the stack and move to state q2.
6 NIST (auto)