FORMAL LANGUAGES AND AUTOMATA THEORY

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

1 Pushdown Automata (PDA) Informally: –A PDA is an NFA-ε with a stack. –Transitions are modified to accommodate stack operations. Questions: –What is a.
Closure Properties of CFL's
Nathan Brunelle Department of Computer Science University of Virginia Theory of Computation CS3102 – Spring 2014 A tale.
1 Introduction to Computability Theory Lecture5: Context Free Languages Prof. Amos Israeli.
CS5371 Theory of Computation
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
Context-Free Grammars Chapter 3. 2 Context-Free Grammars and Languages n Defn A context-free grammar is a quadruple (V, , P, S), where  V is.
Chapter 12: Context-Free Languages and Pushdown Automata
1 Properties of Context-free Languages Reading: Chapter 7.
Context-Free Grammars
Context-free Grammars Example : S   Shortened notation : S  aSaS   | aSa | bSb S  bSb Which strings can be generated from S ? [Section 6.1]
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.
Grammars CPSC 5135.
Dept. of Computer Science & IT, FUUAST Automata Theory 2 Automata Theory V Context-Free Grammars andLanguages.
Section 12.4 Context-Free Language Topics
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 11 Midterm Exam 2 -Context-Free Languages Mälardalen University 2005.
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.
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.
1 Chapter 6 Simplification of CFGs and Normal Forms.
Introduction Finite Automata accept all regular languages and only regular languages Even very simple languages are non regular (  = {a,b}): - {a n b.
Context-Free Languages
CSC312 Automata Theory Lecture # 26 Chapter # 12 by Cohen Context Free Grammars.
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.
Theory of Languages and Automata By: Mojtaba Khezrian.
CSCI 2670 Introduction to Theory of Computing September 16, 2004.
1 Context-Free Languages & Grammars (CFLs & CFGs) Reading: Chapter 5.
Context-Free Languages & Grammars (CFLs & CFGs) (part 2)
5. Context-Free Grammars and Languages
CONTEXT-FREE LANGUAGES
Closed book, closed notes
Context-Free Languages & Grammars (CFLs & CFGs)
Context-Free Grammars: an overview
Formal Language & Automata Theory
FORMAL LANGUAGES AND AUTOMATA THEORY
FORMAL LANGUAGES AND AUTOMATA THEORY
7. Properties of Context-Free Languages
Lecture 22 Pumping Lemma for Context Free Languages
PDAs Accept Context-Free Languages
FORMAL LANGUAGES AND AUTOMATA THEORY
PARSE TREES.
Context Free Languages
Context-Free Grammars Pushdown Store Automata Properties of the CFLs
Pushdown Automata Reading: Chapter 6.
Jaya Krishna, M.Tech, Assistant Professor
More on Context Free Grammars
Context-Free Languages
Context-Free Grammars and Languages
Context-free Languages
Chapter Fourteen: The Context-Free Frontier
5. Context-Free Grammars and 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
فصل دوم Context-Free Languages
Finite Automata and Formal Languages
Properties of Context-Free Languages
Department of Computer Science & Engineering
The Pumping Lemma for CFL’s
Context-Free Languages
Subject Name: Finite Automata & Formal Languages Subject Code 10CS56.
Theory of Computation Lecture #
Chapter 2 Context-Free Language - 02
Formal Languages Context free languages provide a convenient notation for recursive description of languages. The original goal of formalizing the structure.
Presentation transcript:

FORMAL LANGUAGES AND AUTOMATA THEORY C K Nagpal M.Tech. Ph.D. Associate Professor Computer Engg. YMCA University of Science & Technology nagpalckumar@rediffmail.com

Chapter 5 Context Free Grammars and Languages After studying this chapter, the reader will be able to understand the following: • Basic structure of a context-free grammar (CFG) • Context-free languages as the superset of regular languages • Identification of ambiguity in a CFG Possible Defects in CFG Order of Defect Removal Superset Property Closure & Non Closure Properties Normal Forms for Context Free Grammars Pumping Lemma for Context Free Grammars Ogden’s Lemma Applications of Context Free Grammars

Recursive Grammars Language L1 = {akbk | k ≥ 0} over {a, b}. Recursive definition for L1 Rule 1: ϵ belongs to L1. Rule 2: For every string w belonging to L1, awb belongs to L1. Rule 3: Nothing else belongs to L1. Language L2 = {w | w is palindrome} over {a, b, c}. Recursive definition for L2 Rule 1: ϵ belongs to L2 Rule 2: a, b and c belong to L2 Rule 3: For every string w belonging to L2, awa, bwb and cwc belongs to L2. Rule 4: Nothing else belongs to L2.

Context Free Grammars (CFG) Context Free Grammar is a 4 tuple structure G (V, ∑, P, S) ∑ is the character set of the language. V is the finite set of variables also known as non terminals or syntactic categories. They are used to define the structure of sentences in the language. P is known as set of productions or production set. Each production in the production set of a CFG is of the form A→ (V U ∑ )*. In CFG, the LHS of a production contains a single non terminal and RHS contains a string composed of terminals and non terminals. A → aBBc | aAb S→AA | BB| Bcc S is known as starting sentential form. It is initial production from where the process of string formation begins.

Context Free language (CFL) CFL : The language corresponding to CFG A string w belongs to CFL L, if it can be derived from the CFG G of L. Approaches used to check if a string w belongs to CFL L Derivation Recursive Inference Derivation approach categories Leftmost derivation Rightmost derivation

Given Grammar S→ AA | BB | ASA | BSB | a | b A → a Given Grammar S→ AA | BB | ASA | BSB | a | b A → a B→ b Given String aaabbbaa

Some Example CFLs L={0n1n | n ≥ 0} L={0n12n | n ≥ 0} L over {0, 1} to generate all the strings having alternate sequence of 0 and 1 L over {a, b, c} such that L={wcwR| w is string over {a, b} and wR is reverse of w} L={anbncmdm| n, m > 0}

Ambiguity in Context Free Grammar A grammar is said to be ambiguous if one or more sentences in the corresponding language can be interpreted in more than one ways. The ambiguity in case of context free grammar is reflected by the occurrence of two or more different parse trees for the same sentence.

Ambiguous Grammar S→S+S |S x S | a | b Sentence a + a x b Two different parse trees

Possible Defects in CFG Failure of non terminal(s) to generate terminal(s) S→ABCD|ABD A→ aA|a B→bB|bb C→cC D → aadd Unit Productions S→ABCD|ABD A→ aA|a B→b|C C→D D→d Unreachable Non terminal S→AB A→ aA|a B→bB|cC C→cc D→d E→a Null productions S→aS | AC | AB A→ϵ C→ϵ B→bB | bb D→c

Order of Defect Removal Eliminate null productions Eliminate unit productions Eliminate non reachable non terminals A grammar in which non terminal fails to generate terminals can not be used and has to be reconstructed.

Superset Property Set of CFLs is proper superset of set of regular languages that is every regular language is context free language but vice versa is not true

Closure & Non Closure Properties If L1 and L2 are context free languages then the language L1L2 (obtained by concatenation) is also CFL. If L1 and L2 are context free languages then the language L1 U L2 (obtained by union) is also CFL. If L is a CFL then language L* is also CFL The CFLs are closed over the operation of string reversal The CFLs are closed over the operation of string homomorphism Non Closure properties Intersection Complement Difference

Normal Forms for Context Free Grammars The production system of CFG: A→ (V U ∑)* No restriction on the RHS of the production. Normal form : Standard form for the RHS of a production in CFG Reduces the complexity of the automation Resulting automation is easier to implement. Requisites for Normal Form It should be broad enough so that all the possible productions in CFG should be convertible to it

Normal Forms Chomsky Normal Form In the Chomsky Normal Form, a CFG G can have only two types of the productions: A →a A→BC Advantage : Parse tree is a binary tree Greibach Normal Form In Greibach normal form (GNF) each production is of the form A→ aα where a belongs to ∑ is a terminal and α belongs to V* Advantages: Since each production contains exactly one terminal, hence a string of length k will require exactly k steps for derivation thereby leading to the availability of information in priori. Corresponding PDA will never go for the ϵ transitions making the machine implementation (automation) process of CFG smooth and unambiguous.

Pumping Lemma for Context Free Grammars Let there be a context free language L. There exist a positive integer m such that for any string z belonging to L, if | z | ≥ m, then z can be decomposed as z=uvwxy such that |vwx| ≤ m and |vx| ≥ 1 and for every positive integer k we have uvkwxky L. Like the pumping lemma for regular languages, the pumping lemma for CFL can be used to show that a particular CFL is not regular. Mechanism to applying Pumping Lemma Step 1: Chose the language, say L, which we want to show is not CFL. Step 2: Choose a suitable m. Step 3: Choose a string z belonging to L such that |z| ≥ m. Step 4: Break z to uvwxy such that |vx| ≥ 1. Step 5: Choose a suitable k, such that uvkwxky L. If it is possible to find such a k then it is proved that L is not a CFL.

Ogden’s Lemma Let there be a context free language L. There exist an integer m such that for any string z, belonging to L and length ≥ m, and containing any m or more positions as distinguished then there exist strings u, v, w, x and y satisfying the following conditions z = uvwxy the string vx contains at least one distinguished position the string vwx contains not more than m distinguished positions the string w contains at least one distinguished position for every k ≥ 0 and uvkwxkyL Ogden’s lemma is a stronger form of pumping lemma for CFL. It focuses on any n distinguished positions of the string z and guarantees that the strings to pumped must have 1 to n number of distinguished positions. This helps us in identifying the substring v and x which are to be pumped. This is in contrast to the pumping lemma which is silent on the fact on how to locate these substrings in the string z.

Applications of Context Free Grammars Design of Programming language Constructs Design of Natural Language Constructs Mark up Languages