Pushdown automata The Chinese University of Hong Kong Fall 2011

Slides:



Advertisements
Similar presentations
Pushdown Automata Section 2.2 CSC 4170 Theory of Computation.
Advertisements

C O N T E X T - F R E E LANGUAGES ( use a grammar to describe a language) 1.
Introduction to Computability Theory
1 Introduction to Computability Theory Lecture7: PushDown Automata (Part 1) Prof. Amos Israeli.
Lecture 3UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 3.
Costas Busch - RPI1 Pushdown Automata PDAs. Costas Busch - RPI2 Pushdown Automaton -- PDA Input String Stack States.
1 … NPDAs continued. 2 Pushing Strings Input symbol Pop symbol Push string.
Courtesy Costas Busch - RPI1 Pushdown Automata PDAs.
CS 310 – Fall 2006 Pacific University CS310 Pushdown Automata Sections: 2.2 page 109 October 9, 2006.
1 Normal Forms for Context-free Grammars. 2 Chomsky Normal Form All productions have form: variable and terminal.
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.2: Pushdown Automata) Prof. Karen Daniels, Fall 2009 with acknowledgement.
Fall 2004COMP 3351 Pushdown Automata PDAs. Fall 2004COMP 3352 Pushdown Automaton -- PDA Input String Stack States.
Fall 2006Costas Busch - RPI1 Pushdown Automata PDAs.
January 14, 2015CS21 Lecture 51 CS21 Decidability and Tractability Lecture 5 January 14, 2015.
Pushdown Automaton (PDA)
CS5371 Theory of Computation Lecture 8: Automata Theory VI (PDA, PDA = CFG)
Prof. Busch - LSU1 Pushdown Automata PDAs. Prof. Busch - LSU2 Pushdown Automaton -- PDA Input String Stack States.
Fall 2005Costas Busch - RPI1 Pushdown Automata PDAs.
1 Pushdown Automata PDAs. 2 Pushdown Automaton -- PDA Input String Stack States.
CS 3240: Languages and Computation Pushdown Automata & CF Grammars NOTE: THESE ARE ONLY PARTIAL SLIDES RELATED TO WEEKS 9 AND 10. PLEASE REFER TO THE TEXTBOOK.
CSCI 2670 Introduction to Theory of Computing September 21, 2005.
Pushdown Automata CS 130: Theory of Computation HMU textbook, Chap 6.
Pushdown Automata (PDAs)
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.2: Pushdown Automata) Prof. Karen Daniels, Fall 2010 with acknowledgement.
CSCI 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Pushdown.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Pushdown.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Pushdown.
Pushdown Automata Hopcroft, Motawi, Ullman, Chap 6.
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.
Grammar Set of variables Set of terminal symbols Start variable Set of Production rules.
Theory of Computation Automata Theory Dr. Ayman Srour.
Lecture 11  2004 SDU Lecture7 Pushdown Automaton.
CSCI 2670 Introduction to Theory of Computing September 22, 2004.
6. Pushdown Automata CIS Automata and Formal Languages – Pei Wang.
Nondeterminism The Chinese University of Hong Kong Fall 2011
Formal Languages, Automata and Models of Computation
Pushdown Automata.
CSE 105 theory of computation
Deterministic FA/ PDA Sequential Machine Theory Prof. K. J. Hintz
CSE 105 theory of computation
Pushdown Automata (PDA). Part 2
CIS Automata and Formal Languages – Pei Wang
Pushdown Automata PDAs
Push-down Automata Section 3.3 Wed, Oct 27, 2004.
Pushdown Automata PDAs
Pushdown Automata PDAs
Pushdown Automata PDAs
PUSHDOWN AUTOMATA. PUSHDOWN AUTOMATA Hierarchy of languages Regular Languages  Finite State Machines, Regular Expression Context Free Languages 
Push-down Automata.
Chapter 7 PUSHDOWN AUTOMATA.
AUTOMATA THEORY VI.
Pushdown automata and CFG ↔ PDA conversions
LR(1) grammars The Chinese University of Hong Kong Fall 2010
COSC 3340: Introduction to Theory of Computation
Context-Free Grammars
Context-Free Languages
Pushdown automata a_introduction.htm.
Definition Moves of the PDA Languages of the PDA Deterministic PDA’s
Chapter 2 Context-Free Language - 01
CSE 105 theory of computation
LR(1) grammars The Chinese University of Hong Kong Fall 2011
Principles of Computing – UFCFA3-30-1
… NPDAs continued.
CSE 105 theory of computation
CSE 105 theory of computation
Normal Forms for Context-free Grammars
Nondeterminism The Chinese University of Hong Kong Fall 2010
CSE 105 theory of computation
CSE 105 theory of computation
Presentation transcript:

