CSCI 2670 Introduction to Theory of Computing September 20, 2005.

Slides:



Advertisements
Similar presentations
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
Advertisements

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…
About Grammars CS 130 Theory of Computation HMU Textbook: Sec 7.1, 6.3, 5.4.
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
Pushdown Automata Part II: PDAs and CFG Chapter 12.
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…
Introduction to Computability Theory
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.
Chap 2 Context-Free Languages. Context-free Grammars is not regular Context-free grammar : eg. G 1 : A  0A1substitution rules A  Bproduction rules B.
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.1: Context-Free Grammars) David Martin With some.
CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT Lecture 4 Context-free grammars Jan Maluszynski, IDA, 2007
1 Normal Forms for Context-free Grammars. 2 Chomsky Normal Form All productions have form: variable and terminal.
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.
1 Normal Forms for Context-free Grammars. 2 Chomsky Normal Form All productions have form: variable and terminal.
CS5371 Theory of Computation Lecture 8: Automata Theory VI (PDA, PDA = CFG)
January 15, 2014CS21 Lecture 61 CS21 Decidability and Tractability Lecture 6 January 16, 2015.
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 PROGRAMS CSci 4011.
INHERENT LIMITATIONS OF COMPUTER PROGAMS CSci 4011.
1 Computer Language Theory Chapter 2: Context-Free Languages.
CSCI 2670 Introduction to Theory of Computing September 21, 2005.
نظریه زبان ها و ماشین ها فصل دوم Context-Free Languages دانشگاه صنعتی شریف بهار 88.
CONVERTING TO CHOMSKY NORMAL FORM
CSCI 2670 Introduction to Theory of Computing September 28, 2005.
Pushdown Automata (PDA) Intro
Context-Free Grammars Normal Forms Chapter 11. Normal Forms A normal form F for a set C of data objects is a form, i.e., a set of syntactically valid.
The Pumping Lemma for Context Free Grammars. Chomsky Normal Form Chomsky Normal Form (CNF) is a simple and useful form of a CFG Every rule of a CNF grammar.
CSCI 2670 Introduction to Theory of Computing September 21, 2004.
Pushdown Automata CS 130: Theory of Computation HMU textbook, Chap 6.
Pushdown Automata (PDAs)
Design contex-free grammars that generate: L 1 = { u v : u ∈ {a,b}*, v ∈ {a, c}*, and |u| ≤ |v| ≤ 3 |u| }. L 2 = { a p b q c p a r b 2r : p, q, r ≥ 0 }
CSCI 2670 Introduction to Theory of Computing September 15, 2005.
Regular Grammars Chapter 7. Regular Grammars A regular grammar G is a quadruple (V, , R, S), where: ● V is the rule alphabet, which contains nonterminals.
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.
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.
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.
CSCI 2670 Introduction to Theory of Computing October 13, 2005.
CSCI 2670 Introduction to Theory of Computing September 14, 2005.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Pushdown.
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.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Pushdown.
Pushdown Automata Hopcroft, Motawi, Ullman, Chap 6.
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.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.
About Grammars Hopcroft, Motawi, Ullman, Chap 7.1, 6.3, 5.4.
Theory of Computation Automata Theory Dr. Ayman Srour.
Theory of Languages and Automata By: Mojtaba Khezrian.
CSCI 2670 Introduction to Theory of Computing September 16, 2004.
Lecture 11  2004 SDU Lecture7 Pushdown Automaton.
CSCI 2670 Introduction to Theory of Computing September 22, 2004.
Computability Joke. Context-free grammars Parsing. Chomsky
CHAPTER 2 Context-Free Languages
Context-Free Languages
فصل دوم Context-Free Languages
Chapter 2 Context-Free Language - 01
Pushdown automata The Chinese University of Hong Kong Fall 2011
Presentation transcript:

CSCI 2670 Introduction to Theory of Computing September 20, 2005

Agenda Last week –Context-free grammars Examples, definition, strategies for building This week –More on CFG’s Chomsky normal form, Pushdown automata, pumping lemma for CFG’s

