fundamentele informatica 1 i e
play

Fundamentele Informatica 1 (I&E) najaar 2011 - PowerPoint PPT Presentation

Fundamentele Informatica 1 (I&E) najaar 2011 http://www.liacs.nl/home/rvvliet/fi1ie/ Rudy van Vliet rvvliet(at)liacs.nl college 9, 21 november 2011 4. Context-Free Languages 4.5. Simplified Forms and Normal Forms 5. Pushdown Automata


  1. Fundamentele Informatica 1 (I&E) najaar 2011 http://www.liacs.nl/home/rvvliet/fi1ie/ Rudy van Vliet rvvliet(at)liacs.nl college 9, 21 november 2011 4. Context-Free Languages 4.5. Simplified Forms and Normal Forms 5. Pushdown Automata 5.1. Definitions and Examples 1

  2. 4.5. Simplified Forms and Normal Forms 2

  3. Definition 4.13. Regular Grammars. A context-free grammar G = ( V, Σ , S, P ) is regular if every production is of the form A → σB or A → Λ , where A, B ∈ V and σ ∈ Σ. 3

  4. Definition 4.29. Chomsky Normal Form A context-free grammar is said to be in Chomsky normal form if every production is of one of these two types: A → BC (where B and C are variables) A → σ (were σ is a terminal symbol) 4

  5. Exercise. For each grammar G below, try to find a grammar G ′ in Chomsky normal form which generates the same language. a. S → TB T → aTb | ab B → bB | b b. S → aSb | B B → bB | b c. S → aSb | aBb B → bB | Λ B → bB | Λ d. S → aSb | B 5

  6. Theorem 4.30 For every context-free grammar G , there is another CFG G 1 in Chomsky normal form such that L ( G 1 ) = L ( G ) − { Λ } . The proof of this result does not have to be known for the exam. What if Λ / ∈ L ( G ) ? 6

  7. reg. languages reg. grammar FA reg. expression cf. languages cf. grammar PDA 7

  8. 5. Pushdown Automata 8

  9. just like FA, PDA accepts strings / language just like FA, PDA has states just like FA, PDA reads input one letter at a time unlike FA, PDA has auxiliary memory: a stack unlike FA, by default PDA is nondeterministic unlike FA, by default Λ-transitions are allowed in PDA 9

  10. Stack in PDA contains symbols from certain alphabet. Usual stack operations: pop, top, push Extra possiblity: replace top element X by string α α = Λ pop α = X top α = Y X push push ∗ α = βX α = . . . Top element X is required to do a move! 10

  11. Example 5.3. A PDA Accepting the Language AnBn 11

  12. Definition 5.1. A Pushdown Automaton A pushdown automaton (PDA) is a 7-tuple M = ( Q, Σ , Γ , q 0 , Z 0 , A, δ ), where Q is a finite set of states. Σ and Γ are finite sets, the input and stack alphabet. q 0 , the initial state, is an element of Q . Z 0 , the initial stack symbol, is an element of Γ. A , the set of accepting states, is a subset of Q . δ , the transition function, is a function from . . . to . . . 12

  13. Definition 5.1. A Pushdown Automaton A pushdown automaton (PDA) is a 7-tuple M = ( Q, Σ , Γ , q 0 , Z 0 , A, δ ), where Q is a finite set of states. Σ and Γ are finite sets, the input and stack alphabet. q 0 , the initial state, is an element of Q . Z 0 , the initial stack symbol, is an element of Γ. A , the set of accepting states, is a subset of Q . δ , the transition function, is a function from Q × (Σ ∪{ Λ } ) × Γ to the set of finite subsets of Q × Γ ∗ . In principle, Z 0 may be removed from the stack, but often it isn’t. 13

  14. Example 5.3. A PDA Accepting the Language AnBn 14

  15. Notation: configuration ( q, x, α ) ( p, x, α ) ⊢ M ( q, y, β ) ( p, x, α ) ⊢ n ( p, x, α ) ⊢ ∗ M ( q, y, β ) M ( q, y, β ) ( p, x, α ) ⊢ n ( q, y, β ) ( p, x, α ) ⊢ ∗ ( q, y, β ) ( p, x, α ) ⊢ ( q, y, β ) 15

  16. Definition 5.2. Acceptance by a PDA If M = ( Q, Σ , Γ , q 0 , Z 0 , A, δ ) and x ∈ Σ ∗ , the string x is accepted by M if ( q 0 , x, Z 0 ) ⊢ ∗ M ( q, Λ , α ) for some α ∈ Γ ∗ and some q ∈ A . A language L ⊆ Σ ∗ is said to be accepted by M , if L is precisely the set of strings accepted by M ; in this case, we write L = L ( M ). Sometimes a string accepted by M , or a language accepted by M , is said to be accepted by final state . 16

  17. Example 5.3. PDAs Accepting the Languages AnBn and SimplePal 17

  18. Example 5.7. A Pushdown Automaton Accepting Pal 18

  19. Exercise 5.4. Consider the PDA in Table 5.8, and for each of the following languages over { a, b } ∗ , modify it to obtain a PDA accepting the language. a. The language of even-length palindromes. b. The language of odd-length palindromes. 19

  20. Exercise 5.5. Give transition diagrams for PDAs accepting each of the follow- ing languages. a. The language of all odd-length strings over { a, b } with middle symbol a . b. { a n x | n ≥ 0 , x ∈ { a, b } ∗ and | x | ≤ n } . c. { a i b j c k | i, j, k ≥ 0 and j = i or j = k } . 20

  21. Exercise 5.6. In both cases below (on the whiteboard), a transition diagram is given for a PDA with intial state q 0 and accepting state q 2 . Describe in each case the language that is accepted. (first case treated) 21

  22. Exercise 5.10. Show that every regular language can be accepted by a (deterministic) PDA M with only two states in which there are no Λ-transitions and no symbols are ever removed from the stack. 22

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