Combination of 2 context free grammars

241 Views Asked by At

I am required to show that the language $L$ is context-free where $$L = \{q_1q_2 \dotsm q_nt_1t_2 \dotsm t_n \mid q_i \in Q, t_i \in T, n \geq 0 \}$$ where $Q$ and $T$ are context-free languages.

I feel the simplest way would be just to write the grammar.

$S \to ASB∣ \epsilon$
where $A$ generates $Q$ and $B$ generates $T$ (whose existence is guaranteed since $Q$, $T$ are CFL) almost solves the problem. But it also generates strings like $q_1q_2t_3t_4$. I cannot make any further progress. Any help would be appreciated !

1

There are 1 best solutions below

1
On

By $s_1s_2t_3t_4$ do you mean $q_1q_2t_3t_4$?

And is it a problem for the subscripts to be different?

I'm under the impression that the important thing is that we are concatenating a string from one CFL with an equal length string from the other, in which case you would merely need to add in something like

$A\rightarrow q_i | q_j$

$B\rightarrow t_i | t_j$

to complete the CFL.