Pushdown automata The Chinese University of Hong Kong Fall 2011 CSCI 3130: Formal languages and automata theory Pushdown automata Andrej Bogdanov http://www.cse.cuhk.edu.hk/~andrejb/csc3130

Motivation regular expression NFA DFA syntactic computational is more powerful than CFG pushdown automaton syntactic computational

Pushdown automata versus NFA state control input 1 NFA

Pushdown automata pushdown automaton (PDA) state control input 1 … stack pushdown automaton (PDA) A PDA is like an NFA with but with an infinite stack

pushdown automaton (PDA) Pushdown automata state control input 1 … $ 1 1 stack pushdown automaton (PDA) As the PDA is reading the input, it can push / pop symbols from the top of the stack

Building a PDA L = {0n1n: n ≥ 1} state control We remember each 0 pop $ push $ We remember each 0 by pushing x onto the stack read 0 push x read 1 pop x When we see a 1, we pop an x from the stack read 1 pop x We want to accept when we hit the stack bottom We’ll use t$ mark bottom

A PDA in action L = {0n1n: n ≥ 1} state control input 1 1 1 … x x x push $ input read 0 1 1 1 push x read 1 pop x … $ x x x read 1 stack pop x pop $

Notation for PDAs read, pop / push push $ e, e / $ read 0 0, e / x 1, x / e 0, e / x e, $ / e e, e / $ q0 q1 q2 q3 read 1 pop x read 0 push x pop $ push $ read, pop / push

Definition of a PDA A pushdown automaton is (Q, , , , q0, F) where: Q is a finite set of states;  is the input alphabet;  is the stack alphabet q0 in Q is the initial state; F  Q is a set of final states;  is the transition function d: Q  (  {})  (  {}) → subsets of Q  (G  {}) state input symbol pop symbol state push symbol

Example S = {0, 1} G = {$, x} d(q0, e, e) = {(q1, $)} d(q0, e, $) = ∅ 1, x / e 0, e / x e, $ / e e, e / $ q0 q1 q2 q3 S = {0, 1} G = {$, x} d(q0, e, e) = {(q1, $)} d(q0, e, $) = ∅ d(q0, e, x) = ∅ d(q0, 0, e) = ∅ ... d: Q  (  {})  (  {}) → subsets of Q  (G  {}) state input symbol pop symbol state push symbol

The language of a PDA A PDA is nondeterministic Multiple transitions on same pop/input allowed Transitions may but do not have to push or pop The language of a PDA is the set of all strings in S* that can lead the PDA to an accepting state

