edited by
7,870 views
34 votes
34 votes

Let $G$ be a context-free grammar where $G=(\{S, A, B, C\}, \{a, b, d\}, P, S)$ with the productions in $P$ given below.

  • $S \rightarrow ABAC$
  • $A \rightarrow aA \mid \varepsilon$
  • $B \rightarrow bB \mid \varepsilon$
  • $C \rightarrow d$

($\varepsilon$ denotes the null string). Transform the grammar $G$ to an equivalent context-free grammar $G'$ that has no $\varepsilon$ productions and no unit productions. (A unit production is of the form $x \rightarrow y$, and $x$ and $y$ are non terminals).

edited by

5 Answers

Best answer
55 votes
55 votes

Final grammar is

  • $S \rightarrow ABAC \mid ABC \mid BAC \mid BC \mid AC \mid AAC \mid d $
  • $A \rightarrow aA \mid a$
  • $B \rightarrow bB \mid b$
  • $C \rightarrow d $  
edited by
3 votes
3 votes
Answer should be

S-----> ABAC  / BAC /AAC/ABC/ABA/AC/BC/d

A------> aA / a

B-------> bB / b

C-------> d
–2 votes
–2 votes

S\rightarrow ABAC \mid BAC \mid AAC\mid ABC \mid ABA

A\rightarrow aA \mid a

B\rightarrow bB \mid b

C\rightarrow d

There are no unit productions.
–3 votes
–3 votes
C->d is a unit production.

so first production will become S -> ABAd | BAd | AAd | ABd | Bd | d

A -> aA | a

B -> bB | b

Related questions

5.7k
views
1 answers
28 votes
Kathleen asked Oct 9, 2014
5,690 views
The grammar whose productions are$\langle\text{stmt}\rangle \to\text{ if id then } \langle\text{stmt}\rangle$\langle\text{stmt}\rangle\to\text{ if id then } \langle\ ... ) the sentenceif a then if b then c:= d else c:= fhas two parse trees
3.6k
views
2 answers
18 votes
Kathleen asked Oct 9, 2014
3,596 views
Consider the syntax-directed translation schema (SDTS) shown below:$E\rightarrow E + E$ {print + }$E\rightarrow E * E$ {print . }$E\rightarrow id$ {print id ... write the translation for the sentence.$(a+b)*(c+d)$, using SDTS given above.
3.9k
views
2 answers
8 votes
Kathleen asked Oct 9, 2014
3,887 views
Which of the following macros can put a macro assembler into an infinite loop?.MACRO M1, X .IF EQ, X ;if X=0 then M1 X + 1 .ENDC .IF NE, X ;if X ≠ O then .WORD ... X .WORD X + 1 .ENDC .ENDM(ii) only(i) onlyboth (i) and (ii)None of the above
13.1k
views
2 answers
39 votes
Kathleen asked Oct 9, 2014
13,078 views
The pass numbers for each of the following activitiesobject code generationliterals added to literal tablelisting printedaddress resolution of local symbols that occur in a two pass assemblerrespectively are ... $1, 2, 2, 2$