Pushdown Automata (Pre Lecture)

Similar documents
Context-Free Languages (Pre Lecture)

CPS 220 Theory of Computation Pushdown Automata (PDA)

Harvard CS 121 and CSCI E-207 Lecture 10: Ambiguity, Pushdown Automata

Harvard CS 121 and CSCI E-207 Lecture 10: CFLs: PDAs, Closure Properties, and Non-CFLs

Definition: A grammar G = (V, T, P,S) is a context free grammar (cfg) if all productions in P have the form A x where

Context-Free Languages

Introduction to Formal Languages, Automata and Computability p.1/42

Push-down Automata = FA + Stack

October 6, Equivalence of Pushdown Automata with Context-Free Gramm

Introduction to Theory of Computing

CSE 105 THEORY OF COMPUTATION

1. Draw a parse tree for the following derivation: S C A C C A b b b b A b b b b B b b b b a A a a b b b b a b a a b b 2. Show on your parse tree u,

Pushdown Automata. We have seen examples of context-free languages that are not regular, and hence can not be recognized by finite automata.

Pushdown Automata: Introduction (2)

(pp ) PDAs and CFGs (Sec. 2.2)

Outline. CS21 Decidability and Tractability. Machine view of FA. Machine view of FA. Machine view of FA. Machine view of FA.

CISC4090: Theory of Computation

Finite Automata. Dr. Neil T. Dantam. Fall CSCI-561, Colorado School of Mines. Dantam (Mines CSCI-561) Finite Automata Fall / 35

(pp ) PDAs and CFGs (Sec. 2.2)

Please give details of your answer. A direct answer without explanation is not counted.

Intro to Theory of Computation

Theory of Computation Turing Machine and Pushdown Automata

CFGs and PDAs are Equivalent. We provide algorithms to convert a CFG to a PDA and vice versa.

Theory of Computation (IV) Yijia Chen Fudan University

Pushdown Automata (2015/11/23)

Finite Automata. Dr. Neil T. Dantam. Fall CSCI-561, Colorado School of Mines. Dantam (Mines CSCI-561) Finite Automata Fall / 43

CSE 105 THEORY OF COMPUTATION

THEORY OF COMPUTATION (AUBER) EXAM CRIB SHEET

Einführung in die Computerlinguistik

CS5371 Theory of Computation. Lecture 7: Automata Theory V (CFG, CFL, CNF)

Accept or reject. Stack

PUSHDOWN AUTOMATA (PDA)

CS Pushdown Automata

Computability and Complexity

SCHEME FOR INTERNAL ASSESSMENT TEST 3

Pushdown automata. Twan van Laarhoven. Institute for Computing and Information Sciences Intelligent Systems Radboud University Nijmegen

Computational Models - Lecture 5 1

Automata Theory (2A) Young Won Lim 5/31/18

Theory of Computation

Pushdown Automata (PDA) The structure and the content of the lecture is based on

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

5 Context-Free Languages

CPS 220 Theory of Computation

DM17. Beregnelighed. Jacob Aae Mikkelsen

AC68 FINITE AUTOMATA & FORMULA LANGUAGES DEC 2013

Homework. Context Free Languages. Announcements. Before We Start. Languages. Plan for today. Final Exam Dates have been announced.

Lecture 11 Sections 4.5, 4.7. Wed, Feb 18, 2009

MA/CSSE 474 Theory of Computation

