1 Push Down Automata Lecture 6-7 Ref. Handout p29-33, 25-28.

Slides:



Advertisements
Similar presentations
4b Lexical analysis Finite Automata
Advertisements

C O N T E X T - F R E E LANGUAGES ( use a grammar to describe a language) 1.
Pushdown Automata CPSC 388 Ellen Walker Hiram College.
1 1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 3 School of Innovation, Design and Engineering Mälardalen University 2012.
Pushdown Automata Chapter 12. Recognizing Context-Free Languages We need a device similar to an FSM except that it needs more power. The insight: Precisely.
CS21 Decidability and Tractability
Introduction to Computability Theory
1 Introduction to Computability Theory Lecture7: PushDown Automata (Part 1) Prof. Amos Israeli.
Costas Busch - RPI1 Pushdown Automata PDAs. Costas Busch - RPI2 Pushdown Automaton -- PDA Input String Stack States.
1 Module 32 Pushdown Automata (PDA’s) –definition –example.
Courtesy Costas Busch - RPI1 Non Deterministic Automata.
61 Nondeterminism and Nodeterministic Automata. 62 The computational machine models that we learned in the class are deterministic in the sense that the.
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 Lecture 30 Pushdown Automata (PDA’s) –definition –example.
Fall 2004COMP 3351 Pushdown Automata PDAs. Fall 2004COMP 3352 Pushdown Automaton -- PDA Input String Stack States.
Lecture 3 Goals: Formal definition of NFA, acceptance of a string by an NFA, computation tree associated with a string. Algorithm to convert an NFA to.
Fall 2006Costas Busch - RPI1 Non-Deterministic Finite Automata.
1 Non-Deterministic Automata Regular Expressions.
CS5371 Theory of Computation Lecture 8: Automata Theory VI (PDA, PDA = CFG)
1.Defs. a)Finite Automaton: A Finite Automaton ( FA ) has finite set of ‘states’ ( Q={q 0, q 1, q 2, ….. ) and its ‘control’ moves from state to state.
Costas Busch - LSU1 Non-Deterministic Finite Automata.
1 Finite Automata (Finite State Machine) Lecture 4-5 Ref. Handout p18-24.
1 Computer Language Theory Chapter 2: Context-Free Languages.
Pushdown Automata.
By: Er. Sukhwinder kaur.  What is Automata Theory? What is Automata Theory?  Alphabet and Strings Alphabet and Strings  Empty String Empty String 
Pushdown Automata (PDAs)
Cs3102: Theory of Computation Class 6: Pushdown Automata Spring 2010 University of Virginia David Evans TexPoint fonts used in EMF. Read the TexPoint manual.
4b 4b Lexical analysis Finite Automata. Finite Automata (FA) FA also called Finite State Machine (FSM) –Abstract model of a computing entity. –Decides.
Push-down Automata Section 3.3 Fri, Oct 21, 2005.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2010.
Chapter 7 Pushdown Automata
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.
UNIT - I Formal Language and Regular Expressions: Languages Definition regular expressions Regular sets identity rules. Finite Automata: DFA NFA NFA with.
using Deterministic Finite Automata & Nondeterministic Finite Automata
Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1 Chapter 2 Context-Free Languages Some slides are in courtesy.
CSE 311 Foundations of Computing I Lecture 24 FSM Limits, Pattern Matching Autumn 2011 CSE 3111.
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture 1 Ahmed Ezzat.
LECTURE 5 Scanning. SYNTAX ANALYSIS We know from our previous lectures that the process of verifying the syntax of the program is performed in two stages:
Deterministic Finite Automata Nondeterministic Finite Automata.
CS 154 Formal Languages and Computability March 10 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
Lecture 11  2004 SDU Lecture7 Pushdown Automaton.
Pushdown Automata - like NFA-  but also has a stack - transition takes the current state, the current input symbol, and the top-of-the-stack symbol (which.
Pushdown Automata.
Theory of Computation Pushdown Automata pda Lecture #10.
Lexical analysis Finite Automata
Non Deterministic Automata
Pushdown automata Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Pushdown Automata PDAs
Push-down Automata Section 3.3 Wed, Oct 27, 2004.
Pushdown Automata PDAs
Pushdown Automata PDAs
Pushdown Automata PDAs
Theory of Computation Lecture #27-28.
Push-down Automata.
Pushdown Automata.
Pushdown Automata (PDA). Part 3
Chapter 2 FINITE AUTOMATA.
Non-Deterministic Finite Automata
Non Deterministic Automata
4b Lexical analysis Finite Automata
4b Lexical analysis Finite Automata
Pushdown automata Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Principles of Computing – UFCFA3-30-1
Pushdown automata Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Pushdown automata The Chinese University of Hong Kong Fall 2011
Pushdown automata Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Pushdown automata Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Pushdown automata Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Presentation transcript:

1 Push Down Automata Lecture 6-7 Ref. Handout p29-33, 25-28

2 A Stack of Chairs Only the top chair is accessible. If a new chair is added, it can be only added at the top. When removing a chair, we must from it from the top. The last chair added will be the first one removed.

3 Stacks – an abstract data type x hidden values top Operations: push(z) - put z on top of stack pop -discard top of stack

4 Stacks and Interrupts Watching Video Phone rings Knock at door Toast catches fire Interrupted by something more urgent Another name for stacks: last-in-first-out (LIFO)

5 Stacks Stacks are used extensively at every level of a modern computer system. For example, evaluating an expression x = 3*(4/(2+2)); In programming x = get_requests(); process(x); get_request() { connect(); read(); } connect(){ open(); check()...} Need a stack to remember the back points 1 2 3

6 Push Down Automata (PDA) PDA = FA + a stack A State Transition with a Stack a,x / push(y) a,x / pop a – input symbol x – value at the top of the stack A A B B

7 Comparing with FA Transitions in FA Transitions in PDA a a,x / op state new state new state a – the input symbol x – the value at the top of stack op – the stack operation read a, move to the new state read a, the top of stack is x, perform op, then move to the new state

8 Some extras... a, x / nopdo not perform the stack operation a, _ / opdo the operation whatever is on top of the stack Λ, x / opwhatever the input is... (do not ‘consume’ the input)

9 Initialising a Stack We need to know whether a stack is empty This is handled by initialising a special value onto the stack. So as long as the special value is seen at the top of the stack, we know that the stack is empty start Λ,_/ push(Z) real start push(Z) real start or simply

10 A Push Down Automata push(Z) a,_/push(a)b,a/pop Λ,Z/pop { a n b n | n >0 } = {ab, aabb, aaabbb, aaaabbbb,...}

11 Operation of the Push Down Automata push(Z) a,_/push(a)b,a/pop Λ,Z/pop Input string: aaabbb

12 Operation of the Push Down Automata - examples of rejecting a string push(Z) a,_/push(a)b,a/pop Λ,Z/pop Illegal strings: abb aab

13 Another Push Down Automata push($) a,_/push(a)b,a/nop Λ,$/pop How about { (a n b 2n ) m | n>0, m>0} ? {a n b 2n | n>0} b,a/pop

14 Another Push Down Automata push($) a,_/push(a)b,a/nop Λ,$/pop How about { (a n b 2n ) m | n>0, m>0} ? {a n b 2n | n>0} b,a/pop a,$/push(a)

15 Extending an FA to a PDA From {1 n | n>0} 1 1 To { 1,11,111,...(1),1(11),((1)),(1)(1),((11))1,((1)(1)),... }

16 Memo for In-class test 6 [ /5] questionsmy answers correct answers comments

17 Determinism v Non-Determinism Deterministic Transitions a,X/op2 a,Y/op1 b,X/op3 Λ, Z/op3

18 Determinism v Non-Determinism Non-Deterministic Transitions a,X/op2 a,X/op1 Λ,X/op3

19 Non-Determinism PDA Recall FA – every NFA can be converted to a DFA which accepts the same language. NFA == DFA Can we do same for Push Down Automata? The answer is NO. NPDA \== DPDA

20 An Example to Show NPDA\==DPDA A palindrome is a string which read the same left to right as right to left. A deterministic PDA cannot recognise palindromes. With a stack we can push symbols onto the stack until we reach the middle of the string, then pop the stack against the rest of the palindrome. However, there is no way we can tell where is the middle!

21 A Non-deterministic PDA for Palindromes push(z) b,b/pop a,a/pop a,_/push(a) b,_/push(b) b,b/pop a,a/pop Λ,z/pop Here we assume palindromes involving only two symbols a and b

22 Regular Expressions Suppose you want to search for strings Mr Smith or Mr. Smith or Mr Smith or Mr. Smith or Mr J Smith or Mr. J. Smith or A very big file

23 We can use a regular expression (instead of drawing a FA) Mr “.” ? “ ” ∗ (J|J “.”) ? “ ” ∗ Smith Mr “.” ? optionally a “.” “ ” ∗ 0 or more spaces “ ” ∗ 0 or more spaces (J|J“.”)? optionally J or J. Smith

24 A Subset of Regular Expressions symbolmeaningexampleexplanation |Alternatives (logical or) a | ba or b ∗ repeat the last item 0 or more times a ∗ 0 or more occurrences of a +repeat the last item 1 or more times a + 1 or more occurrences of a [ ]any character in [ ][xyz] [a-z] any of x,y or z any from a-z ( )brackets(a|c)cgrouping

25 Some Examples 1 ∗ = ab ∗ = 1 ∗ | 0 ∗ = (1|0) ∗ = xy ∗ | yz ∗ = [a-z][a-z0-9] =

26 Where are Regular Expressions Used? grep(unix) program for searching files Perlused with programming language editorsstring searching lex program for generating pattern matching programs

27 Regular Expressions = NFAs = DFAs abcd ∗ | e ∗ design an FA to accept abcd ∗ e∗e∗ combine them (convert to DFA)

28 Regular Expressions, Regular Languages, and Finite Automata Regular expressions have the equal power as finite automata The languages accepted by finite automata are called regular languages FA = Regular Language Examples of regular languages: names, numbers, arithmetic expression without brackets

29 Context Free Languages and PDA Languages CNANOT be accepted by FA, but CAN be accepted by PDA are classified as context free languages Context free languages form the basis of all the languages used in computing Regular languages are subset of context free language regular languages (FA) context free (PDA) languages

30 Memo for In-class test 7 [ /5] questionsmy answers correct answers comments