1

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?

Eran
  • 11
  • 2

1 Answers1

4

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.

Hendrik Jan
  • 31,459
  • 1
  • 54
  • 109