Context-free Languages

Slides:



Advertisements
Similar presentations
Theory of Computation CS3102 – Spring 2014 A tale of computers, math, problem solving, life, love and tragic death Nathan Brunelle Department of Computer.
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.
Nathan Brunelle Department of Computer Science University of Virginia Theory of Computation CS3102 – Spring 2014 A tale.
CFGs and PDAs Sipser 2 (pages ). Long long ago…
CS 3240: Languages and Computation Properties of Context-Free Languages.
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
PDAs => CFGs Sipser 2.2 (pages ). Last time…
CFGs and PDAs Sipser 2 (pages ). Last time…
Turing machines Sipser 2.3 and 3.1 (pages )
PDAs => CFGs Sipser 2.2 (pages ). Last time…
CFG => PDA Sipser 2 (pages ).
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.
CS5371 Theory of Computation
Applied Computer Science II Chapter 2 : Context-free languages Prof. Dr. Luc De Raedt Institut für Informatik Albert-Ludwigs Universität Freiburg Germany.
Introduction to the Theory of Computation John Paxton Montana State University Summer 2003.
Chap 2 Context-Free Languages. Context-free Grammars is not regular Context-free grammar : eg. G 1 : A  0A1substitution rules A  Bproduction rules B.
CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT Lecture 4 Context-free grammars Jan Maluszynski, IDA, 2007
Fall 2004COMP 3351 NPDA’s Accept Context-Free Languages.
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.2: Pushdown Automata) Prof. Karen Daniels, Fall 2009 with acknowledgement.
CS5371 Theory of Computation Lecture 9: Automata Theory VII (Pumping Lemma, Non-CFL)
CS5371 Theory of Computation Lecture 8: Automata Theory VI (PDA, PDA = CFG)
1 Context-Free Languages. 2 Regular Languages 3 Context-Free Languages.
January 15, 2014CS21 Lecture 61 CS21 Decidability and Tractability Lecture 6 January 16, 2015.
Today Chapter 2: (Pushdown automata) Non-CF languages CFL pumping lemma Closure properties of CFL.
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
1 PDAs Accept Context-Free Languages. 2 Context-Free Languages (Grammars) Languages Accepted by PDAs Theorem:
1 Context-Free Languages. 2 Regular Languages 3 Context-Free Languages.
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.
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
INHERENT LIMITATIONS OF COMPUTER PROGAMS CSci 4011.
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 7 Mälardalen University 2010.
1 Computer Language Theory Chapter 2: Context-Free Languages.
Lecture 16 Oct 18 Context-Free Languages (CFL) - basic definitions Examples.
CSE 3813 Introduction to Formal Languages and Automata Chapter 8 Properties of Context-free Languages These class notes are based on material from our.
نظریه زبان ها و ماشین ها فصل دوم Context-Free Languages دانشگاه صنعتی شریف بهار 88.
CSCI 2670 Introduction to Theory of Computing September 21, 2004.
Context-free Grammars [Section 2.1] - more powerful than regular languages - originally developed by linguists - important for compilation of programming.
1 Context-Free Languages. 2 Regular Languages 3 Context-Free Languages.
Context-free Languages Chapter 2. Ambiguity.
CSCI 2670 Introduction to Theory of Computing September 22, 2005.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 11 Midterm Exam 2 -Context-Free Languages Mälardalen University 2005.
Cs3102: Theory of Computation Class 8: Non-Context-Free Languages Spring 2010 University of Virginia David Evans.
Equivalence of Pushdown Automata and Context-Free Grammar Prof. Héctor Muñoz-Avila.
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.
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.2: Pushdown Automata) Prof. Karen Daniels, Fall 2010 with acknowledgement.
CSCI 2670 Introduction to Theory of Computing September 23, 2004.
Introduction Finite Automata accept all regular languages and only regular languages Even very simple languages are non regular (  = {a,b}): - {a n b.
Chapter 8 Properties of Context-free Languages These class notes are based on material from our textbook, An Introduction to Formal Languages and Automata,
January 20, 2016CS21 Lecture 71 CS21 Decidability and Tractability Lecture 7 January 20, 2016.
Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1 Chapter 2 Context-Free Languages Some slides are in courtesy.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen Department of Computer Science University of Texas-Pan American.
Transparency No. 1 Formal Language and Automata Theory Homework 5.
Grammar Set of variables Set of terminal symbols Start variable Set of Production rules.
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
 2004 SDU Lecture8 NON-Context-free languages.  2004 SDU 2 Are all languages context free? Ans: No. # of PDAs on  < # of languages on  Pumping lemma:
Theory of Languages and Automata By: Mojtaba Khezrian.
Complexity and Computability Theory I Lecture #12 Instructor: Rina Zviel-Girshin Lea Epstein.
Lecture 11  2004 SDU Lecture7 Pushdown Automaton.
NPDAs Accept Context-Free Languages
CSE 105 theory of computation
PDAs Accept Context-Free Languages
Context-free Languages
Context-Free Grammars
فصل دوم Context-Free Languages
Midterm #2 — Review problems
Chapter 2 Context-Free Language - 01
Presentation transcript:

Context-free Languages

2 Context-free grammar G 1

3 Parse tree for 000#111 in grammar G 1 A A A A B # 1 1 1

4 The English Language   |  |    |  a | the  boy | girl | flower  touches | likes | sees  with

5 Definition 2.1

6 Context-free Languages

7 Context Dependency

8 Example 2.2 G 3

9 Example 2.3 G 4

10 Parse tree for a+aXa a + a X a

11 Parse tree for (a+a)Xa ( a + a ) X a

12 Ambiguity in grammar G 5

13 A parse tree for a+aXa a + a X a

14 Another parse tree for a+aXa a + a X a

15 Different derivations for the same parse tree a + a X a

16 Leftmost Derivation If a string has two different parse trees, we say that the grammar is ambiguous. A derivation of a string is a leftmost derivation if at every step the leftmost remaining variable is the one replaced. Every parse tree has unique leftmost derivation.

17 Definition 2.4 Ambiguity

18 Definition 2.5 Chomsky normal form

19 Theorem 2.6

20 Proof of Th. 2.6

21 Proof of Th. 2.6

22 Example 2.7 G 6

23 Example 2.7 Step 2

24 Example 2.7 Step 3

25 Example 2.7 Step 4

26 Pushdown Automata state control aabb input state control aabb input x y z... stack pushdown automaton finite automaton

27 Definition 2.8

28 Computation

29 Theorem 2.12 A language is context free if and only if some pushdown automaton recognizes it. Lemma 2.13 –If a language is context free, then some pushdown automaton recognizes it. Lemma 2.15 –If a pushdown automaton recognizes some language, then it is context free.

30 Proof of Lemma 2.13 CFL  Recognized by PDA

31 Proof of Lemma 2.13

32 State Diagram of P q start q loop q accept   S$ ,$   ,A  w for rule A  w a,a   for terminal a

33 Example 2.14 q start q loop q accept ,S  b ,T   a,a   b,b   ,Sb,Sb ,T,T ,a,a ,Ta,Ta ,T,T ,S$,S$ ,$   S  aTb | b T  Ta | 

34 Proof of Lemma 2.15 Recognized by PDA  CFL

35 Proof of Lemma 2.15

36 A pq  A pr A rq stack height input string generated by A pq p q r generated by A pr generated by A rq

37 A pq  aA rs b stack height input string generated by A pq p q rs generated by A rs ab

38 Claim 2.16 If A pq generates x, then x can bring P from p with empty stack to q with empty stack.

39 Proof (continued)

40 Proof (continued)

41 Proof (continued)

42 Claim 2.17 If x can bring P from p with empty stack to q with empty stack, A pq generates x.

43 Proof (continued)

44 Proof (continued)

45 Corollary 2.18 Every regular language is context free. context-free languages regular languages

46 Theorem 2.19 [Pumping Lemma]

47 Proof T R R u v x y z T R u v T R u R R v x y y z x z

48 Proof

49 Proof

50 Example 2.20 apap bpbp cpcp vy vy v y Case v and y are homogeneous vy Case v or y is heterogeneous or vy vy

51 Example 2.21 apap bpbp cpcp vy vy v y Case v and y are homogeneous vy Case v or y is heterogeneous or See if uv 0 xy 0 z=uxz breaks the balance. See if uv 2 xy 2 z breaks the balance. See if uv 2 xy 2 z or uxz destroys the order. vy vy

52 Example p0p 0p0p 1p1p 1p1p vxy 0p0p 0p0p 1p1p 1p1p 0p0p 0p0p 1p1p 1p1p See if the first half of uv 2 xy 2 z begins with 0 while the latter half begins with 1. See if the first half of uv 2 xy 2 z ends with 0 while the latter half ends with 1. See if uv 0 xy 0 z=uxz =0 p 1 i 0 j 1 p, where i and j can not both be p.