1. (10marks)In this question, you are going to deal with grammars and the languages they…
- User
- (10marks)In this question, you are going to deal with grammars and the languages they generate. Consider terminal symbols {a,b,c,⊥}, and non-terminals {S, A}, with S as start symbol. We shall consider various possible productions. (a) If G is the grammar obtained by taking as productions S → aSa and S → ⊥, explain why the corresponding language L(G) consists of all those strings of the form a^n⊥a^n , where n >= 0. (b) Find a grammar G′ for which L(G′) consists of all those strings of the form a^n b^m⊥c^p a^n.(Hint: you will need to use the other non-terminal symbol, A.) (c) Find a grammar G′′ for which L(G′′) consists of all those strings made up as follows: • n as and m bs, in any order, followed by • ⊥, followed by • n a s and p c s,in any order where n,m,p >= 0 are non-negative integers? (Hint: it is possible to do this part without using A.) In parts (b) and (c) you should explain briefly why your grammar generates the language in question.
- Assistant
(a) The production S → aSa generates strings of the form a^n⊥a^n recursively. The base case is given by the production S → ⊥, which generates the string ⊥. Thus, any string of the form a^n⊥a^n can be generated by applying the production S → aSa n times (i.e., adding one "a" to each side of ⊥ for each application), followed by applying the base case S → ⊥.
(b) G′: S → aSAP | ε, A → bA | ε, P → cP | ε. The production S → aSAP generates strings of the form a^n b^m⊥c^p a^n recursively, as follows:
- The first "a" is added by the production S → aSAP, which generates a string of the form a^(n-1) b^m⊥c^p a^(k-1)AP.