Part VII. Models for Context-Free Languages 1/50.

Slides:



Advertisements
Similar presentations
Chapter 5 Pushdown Automata
Advertisements

1 Pushdown Automata (PDA) Informally: –A PDA is an NFA-ε with a stack. –Transitions are modified to accommodate stack operations. Questions: –What is a.
C O N T E X T - F R E E LANGUAGES ( use a grammar to describe a language) 1.
CFGs and PDAs Sipser 2 (pages ). Long long ago…
COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University.
CFGs and PDAs Sipser 2 (pages ). Last time…
1 Introduction to Computability Theory Lecture7: PushDown Automata (Part 1) Prof. Amos Israeli.
CS5371 Theory of Computation
Theory of Computation What types of things are computable? How can we demonstrate what things are computable?
CS 310 – Fall 2006 Pacific University CS310 Pushdown Automata Sections: 2.2 page 109 October 11, 2006.
Transparency No. P2C3-1 Formal Language and Automata Theory Chapter 3 Pushdown Automata and Context-Free Languages.
CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT Lecture 4 Context-free grammars Jan Maluszynski, IDA, 2007
1 Module 28 Context Free Grammars –Definition of a grammar G –Deriving strings and defining L(G) Context-Free Language definition.
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.2: Pushdown Automata) Prof. Karen Daniels, Fall 2009 with acknowledgement.
January 14, 2015CS21 Lecture 51 CS21 Decidability and Tractability Lecture 5 January 14, 2015.
79 Regular Expression Regular expressions over an alphabet  are defined recursively as follows. (1) Ø, which denotes the empty set, is a regular expression.
Transparency No. P2C1-1 Formal Language and Automata Theory Part II Pushdown Automata and Context-Free Languages.
CS5371 Theory of Computation Lecture 8: Automata Theory VI (PDA, PDA = CFG)
MA/CSSE 474 Theory of Computation
Lecture 9UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 9.
Context-Free Grammars Chapter 3. 2 Context-Free Grammars and Languages n Defn A context-free grammar is a quadruple (V, , P, S), where  V is.
1 Pushdown Automata PDAs. 2 Pushdown Automaton -- PDA Input String Stack States.
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
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.
Languages & Strings String Operations Language Definitions.
Lecture 16 Oct 18 Context-Free Languages (CFL) - basic definitions Examples.
CSCI 2670 Introduction to Theory of Computing September 21, 2005.
Chapter 7 PDA and CFLs.
1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.
CS/IT 138 THEORY OF COMPUTATION Chapter 1 Introduction to the Theory of Computation.
CSCI 2670 Introduction to Theory of Computing September 20, 2005.
CSCI 2670 Introduction to Theory of Computing September 21, 2004.
Pushdown Automata CS 130: Theory of Computation HMU textbook, Chap 6.
Pushdown Automata (PDAs)
Context-free Languages
Context-free Languages Chapter 2. Ambiguity.
Regulated Pushdown Automata Alexander Meduna 1/22 Faculty of Information Technology Brno University of Technology Brno, Czech Republic, Europe.
CS 3813: Introduction to Formal Languages and Automata
Introduction to Language Theory
Lecture Pushdown Automata. stack stack head finite control tape head tape.
Complexity and Computability Theory I Lecture #9 Instructor: Rina Zviel-Girshin Lea Epstein.
Deep Pushdown Automata Alexander Meduna Brno University of Technology, Czech Republic  Based on Meduna, A.: Deep Pushdown Automata,
1 A well-parenthesized string is a string with the same number of (‘s as )’s which has the property that every prefix of the string has at least as many.
Chapter 7 Pushdown Automata
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
Grammars CS 130: Theory of Computation HMU textbook, Chap 5.
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.2: Pushdown Automata) Prof. Karen Daniels, Fall 2010 with acknowledgement.
Introduction Finite Automata accept all regular languages and only regular languages Even very simple languages are non regular (  = {a,b}): - {a n b.
1 Pushdown Automata There are context-free languages that are not regular. Finite automata cannot recognize all context-free languages.
Three Basic Concepts Languages Grammars Automata.
1 Alphabets: An Alphabet is a finite set of symbols. We will usually use  to denote the alphabet of input symbols or “terminal characters.” String: A.
Mathematical Foundations of Computer Science Chapter 3: Regular Languages and Regular Grammars.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen Department of Computer Science University of Texas-Pan American.
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.
1 A well-parenthesized string is a string with the same number of (‘s as )’s which has the property that every prefix of the string has at least as many.
Lecture 6: Context-Free Languages
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.
Akram Salah ISSR Basic Concepts Languages Grammar Automata (Automaton)
Theory of Languages and Automata By: Mojtaba Khezrian.
Week 14 - Friday.  What did we talk about last time?  Simplifying FSAs  Quotient automata.
CS6800 Advance Theory of Computation Spring 2016 Nasser Alsaedi
Lecture 17: Theory of Automata:2014 Context Free Grammars.
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.
Formal Language & Automata Theory
Chapter 7 PUSHDOWN AUTOMATA.
Pushdown Automata Reading: Chapter 6.
Context-free Languages
Chapter 2 Context-Free Language - 01
… NPDAs continued.
Presentation transcript:

Part VII. Models for Context-Free Languages 1/50

Context-Free Grammar (CFG) Gist: A grammar is based on a finite set of grammatical rules, by which it generates strings of its language. Illustration: Grammar G: Start nonterminal Terminals: a, b, c, d Nonterminals: A, B, S S Rules: S  AB, A  aAb, A  ab, B  bBa, B  ba ABabBabbBa abbbaa Rule: S  AB Rule: A  ab Rule: B  bBa Rule: B  ba  L(G) L(G) 2/50

Context-Free Grammar: Definition Definition: A context-free grammar (CFG) is a quadruple G = (N, T, P, S), where N is an alphabet of nonterminals T is an alphabet of terminals, N  T =  P is a finite set of rules of the form A  x, where A  N, x  (N  T) * S  N is the start nonterminal Strictly mathematically, P is a relation from N to (N  T) * Instead of (A, x)  P, we write A  x  P A  x means that A can be replaced with x A   is called  -rule Mathematical Note on Rules: 3/50

Convention A, …, F, S: nonterminals S: the start nonterminal a, …, d: terminals U, …, Z: members of (N  T) u, …, z: members of (N  T) *  : sequence of productions 4/50 A subset of rules of the form: A  x 1, A  x 2, …, A  x n can be simply written as: A  x 1 | x 2 | … | x n

A Derivation Step Definition: Let G = (N, T, P, S) be a CFG. Let u, v  (N  T) * and p = A  x  P. Then, uAv directly derives uxv according to p in G, written as uAv  uxv [p] or, simply, uAv  uxv. Note: If uAv  uxv in G, we also say that G makes a derivation step from uAv to uxv. Gist: A change of a string by a rule. vu Rule: A  x x … uv … 5/50

Definition: Let u  (N  T) *. G makes a zero-step derivation from u to u; in symbols, u  0 u [  ] or, simply, u  0 u Definition: Let u 0,…,u n  (N  T) *, n  1, and u i-1  u i [p i ], p i  P, for all i = 1,…, n; that is u 0  u 1 [p 1 ]  u 2 [p 2 ] …  u n [p n ] Then, G makes n derivation steps from u 0 to u n, u 0  n u n [p 1... p n ] or, simply, u 0  n u n Sequence of Derivation Steps 1/2 Gist: Several consecutive derivation steps. 6/50

If u 0  n u n [  ] for some n  1, then u 0 properly derives u n in G, written as u 0  + u n [  ]. If u 0  n u n [  ] for some n  0, then u 0 derives u n in G, written as u 0  * u n [  ]. Example: Consider aAb  aaBbb[1: A  aBb], and aaBbb  aacbb [2: B  c]. Then, aAb  2 aacbb [1 2], aAb  + aacbb [1 2], aAb  * aacbb [1 2] Sequence of Derivation Steps 2/2 7/50

Definition: Let G = (N, T, P, S) be a CFG. The language generated by G, L(G), is defined as L(G) = {w: w  T *, S  * w} Generated Language G = (N, T, P, S), let w = a 1 a 2 …a n ; a i  T for i = 1..n S  …  …  a1a2…anS  …  …  a1a2…an w G generates a terminal string w by a sequence of derivation steps from S to w Gist: if then w  L(G); otherwise, w  L(G) Illustration: 8/50

Definition: Let L be a language. L is a context- free language (CFL) if there exists a context-free grammar that generates L. Example: L = {a n b n : n  0} is a CFL. Context-Free Language (CFL) Gist: A language generated by a CFG. G = (N, T, P, S), where N = {S}, T = {a, b}, P = {1: S  aSb, 2: S   } S   [2] S  aSb [1]  ab [2] S  aSb [1]  aaSbb [1]  aabb [2] … L(G)L(G) = {a n b n : n  0} 9/50

Pushdown Automata (PDA) AmAm A1A1 A2A2 …aiai anan …a1a1 a2a2 … Read-write head Read head Finite State Control Pushdown:Input tape: top Gist:An FA extended by a pushdown store. move of head 20/50

Pushdown Automata: Definition Definition: A pushdown automaton (PDA) is a 7-tuple M = (Q, , , R, s, S, F), where Q is a finite set of states  is an input alphabet  is a pushdown alphabet R is a finite set of rules of the form: Apa  wq where A  , p, q  Q, a    {  }, w   * s  Q is the start state S   is the start pushdown symbol F  Q is a set of final states 21/50

Notes on PDA Rules Interpretation of Apa  wq: if the current state is p, current input symbol is a, and the topmost symbol on the pushdown is A, then M can read a, replace A with w and change state p to q. Note: if a = , no symbol is read Strictly mathematically, R is a relation from   Q  (   {  }) to  *  Q Instead of ( Apa, wq )  R, however, we write Apa  wq  R Mathematical note on rules: 22/50

PDA Configuration Definition: Let M = (Q, , , R, s, S, F) be a PDA. A configuration of M is a string    * Q  * Gist: Instantaneous description of PDA Configuration AmAm A1A1 A2A2 … aiai anan …a1a1 a2a2 … Read-write head Read head Finite State Control Pushdown: Input tape: p = current state p 25/50

Move Definition: Let xApay and xwqy be two configurations of a PDA, M, where x, w   *, A  , p, q  Q, a    {  }, and y   *. Let r = Apa  wq  R be a rule. Then, M makes a move from xApay to xwqy according to r, written as xApay |– xwqy [r] or, simply, xApay |– xwqy. Note: if a = , no input symbol is read Rule: Apa  wq Gist: A computational step made by a PDA Configuration: a p Ayx New configuration: q … w … yx 26/50

Definition: Let  be a configuration. M makes zero moves from  to  ; in symbols,  |– 0  [  ] or, simply,  |– 0  Definition: Let  0,  1,...,  n be a sequence of configurations, n  1, and  i-1 |–  i [r i ], r i  R, for all i = 1,..., n; that is,  0 |–  1 [r 1 ] |–  2 [r 2 ] … |–  n [r n ] Then M makes n moves from  0 to  n,  0 |– n  n [r 1... r n ] or, simply,  0 |– n  n Sequence of Moves 1/2 Gist: Several consecutive computational steps 27/50

If  0 |– n  n [  ] for some n  1, then  0 |– +  n [  ] or, simply,  0 |– +  n If  0 |– n  n [  ] for some n  0, then  0 |– *  n [  ] or, simply,  0 |– *  n Example: Consider AApabc |– ABqbc [1: Apa  Bq], and ABqbc |– ABCrc [2: Bqb  BCr]. Then, AApabc |– 2 ABCrc [1 2], AApabc |– + ABCrc [1 2], AApabc |– * ABCrc [1 2] Sequence of Moves 2/2 28/50

Definition: Let M = (Q, , , R, s, S, F) be a PDA. 1) The language that M accepts by final state, denoted by L(M) f, is defined as L(M) f = {w: w   *, Ssw |– * zf, z   *, f  F} 2) The language that M accepts by empty pushdown, denoted by L(M) , is defined as L(M)  = {w: w   *, Ssw |– * zf, z = , f  Q} 3) The language that M accepts by final state and empty pushdown, denoted by L(M) f , is defined as L(M) f  = {w: w   *, Ssw |– * zf, z = , f  F} Accepted Language: Three Types 29/50

PDA: Example M = (Q, , , R, s, S, F)  = {a, b}; where:  = {a, S}; apa  aap, Q = {s, p, q, f}; R = {Ssa  Sap, apb  q,apb  q, Sq  f} F = {f} aqb  q,aqb  q, Question: aabb  L(M) f  ? Ssaabb|– Sapabb|– Saapbb|– Saqb|– Sq|– f Rule: Ssa  Sap S s baab p aSabb q Sab p Saabb Rule: apa  aap Rule: apb  q Rule: aqb  q Rule: Sq  f S q f Answer: YES Empty pushdown Final state Note: L(M) f = L(M)  = L(M) f  = {a n b n : n  1} 30/50

Models for Context-free Languages Proof: See the previous algorithm. Theorem: For every CFG G, there is an PDA M such that L(G) = L(M) . Proof: See page 486 in [Meduna: Automata and Languages] Theorem: For every PDA M, there is a CFG G such that L(M)  = L(G). Conclusion: The fundamental models for context-free languages are 1) Context-free grammars2) Pushdown automata 50/50