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

Similar documents
(pp ) PDAs and CFGs (Sec. 2.2)

(pp ) PDAs and CFGs (Sec. 2.2)

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

MTH401A Theory of Computation. Lecture 17

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

Pushdown Automata (Pre Lecture)

UNIT-VI PUSHDOWN AUTOMATA

CSE 105 THEORY OF COMPUTATION

Pushdown Automata. Reading: Chapter 6

Theory of Computation (IV) Yijia Chen Fudan University

AC68 FINITE AUTOMATA & FORMULA LANGUAGES DEC 2013

Accept or reject. Stack

Foundations of Informatics: a Bridging Course

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

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

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,

Einführung in die Computerlinguistik

Miscellaneous. Closure Properties Decision Properties

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

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

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

CPSC 421: Tutorial #1

Pushdown Automata: Introduction (2)

CISC4090: Theory of Computation

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Introduction to Theory of Computing

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

Push-down Automata = FA + Stack

Section 1 (closed-book) Total points 30

CSE 105 THEORY OF COMPUTATION

Pushdown Automata (2015/11/23)

Turing Machines. Our most powerful model of a computer is the Turing Machine. This is an FA with an infinite tape for storage.

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

Equivalence of CFG s and PDA s

CSCC63 Worksheet Turing Machines

Undecidable Problems and Reducibility

SCHEME FOR INTERNAL ASSESSMENT TEST 3

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

Outline 1 PCP. 2 Decision problems about CFGs. M.Mitra (ISI) Post s Correspondence Problem 1 / 10

Part I: Definitions and Properties

Properties of Context-Free Languages. Closure Properties Decision Properties

CS 301. Lecture 18 Decidable languages. Stephen Checkoway. April 2, 2018

CPS 220 Theory of Computation Pushdown Automata (PDA)

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

Context Free Languages: Decidability of a CFL

Context-Free Languages

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

TAFL 1 (ECS-403) Unit- IV. 4.1 Push Down Automata. 4.2 The Formal Definition of Pushdown Automata. EXAMPLES for PDA. 4.3 The languages of PDA

Busch Complexity Lectures: Turing s Thesis. Costas Busch - LSU 1

Intro to Theory of Computation

Lecture 13: Turing Machine

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

CSE 105 THEORY OF COMPUTATION

CSE 105 THEORY OF COMPUTATION

Computational Models - Lecture 5 1

Theory of Computation

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

CISC 4090 Theory of Computation

C6.2 Push-Down Automata

Formal Definition of a Finite Automaton. August 26, 2013

Context-free Languages and Pushdown Automata

Computational Models: Class 5

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

CFG and PDA accept the same languages

Theory of Computation (IX) Yijia Chen Fudan University

THEORY OF COMPUTATION (AUBER) EXAM CRIB SHEET

CS154 Final Examination

Languages, regular languages, finite automata

Introduction to Languages and Computation

Decidability (What, stuff is unsolvable?)

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

Theory of Computation Turing Machine and Pushdown Automata

Homework Assignment 6 Answers

Lecture 17: Language Recognition

