CFGs and PDAs Sipser 2 (pages 99-115). Last time…

Slides:



Advertisements
Similar presentations
Chapter 5 Pushdown Automata
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…
Regular operations Sipser 1.1 (pages 44 – 47). CS 311 Mount Holyoke College 2 Building languages If L is a language, then its complement is L’ = {w |
PDAs => CFGs Sipser 2.2 (pages ). Last time…
PDAs => CFGs Sipser 2.2 (pages ). Last time…
Turing machines Sipser 2.3 and 3.1 (pages )
Context-Free Grammars Sipser 2.1 (pages 99 – 109).
Regular expressions Sipser 1.3 (pages 63-76). CS 311 Mount Holyoke College 2 Looks familiar…
CFG => PDA Sipser 2 (pages ).
NFAs Sipser 1.2 (pages 47–54). CS 311 Mount Holyoke College 2 Recall… Last time we showed that the class of regular languages is closed under: –Complement.
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.
Decidable languages Sipser 4.1 (pages ). CS 311 Mount Holyoke College 2 Hierarchy of languages All languages Turing-recognizable Turing-decidable.
Context-Free Grammars Sipser 2.1 (pages 99 – 109).
CS5371 Theory of Computation
1 … NPDAs continued. 2 Pushing Strings Input symbol Pop symbol Push string.
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 9, 2006.
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.
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.
CS 490: Automata and Language Theory Daniel Firpo Spring 2003.
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.
1 Pushdown Automata PDAs. 2 Pushdown Automaton -- PDA Input String Stack States.
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.
Lecture 21: Languages and Grammars. Natural Language vs. Formal Language.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 8 Mälardalen University 2010.
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 (PDAs)
Context-free Grammars [Section 2.1] - more powerful than regular languages - originally developed by linguists - important for compilation of programming.
Grammars CPSC 5135.
Context-free Languages
1 Context-Free Languages. 2 Regular Languages 3 Context-Free Languages.
1 Context-Free Languages. 2 Regular Languages 3 Context-Free Languages.
Push-down Automata Section 3.3 Fri, Oct 21, 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.
Grammars Hopcroft, Motawi, Ullman, Chap 5. Grammars Describes underlying rules (syntax) of programming languages Compilers (parsers) are based on such.
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.
CSC312 Automata Theory Lecture # 26 Chapter # 12 by Cohen Context Free Grammars.
Chapter 5 Context-Free Languages Regular language are effective in describing certain simple patterns. But it is not enough to describe programming languages.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen Department of Computer Science University of Texas-Pan American.
Grammar Set of variables Set of terminal symbols Start variable Set of Production rules.
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
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.
Costas Busch - LSU1 PDAs Accept Context-Free Languages.
Theory of Languages and Automata By: Mojtaba Khezrian.
Context-Free Grammars: an overview
Chapter 7 PUSHDOWN AUTOMATA.
Context-free Languages
CHAPTER 2 Context-Free Languages
فصل دوم Context-Free Languages
Chapter 2 Context-Free Language - 01
… NPDAs continued.
Presentation transcript:

CFGs and PDAs Sipser 2 (pages )

Last time…

CS 311 Mount Holyoke College 3 Context-free grammars A context-free grammar G is a quadruple (V, Σ, R, S), where – V is a finite set called the variables – Σ is a finite set, disjoint from V, called the terminals – R is a finite subset of V × ( V ∪ Σ )* called the rules – S ∈ V is called the start symbol For any A ∈ V and u ∈ (V ∪ Σ) *, we write A → G u whenever (A, u) ∈ R

CS 311 Mount Holyoke College 4 Arithmetic expressions and parse trees Consider G = (V, Σ, R, S), where – V ={,, } – Σ ={a, +, ×, (, )} – R ={ → G + |, → G × |, → G ( ) | a } – S = What about a × a +a ?

CS 311 Mount Holyoke College 5 Leftmost derivation A derivation of a string in a grammar is a leftmost derivation if: at every step the leftmost remaining variable is the one replaced

CS 311 Mount Holyoke College 6 Needlessly complicated? How about just → G + | × | | a A grammar G is ambiguous if some string w has two or more different leftmost derivations

CS 311 Mount Holyoke College 7 Regular languages are context-free

CS 311 Mount Holyoke College 8 Chomsky normal form A context-free grammar G is in Chomsky normal form –If every rule is of the form A → BC A → a where A,B,C ∈ V, B ≠ S ≠ C, and a ∈ Σ –We permit S → ε

CS 311 Mount Holyoke College 9 Chomsky normal form Theorem 2.9: Any context-free language is generated by a context-free grammar in Chomsky normal form Proof: 1.Make sure S appears only on the left 2.Remove empty rules: A → ε 3.Handle unit rules: A → B 4.Fix all the rest… For instance: – S → G ASA | aA – A → G b | ε

CS 311 Mount Holyoke College 10

CS 311 Mount Holyoke College 11 Balanced Brackets The grammar G = (V, Σ, R, S), where V = {S} Σ = {[, ]} R = { S → G ε, S → G SS, S → G [S]} generates all strings of balanced brackets Is the language L(G) is regular? –Why/Why not?

CS 311 Mount Holyoke College 12 Recognizing Context-Free Languages Grammars are language generators. It is not immediately clear how they might be used as language recognizers. The language L(G) of balanced brackets is not regular. It cannot be recognized by a finite state automaton. However, it is very similar to the BEGIN…END blocks of many procedural languages and, therefore, must be recognizable by some compiler or interpreter!

CS 311 Mount Holyoke College 13 Auxiliary storage We could recognize the language L(G) of balanced brackets by reading left to right, if we could remember left brackets along the way. [[][[]]] Must match some left bracket along the way

CS 311 Mount Holyoke College 14 Pushdown Automata The last left bracket seen matches the first right bracket. This suggests a stack storage mechanism. [ [ [ [ ] ] [ [ [ [ ] ] ] ] ] ] [ [ [ [ [ [ Finite control $ $ stack or pushdown store reading head

CS 311 Mount Holyoke College 15 Describing a pushdown machine

CS 311 Mount Holyoke College 16 Formally… A pushdown automaton is a sextuple M = (Q, Σ, Γ, δ, q 0, F), where – Q is a finite set of states – Σ is a finite alphabet (the input symbols) – Γ is a finite alphabet (the stack symbols) – δ: (Q × Σ ε ×Γ ε ) → P(Q × Γ ε ) is the transition function – q 0 ∈ Q is the initial state, and – F ⊆ Q is the set of accept states