CHAPTER 18 (1997 edition) Chapter 18, page 429, number 1(v) The given CFG has the productions: SAB ABSB BAAS ACC BCC CSS Aab Cbbb. (Note that Λ cannot be generated.) We are going to use Theorem 42 to decide whether or not any words are generated by the above grammar. Look at the reformulation of the algorithm in the study guide. First of all we convert the CFG into CNF: SAB ABR1 R1SB BAR2 R2AS ACC BCC CSS CXX Aab Cb Xb. By repetition of Step 1 we get: Choose Aa in order to eliminate A. We get: SaB R1SB BaR2 R2aS BCC CSS CXX Cb Xb. Choose Cb in order to eliminate C. We get: SaB R1SB BaR2 R2aS Bbb Xb. Choose Xb in order to eliminate X. We get: SaB R1SB BaR2 R2aS Bbb. Now, choose Bbb to eliminate B. We get: Sabb R1Sbb R2aS Finally, choose Sabb to eliminate S. So, according to Step 2 of Theorem 42, the CFG generates at least one word, so the CFL is nonempty. Chapter 18, page 429, number 3(viii) The CFG has productions: SXX XSSa. Apply Theorem 42. Use Xa to eliminate X. We then get Saa. Use Saa to eliminate S. We get no productions. It follows that the CFG generates at least one word. We are left with no nonterminals, so none of the nonterminals are unproductive. Apply Theorem 43. There are no nonterminals to eliminate from the productions, so we have: SXX XSSa Is X useful? Paint all X's blue (well okay, just underline them) and we get: SXX XSS│a and then SXX XSS│a. S is blue, so X is useful. Is S useful? Paint all S's blue and we get: SXX XSS│a and so, trivially, S is useful. Apply Theorem 44. There are no productions to eliminate, so we have: SXX XSS│a. Is X self-embedded? Change X to on the left sides. We get: SXX SS│a. Paint all X's blue. We get: SXX SS│a and then SXX SS│a followed by SXX SS│a. Thus X is self-embedded and the CFL is infinite. As X is useful, we can stop at this point. We opt however to also check whether S is self-embedded; remember all teachers' favourite maxim: "Practice makes perfect". Is S self-embedded? Change S to on the left sides: XX XSS│a Paint all S's blue (in our case underline them): XX XSS│a and then XX XSS│a followed by XX XSS│a. It follows that S is self-embedded and the CFL is infinite. Chapter 18, page 430, number 5 Cohen defines live and dead productions on page 351. Now, if S is the only nonterminal, all live productions have the form SSS and dead productions are of the form St where t is some terminal in the grammar. We give two solutions to this problem. Here is our first solution. We observe that S is useful as it generates at least one word (namely t above we are given that there is at least one dead production). Also, S is self-embedded due to the presence of the production SSS so that infinitely many words can be generated (by repeating the production SSS any number of times). Therefore the language generated by this CFG is infinite. Our second solution shows how to apply the algorithm in the proof of Theorem 44 to show that the language generated by the CFG is infinite. Step 1 of the algorithm given in the proof of Theorem 44, involves the algorithm of Theorem 43. Step 1 of Theorem 43 involves the algorithm of Theorem 42 and that algorithm starts off by converting the given CFG into CNF. So, during the application of Theorem 42 to prove that the CFG generates at least one word, we convert the given CFG into CNF. As S is the only nonterminal, productions of the form SSS and St will also be present in the grammar converted into CNF. It follows from the presence of the production St that the grammar generates at least one word, so S is not unproductive. Now apply the algorithm of Theorem 43. There are no nonterminals to eliminate (as the only nonterminal S is not unproductive), so we start again with the original set of productions. Is S useful? Well, paint all S's blue, then obviously S is blue, so S is useful. We are now in a position to apply the algorithm of Theorem 44. There are no productions to eliminate since all nonterminals (well O.K., only S) are useful, so we start with the original productions. Is S self-embedded? According to the algorithm, change S to on the left sides of all productions. In particular, the production SSS will now become SS. Paint all the S's blue. It is clear that becomes blue in the next step because of the existence of the production SS, so S is self-embedded. According to the algorithm of Theorem 44, the CFL is infinite. Chapter 18, page 431, number 13(ii) The grammar for PLUS-TIMES, given on page 415, is: SE ET+E│T TF*T│F F(E)│i. The expression we wish to parse is: i*i+i*i. Let us see: S E T T+E F*T+E i*T+E i*F+E i*i+E i*i+T i*i+T+E i*i+F*T i*i+F i*i+i*T i*i+(E)*T i*i+i*F i*i+i*i i * i + i *F * T i*i+i*(E) i*F*T+E i*(E)+E (E)*T+E F+E So a left-most derivation is: SET+EF*T+Ei*T+Ei*F+Ei*i+E i*i+Ti*i+F*Ti*i+i*Ti*i+i*Fi*i+i*i Note that in the figure above we terminated the first rightmost branch at the non-terminal T. Strictly speaking this is not correct as this branch can be expanded three more levels downwards before all branches are terminated. As all branches eventually terminate, we opted not to draw these expansions in. You however, should in general not follow such shortcuts but rather give completely motivated answers. Check the validity of this remark by filling in the missing expansions on the above figure. Also, give reasons for terminating all the rightmost branches. Chapter 18, page 431, number 14(ii) The expression is ((i)+((i))). We will only follow a correct path - you should fill in the whole tree. . Write down a derivation of ((i)+((i))) from the above.