given CFG G1 = {V1, Σ1, R1, S1} in its CNF form,
I have to define a new G5 grammar that constructs L(G5) using {V1, Σ1, R1, S1}:
while L(G5) = { x ∈ L(G1) | |x| is even }
i . e .
L(G5) composed of all even length words in L(G1)
How can I do it?
given CFG G1 = {V1, Σ1, R1, S1} in its CNF form,
I have to define a new G5 grammar that constructs L(G5) using {V1, Σ1, R1, S1}:
while L(G5) = { x ∈ L(G1) | |x| is even }
i . e .
L(G5) composed of all even length words in L(G1)
How can I do it?
This is a specific application of the fact that context-free languages are closed under under intersection with a regular languages. The usual proof is to use the fact that we can find a pushdown automaton and a finite state automaton, and then for the intersection simulate the pair in parallel. This is called the product construction.
Here there is a simple solution directly on the context-free grammar. For each nonterminal $A$ introduce two copies $A_e$ and $A_o$ that together derive the same set of strings, but separated into even length and odd length respectively. The productions must be annotated with odd and even accordingly.