1 / 18

CSE 105 Theory of Computation

CSE 105 Theory of Computation. Alexander Tsiatas Spring 2012. Theory of Computation Lecture Slides by Alexander Tsiatas is licensed under a Creative Commons Attribution- NonCommercial - ShareAlike 3.0 Unported License. Based on a work at http://peerinstruction4cs.org.

mariko
Download Presentation

CSE 105 Theory of Computation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSE 105Theory of Computation Alexander Tsiatas Spring 2012 Theory of Computation Lecture Slides by Alexander Tsiatas is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. Based on a work at http://peerinstruction4cs.org. Permissions beyond the scope of this license may be available at http://peerinstruction4cs.org.

  2. From Preliminary Exam 1 • Regular languages are closed under union. • If L1 and L2 are regular, then is L1 U L2 regular? • a) true • b) false

  3. From Preliminary Exam 1 • Regular languages are closed under union. • If L1 U L2 is regular, are L1 and L2 both regular? • a) true • b) false

  4. From Preliminary Exam 1 • Direction Matters. • “If P, then Q” does NOT mean “if Q, then P”. • It does mean “If not Q, then not P”, which is how we use the pumping lemma to prove that languages are not regular. • Direction Matters even more, later in the course.

  5. Back to your [English/Spanish/French/…] class Context-Free GrammarsCFGs

  6. Context-free Grammars (CFG) • Context-free grammars are one way that scholars have tried to model how language, and our brain’s models of language, might be structured • Key concept: representing and generating infinite complexity, with just a few simple rules

  7. What is the language of this CFG? S → 0S S → 0 • {0} • {0, 00, 000, …} • {ε, 0, 00, 000, …} • None of the above

  8. The LANGUAGE of a CFG • The set of strings that can be generated following the given production rules. • Every string generated is in the language, and every string that cannot be generated is not in the language.

  9. What is the language of this CFG? S → 0S S → 1S S → ε • Same as the regular expression 0*1* • Same as the regular expression 0* U 1* • Same as the regular expression (0 U 1)* • None of the above

  10. What is the language of this CFG? S → T0T T → TT T → 0T1 T → 1T0 T → 0 T → ε • All strings of 0’s and 1’s • All strings of 0’s and 1’s with at least one 0 in it • All strings of 0’s and 1’s with at least two 0’s in it • All strings of 0’s and 1’s that have the same number of 0’s and 1’s • All strings of 0’s and 1’s that have more 0’s than 1’s

  11. Are CFG’s more powerful than DFA’s? • In other words: is there a CFG G such that the language of G is not regular? • Yes • No

  12. Demonstrating the power of CFG’s • The language L = {0n 1n | n ≥ 0} is NOT regular. (Why not?) • Which of these grammars describes the language L? a) S → AB A → 0A | ε B → 1B | ε c) S → 0S1 | ε d) S → 01S01 | ε b) S → AB A → 0A1 | ε B → 0B1 | ε e) There is no CFG that describes L.

  13. Why do we care about CFG’s? • You write a Java program but forget a semicolon. How does the compiler catch it? • You type (5+81(*24) in your fancy TI-89 calculator. How does it not blow up? • You want to recursively define a tree datatype in O’Caml. How do you do this? • You pull out your iPhone and ask Siri “When is the Sungod festival this year?” How does Siri have any hope of figuring out what you’re asking?

  14. Why do we care about CFG’s? • All of those situations (and more!) can be handled using CFG’s and parsing a string to see if it can be generated by a CFG. • Programming languages are often specified as a grammar. • There are programs (yacc) that can build parsers out of grammars. • Doesn’t tell you anything about the meaning of the string. This is why they are “context-free” languages.

  15. Sometimes a string can be parsed two different ways. S   → NP VP NP → CN | CN PP VP → CV | CV PP PP → P CN CN → A N CV → V | V NP A   → a | the N   → boy | girl | flower V   → touches | likes | sees P   → with S = Sentence NP = Noun-Phrase VP = Verb-Phrase PP = Prep-Phrase CN = Complex-Noun CV = Complex-Verb A = Article N = Noun V = Verb P = Preposition

  16. S   → NP VP NP → CN | CN PP VP → CV | CV PP PP → P CN CN → A N CV → V | V NP A   → a | the N   → boy | girl | flower V   → touches | likes | sees P   → with Parse Tree • “The girl touches the boy with the flower.” (a) (b)

  17. S   → NP VP NP → CN | CN PP VP → CV | CV PP PP → P CN CN → A N CV → V | V NP A   → a | the N   → boy | girl | flower V   → touches | likes | sees P   → with Parse Tree 2 • “The girl touches the boy with the flower.” (a) (b)

  18. Ambiguity

More Related