positive properties
play

Positive Properties are closed under: Union of Context-Free - PDF document

Review Languages and Grammars Alphabets, strings, languages Regular Languages CS 301 - Lecture 18 Deterministic Finite and Nondeterministic Automata Equivalence of NFA and DFA Regular Expressions Properties of Context


  1. Review • Languages and Grammars – Alphabets, strings, languages • Regular Languages CS 301 - Lecture 18 – Deterministic Finite and Nondeterministic Automata – Equivalence of NFA and DFA – Regular Expressions Properties of Context Free – Regular Grammars – Properties of Regular Languages – Languages that are not regular and the pumping lemma Grammars • Context Free Languages – Context Free Grammars Fall 2008 – Derivations: leftmost, rightmost and derivation trees – Parsing and ambiguity – Simplifications and Normal Forms – Nondeterministic Pushdown Automata – Pushdown Automata and Context Free Grammars – Deterministic Pushdown Automata – Pumping Lemma for Context Free Grammars • Today: – Closure and Decidable Properties for Context Free Languages Union Context-free languages Positive Properties are closed under: Union of Context-Free languages L is context free 1 L ∪ L 1 2 L is context free is context-free 2 1

  2. Example In general: L 1 , L Language Grammar For context-free languages 2 with context-free grammars G 1 , G 2 n b n L = { a } S → aS b | and start variables λ 1 S 1 , S 1 1 2 R L = { ww } S → aS a | bS b | λ 2 2 2 2 L ∪ L The grammar of the union 1 2 Union S has new start variable and additional production S → S 1 | S n n R 2 S → S 1 | S L { a b } { ww } = ∪ 2 Example Concatenation Language Grammar Context-free languages n b n Concatenation are closed under: L = { a } S → aS b | λ 1 1 1 R L = { ww } S → aS a | bS b | λ 2 L is context free 2 2 2 1 L 1 L 2 Concatenation L is context free is context-free 2 n n R S → S 1 S L = { a b }{ ww } 2 2

  3. In general: Star Operation L 1 , L For context-free languages 2 with context-free grammars G 1 , G 2 and start variables S 1 , S Context-free languages 2 are closed under: Star-operation L 1 L The grammar of the concatenation 2 S has new start variable * L is context free L is context-free and additional production S → S 1 S 2 Example In general: For context-free language L Language Grammar with context-free grammar G and start variable n b n S L = { a } S → aSb | λ Star Operation The grammar of the star operation L * S has new start variable 1 and additional production S → SS | n b n λ L = { a } * S → SS | 1 1 λ 1 1 3

  4. Intersection Negative Properties Context-free languages are not closed under: intersection of Context-Free Languages L is context free 1 L ∩ L 1 2 L is context free not necessarily 2 context-free Example Complement n n m n m m L = { a b c } L = { a b c } 1 2 Context-free: Context-free: Context-free languages S AC S AB are not closed under: complement → → A aAb | A aA | → λ → λ C cC | B bBc | → λ → λ is context free L not necessarily L context-free Intersection n n n L L { a b c } NOT context-free ∩ = 1 2 4

  5. Example n n m n m m L = { a b c } L = { a b c } Intersection 1 2 Context-free: Context-free: of S AC S AB Context-free languages → → A aAb | A aA | and → λ → λ C cC | B bBc | Regular Languages → λ → λ Complement n n n L L L L { a b c } ∪ = ∩ = 1 2 1 2 NOT context-free The intersection of Machine M Machine M 1 2 a context-free language and DFA for L NPDA for L 2 a regular language 1 regular is a context-free language context-free Construct a new NPDA machine M L context free that accepts L ∩ L 1 1 2 L ∩ L 1 2 regular L M M context-free M simulates in parallel and 2 1 2 5

  6. NPDA M DFA M NPDA M DFA M 1 2 1 2 a , b c , b → c a → λ q q q q p p p 1 2 1 2 1 2 1 transition transition transition NPDA NPDA M M a , b c , b → c → λ q 1 , p q 1 , p q 2 , p q 2 , p 1 1 2 1 transition transition NPDA M DFA M NPDA M DFA M 1 2 1 2 q p q p p 1 1 0 2 0 initial state final state initial state final states NPDA NPDA M M q 0 , p q 1 , p q 1 , p 0 1 2 Initial state final states 6

  7. Example: context-free regular * * * L { w w : | w | | w |, w { a , b } , w { c , d } } = = ∈ ∈ L = { a , c } 1 1 2 1 2 1 2 2 NPDA M M 1 DFA 2 a , 1 c , 1 a , c λ → → λ b , 1 d , 1 λ → → λ p , , , 0 λ λ → λ λ λ → λ λ λ → λ q q q q 0 1 2 3 context-free In General: n n Automaton for: L L { a c : n 0 } ∩ = ≥ 1 2 M M M simulates in parallel and 1 2 NPDA M M accepts string if and only if w a , 1 c , 1 λ → → λ M accepts string and w 1 accepts string M w , , , λ λ → λ λ λ → λ λ λ → λ 2 q 0 , p q 1 , p q 2 , p q 3 , p 0 0 0 0 L ( M ) L ( M ) L ( M ) = ∩ 1 2 7

  8. Therefore: is NPDA M Applications of L ( M ) L ( M ) is context-free ∩ Regular Closure 1 2 L ∩ L is context-free 1 2 The intersection of An Application of Regular a context-free language and Closure a regular language is a context-free language n n Prove that: L { a b : n 100 , n 0 } = ≠ ≥ Regular Closure is context-free L context free 1 L ∩ L 1 2 regular L context-free 2 8

  9. We also know: We know: n n 100 100 { a b : n 0 } is context-free ≥ L = { a b } is regular 1 * 100 100 is regular L {( a b ) } { a b } = + − 1 n b n * 100 100 { a } L {( a b ) } { a b } = + − 1 Another Application of Regular context-free regular Closure L { w : n n n } Prove that: = = = a b c n n { a b } L (regular closure) context-free ∩ 1 is not context-free n n n n { a b } L { a b : n 100 , n 0 } L ∩ = ≠ ≥ = 1 is context-free 9

  10. L { w : n n n } is context-free If = = = a b c (regular closure) Decidable Properties n n n Then L { a * b * c *} { a b c } ∩ = of Context-Free Languages context-free regular context-free Impossible!!! Therefore, is not context free L Empty Language Question: Membership Question: for context-free grammar G for context-free grammar G find if string w ∈ L ( G ) find if L ( G ) = ∅ Membership Algorithms: Parsers Algorithm: 1. Remove useless variables • Exhaustive search parser • CYK parsing algorithm S 2. Check if start variable is useless 10

  11. Infinite Language Question: Example: S AB → G for context-free grammar A aCb | a → L ( G ) find if is infinite B bB | bb → Algorithm: C cBS → 1. Remove useless variables Infinite language Dependency graph 2. Remove unit and productions λ 3. Create dependency graph for variables A C 4. If there is a loop in the dependency graph S then the language is infinite B S AB → What’s Next A aCb | a → • Read B bB | bb – Linz Chapter 1,2.1, 2.2, 2.3, (skip 2.4), 3, 4, 5, 6.1, 6.2, (skip 6.3), 7.1, 7.2, 7.3, (skip → 7.4), 8, and 9.1 – JFLAP Chapter 1, 2.1, (skip 2.2), 3, 4, 5, 6, 7, (skip 8), 9.1, 9.2 C cBS → • Next Lecture Topics From 9.1 – Turing Machines • Quiz 3 in Recitation on Wednesday 11/12 S AB aCbB acBSbB acbbSbbb – Covers Linz 7.1, 7.2, 7.3, (skip 7.4), 8, and JFLAP 5,6,7 ⇒ ⇒ ⇒ ⇒ – Closed book, but you may bring one sheet of 8.5 x 11 inch paper with any notes you like. – Quiz will take the full hour ∗ ∗ 2 2 Homework • S acbbSbbb ( acbb ) S ( bbb ) ⇒ ⇒ – Homework Due Today – New Homework Available Friday – New Homework Due Next Thursday ∗ i i ( acbb ) S ( bbb ) ⇒ 11

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend