# I want to design a context free grammar for the following [closed]

This below language

$$L = \{ w \in \{a, b\}^n : \lvert w\rvert \text{ mod } 3 = 0 \}$$ where $$n \geq0$$.

## closed as unclear what you're asking by xskxzr, Evil, Discrete lizard♦Oct 9 at 16:57

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

• Could you design a CFG for a language where each string had length exactly three? If so, it's just a tiny modification to get what you want. – Rick Decker Oct 8 at 18:53

## 1 Answer

Since this seems very much like homework, i will give you a little Hint, taking as example a sub-case of your language:

The GFC for the string $$a^3b^3$$ is the following:

$$S ⇒ aSb$$

$$aSb ⇒ aaSbb$$

$$aaSbb ⇒ aaaSbbb$$

$$aaaSbbb ⇒ aaabbb$$

You can take the above as a starting point from which to adapt the grammar to your case.

• Thank you very much – Abhimanyu Bansal Oct 27 at 7:35