Example 1 L = {w#wR: w  {0, 1}*} S = {0, 1, #} G = {0, 1} e, e / $ q0 q3 e, $ / e q2 #, e / e 0, e / 0 q1 1, e / 1 0, 0 / e 1, 1 / e write w on stack read wR from stack

Example 2 L = {wwR: w  S*} S = {0, 1} e, 00, 0110  L e, e / $ q0 q3 e, $ / e e, e / e 0, e / 0 q1 1, e / 1 0, 0 / e 1, 1 / e q2 guess middle of string

Example 3 L = {w: w = wR, w  S*} S = {0, 1} e, 1, 00, 010, 0110  L 0110110110 011010110 or x xR 011 ∉ L e, e / e 0, e / e 1, e / e e, e / $ q0 q3 e, $ / e 0, e / 0 q1 1, e / 1 0, 0 / e 1, 1 / e q2 middle symbol can be e, 0, or 1

Example 4 L = {0n1m0m1n | n  0, m  0} S = {0, 1} input: 0n 1m 0m 1n q1 e, e / e 1, e / 1 q2 e, e / $ q0 e, $ / e q5 input: 0n 1m 0m 1n e, e / e q3 0, 1 / e stack: 0n 1m e, e / e q4 1, 0/ e

Example 5 L = {w: w has same number 0s and 1s} S = {0, 1} Strategy: Stack keeps track of excess of 0s or 1s If at the end, stack is empty, number is equal e, e / $ q0 q3 e, $ / e q1 0, e / 0 1, e / 1 0, 1 / e 1, 0 / e

Example 5 L = {w: w has same number 0s and 1s} S = {0, 1} Invariant: In every execution of the PDA: #1 - #0 on stack = #1 - #0 in input so far 0, e / 0 e, e / $ q0 q1 1, e / 1 q3 e, $ / e 0, 1 / e 1, 0 / e If w is not in L, it must be rejected

Example 5 L = {w: w has same number 0s and 1s} S = {0, 1} Property: In some execution of the PDA: stack consists only of 0s or only of 1s (or e) 0, e / 0 e, e / $ q0 q1 1, e / 1 q3 e, $ / e 0, 1 / e 1, 0 / e If w is in L, some execution will accept

Example 5 L = {w: w has same number 0s and 1s} S = {0, 1} read stack e, e / $ q0 q1 1, e / 1 q3 e, $ / e 0, 1 / e 1, 0 / e read stack w = 001110 $0 $00 1 $0 1 $ 1 $1 $

Example 6 L = {w: w has two 0-blocks with same number of 0s Strategy: 01011, 001011001, 10010101001 01001000, 01111 allowed not allowed Strategy: Detect start of first 0-block Push 0s on stack Detect start of second 0-block Pop 0s from stack

Example 6 1 Detect start of first 0-block 2 Push 0s on stack q0 q1 0, 1 1 e 0, e / 0 1 Detect start of first 0-block 2 Push 0s on stack 1 0, 1 0, 0 / e 3 Detect start of second 0-block 4 Pop 0s from stack

Example 6 L = {w: w has two 0-blocks with same number of 0s 0, e / e q0 q1 1, e / e 1 2 q2 0, e / 0 q3 3 1, e / e q4 0, e / e 1, e / e q6 0, e / e q7 e, $ / e 4 q5 0, 0 / e

CFG ↔ PDA conversions

CFGs and PDAs L has a context-free grammar if and only if it is accepted by some pushdown automaton. context-free grammar pushdown automaton

A convention When we have a sequence of transitions like: We will abbreviate it like this: e, e / c q0 q1 x, a / b e, e / d pop a, then push b, c, and d x, a / bcd q0 q1 replace a by bcd on stack

Converting a CFG to a PDA Idea: Use PDA to simulate derivations A → 0A1 A → B B → # A  0A1  00A11  00B11  00#11 PDA control: stack: input: write start variable e, e / A $A 00#11 replace production in reverse e, A / 1A0 $1A0 00#11 pop terminal and match 0, 0 / e $1A 0#11 replace production in reverse e, A / 1A0 $11A0 0#11 pop terminal and match 0, 0 / e $11A #11 replace production in reverse e, A / B $11B #11

Converting a CFG to a PDA q0 e, e / $A e, $ / e q1 q2 A → 0A1 A → B B → # e, A / 1A0 e, A / B e, B / # 0, 0 / e 1, 1 / e #, # / e CFG input stack $A 00#11 $1A0 00#11 $1A 00#11 $11A0 00#11 $11A 00#11 $11B 00#11 $11# 00#11 $11 00#11 $1 00#11 $ 00#11 A  0A1  00A11  00B11  00#11

General PDA to CFG conversion a, a / e e, A / ak...a1 for every terminal a for every production A → a1...ak e, e / $S e, $ / e q0 q1 q2