Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I construct a grammar that generates this language?

I'm studying for a finite automata & grammars test and I'm stuck with this question:

Construct a grammar that generates L:
L = {a^n b^m c^m+n|n>=0, m>=0}

I believe my productions should go along this lines:

    S->aA | aB
    B->bB | bC
    C->cC | c Here's where I have doubts

How can my production for C remember the numbers of m and n? I'm guessing this must rather be a context-free grammar, if so, how should it be?

like image 902
andandandand Avatar asked Jun 20 '09 15:06

andandandand


2 Answers

Seems like it should be like:

A->aAc | aBc | ac | epsilon
B->bBc | bc | epsilon

You need to force C'c to be counted during construction process. In order to show it's context-free, I would consider to use Pump Lemma.

like image 111
Artem Barger Avatar answered Sep 20 '22 06:09

Artem Barger


S -> X
X -> aXc | Y
Y -> bYc | e

where e == epsilon and X is unnecessary but added for clarity

like image 20
Dr_Bob_Smith Avatar answered Sep 23 '22 06:09

Dr_Bob_Smith