7. Properties of Context-Free Languages

Slides:



Advertisements
Similar presentations
The Pumping Lemma for CFL’s
Advertisements

Theory of Computation CS3102 – Spring 2014 A tale of computers, math, problem solving, life, love and tragic death Nathan Brunelle Department of Computer.
Closure Properties of CFL's
Simplifying CFGs There are several ways in which context-free grammars can be simplified. One natural way is to eliminate useless symbols those that cannot.
About Grammars CS 130 Theory of Computation HMU Textbook: Sec 7.1, 6.3, 5.4.
Fall 2004COMP 3351 Simplifications of Context-Free Grammars.
Dept. of Computer Science & IT, FUUAST Automata Theory 2 Automata Theory VII.
CS 3240: Languages and Computation Properties of Context-Free Languages.
CS5371 Theory of Computation
CS 310 – Fall 2006 Pacific University CS310 Pushdown Automata Sections: 2.2 page 109 October 11, 2006.
Lecture Note of 12/22 jinnjy. Outline Chomsky Normal Form and CYK Algorithm Pumping Lemma for Context-Free Languages Closure Properties of CFL.
1 CSC 3130: Automata theory and formal languages Tutorial 4 KN Hung Office: SHB 1026 Department of Computer Science & Engineering.
Costas Buch - RPI1 Simplifications of Context-Free Grammars.
CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT Lecture 4 Context-free grammars Jan Maluszynski, IDA, 2007
104 Closure Properties of Regular Languages Regular languages are closed under many set operations. Let L 1 and L 2 be regular languages. (1) L 1  L 2.
Normal forms for Context-Free Grammars
Transparency No. P2C5-1 Formal Language and Automata Theory Part II Chapter 5 The Pumping Lemma and Closure properties for Context-free Languages.
1 Module 32 Chomsky Normal Form (CNF) –4 step process.
1 Background Information for the Pumping Lemma for Context-Free Languages Definition: Let G = (V, T, P, S) be a CFL. If every production in P is of the.
Homework #7 Solutions. #1. Use the pumping lemma for CFL’s to show L = {a i b j a i b j | i, j > 0} is not a CFL. Proof by contradiction using the Pumping.
1 Applications of Regular Closure. 2 The intersection of a context-free language and a regular language is a context-free language context free regular.
Properties of Context-Free Languages
1 Properties of Context-free Languages Reading: Chapter 7.
CSE 3813 Introduction to Formal Languages and Automata Chapter 8 Properties of Context-free Languages These class notes are based on material from our.
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.
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.
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.
Pushdown Automata Chapters Generators vs. Recognizers For Regular Languages: –regular expressions are generators –FAs are recognizers For Context-free.
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.
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.
Pumping Lemma for CFLs. Theorem 7.17: Let G be a CFG in CNF and w a string in L(G). Suppose we have a parse tree for w. If the length of the longest path.
Chapter 8 Properties of Context-free Languages These class notes are based on material from our textbook, An Introduction to Formal Languages and Automata,
Transparency No. P2C5-1 Formal Language and Automata Theory Part II Chapter 5 The Pumping Lemma and Closure properties for Context-free Languages.
Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1 Chapter 2 Context-Free Languages Some slides are in courtesy.
Grammar Set of variables Set of terminal symbols Start variable Set of Production rules.
Exercises on Chomsky Normal Form and CYK parsing
1 Context Free Grammars Xiaoyin Wang CS 5363 Spring 2016.
About Grammars Hopcroft, Motawi, Ullman, Chap 7.1, 6.3, 5.4.
Lecture 16 Cocke-Younger-Kasimi Parsing Topics: Closure Properties of Context Free Languages Cocke-Younger-Kasimi Parsing Algorithm June 23, 2015 CSCE.
Closed book, closed notes
Normal Forms for CFG’s Eliminating Useless Variables Removing Epsilon
Properties of Context-Free Languages
Chomsky Normal Form CYK Algorithm
Lecture 22 Pumping Lemma for Context Free Languages
Simplifications of Context-Free Grammars
PDAs Accept Context-Free Languages
FORMAL LANGUAGES AND AUTOMATA THEORY
Context-Free Grammars Pushdown Store Automata Properties of the CFLs
Jaya Krishna, M.Tech, Assistant Professor
More on Context Free Grammars
Properties of Context-free Languages
5. Context-Free Grammars and Languages
4. Properties of Regular Languages
Definition: Let G = (V, T, P, S) be a CFL
NORMAL FORMS FDP ON THEORY OF COMPUTING
7. Properties of Context-Free Languages
Chapter 6 Simplification of Context-free Grammars and Normal Forms
CHAPTER 2 Context-Free Languages
Deterministic PDAs - DPDAs
Closure Properties of Context-Free languages
Properties of Context-Free Languages
Department of Computer Science & Engineering
The Pumping Lemma for CFL’s
Subject Name: Finite Automata & Formal Languages Subject Code 10CS56.
Chapter 2 Context-Free Language - 02
Applications of Regular Closure
Automata, Grammars and Languages
Normal Forms for Context-free Grammars
Context-Free Languages
Presentation transcript:

