formal languages grammars and automata lecture 6
play

Formal Languages, Grammars and Automata Lecture 6 Helle Hvid Hansen - PowerPoint PPT Presentation

Introduction Pushdown Automata Radboud University Nijmegen CFLs and PDAs Closure Properties and Concluding Remarks Formal Languages, Grammars and Automata Lecture 6 Helle Hvid Hansen helle@cs.ru.nl http://www.cs.ru.nl/~helle/ Foundations


  1. Introduction Pushdown Automata Radboud University Nijmegen CFLs and PDAs Closure Properties and Concluding Remarks Formal Languages, Grammars and Automata Lecture 6 Helle Hvid Hansen helle@cs.ru.nl http://www.cs.ru.nl/~helle/ Foundations Group – Intelligent Systems Section Institute for Computing and Information Sciences Radboud University Nijmegen 13 June 2014 Helle Hvid Hansen 13 June 2014 FLGA 1 / 24

  2. Introduction Pushdown Automata Radboud University Nijmegen CFLs and PDAs Closure Properties and Concluding Remarks Overview Last lecture: • Context-free grammars and context-free languages. • Regular grammars. • CYK-algorithm (parsing: w ∈ L ?) Helle Hvid Hansen 13 June 2014 FLGA 2 / 24

  3. Introduction Pushdown Automata Radboud University Nijmegen CFLs and PDAs Closure Properties and Concluding Remarks Overview Last lecture: • Context-free grammars and context-free languages. • Regular grammars. • CYK-algorithm (parsing: w ∈ L ?) Today: • Pushdown automata (NL: stapelautomaten) • Closure properties of context-free languages • Beyond context-free languages Helle Hvid Hansen 13 June 2014 FLGA 2 / 24

  4. Introduction Pushdown Automata Radboud University Nijmegen CFLs and PDAs Closure Properties and Concluding Remarks Automata for Context-Free Languages Language class Syntax/Grammar Automata Context-free context-free grammar ? Regular regular expressions, DFA, NFA, NFA- λ regular grammar Helle Hvid Hansen 13 June 2014 FLGA 3 / 24

  5. Introduction Pushdown Automata Radboud University Nijmegen CFLs and PDAs Closure Properties and Concluding Remarks Automata for Context-Free Languages Language class Syntax/Grammar Automata Context-free context-free grammar ? Regular regular expressions, DFA, NFA, NFA- λ regular grammar • DFA, NFA, NFA- λ : finite memory (states can encode only finite amount of information), for example (for Σ = { a , b } ), • even or odd number of a ’s read: two states even , odd • the last 2 letters read: four states for aa , ab , ba , bb . Helle Hvid Hansen 13 June 2014 FLGA 3 / 24

  6. Introduction Pushdown Automata Radboud University Nijmegen CFLs and PDAs Closure Properties and Concluding Remarks Automata for Context-Free Languages Language class Syntax/Grammar Automata Context-free context-free grammar ? Regular regular expressions, DFA, NFA, NFA- λ regular grammar • DFA, NFA, NFA- λ : finite memory (states can encode only finite amount of information), for example (for Σ = { a , b } ), • even or odd number of a ’s read: two states even , odd • the last 2 letters read: four states for aa , ab , ba , bb . • For example: { a n b n | n ≥ 0 } not regular. We would need to remember how many a ’s we have seen. A DFA with k states can only “count to k ”. Helle Hvid Hansen 13 June 2014 FLGA 3 / 24

  7. Introduction Pushdown Automata Radboud University Nijmegen CFLs and PDAs Closure Properties and Concluding Remarks Automata for Context-Free Languages Language class Syntax/Grammar Automata Context-free context-free grammar ? Regular regular expressions, DFA, NFA, NFA- λ regular grammar • DFA, NFA, NFA- λ : finite memory (states can encode only finite amount of information), for example (for Σ = { a , b } ), • even or odd number of a ’s read: two states even , odd • the last 2 letters read: four states for aa , ab , ba , bb . • For example: { a n b n | n ≥ 0 } not regular. We would need to remember how many a ’s we have seen. A DFA with k states can only “count to k ”. We need some form of unbounded memory. Helle Hvid Hansen 13 June 2014 FLGA 3 / 24

  8. Introduction Pushdown Automata Radboud University Nijmegen CFLs and PDAs Closure Properties and Concluding Remarks Stack Memory Stack of data elements (“stapel”) Note: only top of stack is visible. Helle Hvid Hansen 13 June 2014 FLGA 4 / 24

  9. Introduction Pushdown Automata Radboud University Nijmegen CFLs and PDAs Closure Properties and Concluding Remarks Stack Memory Stack of data elements Stack operations: (“stapel”) push a new pop the top element element onto stack from stack Note: Stack is a Last-In-First-Out (LIFO) only top of stack is visible. data structure. Helle Hvid Hansen 13 June 2014 FLGA 4 / 24

  10. Introduction Pushdown Automata Radboud University Nijmegen CFLs and PDAs Closure Properties and Concluding Remarks Stack Memory: Formal Notation • Stack content described as word over a stack alphabet A Γ = { A , B , C , ..., X , Y , ... } . Last-in = Left-most: B = ABC C • The empty stack is λ ∈ Γ ∗ . Helle Hvid Hansen 13 June 2014 FLGA 5 / 24

  11. Introduction Pushdown Automata Radboud University Nijmegen CFLs and PDAs Closure Properties and Concluding Remarks Stack Memory: Formal Notation • Stack content described as word over a stack alphabet A Γ = { A , B , C , ..., X , Y , ... } . Last-in = Left-most: B = ABC C • The empty stack is λ ∈ Γ ∗ . • Stack operations: X A A A ) = B push ( X , B ) = pop ( B B C C C C push ( X , ABC ) = XABC pop ( ABC ) = BC • Note: The empty stack has no top. Helle Hvid Hansen 13 June 2014 FLGA 5 / 24

  12. Introduction Pushdown Automata Radboud University Nijmegen CFLs and PDAs Closure Properties and Concluding Remarks Pushdown Automaton A pushdown automaton is an NFA- λ equipped with a stack. Helle Hvid Hansen 13 June 2014 FLGA 6 / 24

  13. Introduction Pushdown Automata Radboud University Nijmegen CFLs and PDAs Closure Properties and Concluding Remarks Pushdown Automaton A pushdown automaton is an NFA- λ equipped with a stack. Def. A pushdown automaton (PDA) M = ( Q , Σ , Γ , δ, q 0 , F ) consists of • a finite set of (control) states Q • an input alphabet Σ • an initial state q 0 ∈ Q • a set of final states F ⊆ Q Helle Hvid Hansen 13 June 2014 FLGA 6 / 24

  14. Introduction Pushdown Automata Radboud University Nijmegen CFLs and PDAs Closure Properties and Concluding Remarks Pushdown Automaton A pushdown automaton is an NFA- λ equipped with a stack. Def. A pushdown automaton (PDA) M = ( Q , Σ , Γ , δ, q 0 , F ) consists of • a finite set of (control) states Q • an input alphabet Σ • an initial state q 0 ∈ Q • a set of final states F ⊆ Q • a stack alphabet Γ • a transition function δ : Q × Σ λ × Γ λ → P ( Q × Γ λ ) where Σ λ = Σ ∪ { λ } and Γ λ = Γ ∪ { λ } . That is, for p ∈ Q , a ∈ Σ λ , A ∈ Γ λ , δ ( p , a , A ) is a set of pairs ( q , B ) where q ∈ Q , B ∈ Γ λ (nondeterministic). Helle Hvid Hansen 13 June 2014 FLGA 6 / 24

  15. Introduction Pushdown Automata Radboud University Nijmegen CFLs and PDAs Closure Properties and Concluding Remarks Pushdown Automaton Computation A computation of a PDA M on input word w : Helle Hvid Hansen 13 June 2014 FLGA 7 / 24

  16. Introduction Pushdown Automata Radboud University Nijmegen CFLs and PDAs Closure Properties and Concluding Remarks Pushdown Automaton Computation A computation of a PDA M on input word w : • Start configuration ( q 0 , w , λ ) (start in initial state with empty stack) Helle Hvid Hansen 13 June 2014 FLGA 7 / 24

  17. Introduction Pushdown Automata Radboud University Nijmegen CFLs and PDAs Closure Properties and Concluding Remarks Pushdown Automaton Computation A computation of a PDA M on input word w : • Start configuration ( q 0 , w , λ ) (start in initial state with empty stack) • Transitions are taken (nondeterministically) depending on – the next input symbol (as in DFA, NFA) and – the stack top symbol. (Details next slide.) Changes configuration ( p , u , α ) → ( q , v , β ) according to transition function (where p , q ∈ Q , ; u , v ∈ Σ ∗ , α, β ∈ Γ ∗ ). Helle Hvid Hansen 13 June 2014 FLGA 7 / 24

  18. Introduction Pushdown Automata Radboud University Nijmegen CFLs and PDAs Closure Properties and Concluding Remarks Pushdown Automaton Computation A computation of a PDA M on input word w : • Start configuration ( q 0 , w , λ ) (start in initial state with empty stack) • Transitions are taken (nondeterministically) depending on – the next input symbol (as in DFA, NFA) and – the stack top symbol. (Details next slide.) Changes configuration ( p , u , α ) → ( q , v , β ) according to transition function (where p , q ∈ Q , ; u , v ∈ Σ ∗ , α, β ∈ Γ ∗ ). • Computation is successful if it ends in a configuration ( q , λ, λ ) where q ∈ F . (Acceptance by final state and empty stack) Helle Hvid Hansen 13 June 2014 FLGA 7 / 24

  19. Introduction Pushdown Automata Radboud University Nijmegen CFLs and PDAs Closure Properties and Concluding Remarks Pushdown Automaton Transitions a , A / B � q : p ( q , B ) ∈ δ ( p , a , A ) i.e. • can be taken if: next input symbol is a , stack top is A • actions: read/consume a , pop A from stack, push B . Helle Hvid Hansen 13 June 2014 FLGA 8 / 24

  20. Introduction Pushdown Automata Radboud University Nijmegen CFLs and PDAs Closure Properties and Concluding Remarks Pushdown Automaton Transitions a , A / B � q : p ( q , B ) ∈ δ ( p , a , A ) i.e. • can be taken if: next input symbol is a , stack top is A • actions: read/consume a , pop A from stack, push B . λ, A / B � q p ( q , B ) ∈ δ ( p , λ, A ) i.e. (input λ -transition): • can be taken if: stack top is A (regardless of next input) • actions: pop A from stack, push B . Helle Hvid Hansen 13 June 2014 FLGA 8 / 24

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