Free context grammar for $\mathscr{L_2}=\{0^i1^j2^k|i,j,k\geq0,i+j=2k\}$

351 Views Asked by At

I need to bulid a free context grammar for $\mathscr{L_2}=\{0^i1^j2^k|i,j,k\geq0,i+j=2k\}$

My try: Let denote $T_{x}$ for $k=x$

$$S\to T_{0,1}|T_2\\T_{0,1}\to\epsilon|002|112|012\\T_2\to 00T_{0,1}2|011122|111122$$

Maybe similar question here

I'm stuck here

1

There are 1 best solutions below

0
On BEST ANSWER

You need to add any two symbols of $\{0,1\}$ when adding one $2$, so there are three options: $$S \to T_{00} \\ T_{00} \to 00T_{00}2|T_{01} \\ T_{01} \to 01T_{11}2|T_{11} \\ T_{11} \to 11T_{11}2|\epsilon$$