So in preparation for an interview, I have been revising and studying by solving some CFGs, and here is a question, which I solved, but I feel like I haven't solved it right, given its boundary requirements.
Give a CFG for the set of all strings in the form $O^i 1^j 2^k 3^l$ where $0 \leq j \leq 2i$ and $k=l$.
My approach: When $j=2$, $i=2$, and $k=3$ I started solving this (do share some of your tips and hints in solving CFGs, it would help me alot and I would appreciate your expertise tips) I produced a string
$$011222333$$
And given that, after analyzing it, I came up with this grammar
$$S \to OA$$ $$A \to 1A1B|\epsilon$$ $$B \to 2BC|\epsilon$$ $$C \to 3c|\epsilon$$
I was able to produce that string from the above grammar, but I feel like I was intentionally selecting and choosing when to choose epsilon, almost forcing my grammar to work, it felt weird.
Your assistance, plus tips will greatly help!
0
,01
and011
are in the language. When you pick $i = 2$ then you get00
,001
,0011
,00111
and001111
. Similarly for bigger $i$-s. – dtldarek Apr 05 '13 at 19:40