Theory Of Computation (2160704)

BE | Semester-7   Winter-2018 | 27/11/2018

Q3) (b)

Explain Union Rule and Concatenation Rule for Context Free Grammar

Union Rule

  • If L1 and L2 are context - free languages, then the languages L1 U L2 is also CFL(context - free languages).
  • Union : Gu = (Vu, Σ, Su, Pu)

    • A grammar Gu = (Vu, Σ, Su, Pu) generating L1 U L2.
    • First we rename the element of V2 if necessary so that V1 n V2= ∅
    • Vu= V1 U V2 U {Su}
    • Where Su is a new symbol not in V1 or V2.
    • Then we let Pu= P1 U P2 U { Su --> S1 | S2 }
    • On the other hand, if x is derivable from Su in Gu, the first step in any derivation must be
    • Su -> S1 or Su -> S2
    • In the first case, all subsequent productions used must be productions in G1, because no variables in V2 are involved, and thus x ∈ L1; in the second case, x ∈ L2. Therefore,
    • L(Gu) ⊆ L1 U L2

Concatenation

  • If L1 and L2 are context - free languages, then the languages L1L2 is also CFL(context - free languages).
  • Concatenation Gc= (Vc, Σ, Sc, Pc)

    • A grammar Gc= (Vc, Σ, Sc, Pc) generating L1L2 .
    • Again we relabeled variables if necessary so that V1 ∩ V2 = ∅ and
    • define Vc = V1 ∪ V2 ∪ {Sc}
    • This time we let
    • Pc= P1 ∪ P2 ∪ { Sc -> S1S2 }
    • If x ∈ L1L2 then x = x1x2 , where xi ∈ Li for each i. we may then derive x in Gc as follows:
    • Sc -> S1 S2 -> *x1 S2 -> * x1x2 = x
    • First step in the derivation must be Sc -> S1S2 Where the second step is the derivation of x1 in G1 and the third step is the derivation of x2 in G2. So x ∈ L1L2