About Grammars Hopcroft, Motawi, Ullman, Chap 7.1, 6.3, 5.4.

Slides:



Advertisements
Similar presentations
Chapter 5 Pushdown Automata
Advertisements

Closure Properties of CFL's
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.
Fall 2004COMP 3351 Simplifications of Context-Free Grammars.
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
PDAs => CFGs Sipser 2.2 (pages ). Last time…
CFGs and PDAs Sipser 2 (pages ). Last time…
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 11, 2006.
Costas Busch - RPI1 NPDAs Accept Context-Free Languages.
Courtesy Costas Busch - RPI1 NPDAs Accept Context-Free Languages.
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.
Fall 2004COMP 3351 NPDA’s Accept Context-Free Languages.
1 Normal Forms for Context-free Grammars. 2 Chomsky Normal Form All productions have form: variable and terminal.
Normal forms for Context-Free Grammars
CS5371 Theory of Computation Lecture 8: Automata Theory VI (PDA, PDA = CFG)
Cs466(Prasad)L8Norm1 Normal Forms Chomsky Normal Form Griebach Normal Form.
Fall 2006Costas Busch - RPI1 PDAs Accept Context-Free Languages.
1 Pushdown Automata PDAs. 2 Pushdown Automaton -- PDA Input String Stack States.
1 PDAs Accept Context-Free Languages. 2 Context-Free Languages (Grammars) Languages Accepted by PDAs Theorem:
CS 3813 Introduction to Formal Languages and Automata Chapter 6 Simplification of Context-free Grammars and Normal Forms These class notes are based on.
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.
Lecture 21: Languages and Grammars. Natural Language vs. Formal Language.
Context-Free Grammars
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 8 Mälardalen University 2010.
CONVERTING TO CHOMSKY NORMAL FORM
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.
CSCI 2670 Introduction to Theory of Computing September 20, 2005.
Normal Forms for Context-Free Grammars Definition: A symbol X in V  T is useless in a CFG G=(V, T, P, S) if there does not exist a derivation of the form.
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 Grammar. Introduction Why do we want to learn about Context Free Grammars?  Used in many parsers in compilers  Yet another compiler-compiler,
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 11 Midterm Exam 2 -Context-Free Languages Mälardalen University 2005.
Chapter 6 Simplification of Context-free Grammars and Normal Forms These class notes are based on material from our textbook, An Introduction to Formal.
1 Simplification of Context-Free Grammars Some useful substitution rules. Removing useless productions. Removing -productions. Removing unit-productions.
Closure Properties Lemma: Let A 1 and A 2 be two CF languages, then the union A 1  A 2 is context free as well. Proof: Assume that the two grammars are.
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
1 Chapter 6 Simplification of CFGs and Normal Forms.
Formal Languages, Automata and Models of Computation
Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1 Chapter 2 Context-Free Languages Some slides are in courtesy.
Pushdown Automata Hopcroft, Motawi, Ullman, Chap 6.
Grammar Set of variables Set of terminal symbols Start variable Set of Production rules.
Exercises on Chomsky Normal Form and CYK parsing
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 8 Mälardalen University 2011.
CS 154 Formal Languages and Computability March 8 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
Costas Busch - LSU1 PDAs Accept Context-Free Languages.
Formal Languages, Automata and Models of Computation
Closed book, closed notes
Normal Forms for CFG’s Eliminating Useless Variables Removing Epsilon
Context-Free Grammars: an overview
PDAs Accept Context-Free Languages
Complexity and Computability Theory I
7. Properties of Context-Free Languages
NPDAs Accept Context-Free Languages
Simplifications of Context-Free Grammars
Simplifications of Context-Free Grammars
NPDAs Accept Context-Free Languages
Regular Grammar.
7. Properties of Context-Free Languages
Chapter 6 Simplification of Context-free Grammars and Normal Forms
CHAPTER 2 Context-Free Languages
Chapter 2 Context-Free Language - 01
… NPDAs continued.
Normal Forms for Context-free Grammars
Context-Free Languages
Presentation transcript:

About Grammars Hopcroft, Motawi, Ullman, Chap 7.1, 6.3, 5.4

About grammars Normal forms for grammars Equivalence between CFGs and PDAs Grammar Ambiguity

Grammar Productions Formal definition of a grammar provides much leeway Productions can be simplified or restricted to make proofs about CFGs simpler

Simplifications Removing useless symbols Those that cannot be derived from S and those that cannot reduce to a terminal string Removing є-productions A  є Removing unit productions A  B Normal forms e.g., Chomsky Normal Form

Useless symbols We want to ensure all productions in the grammar have no useless symbols, i.e., all symbols are generating and reachable Generating symbols All variables that could eventually derive a string of terminals; i.e., all A in V, such that there exists a string w of terminals where A  * w Reachable symbols All variables that can be reached from the start symbol; i.e., all A in V, such that S  * uAw, for some u and w

Removing useless productions Remove productions with non-generating symbols Requires identifying generating symbols recursively: right hand side of production contains only terminals and generating symbols Remove productions with non-reachable symbols Requires identifying reachable symbols recursively: S is reachable, and so are symbols that exist on the right hand side of productions with reachable symbols on the left hand side

Epsilon Productions є-productions: productions of the form A  є Nullable symbols: symbols A where A  є or A  B 1 B 2 …B n such that each B i is nullable For each production that has a nullable symbol on the right hand side, add a production without that symbol; apply rule iteratively on resulting productions After this step, all є-productions can be removed Note, if the language L generated by the original grammar includes є, then the language generated by the resulting grammar will be L – {є}

Unit Productions Unit productions: all productions of the form A  B Removing unit productions Identify unit pairs: pairs of variables (A, B) such that A  * B, and the derivation involves only unit productions For each unit pair (A, B), add the production A  w, whenever B  w and w is not a variable Unit productions may now be removed

Chomsky Normal Form CNF: all productions are of the form A  BC(B, C are variables) A  a(a is a terminal) How do we convert a grammar to an equivalent CNF grammar?

Greibach Normal Form GNF: all productions are of the form A  aB 1 B 2 …B n Note that A  a is allowed Note that if the grammar is GNF, each step in a derivation of a string adds a terminal How do we convert a grammar to an equivalent GNF grammar?

Equivalence between CFGs and PDAs Converting CFGs to PDAs Easier to use PDA version that accepts by empty stack Given a context free grammar G = (V,T,P,S), construct a pushdown automaton M Need to specify states, input and stack symbols and the transition function

CFG to PDA M = (Q, , , , q 0, Z 0 ), where Q contains a single state, q 0  = T  = {V  T} Z 0 = S Note: no need for F (final states) since we are accepting by empty stack And  is …

CFG to PDA Transition function  is based on the variables, productions and terminals of the grammar:  (q 0, є, A) = (q 0, w) whenever A  w  (q 0, a, a) = (q 0, є ) for each a in T Easier and more intuitive if the grammar is of GNF  (q 0, a, A) = (q 0, B 1 B 2 …B n ) for each production A  aB 1 B 2 …B n

PDA to CFG More elaborate construction Variables in the resulting grammar dependent on states and stack symbols Read section 6.3