Remove all lambda-productions, unit-productions, and useless productions from the following grammar.
S -> AB | BC | aAb
A -> Aa | D | lambda
B -> aSC | bB | lambda
C -> aC | bBC
D -> abS | ab
First, we have to remove useless productions. Two types of productions are called useless productions. a) The ones that cannot be reached from the starting symbol or b) the ones that cannot be terminated.
Production C is such a production. So we can remove that production. So the new production set is:
S -> AB | B | aAb
A -> Aa | D | λ
B -> aS | bB | λ
D -> abS | ab
Next, we have to remove Null productions.
First, we have to determine all the productions that can have Null productions. See productions for A & B are clear. But other productions can also derive Null productions, we need to find such productions. If we substitute B Null in S we get 2 new productions for S, similarly, we get 1 new production for D (i.e., ab which is already present for D).
S -> AB | B | A | aAb | λ
A -> Aa | D | λ
B -> aS | bB | λ
D -> abS | ab | λ
Now we finally have to remove Null production. We do so by substituting Null in all the ways possible and generate all the possible productions.
S -> A | B | AB | aAb | ab
A -> Aa | D | a
B -> aS | bB | a | b
D -> abS | ab
These are the productions that we get after removing Null productions.
Now, we have to remove Unit productions. To do so we use direct substitution.
S -> A | B | AB | aAb | ab
A -> Aa | D | a
B -> aS | bB | a | b
D -> abS | ab
First, we need to find what unit production can we derive from what symbols, just like we did for Null productions. So, we get:-
S -*-> A, S -*-> B, A -*-> D
where -*-> means after some unknown no. of steps.
Now, we need the original non-unit productions.
S -> AB | aAb | ab
A -> Aa | a
B -> aS | bB | a | b
D -> abS | ab
Now since S -*-> A, this means that we will ultimately at some point we may need to substitute for A if we start from S. So to remove that unit production we include all its values beforehand, & similarly for others, so we get new production set.
S -> a | b | ab | Aa | abS | aS |
bB | AB | aAb
A -> Aa | abS | ab | a
B -> aS | bB | a | b
D -> abS | ab
The above grammar does not have any useless, Null, and unit productions.
Hope this helps. If you like the answer please upvote. If you have any queries or suggestions regarding the answers please leave them in the comments section so I can update and improve the answer. Thank you.
Remove all lambda-productions, unit-productions, and useless productions from the following grammar.
Remove the λ - productions from the grammar: S → aAb | BBa A → bb B → AA | λ
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)...
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...
7.1.2 Below:
Exercise 7.1.3: Repeat Exercise 7.1.2 for the following grammar: S040 1B1 BB a) Eliminate e-productions b) Eliminate any unit productions in the resulting grammar e) Eliminate any useless syunlbol in themesuling granmmar. d) Put the resulting grammar into Chomsky Normal Form
Exercise 7.1.3: Repeat Exercise 7.1.2 for the following grammar: S040 1B1 BB
a) Eliminate e-productions b) Eliminate any unit productions in the resulting grammar e) Eliminate any useless syunlbol in themesuling granmmar. d) Put the resulting grammar...
Remove the ε productions from the following grammar: S -> ADS | AD | ADE A -> DAD | DES | a | ε D -> AEA | ED | b | ε E -> DE | AD | c
grammar to remove the indirect left recursion froma 9. Get the algorithm from Aho et al. (2006). Use this algorithm to remove all left recursion from the following grammar: S Aa Bb AAa | Abc c | Sb Bbb
grammar to remove the indirect left recursion froma 9. Get the algorithm from Aho et al. (2006). Use this algorithm to remove all left recursion from the following grammar: S Aa Bb AAa | Abc c | Sb Bbb
Eliminate a productions from the following grammar. Show your work. S → AaB | aaB A → à B → bbA 1a
In each of the following, find a Chomsky Normal Form (CNF) grammar equivalent to the given context-free grammar (CFG). 1. SaA Sab A+ ab | BA ASD BaS b 2. SAIC A → AaB AaC | B | a B Bb Cb (→ cclc 3. S → SabA; AAA bc | Bc; B → Aab | BS a
1. (20 points) Given the following Grammar G,
S->ASB
A -> aAS | a | λ
B -> SbS | A|bb
(a) Identify and remove the λ-productions.
(b) Identify and remove unit-productions from the result of
(a).
(c) Convert it to Chomsky Normal Form.
1. (20 points) Given the following Grammar G, S->ASB A -> AS | a 1a B -> Sbs | Albb (a) Identify and remove the -productions. (b) Identify and remove unit-productions from the result of (a)....
Given the following Grammar G, S->ASB A -> AAS | a B -> Sbs | A|bb (a) Identify and remove the A-productions. (b) Identify and remove unit-productions from the result of (a). (c) Convert it to Chomsky Normal Form.