Solution Scoring: SD Reg exp.: a(a

CS375: Logic and Theory of Computing

COM364 Automata Theory Lecture Note 2 - Nondeterminism

CSE 355 Test 2, Fall 2016

CSCI 2200 Foundations of Computer Science Spring 2018 Quiz 3 (May 2, 2018) SOLUTIONS

ECS 120 Lesson 15 Turing Machines, Pt. 1

How to Pop a Deep PDA Matters

Turing Machines (TM) Deterministic Turing Machine (DTM) Nondeterministic Turing Machine (NDTM)

Theory Bridge Exam Example Questions

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

Languages. Non deterministic finite automata with ε transitions. First there was the DFA. Finite Automata. Non-Deterministic Finite Automata (NFA)

The Idea of a Pushdown Automaton

Turing Machines. Nicholas Geis. February 5, 2015

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Theory of Computation - Module 3

Theory of Computation

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

Solutions to Old Final Exams (For Fall 2007)

5 Context-Free Languages

PUSHDOWN AUTOMATA (PDA)

What languages are Turing-decidable? What languages are not Turing-decidable? Is there a language that isn t even Turingrecognizable?

Pushdown Automata. Chapter 12

CpSc 421 Final Exam December 15, 2006

Fundamentele Informatica II

Computability and Complexity

Turing Machines. The Language Hierarchy. Context-Free Languages. Regular Languages. Courtesy Costas Busch - RPI 1

Transcription:

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

CFGs and PDAs are Equivalent We now prove that a language is generated by some CFG if and only if it is accepted by some PDA The proof consists of two conversions. Goddard 8b: 2

Conversion from CFG to PDA For the conversion from CFG to PDA, the idea is that the PDA guesses the leftmost derivation and checks that it is correct. (proof by simulation) Each step of the derivation is a string. The machine guesses the next step. The problem is to do this with only a stack. Terminals to the left of leftmost variable are not stored, but are matched with input string. Only current string from leftmost variable onwards is stored on stack, with leftmost symbol on top. Goddard 8b: 3

Operating the PDA The PDA starts with start variable on the stack. At each step: If stack-top is a variable, then PDA guesses a production and replaces variable by RH of that production. If stack-top is a terminal, then PDA pops it and reads one symbol from input and checks that the two match. Accept if and only if reach empty stack at end of string. (Note that PDA not guaranteed to halt.) Goddard 8b: 4

Example 01 10 ε The sequence of stacks for the accepting branch of the PDA for 011100 starts: stack 0 1 1 1 1 0 0 1 0 0 to read 011100 011100 11100 11100 1100 1100 100 100 Goddard 8b: 5

An Alternative Representation of PDA We show next how to convert from PDA to CFG. This procedure is slightly easier if PDA is in another form: where only the reading states are retained and stack operations are part of the transitions. Goddard 8b: 6

Example Here is earlier PDA for 0 n 1 n redrawn: 0 push x 1 pop x 1 pop x pop F G H Goddard 8b: 7

Formal Definition In this light, a formal definition of a PDA is a 7-tuple (Q, Σ, Γ, q 0, h a,, δ) where: Q is finite set of states; Σ is finite input alphabet; Γ is finite stack alphabet; q 0 is start state; h a is accept state; is empty-stack and end-of-string symbol; and δ is transition function. The transition function needs more explanation... Goddard 8b: 8

The Transition Function The transition function is a function from Q (Γ { }) (Σ {ε, }) to finite subsets of Q (Γ { }). That is, it looks at current state, current stacktop symbol, and (possibly) input symbol; then it updates the state and replaces the current stack-top symbol by a string of symbols: pop = replace stack-top symbol by nothing; push = replace stack-top symbol by itself and a new symbol. Goddard 8b: 9

Example For example, δ(q, A, a) = {(p, AB)} means that in state q with A on stack-top, on reading a the PDA pushes symbol B and changes to state p. Goddard 8b: 10

Conversion from PDA to CFG The idea for the conversion from PDA to CFG is to make each step in a derivation correspond to a move by the PDA. This is far from trivial! We use the earlier alternative representation. Further, we assume that: (a) stack of the PDA M is empty if and only M is in the accept state; (b) every move is either a push of a single symbol or a pop of a single symbol (Exercise). Goddard 8b: 11

The Variables are Triples The variables of the CFG will be all the ordered triples q A p where q, p are states of the PDA, and A is a symbol from the stack alphabet. Goddard 8b: 12

Invariant for Triples We construct the CFG such that for all strings w: q A p = w M can go from state q to p while reading w with the net effect of popping symbol A. [q 0,, h a ] will be start variable for the CFG: it will generate string w if and only if one can go from q 0 to h a while reading w and popping the emptystack symbol; that is, w is accepted. Goddard 8b: 13

The Productions: Pops The two types of moves of the PDA become productions. Consider a pop move; say (p, ε) δ(q, A, a). That is, in state q the PDA can pop symbol A while reading a and changing to state p (a can be ε). Then we add one production: q A p a Goddard 8b: 14

The Productions: Pushes Consider a push move; say (p, AB) δ(q, A, a). That is, in state q with A on stack-top, one can push symbol B while reading a and changing to state p. Then we add the collection of productions: q A r a p B s s A r for every state r and s. Essentially, there are two ways that effectively erase the stack-top symbol: (a) pop it, or (b) push something, and then later erase both symbols. Goddard 8b: 15

Proof Details Omitted The rest of the proof is to show that every derivation in this grammar corresponds to a legitimate computation of the PDA. Goddard 8b: 16

Example Conversion We use the PDA for {0 n 1 n } from before. 0 push x 1 pop x F 1 pop x G pop H Here goes... Goddard 8b: 17

Example CFG tart symbol: F H Popping occurs in three places: F x G 1 G x G 1 G H ε Pushing yields 18 productions of the form F A r 0 F x s s A r for each A {x, } and r, s {F, G, H}. We could stop, but one can simplify: Goddard 8b: 18

implification Omit productions that produce triples that are never LH; this leaves 1) F x F 0 F x F F x F 2) F x G 0 F x F F x G 3) F x H 0 F x F F x H 4) F F 0 F x F F F 5) F G 0 F x F F G 6) F H 0 F x F F H 7) F x G 0 F x G G x G 8) F H 0 F x G G H F x F is also unusable (why?); omit its rules. Goddard 8b: 19

Final CFG This leaves us with the CFG with start variable F H : F x G 1 G x G 1 G H ε F x G 0 F x G G x G F H 0 F x G G H Whew! Goddard 8b: 20

ummary There is an algorithm to convert a CFG to an equivalent PDA: the PDA guesses the leftmost derivation. The algorithm to convert from PDA to CFG is more complex. Goddard 8b: 21