CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Pushdown.

Slides:



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

Pushdown Automata Chapter 12. Recognizing Context-Free Languages Two notions of recognition: (1) Say yes or no, just like with FSMs (2) Say yes or no,
Pushdown Automata (PDA)
CS21 Decidability and Tractability
PDAs => CFGs Sipser 2.2 (pages ). Last time…
Introduction to Computability Theory
1 Introduction to Computability Theory Lecture7: PushDown Automata (Part 1) Prof. Amos Israeli.
CFG => PDA Sipser 2 (pages ). CS 311 Fall Formally… A pushdown automaton is a sextuple M = (Q, Σ, Γ, δ, q 0, F), where – Q is a finite set.
Costas Busch - RPI1 Pushdown Automata PDAs. Costas Busch - RPI2 Pushdown Automaton -- PDA Input String Stack States.
Courtesy Costas Busch - RPI1 Pushdown Automata PDAs.
Introduction to the Theory of Computation John Paxton Montana State University Summer 2003.
CS 310 – Fall 2006 Pacific University CS310 Pushdown Automata Sections: 2.2 page 109 October 9, 2006.
CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT Lecture 4 Context-free grammars Jan Maluszynski, IDA, 2007
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Regular.
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.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Nondeterminism.
CS 490: Automata and Language Theory Daniel Firpo Spring 2003.
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.
Nathan Brunelle Department of Computer Science University of Virginia Theory of Computation CS3102 – Spring 2014 A tale.
CSCI 2670 Introduction to Theory of Computing September 21, 2005.
Pushdown Automata.
CS490 Presentation: Automata & Language Theory Thong Lam Ran Shi.
Pushdown Automata CS 130: Theory of Computation HMU textbook, Chap 6.
Pushdown Automata (PDAs)
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong NFA to DFA.
Push-down Automata Section 3.3 Fri, Oct 21, 2005.
Pushdown Automata Chapters Generators vs. Recognizers For Regular Languages: –regular expressions are generators –FAs are recognizers For Context-free.
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
PushDown Automata. What is a stack? A stack is a Last In First Out data structure where I only have access to the last element inserted in the stack.
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.
1 Pushdown Automata Definition Moves of the PDA Languages of the PDA Deterministic PDA’s.
Lecture 14 Push Down Automata (PDA) Topics:  Definition  Moves of the PDA  Languages of the PDA  Deterministic PDA’s June 18, 2015 CSCE 355 Foundations.
Lecture 14UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 14.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Pushdown.
Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1 Chapter 2 Context-Free Languages Some slides are in courtesy.
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.
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
Pushdown Automata Chapter 12. Recognizing Context-Free Languages Two notions of recognition: (1) Say yes or no, just like with FSMs (2) Say yes or no,
Theory of Computation Automata Theory Dr. Ayman Srour.
Lecture 11  2004 SDU Lecture7 Pushdown Automaton.
6. Pushdown Automata CIS Automata and Formal Languages – Pei Wang.
Nondeterminism The Chinese University of Hong Kong Fall 2011
Pushdown Automata.
Lecture 14 Push Down Automata (PDA)
CSE 105 theory of computation
Pushdown Automata PDAs
Pushdown Automata PDAs
Pushdown Automata PDAs
Pushdown Automata PDAs
Pushdown automata and CFG ↔ PDA conversions
Context-Free Languages
Definition Moves of the PDA Languages of the PDA Deterministic PDA’s
Definition Moves of the PDA Languages of the PDA Deterministic PDA’s
Chapter 2 Context-Free Language - 01
CSE 105 theory of computation
Pushdown automata The Chinese University of Hong Kong Fall 2011
CSE 105 theory of computation
CSE 105 theory of computation
Presentation transcript:

CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Pushdown automata Fall 2008

Motivation We had two ways to describe regular languages How about context-free languages? regular expression DFANFA syntactic computational CFGpushdown automaton syntactic computational

Pushdown automata versus NFA Since context-free is more powerful than regular, pushdown automata must generalize NFAs state control 0100 input NFA

Pushdown automata A pushdown automaton has access to a stack, which is a potentially infinite supply of memory state control 0100 input pushdown automaton (PDA) … stack

Pushdown automata As the PDA is reading the input, it can push / pop symbols in / out of the stack state control 0100 input pushdown automaton (PDA) Z0Z0 01 stack … 1

Rules for pushdown automata The transitions are nondeterministic Stack is always accessed from the top Each transition can pop a symbol from the stack and / or push another symbol onto the stack Transitions depend on input symbol and on last symbol popped from stack Automaton accepts if after reading whole input, it can reach an accepting state

