Explain the context free language closure under concatenation?


Here CFL refers to Context Free Language. Now, let us understand closure under concatenation.

Closure under Concatenations

If L1 and L2 are CFLs, then L1L2 is a CFL.

Follow the steps given below −

L1 CFL implies that L1 has CFG1 that generates it.

  • Assume that the nonterminals in CFG1 are S, A, B, C, . . ..

  • Change the nonterminal in CFG1 to S1, A1, B1, C1, . . ..

  • Don’t change the terminals in the CFG1.

L2 CFL implies that L2 has CFG2 that generates it.

  • Assume that the nonterminals in CFG2 are S, A, B, C, . . ..

  • Change the nonterminal in CFG2 to S2, A2, B2, C2, . . ..

  • Don’t change the terminals in the CFG2.

Now CFG1 and CFG2 have non intersecting sets of nonterminals.

Then we create a CFG for L1L2 as follows −

  • Include all the nonterminal S1, A1, B1, C1, . . . and S2, A2, B2, C2, . . ..

  • Include all the productions of CFG1 and CFG2.

Create a new nonterminal S and a production

S → S1S2

Example

CFG1 for L1
S → SS | TaTb |FFF | ∧
T → SaS | bFb | abba
F → SSS | baab
CFG2 for L2
S → aS | aTba | FbF | ∧
T → aSa | abab
F → FabaF | bb

To construct CFG for L1L2, follow the steps given below −

  • Transform CFG1

S1 → S1S1 | T1aT1b | F1F1F1 | ∧
T1 → S1aS1 | bF1b | abba
F1 → S1S1S1 | baab
  • Transform CFG2

S2 → aS2 | aT2ba | F2bF2 | ∧
T2 → aS2a | abab
F2 → F2abaF2 | bb
  • Construct CFG for L1L2 −

S → S1S2
S1 → S1S1 | T1aT1b | F1F1F1 | ∧
T1 → S1aS1 | bF1b | abba
F1 → S1S1S1 | baab
S2 → aS2 | aT2ba | F2bF2 | ∧
T2 → aS2a | abab
F2 → F2abaF2 | bb

Updated on: 16-Jun-2021

616 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements