You are on page 1of 4
We need to write a grammar that generates all strings over (a, } starting with an a Lot $ be the start symbol Start symbol = 5 T contains all terminal symbols, which are the a’s and the b's in this ease. Next, we want to string to start with an a and thus the string needs to be ‘of the form aA with A any string over (a, 5). Saad Next, we want A to be any string, thus we can add an a or b to the string ft any time, or we do not add anything at all Asad AsbA AsA $404, Asad, ASO AD a, Lot S be the start symbol ubol = $ Start sy T contains all terminal symbols, which are the a’s and the 8's in this ease T= {a,b} Next, we want to string to contain ab and thus the string needs to be of the form AabA with A any string over {a,b} (while the two oceurrences of A do not need to be the same string) S AabA Next, we want A to be any string, thus we can add an a o 6 to the string fat any time, or we do not add anything at all Asad Aba AOD Finally, is the set of all nonterminal symbols, which are $ and A in this S.A} RESULT S AabA Asad Asta Ad We need to write a grammar that generates all strings over {a,} ending swith bt Let S be the start symbol. Start symbol = 5 T contains all terminal symbols, which are the a’s and the b's in this case T= {a,b} Next, we want to string to end with ba and thus the string needs to be of ‘the form Aba with A any string over {a,5}. S> Aba Next, we want A to be any string, thus we ean add an @ or 6 to the string ‘at any time, or we do not add angthing at all. Asad Asta Aad Finally, Nis the sot of all nonterminal symbols, which are S and A in this = {SA} RESULT S3 Aba Asad As bA Ao) T contains all terminal symbols, which aro the a's and the 5's in this ease. T= (2.8) ‘The strings can't end with ad, thus the strings need to end with aa, 6a, oF bf they contain at least two syrabols. This implies thot the strings are of ‘the form Aaa, Aba or Abb, with A any string aver (a, 8) S Aaa So Aba Sab However, the empty string ond the strings ofone symhol need to be generates as woll Sos Sasa sb Next, we want 4 to be any string, thus we can add an a or f to the string at any time, or we do not odd anthing ot al Asad AsbA Aa) Finally, is the set of all nonterminal symbols, which are $ and Ain this N ={S.A} S + Aaa S+ Aba S+ Ab 54. Sa Sb Asad AsbA As)

You might also like