Example L = {0 n #1 n : n ≥ 0} state control 000# input Z0Z0 aa stack a … 111 read 0 push a read # read 1 pop a pop Z 0

Shorthand notation read 0 push a read # read 1 pop a pop Z 0 0,  / a #,  /  , Z 0 /  1, a /  read, pop / push

Formal definition A pushdown automaton is (Q, , , , q 0, Z 0, F) : –Q is a finite set of states; –  is the input alphabet; –  is the stack alphabet, including a special symbol Z 0 ; –q 0 in Q is the initial state; –Z 0 in  is the start symbol; –F  Q is a set of final states; –  is the transition function  : Q  (   {  })  (   {  }) → subsets of Q  (   {  }) stateinput symbolpop symbolstatepush symbol

Notes on definition We use slightly different definition than textbook Example 0,  / a #,  / , Z 0 /  1, a /   : Q  (   {  })  (   {  }) → subsets of Q  (   {  }) q0q0 q1q1 q2q2  (q 0, 0,  ) = {(q 0, a)}  (q 0, 1,  ) = ∅  (q 0, #,  ) = {(q 1,  )}  (q 0, 0,  ) = ∅...

A convention Sometimes we denote “transitions” by: This will mean: –Intuitively, pop b, then push c 1, c 2, and c 3 a, b  / c 1 c 2 c 3 q0q0 q1q1 ,  / c 2 q0q0 q1q1 a, b  / c 1 ,  / c 3 intermediate states

Examples Describe PDAs for the following languages: –L = {w#w R : w  ∈  *},  = {0, 1, #} –L = {ww R : w  ∈  *},  = {0, 1} –L = {w: w has same number of 0s and 1s},  = {0, 1} –L = {0 i 1 j : i ≤ j ≤ 2i},  = {0, 1}

Main theorem A language L is context-free if and only if it is accepted by some pushdown automaton. context-free grammarpushdown automaton

From CFGs to PDAs Idea: Use PDA to simulate (rightmost) derivations A → 0A1 A → B B → # A  0A1  00A11  00B11  00#11 PDA control: CFG: write start variable stack: Z0AZ0A replace production in reverse Z 0 1A0 pop terminals and match Z 0 1A e, e / A 0, 0 / e e, A / 1A0 input: 00#11 0#11 replace production in reverse Z 0 11A0e, A / 1A0 0#11 pop terminals and match Z 0 11A0, 0 / e #11 replace production in reverse Z 0 11Be, A / B #11

From CFGs to PDAs If, after reading whole input, PDA ends up with an empty stack, derivation must be valid Conversely, if there is no valid derivation, PDA will get stuck somewhere –Either unable to match next input symbol, –Or match whole input but stack non empty

Description of PDA for CFGs Repeat the following steps: –If the top of the stack is a variable A : Choose a rule A →  and substitute A with  –If the top of the stack is a terminal a : Read next input symbol and compare to a If they don’t match, reject (die) –If top of stack is Z 0, go to accept state

Description of PDA for CFGs q0q0 q1q1 q2q2 ,  / S a, a /  for every terminal a , A /  k...  1 for every production A →  1...  k , Z 0 / 

From PDAs to CFGs First, we simplify the PDA: –It has a single accept state q f –Z 0 is always popped exactly before accepting –Each transition is either a push, or a pop, but not both context-free grammarpushdown automaton ✓

From PDAs to CFGs We look at the stack in an accepting computation: a Z0Z0 Z0Z0 a Z0Z0 a Z0Z0 a Z0Z0 a Z0Z0 a Z0Z0 a Z0Z0 a Z0Z0 a Z0Z0 Z0Z0 baccc a portions that preserve the stack q0q0 q1q1 q3q3 q1q1 q7q7 q0q0 q1q1 q2q2 q1q1 q3q3 q7q7 A 03 = {x: x leads from q 0 to q 3 and preserves stack}  11  01  0 00 input state stack qfqf

From PDAs to CFGs a Z0Z0 Z0Z0 a Z0Z0 a Z0Z0 a Z0Z0 a Z0Z0 a Z0Z0 a Z0Z0 a Z0Z0 a Z0Z0 Z0Z0 baccc a q0q0 q1q1 q3q3 q1q1 q7q7 q1q1 q2q2 q1q1 q7q7  11  01  0 00 input state stack A 11 A 03 0  A 11 → 0A 03  q0q0 q3q3 qfqf

From PDAs to CFGs a Z0Z0 Z0Z0 a Z0Z0 a Z0Z0 a Z0Z0 a Z0Z0 a Z0Z0 a Z0Z0 a Z0Z0 a Z0Z0 Z0Z0 baccc a q0q0 q1q1 q3q3 q1q1 q7q7 q1q1 q2q2 q1q1 q7q7  11  01  0 00 input state stack A 03 A 13 A 13 → A 10 A 03 q0q0 q3q3 A 10 qfqf

From PDAs to CFGs qiqi qjqj a,  / t b, t /  q i’ q j’ A ij → aA i’j’ b qiqi qjqj qkqk A ik → A ij A jk qiqi A ii →  variables: A ij qfqf a, Z 0 /  qiqi A 0f → A 0i a start variable: A0fA0f

Example 0,  / a #,  / , Z 0 /  1, a /  q0q0 q1q1 q2q2 start variable: A 02 productions: A 00 → A 00 A 00 A 00 → A 01 A 10 A 00 → A 03 A 30 A 01 → A 01 A 11 A 01 → A 02 A 21 A 00 → ... A 11 →  A 22 →  A 01 → 0A 01 1 A 01 → #A 33 A 33 →  0,  / a #,  / $ , Z 0 /  1, a /  q0q0 q1q1 q2q2 q3q3 , $ /  A 02 → A 01