Announcement Recommended problems to do prior to next Tuesday (9/27) –2.8, 2.9, 2.12, 2.13, 2.15, 2.16, 2.30 d I will post solutions to these problems on Friday Midterm next Tuesday –Chapters 1 & 2 I will hand out practice midterm tomorrow and solutions the next day I will hold extra office hours on Friday 11:00 – 12:30

Chomsky normal form Method of simplifying a CFG Definition: A context-free grammar is in Chomsky normal form if every rule is of one of the following forms A  BC A  a where a is any terminal and A is any variable, and B, and C are any variables or terminals other than the start variable if S is the start variable then the rule S  ε is the only permitted  rule

CFG’s and Chomsky normal form Theorem: Any context-free language is generated by a context-free grammar in Chomsky normal form. Proof idea: Convert any CFG to one in Chomsky normal form by removing or replacing all rules in the wrong form 1.Add a new start symbol 2.Eliminate ε rules of the form A  ε 3.Eliminate unit rules of the form A  B 4.Convert remaining rules into proper form

Convert a CFG to Chomsky normal form 1.Add a new start symbol -Create the following new rule S 0  S where S is the start symbol and S 0 is not used in the CFG

Convert a CFG to Chomsky normal form 2.Eliminate all ε rules A  ε, where A is not the start variable -For each rule with an occurrence of A on the right-hand side, add a new rule with the A deleted R  uAv becomes R  uAv | uv R  uAvAw becomes R  uAvAw | uvAw | uAvw | uvw -If we have R  A, replace it with R  ε unless we had already removed R  ε

Convert a CFG to Chomsky normal form 3.Eliminate all unit rules of the form A  B -For each rule B  u, add a new rule A  u, where u is a string of terminals and variables, unless this rule had already been removed -Repeat until all unit rules have been replaced

Convert a CFG to Chomsky normal form 4.Convert remaining rules into proper form -What’s left? -Replace each rule A  u 1 u 2 …u k, where k  3 and u i is a variable or a terminal with k-1 rules A  u 1 A 1 A 1  u 2 A 2 … A k-2  u k-1 u k

Example S  S 1 | S 2 S 1  S 1 b | Ab A  aAb | ab | ε S 2  S 2 a | Ba B  bBa | ba| ε Step 1: Add a new start symbol

Example S 0  S S  S 1 | S 2 S 1  S 1 b | Ab A  aAb | ab | ε S 2  S 2 a | Ba B  bBa | ba | ε Step 2: Eliminate ε rules

Example S 0  S S  S 1 | S 2 S 1  S 1 b | Ab | b A  aAb | ab S 2  S 2 a | Ba | a B  bBa | ba Step 3: Eliminate all unit rules

Example S 0  S 1 b | Ab | b | S 2 a | Ba | a S  S 1 b | Ab | b | S 2 a | Ba | a S 1  S 1 b | Ab | b A  aAb | ab S 2  S 2 a | Ba | a B  bBa | ba Step 4: Convert remaining rules to proper form

Example S 0  S 1 b | Ab | b | S 2 a | Ba | a S  S 1 b | Ab | b | S 2 a | Ba | a S 1  S 1 b | Ab | b A  aA 1 | ab A 1  Ab S 2  S 2 a | Ba | a B  bB 1 | ba B 1  Ba

Pushdown automata Similar to finite automata, but for CFG’s Finite automata are not adequate for CFG’s because we cannot keep track of what we’ve done –At any point, we only know the current state, not previous states Need memory –PDA’s are finite automata with a stack

Finite automata and PDA schematics State control a a b b State control a a b b xyzxyz FA PDA Stack: Infinite LIFO (last in first out) device

Example read 0 & push 0 on stack read ε & push ε on stack read ε & push $ on stack read 1 & pop 0 off stack read ε & pop $ off stack Language accepted: {0 n 1 n | n  0}

Differences between PDA’s and NFA’s Transitions read a symbol of the string and push a symbol onto or pop a symbol off of the stack Stack alphabet is not necessarily the same as the alphabet for the language –e.g., $ marks bottom of stack in previous (0 n 1 n ) example