Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Module 31 Closure Properties for CFL’s –Kleene Closure –Union –Concatenation CFL’s versus regular languages –regular languages subset of CFL.

Similar presentations


Presentation on theme: "1 Module 31 Closure Properties for CFL’s –Kleene Closure –Union –Concatenation CFL’s versus regular languages –regular languages subset of CFL."— Presentation transcript:

1 1 Module 31 Closure Properties for CFL’s –Kleene Closure –Union –Concatenation CFL’s versus regular languages –regular languages subset of CFL

2 2 Closure Properties for CFL’s Kleene Closure

3 3 CFL closed under Kleene Closure Let L be an arbitrary CFL Let G 1 be a CFG s.t. L(G 1 ) = L –G 1 exists by definition of L 1 in CFL Construct CFG G 2 from CFG G 1 Argue L(G 2 ) = L * There exists CFG G 2 s.t. L(G 2 ) = L * L * is a CFL

4 4 Visualization L*L* L CFL CFG’s Let L be an arbitrary CFL Let G 1 be a CFG s.t. L(G 1 ) = L –G 1 exists by definition of L 1 in CFL Construct CFG G 2 from CFG G 1 Argue L(G 2 ) = L * There exists CFG G 2 s.t. L(G 2 ) = L * L * is a CFL G1G1 G2G2

5 5 Algorithm Specification Input –CFG G 1 Output –CFG G 2 such that L(G 2 ) = CFG G 1 CFG G 2 A

6 6 Construction Input –CFG G 1 = (V 1, , S 1, P 1 ) Output –CFG G 2 = (V 2, , S 2, P 2 ) V 2 = V 1 union {T} – T is a new symbol not in V 1 or  S 2 = T P 2 = P 1 union ??

7 7 Closure Properties for CFL’s Kleene Closure Examples

8 8 Input grammar: –V = {S} –  = {a,b} –S = S –P: S → aa | ab | ba | bb Output grammar –V = –  = {a,b} –Start symbol is –P: Example 1 V 2 = V 1 union {T} T is a new symbol not in V 1 or  S 2 = T P 2 = P 1 union {T → ST | }

9 9 Input grammar: –V = {S, T} –  = {a,b} –Start symbol is T –P: T → ST | S → aa | ab | ba | bb Output grammar –V = –  = {a,b} –Start symbol is –P: Example 2 V 2 = V 1 union {T} T is a new symbol not in V 1 or  S 2 = T P 2 = P 1 union {T → ST | }

10 10 Construction for Set Union Input –CFG G 1 = (V 1, , S 1, P 1 ) –CFG G 2 = (V 2, , S 2, P 2 ) Output –CFG G 3 = (V 3, , S 3, P 3 ) V 3 = V 1 union V 2 union {T} –Variable renaming to insure no names shared between V 1 and V 2 – T is a new symbol not in V 1 or V 2 or  S 3 = T P 3 =

11 11 Construction for Set Concatenation Input –CFG G 1 = (V 1, , S 1, P 1 ) –CFG G 2 = (V 2, , S 2, P 2 ) Output –CFG G 3 = (V 3, , S 3, P 3 ) V 3 = V 1 union V 2 union {T} –Variable renaming to insure no names shared between V 1 and V 2 – T is a new symbol not in V 1 or V 2 or  S 3 = T P 3 =

12 12 CFL’s and regular languages

13 13 CFL Closure Properties What have we just proven –CFL’s are closed under Kleene closure –CFL’s are closed under set union –CFL’s are closed under set concatenation What can we conclude from these 3 results? –It follows that regular languages are a subset of CFL’s

14 14 Regular languages subset of CFL Similar to reg-exp to NFA-λ construction from module 22 –Base Case: {}, { }, {a}, {b} are regular languages over {a,b} P={}, P={S → }, P={S → a}, P={S → b} –Inductive Case: If L 1 and L 2 are are regular languages, then L 1 *, L 1 L 2, L 1 union L 2 are regular languages Use previous constructions to see that these resulting languages are also context-free

15 15 Other CFL Closure Properties We will show that CFL’s are NOT closed under many other set operations Examples include –set complement –set intersection –set difference

16 16 Language class hierarchy All languages over alphabet  RE REG H H Equal CFL REC ?


Download ppt "1 Module 31 Closure Properties for CFL’s –Kleene Closure –Union –Concatenation CFL’s versus regular languages –regular languages subset of CFL."

Similar presentations


Ads by Google