5
votes

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?

6
If it had been homework I would have marked it, like I said, I'm studying for a test. I'm taking away the homework tag. Man, Homework != Testandandandand
Why so defensive on the homework tag? Studying for a test sounds like homework or at least "schoolwork" & the tag helps people looking for such questions find this one.CoderDennis
Actually it's the "finite automata & grammars" part that sounds like homework. Doesn't matter if it's for a test or not.CoderDennis
people looking for this question would look for "automata", "language" or "grammar" not "homework". Since I'm not asking you to do my homework it would be both a misplaced and meaningless tag.andandandand
Shouldn't such questions be migrated to Theoretical Computer Science?Pale Blue Dot

6 Answers

8
votes

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.

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

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

2
votes

Yes, this does sound like homework, but a hint:

Every time you match an 'a', you must match a 'c'. Same for matching a 'b'.

0
votes

S->aSc|A A->bAc|λ

This means when ever you get a at least you have 1 c or if you get a and b you must have 2 c. i hope it has been helpful

0
votes

Well guys, this is how I'll do it:

P={S::=X|epsilon,
   X::=aXc|M|epsilon,
   M::=bMc|epsilon}
0
votes

My answer:

S -> aAc | aSc

A -> bc | bAc

where S is the start symbol.