PZ03A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, 2000 1 PZ03A - Pushdown automata Programming Language Design.

Slides:



Advertisements
Similar presentations
Formal Languages: main findings so far A problem can be formalised as a formal language A formal language can be defined in various ways, e.g.: the language.
Advertisements

Chapter 5 Pushdown Automata
C O N T E X T - F R E E LANGUAGES ( use a grammar to describe a language) 1.
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 Chapter 12. Recognizing Context-Free Languages We need a device similar to an FSM except that it needs more power. The insight: Precisely.
Pushdown Automata Consists of –Pushdown stack (can have terminals and nonterminals) –Finite state automaton control Can do one of three actions (based.
Pushdown Automata Part II: PDAs and CFG Chapter 12.
Introduction to Computability Theory
Costas Busch - RPI1 NPDAs Accept Context-Free Languages.
Courtesy Costas Busch - RPI1 NPDAs Accept Context-Free Languages.
CS 310 – Fall 2006 Pacific University CS310 Pushdown Automata Sections: 2.2 page 109 October 9, 2006.
PZ02A - Language translation
1 Normal Forms for Context-free Grammars. 2 Chomsky Normal Form All productions have form: variable and terminal.
Fall 2004COMP 3351 NPDA’s Accept Context-Free Languages.
1 Normal Forms for Context-free Grammars. 2 Chomsky Normal Form All productions have form: variable and terminal.
1 Foundations of Software Design Lecture 23: Finite Automata and Context-Free Grammars Marti Hearst Fall 2002.
PZ02B Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ02B - Regular grammars Programming Language Design.
CS5371 Theory of Computation Lecture 8: Automata Theory VI (PDA, PDA = CFG)
Table-driven parsing Parsing performed by a finite state machine. Parsing algorithm is language-independent. FSM driven by table (s) generated automatically.
Fall 2006Costas Busch - RPI1 The Chomsky Hierarchy.
A shorted version from: Anastasia Berdnikova & Denis Miretskiy.
Grammars, Languages and Finite-state automata Languages are described by grammars We need an algorithm that takes as input grammar sentence And gives a.
1 Pushdown Automata PDAs. 2 Pushdown Automaton -- PDA Input String Stack States.
1 PDAs Accept Context-Free Languages. 2 Context-Free Languages (Grammars) Languages Accepted by PDAs Theorem:
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 8 Mälardalen University 2010.
Pushdown Automata.
PZ02B Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ02B - Regular grammars Programming Language Design.
Pushdown Automata CS 130: Theory of Computation HMU textbook, Chap 6.
Pushdown Automata (PDAs)
Parsing Introduction Syntactic Analysis I. Parsing Introduction 2 The Role of the Parser The Syntactic Analyzer, or Parser, is the heart of the front.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 11 Midterm Exam 2 -Context-Free Languages Mälardalen University 2005.
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 6 Mälardalen University 2010.
Pushdown Automata Chapters Generators vs. Recognizers For Regular Languages: –regular expressions are generators –FAs are recognizers For Context-free.
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
PZ03A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ03A - Pushdown automata Programming Language Design.
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.2: Pushdown Automata) Prof. Karen Daniels, Fall 2010 with acknowledgement.
PZ03BX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ03BX –Recursive descent parsing Programming Language.
98 Nondeterministic Automata vs Deterministic Automata We learned that NFA is a convenient model for showing the relationships among regular grammars,
Pushdown Automata Hopcroft, Motawi, Ullman, Chap 6.
Grammar Set of variables Set of terminal symbols Start variable Set of Production rules.
Formal grammars A formal grammar is a system for defining the syntax of a language by specifying sequences of symbols or sentences that are considered.
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,
1 Chapter Pushdown Automata. 2 Section 12.2 Pushdown Automata A pushdown automaton (PDA) is a finite automaton with a stack that has stack operations.
CMSC 330: Organization of Programming Languages Pushdown Automata Parsing.
Week 14 - Friday.  What did we talk about last time?  Simplifying FSAs  Quotient automata.
CS 154 Formal Languages and Computability March 22 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
Lecture 11  2004 SDU Lecture7 Pushdown Automaton.
6. Pushdown Automata CIS Automata and Formal Languages – Pei Wang.
Formal Languages, Automata and Models of Computation
Pushdown Automata.
CSE 105 theory of computation
Table-driven parsing Parsing performed by a finite state machine.
Pushdown automata Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
NPDAs Accept Context-Free Languages
PDAs Accept Context-Free Languages
Chapter 7 PUSHDOWN AUTOMATA.
PZ03A - Pushdown automata
NPDAs Accept Context-Free Languages
CSE322 The Chomsky Hierarchy
Jaya Krishna, M.Tech, Assistant Professor
CSE 105 theory of computation
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 Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
The Chomsky Hierarchy Costas Busch - LSU.
Pushdown automata Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Normal Forms for Context-free Grammars
Pushdown automata Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
CH 4 - Language semantics
Presentation transcript:

PZ03A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ03A - Pushdown automata Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section

PZ03A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, Pushdown Automaton A pushdown automaton (PDA) is an abstract model machine similar to the FSA It has a finite set of states. However, in addition, it has a pushdown stack. Moves of the PDA are as follows: 1. An input symbol is read and the top symbol on the stack is read. 2. Based on both inputs, the machine enters a new state and writes zero or more symbols onto the pushdown stack. 3. Acceptance of a string occurs if the stack is ever empty. (Alternatively, acceptance can be if the PDA is in a final state. Both models can be shown to be equivalent.)

PZ03A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, Power of PDAs PDAs are more powerful than FSAs. a n b n, which cannot be recognized by an FSA, can easily be recognized by the PDA. Stack all a symbols and, for each b, pop an a off the stack. If the end of input is reached at the same time that the stack becomes empty, the string is accepted. It is less clear that the languages accepted by PDAs are equivalent to the context-free languages.

PZ03A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PDAs to produce derivation strings Given some BNF (context free grammar). Produce the leftmost derivation of a string using a PDA: 1. If the top of the stack is a terminal symbol, compare it to the next input symbol; pop it off the stack if the same. It is an error if the symbols do not match. 2. If the top of the stack is a nonterminal symbol X, replace X on the stack with some string , where  is the right hand side of some production X  . This PDA now simulates the leftmost derivation for some context-free grammar. This construction actually develops a nondeterministic PDA that is equivalent to the corresponding BNF grammar. (i.e., step 2 may have multiple options.)

PZ03A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, NDPDAs are different from DPDAs What is the relationship between deterministic PDAs and nondeterministic PDAs? They are different. Consider the set of palindromes, strings reading the same forward and backward, generated by the grammar S  0S0 | 1S1 | 2 We can recognize such strings by a deterministic PDA: –1. Stack all 0s and 1s as read. –2. Enter a new state upon reading a 2. –3. Compare each new input to the top of stack, and pop stack. However, consider the following set of palindromes: S  0S0 | 1S1 | 0 | 1 In this case, we never know where the middle of the string is. To recognize these palindromes, the automaton must guess where the middle of the string is (i.e., is nondeterministic).

PZ03A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PDA example Given the palindrome , the PDA needs to guess where the middle symbol is: Stack: Guess Middle: Match remainder: Only the fifth option, where the machine guesses that 0110 is the first half, terminates successfully. If some sequence of guesses leads to a complete parse of the input string, then the string is valid according to the grammar.

PZ03A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, Language-machine equivalence Already shown: Regular languages = FSA = NDFSA Context free languages = NDPDA. It can be shown that NDPDA not the same as DPDA For context sensitive languages, we have Linear Bounded Automata (LBA) For unrestricted languages we have Turing machines (TM) Unrestricted languages = TM = NDTM Context sensitive languages = NDLBA. It is still unknown if NDLBA=DLBA

PZ03A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, Grammar-machine equivalence

PZ03A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, General parsing algorithms Knuth in 1965 showed that the deterministic PDAs were equivalent to a class of grammars called LR(k) [Left- to-right parsing with k symbol lookahead] Create a PDA that would decide whether to stack the next symbol or pop a symbol off the stack by looking k symbols ahead. This is a deterministic process. For k=1 process is efficient. Tools built to process LR(k) grammars (YACC - Yet Another Compiler Compiler) LR(k), SLR(k) [Simple LR(k)], and LALR(k) [Lookahead LR(k)] are all techniques used today to build efficient parsers.