# How to find a context-free grammar from a difficult language? [duplicate]

Some Languages are trivial to find their respective context-free grammar. Like for example $$L= \{a^nb^n: n \geqslant 0\}$$. However some are really difficult to solve. I would like to have some advice on how I can tackle them.

For example I have the following language that I have been trying to solve for a while :

I tried to divide the problem into three cases as follow:

case i: na $$\le$$ nb

case ii: nb $$\le$$ na $$<$$ 2nb

case iii: na $$\ge$$ 2nb

The first case was easy to solve however I am stuck in case ii. At this point I don't even know if the procedure that I chose is the correct one.

EDIT: It is not an duplicate 3 of the links that you have provided me are not the same problem one of them is the same suggests the same strategy however doesn't solve the problem.

• @D.W.♦ It is not an duplicate 3 of the links that you have provided me are not the same problem one of them is the same suggests the same strategy however doesn't solve the problem. Oct 19 '19 at 16:20
• You should be able to adapt the methods there; it's the same idea. Hint: build a PDA.
– D.W.
Oct 19 '19 at 20:22