7. Properties of Context-Free Languages CIS 5513 - Automata and Formal Languages – Pei Wang

Chomsky normal form A CFL can be generated by many CFGs Every CFL  {ɛ} can be generated by a CFG in Chomsky normal form (CNF), where each rule is in the form of A → BC or A → a, i.e., every variable becomes either two variables or one terminal Every CFG can be converted into CNF in several steps

Removing ɛ-productions A symbol A is nullable if A * ɛ, i.e., there is a production A → ɛ, or A → B1B2 … Bk where B1B2 … Bk are all nullable If A is nullable, then B → CAD should produce a variant B → CD, and A cannot derive ɛ anymore in B → CAD All the ɛ-productions can be eliminated by treating all the variables the above way

Removing ɛ-productions: example S → AB A → aAA | ɛ B → bBB | ɛ S, A, and B are all nullable. New grammar: S → AB | A | B A → aAA | aA | a B → bBB | bB | b

Removing unit productions A unit production has the form A → B, and (A, B) is a unit pair if A * B A unit pair can be removed by expanding the involved variables all the way until the result is not a unit production If there is a cycle of expansion like A → B → C →  → A then all the variables involved can be merged

Removing unit productions: example I → a | b | Ia | Ib | I0 | I1 F → I | (E) T → F | T * F E → T | E + T changes to F → a | b | Ia | Ib | I0 | I1 | (E) T → a | b | Ia | Ib | I0 | I1 | (E) | T * F E → a | b | Ia | Ib | I0 | I1 | (E) | T * F | E + T

Removing useless symbols A symbol X is useful if it is both reachable and generating, i.e., S * αXβ * w Removing a useless symbol in a grammar will not change the language it generates Eliminate nongenerating symbols and all productions involving such symbols Eliminate unreachable symbols The order of the above steps matters

Useless symbols: example Given CFG: S → AB | a A → b B is not generating, so the grammar is S → a Now A is not reachable, so the grammar is

CFG to Chomsky normal form Convert a CFG into CNF (not unique): Eliminate ɛ-productions Eliminate unit productions Eliminate useless symbols Change non-CNF productions into CNF productions, i.e., A → BCD becomes A → BE, E → CD A → Fg becomes A → FG, G → g

Greibach normal form Every nonempty CFL without ɛ can be generated from a grammar each of whose production rule has the form A → aα where a is a terminal, and α is a string of zero or more variables This form can be obtained from PDA with a single state and accept by empty stack

Pumping lemma for CFL A sufficiently long string must be derived by using the same variable repeatedly in a path of the parse tree

Pumping lemma for CFL (cont) A part of the parse tree can be repeated: S * uAy A * vAx A * w

Languages that are not CFL The pumping lemma can be used to show that some languages are not CFL: L = {0m1m2m | m 1} : for the n in pumping lemma, pick the word z = 0n1n2n = uvwxy, since there are n 1’s in the middle, vwx cannot contains both 0 and 2, so repeat it will produce a word not in the language To prove L = {ww} is not CFL, pump the word 0n1n0n1n , then discuss the cases

Closure properties of CFL CFLs are closed under the operation of Substitution (replace a terminal by a CFL) Union Concatenation Closure (* and +) Reversal Homomorphism Inverse homomorphism

Closure properties of CFL (cont.) CFL’s are not closed under complement, intersection, and difference Example: {0n1n2i | n 1, i 1} and {0i1n2n | n 1, i 1} are both CFL’s, but their intersection is not Example: {0,1}*  {ww} is CFL, but {ww} is not The intersection or difference of a CFL and a regular language is a CFL

Decision properties of CFL’s [Complexity-related topics will not be covered] Whether a CFL is empty can be decided by checking whether the start symbol of its grammar is generating Whether a string belongs to a CFL can be decided using dynamic programming to incrementally build up the string

Testing membership in a CFL The CYK algorithm: use a CFG in CNF to incrementally find all variables that generate the substrings The triangular table is filled bottom-up, where Xij comes from XikX(k+1)j for all possible k values, according to the grammar

Membership decision for CFL