Solution Scoring: SD Reg exp.: a(a

CS481F01 Prelim 2 Solutions

Lecture 17: Language Recognition

Pushdown Automata. Chapter 12

Part I: Definitions and Properties

Theory of Computation

Foundations of Informatics: a Bridging Course

Theory of Computation - Module 3

60-354, Theory of Computation Fall Asish Mukhopadhyay School of Computer Science University of Windsor

Pushdown Automata. Pushdown Automata. Pushdown Automata. Pushdown Automata. Pushdown Automata. Pushdown Automata. The stack

Lecture VII Part 2: Syntactic Analysis Bottom-up Parsing: LR Parsing. Prof. Bodik CS Berkley University 1

Pushdown Automata. Reading: Chapter 6

MTH401A Theory of Computation. Lecture 17

Computational Models - Lecture 4

THEORY OF COMPILATION

CMSC 330: Organization of Programming Languages. Pushdown Automata Parsing

Part 4 out of 5 DFA NFA REX. Automata & languages. A primer on the Theory of Computation. Last week, we showed the equivalence of DFA, NFA and REX

Final exam study sheet for CS3719 Turing machines and decidability.

Computational Models: Class 5

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION

CISC 4090 Theory of Computation

Administrivia. Test I during class on 10 March. Bottom-Up Parsing. Lecture An Introductory Example

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

CMP 309: Automata Theory, Computability and Formal Languages. Adapted from the work of Andrej Bogdanov

Top-Down Parsing and Intro to Bottom-Up Parsing

Computability Theory

Decidable and undecidable languages

Midterm Exam 2 CS 341: Foundations of Computer Science II Fall 2018, face-to-face day section Prof. Marvin K. Nakayama

Pushdown Automata. Notes on Automata and Theory of Computation. Chia-Ping Chen

CISC 4090 Theory of Computation

Nondeterministic Finite Automata

CPSC 421: Tutorial #1

Fundamentele Informatica II

Everything You Always Wanted to Know About Parsing

Theory of Computation

CS311 Computational Structures More about PDAs & Context-Free Languages. Lecture 9. Andrew P. Black Andrew Tolmach

CS21 Decidability and Tractability

Section 1 (closed-book) Total points 30

CSE 211. Pushdown Automata. CSE 211 (Theory of Computation) Atif Hasan Rahman

Introduction to Computers & Programming

CS20a: summary (Oct 24, 2002)

SYLLABUS. Introduction to Finite Automata, Central Concepts of Automata Theory. CHAPTER - 3 : REGULAR EXPRESSIONS AND LANGUAGES

Computability and Complexity

Note: In any grammar here, the meaning and usage of P (productions) is equivalent to R (rules).

Harvard CS 121 and CSCI E-121 Lecture 14: Turing Machines and the Church Turing Thesis

Everything You Always Wanted to Know About Parsing

Homework Assignment 6 Answers

CS5371 Theory of Computation. Lecture 14: Computability V (Prove by Reduction)

LR2: LR(0) Parsing. LR Parsing. CMPT 379: Compilers Instructor: Anoop Sarkar. anoopsarkar.github.io/compilers-class

Handout 8: Computation & Hierarchical parsing II. Compute initial state set S 0 Compute initial state set S 0

ECS 120 Lesson 15 Turing Machines, Pt. 1

COM364 Automata Theory Lecture Note 2 - Nondeterminism

Transcription:

Pushdown Automata (Pre Lecture) Dr. Neil T. Dantam CSCI-561, Colorado School of Mines Fall 2017 Dantam (Mines CSCI-561) Pushdown Automata (Pre Lecture) Fall 2017 1 / 41

Outline Pushdown Automata Pushdown Automata and Context-Free Grammar Equivalence Dantam (Mines CSCI-561) Pushdown Automata (Pre Lecture) Fall 2017 2 / 41

Pushdown Automata Outline Pushdown Automata Pushdown Automata and Context-Free Grammar Equivalence Dantam (Mines CSCI-561) Pushdown Automata (Pre Lecture) Fall 2017 3 / 41

Pushdown Automata Conceptual Finite Automaton Operation M : Σ {accept, reject} input tape σ = σ [0] σ [1]... σ [k 1] }{{} history σ [k] σ [k+1] }... {{ σ [n] } future Finite Control Q {accept, reject} Dantam (Mines CSCI-561) Pushdown Automata (Pre Lecture) Fall 2017 4 / 41

Pushdown Automata Conceptual Pushdown Automaton Operation input tape σ = σ [0] σ [1]... σ [k 1] }{{} history σ [k] σ [k+1] }... {{ σ [n] } future stack γ [m] γ [m 1]. γ [0] $ Finite Control Q {accept, reject} Dantam (Mines CSCI-561) Pushdown Automata (Pre Lecture) Fall 2017 5 / 41

Pushdown Automata Pushdown Automaton Definition (Pushdown Automaton) A pushdown automaton is a 6-tuple M = (Q, Σ, Γ, δ, q 0, F ), where: Q is the finite set of states Σ is the input alphabet Γ is the stack alphabet δ : Q Σ Γ P (Q Γ) is transition function q 0 is the start state F Q is the set of accept states Dantam (Mines CSCI-561) Pushdown Automata (Pre Lecture) Fall 2017 6 / 41

Pushdown Automata PDA State Diagrams Transitions Stack Symbols q i input {}}{ σ, pop {}}{ γ k push {}}{ γ l q j ɛ: push/pop nothing $: marks bottom of stack γ Γ: any other symbol Dantam (Mines CSCI-561) Pushdown Automata (Pre Lecture) Fall 2017 7 / 41

Pushdown Automata Example: PDA for 0 n 1 n start 0, ɛ m 1, m ɛ ɛ, ɛ $ 1, m ɛ ɛ, $ ɛ q 0 q 1 q 2 q 3 Dantam (Mines CSCI-561) Pushdown Automata (Pre Lecture) Fall 2017 8 / 41

Pushdown Automata Example: Recognize 0011 start 0, ɛ m 1, m ɛ ɛ, ɛ $ 1, m ɛ ɛ, $ ɛ 0 0 1 1 q 0 q 1 q 2 q 3 stack start 0, ɛ m 1, m ɛ ɛ, ɛ $ 1, m ɛ ɛ, $ ɛ 0 0 1 1 q 0 q 1 q 2 q 3 $ stack Dantam (Mines CSCI-561) Pushdown Automata (Pre Lecture) Fall 2017 9 / 41

Pushdown Automata Example: Recognize 0011 continued (0) start 0, ɛ m 1, m ɛ ɛ, ɛ $ 1, m ɛ ɛ, $ ɛ m 0 0 1 1 q 0 q 1 q 2 q 3 $ stack start 0, ɛ m 1, m ɛ m ɛ, ɛ $ 1, m ɛ ɛ, $ ɛ m 0 0 1 1 q 0 q 1 q 2 q 3 $ stack Dantam (Mines CSCI-561) Pushdown Automata (Pre Lecture) Fall 2017 10 / 41

Pushdown Automata Example: Recognize 0011 continued (1) start 0, ɛ m 1, m ɛ ɛ, ɛ $ 1, m ɛ ɛ, $ ɛ m 0 0 1 1 q 0 q 1 q 2 q 3 $ stack start 0, ɛ m 1, m ɛ ɛ, ɛ $ 1, m ɛ ɛ, $ ɛ 0 0 1 1 q 0 q 1 q 2 q 3 $ stack Dantam (Mines CSCI-561) Pushdown Automata (Pre Lecture) Fall 2017 11 / 41

Pushdown Automata Example: Recognize 0011 continued (2) start 0, ɛ m 1, m ɛ ɛ, ɛ $ 1, m ɛ ɛ, $ ɛ 0 0 1 1 q 0 q 1 q 2 q 3 stack Dantam (Mines CSCI-561) Pushdown Automata (Pre Lecture) Fall 2017 12 / 41

Pushdown Automata Example: PDA for ωω R { ωω R ω {0, 1} } Dantam (Mines CSCI-561) Pushdown Automata (Pre Lecture) Fall 2017 13 / 41

Pushdown Automata Example: Recognize 0110 Dantam (Mines CSCI-561) Pushdown Automata (Pre Lecture) Fall 2017 14 / 41

Pushdown Automata Example: Recognize 0110 continued (0) Dantam (Mines CSCI-561) Pushdown Automata (Pre Lecture) Fall 2017 15 / 41

Pushdown Automata Example: Recognize 0110 continued (1) Dantam (Mines CSCI-561) Pushdown Automata (Pre Lecture) Fall 2017 16 / 41

Pushdown Automata Example: Recognize 0110 continued (2) Dantam (Mines CSCI-561) Pushdown Automata (Pre Lecture) Fall 2017 17 / 41

Outline Pushdown Automata Pushdown Automata and Context-Free Grammar Equivalence Dantam (Mines CSCI-561) Pushdown Automata (Pre Lecture) Fall 2017 18 / 41

Definition: Context-Free Grammar Definition Context-Free Grammar A context-free grammar G is the tuple G = (V, T, P, S), where: V is a finite set of variables or nonterminals T is a finite set of terminals P is a finite set of productions in the form V (V T ) S V is the start symbol Dantam (Mines CSCI-561) Pushdown Automata (Pre Lecture) Fall 2017 19 / 41

Extended PDA Diagrams p a, s xyz q p a, s z ɛ, ɛ y ɛ, ɛ x (pq) 0 (pq) 1 q Dantam (Mines CSCI-561) Pushdown Automata (Pre Lecture) Fall 2017 20 / 41

CFGs to PDAs nondeterministically expand productions on stack { }} { ɛ, }{{} A }{{} ω for every (A ω) P pop A push RHS start push start symbol and end mark {}}{ pop end mark {}}{ q start ɛ, ɛ S$ q loop ɛ, $ ɛ q accept a, a ɛ for every a Σ }{{} nondeterministically pop terminals off stack Dantam (Mines CSCI-561) Pushdown Automata (Pre Lecture) Fall 2017 21 / 41

Example: CFG to PDA S [a] T [b] [b] T T [a] ɛ Dantam (Mines CSCI-561) Pushdown Automata (Pre Lecture) Fall 2017 22 / 41

Example: Parse tree for aab Grammar Parse Tree S [a] T [b] [b] T T [a] ɛ Dantam (Mines CSCI-561) Pushdown Automata (Pre Lecture) Fall 2017 23 / 41

Example: Recognize aab Dantam (Mines CSCI-561) Pushdown Automata (Pre Lecture) Fall 2017 24 / 41

Example: Recognize aab continued (0) Dantam (Mines CSCI-561) Pushdown Automata (Pre Lecture) Fall 2017 25 / 41

Example: Recognize aab continued (1) Dantam (Mines CSCI-561) Pushdown Automata (Pre Lecture) Fall 2017 26 / 41

Example: Recognize aab continued (2) Dantam (Mines CSCI-561) Pushdown Automata (Pre Lecture) Fall 2017 27 / 41

Example: Recognize aab continued (3) Dantam (Mines CSCI-561) Pushdown Automata (Pre Lecture) Fall 2017 28 / 41

PDA to CFG PDA M = (Q, Σ, Γ, δ, q 0, F ) Assume single start state pushes $ Assume single accept state with empty stack Can always do this with new symbols/states push/empty stack CFG G = (V, T, P, S) S Nonterminals q, A, p, q, p Q and A Γ Idea: q, A, p derives ω going from state q to p and erasing A Dantam (Mines CSCI-561) Pushdown Automata (Pre Lecture) Fall 2017 29 / 41

PDA to CFG nonterminals Nonterminal Elements p Q: initial PDA state p, A, q q Q: ending PDA state A Γ: stack symbol popped p β, A ɛ q β Σ : derived string Dantam (Mines CSCI-561) Pushdown Automata (Pre Lecture) Fall 2017 30 / 41

PDA to CFG Productions S q 0, $, f for f F p p p a, X ɛ q p, X, q a a, X Y r p, X, q a r, Y, q a, ɛ Y r p, X, q a r, Y, s s, X, q for all s Q Dantam (Mines CSCI-561) Pushdown Automata (Pre Lecture) Fall 2017 31 / 41

PDA to CFG Productions, case 0 X... $... $ p, X, q p a, X ɛ q p, X, q a Dantam (Mines CSCI-561) Pushdown Automata (Pre Lecture) Fall 2017 32 / 41

PDA to CFG Productions, case 1 X... $ Y... $ p, X, q... $ φ, Y ɛ a, X Y p r q p, X, q a r, Y, q r, Y, q Dantam (Mines CSCI-561) Pushdown Automata (Pre Lecture) Fall 2017 33 / 41

PDA to CFG Productions, case 2 Y X... $ X... $ X... $... $ p, X, q φ, Y ɛ θ, X ɛ a, ɛ Y p r s q p, X, q a r, Y, s s, X, q r, Y, s s, X, q Dantam (Mines CSCI-561) Pushdown Automata (Pre Lecture) Fall 2017 34 / 41

Example: PDA to CFG {0 m 1 n (m n) (n 1)} Edges start 0, ɛ x 1, x ɛ ɛ, x ɛ ɛ, ɛ $ 1, x ɛ ɛ, $ ɛ q s q 0 q 1 q a q 0 q 0 q 1 q 1 0, ɛ x q 0 1, x ɛ q 1 1, x ɛ q 1 ɛ, x ɛ q 1 Dantam (Mines CSCI-561) Pushdown Automata (Pre Lecture) Fall 2017 35 / 41

Example: PDA to CFG ɛ, ɛ $ 1, x ɛ ɛ, $ ɛ continued: nonterminals q s q 0 q 1 q a start Nonterminals 0, ɛ x 1, x ɛ ɛ, x ɛ Dantam (Mines CSCI-561) Pushdown Automata (Pre Lecture) Fall 2017 36 / 41

Example: PDA to CFG continued: productions Edges Productions q 0 q 0 q 1 q 1 0, ɛ x q 0 1, x ɛ q 1 1, x ɛ q 1 ɛ, x ɛ q 1 Dantam (Mines CSCI-561) Pushdown Automata (Pre Lecture) Fall 2017 37 / 41

Example: Simulation/Derivation on 001 Dantam (Mines CSCI-561) Pushdown Automata (Pre Lecture) Fall 2017 38 / 41

Example: Simulation/Derivation on 001 continued (0) Dantam (Mines CSCI-561) Pushdown Automata (Pre Lecture) Fall 2017 39 / 41

Example: Simulation/Derivation on 001 continued (1) Dantam (Mines CSCI-561) Pushdown Automata (Pre Lecture) Fall 2017 40 / 41

Example: Simulation/Derivation on 001 continued (2) Dantam (Mines CSCI-561) Pushdown Automata (Pre Lecture) Fall 2017 41 / 41