Question

In: Computer Science

convert the following grammar to Chomsky Normal Form S -> D0S1 | 1 D -> F0D1...

convert the following grammar to Chomsky Normal Form

S -> D0S1 | 1
D -> F0D1 | 0 | e | FG
F -> SF | DD | S
G -> GK | DG

Solutions

Expert Solution

A context free grammar (CFG) is in Chomsky Normal Form (CNF) if all production rules satisfy one of the following conditions:

  • A ->a
  • B ->CD
  • S-> ε

GIVEN grammer :S -> D0S1 | 1

D -> F0D1 | 0 | e | FG

F -> SF | DD | S

G -> GK | DG

FIRSTLY we will check whether the grammer is in cnf form:- The given grammer is not in cnf form

1) Create new start variable:-

S0 -> S

S -> D0S1 | 1

D -> F0D1 | 0 | e | FG

F -> SF | DD | S

G -> GK | DG

2) Eliminate unit production F -> S, Also removal of unit production S->S and S0->S from grammar yields: :-

S0 -> D0S1 | 1

S -> D0S1 | 1

D -> F0D1 | 0 | e | FG

F -> SF | DD | D0S1 | 1 // NEW PRODUCTION

G -> GK | DG

3) Removing useless variables and productions:-

S0 -> D0S1|1

S -> D0S1 | 1 (1 is generated from S so, it is useful)

D -> F0D1 | 0 | e | FG (0 is generated from D so, it is useful)

F -> D0S1

G -> GK | DG

4) Delete all the REMOVING production  which is present in LHS as well as RHS:-

S0 -> D0S1|1

S -> D0S1 | 1  

D -> 0 |e

F -> D0S1

G -> GK | DG

5) THIS is the converted cnf

S0 -> D0S1|1

S -> D0S1 | 1  

D -> 0

J -> e

F -> D0S1

G -> GK | DG


Related Solutions

Let G = (AN , AT , S, P) be a context-free grammar in Chomsky normal...
Let G = (AN , AT , S, P) be a context-free grammar in Chomsky normal form. Prove that if there exists a word w ∈ L(G) generated by a derivation that uses more than |P| + |AT | steps, then L(G) is infinite.
Assuming normal heptane and normal octane to form ideal solutions, do the following: d) Calculate the...
Assuming normal heptane and normal octane to form ideal solutions, do the following: d) Calculate the dew pressure of the solution at 40 ◦C. e) Calculate the bubble temperature at 1 bar. f) Calculate the dew temperature at 1 bar. g) Calculate the amount and composition of vapor and liquid when a solution with z1 = 0.45 is flashed to 40 ◦C, 0.065 bar. The saturation pressures of the two components are given by the Antoine equation: ln Pi sat...
Add or subtract the following 2’s complement form signed numbers, then convert the entire problem to...
Add or subtract the following 2’s complement form signed numbers, then convert the entire problem to decimal and confirm: 110110 + 111000 001100 – 011100
Convert the logical statement ~(P || ~R) || (Q -> R) to conjunctive normal form. Please...
Convert the logical statement ~(P || ~R) || (Q -> R) to conjunctive normal form. Please explain the steps!!
Question 1. Put the following game into the normal form. That is, describe the set of...
Question 1. Put the following game into the normal form. That is, describe the set of players, the strategy sets for each player, the payoff functions, and draw the game in matrix form. What do you expect would happen in this game, and why?Two kids are playing a game of Chicken. In this game, they ride their bikes as fast as theycan at each other. The one to swerve or turn out of the way loses, he is a Chicken...
1. For each of the following statements find an equivalent statement in conjunctive normal form. a)...
1. For each of the following statements find an equivalent statement in conjunctive normal form. a) ¬(A ∨ B) b) ¬(A ∧ B) c) A ∨ (B ∧ C) 2. Is the following implication true or false? And if false, give an example that shows that it is false. ---> If S1 ∈ S2 and S2 ∈ S3, then S1 ∈ S3.
Convert the decimal number, 315.56 into binary form?
Convert the decimal number, 315.56 into binary form?
Consider the context-free grammar G = ( {S}, {a, b}, S, P) where P = {...
Consider the context-free grammar G = ( {S}, {a, b}, S, P) where P = { S -> aaSb | aab }. Construct a NPDA M that such that L(M) = L(G). I would like the transition graph for this NPDA please.
For a grammar G with the productions where G = ( {S, A, B}, {a, b},...
For a grammar G with the productions where G = ( {S, A, B}, {a, b}, S, P ) with productions                                              S --> AB | bbbB,              A --> b | Ab,       B --> a.. 1.Show that the grammar G is ambiguous. 2.Give language L that is generated by G, L = L(G), in a formal expression (including a regular expression). 3.Can you construct an unambiguous grammar that is equivalent to G? Otherwise, show that G is inherently ambiguous.
7. Find the FIRST and FOLLOW sets for the grammar S --> ABC A --> a...
7. Find the FIRST and FOLLOW sets for the grammar S --> ABC A --> a | Cb | ε B --> c | dA | ε C --> e | f Construct LL(1) parsing table from grammar
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT