70 likes | 161 Views
Chapter 8 Properties of CFL. 8.2: Closure Properties for CFL (1). A set is closed under some operation if performing that operation on members of the set always produces a member of that set. Assume that L 1 , L 2 are context-free languages
E N D
8.2: Closure Properties for CFL (1) A set is closed under some operation if performing that operation on members of the set always produces a member of that set. Assume that L1, L2 are context-free languages CFG for L1is G1 = (NT1 , 1, P1, S1} CFG for L2is G2 = (NT2 , 2, P2, S2} R is a regular language CFLs are closed under the operations of Union, concatenation, Kleene closure CFLs are not closed under Intersection, complementation
8.2: Closure Properties for CFL (2) UnionL = L1L2 G = ({S} NT1 NT2, 1 2, P1 P2 {SS1| S2}, S) Concatenation L = L1L2 G = ({S} NT1 NT2, 1 2, P1 P2 {SS1S2}, S) Closure L = L1* G = ({S} NT1, 1, P1 {S | S1S}, S) Assumes Non-terminl names distinct in NT1 and NT2. Otherwise, can rename consistently.
8.2: Closure Properties for CFL (3) Intersection L = L1L2 L not necessarily context-free. CFLs are not closed under intersection! Can’t simulate two stacks by one stack. L1 = {anbncm | n, m 0} is CFL L2 = {anbmcm | n, m 0} is CFL L = L1L2 = {akbkck | k 0} is NOT CFL
8.2: Closure Properties for CFL (4) __ Complementation L = L1 L not necessarily context-free. CFLs are not closed under complementation! By DeMorgan’s Law, since union closed, if complementation closed, so is intersection. (contradiction)
8.2: Closure Properties for CFL (5) Intersection with RL L = L1R L is context-free. Intuition: Only one stack to simulate, so OK. Example: show that L = {anbn: n ≥ 0, n ≠ 100} is context-free L1= {anbn: n ≥ 0} is context-free L2= {a100b100} is finite, so it is regular __ L2 is regular (regular languages closed under complementation) __ L = L1L2 is context-free
8.2: Closure Properties for CFL (6) For any context free grammar, we can decide: membership (can the grammar generate a given string) if it is empty (the grammar does not generate any strings) if it is infinite (the grammar generates and infinite number of strings) However, there is no algorithm for deciding whether two context-free grammars generate the same language!