CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT 20074.1 Lecture 4 Context-free grammars Jan Maluszynski, IDA, 2007

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

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.
The CYK Algorithm David Rodriguez-Velazquez CS – 6800 Summer I
COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University.
1 Introduction to Computability Theory Lecture12: Decidable Languages Prof. Amos Israeli.
PDAs => CFGs Sipser 2.2 (pages ). Last time…
CFGs and PDAs Sipser 2 (pages ). Last time…
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.
1 Introduction to Computability Theory Lecture5: Context Free Languages 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.
Lecture 15UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 15.
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.
CS 310 – Fall 2006 Pacific University CS310 Pushdown Automata Sections: 2.2 page 109 October 11, 2006.
Chap 2 Context-Free Languages. Context-free Grammars is not regular Context-free grammar : eg. G 1 : A  0A1substitution rules A  Bproduction rules B.
1 CSC 3130: Automata theory and formal languages Tutorial 4 KN Hung Office: SHB 1026 Department of Computer Science & Engineering.
1 Normal Forms for Context-free Grammars. 2 Chomsky Normal Form All productions have form: variable and terminal.
CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT Lecture 1 Introduction Jan Maluszynski, IDA, 2007
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.
CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT Lecture 6 Decidability Jan Maluszynski, IDA, 2007
CS5371 Theory of Computation Lecture 9: Automata Theory VII (Pumping Lemma, Non-CFL)
January 23, 2015CS21 Lecture 81 CS21 Decidability and Tractability Lecture 8 January 23, 2015.
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
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 PROGAMS CSci 4011.
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
Lecture 16 Oct 18 Context-Free Languages (CFL) - basic definitions Examples.
CSCI 2670 Introduction to Theory of Computing September 21, 2005.
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.
Context-free Grammars Example : S   Shortened notation : S  aSaS   | aSa | bSb S  bSb Which strings can be generated from S ? [Section 6.1]
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
The CYK Algorithm Presented by Aalapee Patel Tyler Ondracek CS6800 Spring 2014.
Membership problem CYK Algorithm Project presentation CS 5800 Spring 2013 Professor : Dr. Elise de Doncker Presented by : Savitha parur venkitachalam.
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.
Pushdown Automata Chapters Generators vs. Recognizers For Regular Languages: –regular expressions are generators –FAs are recognizers For Context-free.
Cs3102: Theory of Computation Class 8: Non-Context-Free Languages Spring 2010 University of Virginia David Evans.
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.
Non-CF Languages The language L = { a n b n c n | n  0 } does not appear to be context-free. Informal: A PDA can compare #a’s with #b’s. But by the time.
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.
Chapter 8 Properties of Context-free Languages These class notes are based on material from our textbook, An Introduction to Formal Languages and Automata,
Lecture # 31 Theory Of Automata By Dr. MM Alam 1.
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
Lecture 6: Context-Free Languages
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.
David Rodriguez-Velazquez CS – 6800 Summer I
Context-free Languages
Context-Free Grammars
فصل دوم Context-Free Languages
Chapter 2 Context-Free Language - 01
Presentation transcript:

CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT Lecture 4 Context-free grammars Jan Maluszynski, IDA, ida.liu.se

CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT Outline (Sipser 2.1 – 2.3) 1.Motivating example 2.CFG Definition 3.Parse trees, ambiguity 4.Push-down automata 5.Equivalence CFG – PDA 6.Pumping lemma for CFG

CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT Motivating example A  (A) A   Gramatical rules used for rewriting: A  (A)  () A  (A)  ((A))  (((A)))  ((())) L(A) : all terminal strings derivable L(A) is not regular!

CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT Context Free Grammars A CFG : (V, , R, S) V a finite set of nonterminals (variables)  a finite set of terminals, disjoint with V R a finite set of rules of the form X  w where X  V and w  (V+  )* S  V is a start nonterminal

CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT Context-Free Languages A CFG G: (V, , R, S) L(G) denotes the language of G: the set of all terminal strings derivable in G from S A language is a context-free language iff it is the language of a CFG

CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT Ambiguity E  E+E E  E#E E  (E) E  a

CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT Chomsky Normal Form G is in CNF if every rule is of the form A  BC or A  a In addition, there may be the rule S   Where S is the start nonterminal Every CFL is generated by a CNF grammar. An application: the CYK parsing algorithm

CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT Cocke-Younger- Kasami parsing G CNF grammar w string w = s 1 s 2 …..s n CYK checks if w is in L(G) by constructing a table T[i,j], 1  i,j  |w| where: T[i,j] = { X | X => s i s i+1 …..s i+j } Thus w is in L(G) iff S is in T[1,|w|]

CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT CYK table Construct T[i,1] for i = 1,…, |w| X is in T[i,1] iff X  s i Having T[i,j] and T[i+j,k] construct T[i,j+k]: Y is in T[i,j+k] iff for some X in T[i,j], Z in T[i+j,k] Y  X Z

CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT CYK (transposed) table example S  AB | BC A  BA | a B  CC | b C  AB | a b a a b a i = substrings: 1 B A,C A,C B A,C length 1 2 S,A B S,C S,A length B B length S,A,C length 4 5 S,A,C length 5 e.g. B  T[2,3] since B  CC, C  T[2,1] C  T[2+1,2]

CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT Pushdown Automaton FA extended with a stack Top stack symbol is an argument of a transition can be accessed and replaced by a new one

CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT (Nondeterministic) Pushdown Automaton (Q, , , , q 0,F) Q states  Input alphabet  Stack alphabet  : (Q  (  {  })  (  {  }))  P (Q  (  {  }) q 0  Q initial state F  Q final states

CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT PDA vs. CFG’s Theorem: A language is context-free iff it is recognized by a pushdown automaton. (p.117) CFG  PDA : Idea: simulate derivations on the stack (see example) PDA  CFG Idea: Nonterminals X pq derive all strings that bring PDA from p to q starting and ending with empty stack (details see pp ).

CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT Regular Languages are Context-free Every Regular Language is Context-free: FA is a special case of PDA Regular grammar: Each rule of the form: A  aB, A  a or A   A CF language L is regular iff there exists a regular CFG G such that L = L(G).

CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT Pumping lemma for CFL a + a # a a+…a+ a # a…# a

CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT Pumping Lemma for CFL For any CFL L there is p such that If s  L and |s|  p then s=uvxyz for some u,v,x,y,z satisfying: For each i  0 uv i xy i z  L |vy|>0 |vxy|  p Used for proving that a language is not a CFL