Math Is Fun Forum

  Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °

You are not logged in.

#1 2008-08-11 08:18:13

Kenshinofkin
Member
Registered: 2008-07-08
Posts: 6

Context-free grammar

Create a context-free grammar that generates the language a^nb^(n+m)c^m.

I came up with this so far:

S -> aAc
A -> bb

But this only does the case with abbc. Can anyone help with this one?

Offline

#2 2008-08-12 01:06:58

TheDude
Member
Registered: 2007-10-23
Posts: 361

Re: Context-free grammar

You're on the right track, but notice that your grammar requires an equal amount of a's and c's.  What you need is a grammar that produces an equal amount of a's and b's at first, then changes to produce an equal amount of b's and c's.  I'll start you off:

S -> aAb
S -> B
S -> empty
A -> aCbB
A -> empty

I'll leave B and C to you.


Wrap it in bacon

Offline

Board footer

Powered by FluxBB