0

enter code hereHallo, this is my question

Give context free grammar for CFL L = {a^nb^mc^n | m, n ∈ N0}

My answer is S-> ASC| B A-> aA| a B-> bB| b C-> cC| c

Whether my answer or not ? I am not sure about it. Need some help. thanks in advance

  • What is N0 in your question? – Ray Toal Jun 20 '17 at 16:47
  • 1
    Also this isn't a programming question. I think you would have better luck on either computerscience.stackexchange.com or cstheory.stackexchange.com – Ray Toal Jun 20 '17 at 16:49
  • 2
    @ray: cstheory.se is for "research-level questions in theoretical computer science". This question does not qualify. Cs.se would be appropriate for simple q's about CFGs but "check my homework" q's are discouraged, even more so than here. Suggesting that a question be migrated to a site for which it is inappropriate is not doing anyone any favours. – rici Jun 20 '17 at 17:23
  • @ejaz: generate the first few sentences from your grammar. Are they all part of the language? If not, you know the grammar is wrong. – rici Jun 20 '17 at 17:26

1 Answers1

3

Your grammar generates the language

L = {a^n b^m c^k | m, n, k ∈ N0}

because the numbers of times that the rules A->aA and C->cC are applied are independent. If you want n=k, then you have to generate the a and c in the same rule. For example like this:

S -> aSc | B .

In a second phase you generate an arbitrary number of b in the middle:

B -> bB | <empty string> .
Peter Leupold
  • 1,162
  • 1
  • 9
  • 16