4. Transform the grammar with productions
S → baAB,
A → bAB|λ,
B → BAa |A| λ
into CNF and GNF
5. Convert the grammar
S → AB|aB,
A → abb|λ,
B → bbA
into CNF and GNF.
Following is the procedure to transform:-
1. We will remove λ-productions: –
Removing A → λ: S → baAA|baA|ba, A → bAB|bB, B → BAa|A|Ba.
Removing B → λ: S → baAA|baA|baA|ba, A → bAB|bB|bA|b, B → BAa|A|Ba|Aa|a.
2. We will remove unit-production:-
B → A: S → baAA|baA|ba, A → bAB|bB|bA|b, B → BAa|bAB|bB|bA|b|Ba|Aa|a.
3. Now convert the grammar into Chomsky normal form: –
a) We will introduce new variables Sa for each a ∈ T and Sb for each b ∈ T:
S → SbSaAA|SbSaA|SbSa,
A → SbAB| SbB| SbA| Sb,
B → BASa|SbAB|SbB|SbA|Sb|B|ASa|Sa,
Sa → a,
Sb→ b.
b) Now we are introducing additional variables to get the first two productions into normal form and we get the final result
S → SbU|SbX |SbSa,
A → SbY |SbB|SbA|Sb,
B → BZ|SbY |SbB|SbA|Sb|BSa|ASa|Sa,
U → SaV,
V → AA,
X →Sa A,
Y → AB,
Z → ASa,
Sa → a,
Sb → b.
Production given are as follows :Converting the grammar into Chomsky normal form: \(-\) Introduce new variables \(\mathrm{S}_{\mathrm{a}}\) for each \(\mathrm{a} \in \mathrm{T}\) and \(\mathrm{S}_{\mathrm{b}}\) for each \(\mathrm{b} \in \mathrm{T}\) :
\(\mathrm{S} \rightarrow \mathrm{S}_{\mathrm{b}} \mathrm{S}_{\mathrm{a}} \mathrm{A} \mathrm{B}\left|\mathrm{S}_{\mathrm{b}} \mathrm{S}_{\mathrm{a}} \mathrm{B}\right| \mathrm{S}_{\mathrm{b}} \mathrm{S}_{\mathrm{a}} \mathrm{A} \mid \mathrm{S}_{\mathrm{b}} \mathrm{S}_{\mathrm{a}}\)
\(\mathrm{A} \rightarrow \mathrm{S}_{\mathrm{b}} \mathrm{AB}\left|\mathrm{S}_{\mathrm{b}} \mathrm{B}\right| \mathrm{S}_{\mathrm{b}} \mathrm{A} \mid \mathrm{S}_{\mathrm{b}}\)
\(\mathrm{B} \rightarrow \mathrm{BAS}_{\mathrm{a}}\left|\mathrm{S}_{\mathrm{b}} \mathrm{AB}\right| \mathrm{S}_{\mathrm{b}} \mathrm{B}\left|\mathrm{S}_{\mathrm{b}} \mathrm{A}\right| \mathrm{S}_{\mathrm{b}}\left|\mathrm{BS}_{\mathrm{a}}\right| \mathrm{AS}_{\mathrm{a}} \mid \mathrm{S}_{\mathrm{a}}\)
\(\mathrm{S}_{\mathrm{a}} \rightarrow \mathrm{a}\)
\(\mathrm{S}_{\mathrm{b}} \rightarrow \mathrm{b}\)
Introducing more variables to get the productions into normal form and the final result are as follows:
\(\mathrm{S} \rightarrow \mathrm{S}_{\mathrm{b}} \mathrm{U}\left|\mathrm{S}_{\mathrm{b}} \mathrm{X}\right| \mathrm{S}_{\mathrm{b}} \mathrm{Y} \mid \mathrm{S}_{\mathrm{b}} \mathrm{S}_{\mathrm{a}}\)
\(\mathrm{A} \rightarrow \mathrm{S}_{\mathrm{b}} \mathrm{V}\left|\mathrm{S}_{\mathrm{b}} \mathrm{B}\right| \mathrm{S}_{\mathrm{b}} \mathrm{A} \mid \mathrm{S}_{\mathrm{b}}\)
\(\mathrm{B} \rightarrow \mathrm{BZ}\left|\mathrm{S}_{\mathrm{b}} \mathrm{V}\right| \mathrm{S}_{\mathrm{b}} \mathrm{B}\left|\mathrm{S}_{\mathrm{b}} \mathrm{A}\right| \mathrm{S}_{\mathrm{b}}\left|\mathrm{BS}_{\mathrm{a}}\right| \mathrm{AS}_{\mathrm{a}} \mid \mathrm{S}_{\mathrm{a}}\)
\(\mathrm{U} \rightarrow \mathrm{S}_{\mathrm{a}} \mathrm{V}\)
\(\mathrm{V} \rightarrow \mathrm{AB}\)
\(\mathrm{X} \rightarrow \mathrm{S}_{\mathrm{a}} \mathrm{B}\)
\(\mathrm{Y} \rightarrow \mathrm{S}_{\mathrm{a}} \mathrm{A}\)
\(\mathrm{Z} \rightarrow \mathrm{AS}_{\mathrm{a}}\)
\(\mathrm{S}_{\mathrm{a}} \rightarrow \mathrm{a}\)
\(\mathrm{S}_{\mathrm{b}} \rightarrow \mathrm{b}\)
\(\mathrm{S} \rightarrow \mathrm{baAB}\)
\(\mathrm{A} \rightarrow \mathrm{bAB} \mid \lambda\)
\(\mathrm{B} \rightarrow \mathrm{BAa}|\mathrm{A}| \lambda\)
Removing the \(\lambda\) -productions:
First removing \(A \rightarrow \lambda:\)
\(\mathrm{S} \rightarrow \mathrm{baAB} \mid \mathrm{baB}\)
\(\mathrm{A} \rightarrow \mathrm{AB} \mid \mathrm{bB}\)
\(\mathrm{B} \rightarrow \mathrm{BAa}|\mathrm{A}| \lambda \mid \mathrm{Ba}\)
Then removing \(\mathrm{B} \rightarrow \lambda\)
\(\mathrm{S} \rightarrow \mathrm{baAB}|\mathrm{baB}| \mathrm{baA} \mid \mathrm{ba}\)
\(\mathrm{A} \rightarrow \mathrm{bAB}|\mathrm{bB}| \mathrm{bA} \mid \mathrm{b}\)
\(\mathrm{B} \rightarrow \mathrm{BAa}|\mathrm{A}| \mathrm{Ba}|\mathrm{Aa}| \mathrm{a}\)
Removing unit-production \(\mathrm{B} \rightarrow \mathrm{A}\) :
\(\mathrm{S} \rightarrow \mathrm{baAB}|\mathrm{baB}| \mathrm{baA} \mid \mathrm{ba}\)
\(\mathrm{A} \rightarrow \mathrm{bAB} / \mathrm{bB}|\mathrm{bA}| \mathrm{b}\)
\(\mathrm{B} \rightarrow \mathrm{BAa}|\mathrm{bAB}| \mathrm{bB}|\mathrm{bA}| \mathrm{b}|\mathrm{Ba}| \mathrm{Aa} \mid \mathrm{a}\)
Convert the following grammar into Chomsky Normal Form
(CNF):
S → aS | A
| bS
A → aA |
bBa | aAa
B → bb |
bBb
Note: you need to first simplify the grammar ( remove any
λ -
productions, unit productions, and useless productions), and then
convert the simplified grammar to CNF.
Convert the following grammar into Chomsky Normal Form (CNF): SaSAS A → AbBa| aAa B+bb | bBb Note: you need to first simplify the grammar...
Consider the grammar provided below: S → AB | aB A → aab | Λ B → bbA Question: Showing all the steps convert the above grammar to Chomsky Normal Form (CNF)
Theory of Computation
7. Write down the Chomsky Normal Form for the context-free language de- fined by the productions: S bAļaB. A bAA laSla, and B aBB bS b, where S, A, B are nonterminal symbols and a, b are terminal symbol 8. For the context-free grammar Ģ -(X, T, R, S) with X (A, B. C, a, b), T a, b and productions R: SAB |BC, ABAa, BCClb,C AB la, check by applying the CYK Theorem whether the string...
Theory of computations
An Introduction to formal language and automata 6th edition.
Chapter 6: Simplification of context free grammars and normal
forms.
Solve the following questions.
Please
solve it clearly
use Keyboard not hand writtin answers.
Thank you.
1. Do Exercise 4 of Section 6.2 at page 176. 4. Transform the grammar with productions S baAB A bABIA, B BAa IAIA into Chomsky normal form.
lIhg derivation in tion for each of the following Post correspondence systems. 16, Find a solution for each la, aaa), taab, b), [abaa, ab la, abl. tba, aba), lb, aba), [bba, b] 17 Show that the following Post coespondence systems have no solutions a) [b, ba], [aa, bl, [bab, aa], [ab, ba] by [ab, al, [ba, bab], [b, aa], [ba, ab] c) [ab, aba], [baa, aa], [aba, baa] lab, bb], laa, ba), lab, abbl, [bb, bab] e) [abb, ab], [aba,...
Conversions to CNF: Textbook problems: 7.1.1 - 7.1.4 (p. 275) 7.1.1) Find a grammar equivalent to the following, but with no useless symbols: S → AB | CA A → a B → BC | AB C → aB | b 7.1.2) Begin with the following grammar, then eliminate ε-productions, eliminate unit productions, eliminate useless symbols, then put the grammar into CNF. S → ASB | ε A → aAS | a B → SbS | A | bb 7.1.3)...
Remove the λ - productions from the grammar: S → aAb | BBa A → bb B → AA | λ
Convert the following grammar into Greibach Normal Form (GNF): S → AaSA | BaBS A → Ba | aB B → bab
1. [10 Points Convert the following grammars into Chomsky Normal Form. (a) S → AaB | BAC A AaB | BA B → ABaC BACC C → Cb CaА | 6C (b) S XSX a Ab | bAa A + XAXX X + ab
Given the following ambiguous context free grammar (3x20) 1. (a) Explain why the grammar is ambiguous (b) Find an equivalent unambiguous context-free grammar. (c) Give the unique leftmost derivation and derivation tree for the string s generated from the unambiguous grammar above. 2. Construct non-deterministic pushdown automata to accept the following language (20) 3. Convert the following CFG into an cquivalent CFG in Chomsky Normal Form (CNF) (20)-