Jaya Krishna, M.Tech, Assistant Professor

Slides:



Advertisements
Similar presentations
Hector Miguel Chavez Western Michigan University.
Advertisements

The Pumping Lemma for CFL’s
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
About Grammars CS 130 Theory of Computation HMU Textbook: Sec 7.1, 6.3, 5.4.
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
CS5371 Theory of Computation
1 CSC 3130: Automata theory and formal languages Tutorial 4 KN Hung Office: SHB 1026 Department of Computer Science & Engineering.
CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT Lecture 4 Context-free grammars Jan Maluszynski, IDA, 2007
Normal forms for Context-Free Grammars
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.
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
Chapter 12: Context-Free Languages and Pushdown Automata
1 Properties of Context-free Languages Reading: Chapter 7.
Lecture 21: Languages and Grammars. Natural Language vs. Formal Language.
CONVERTING TO CHOMSKY NORMAL FORM
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.
CSCI 2670 Introduction to Theory of Computing September 21, 2004.
Section 12.4 Context-Free Language Topics
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.
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.
Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1 Chapter 2 Context-Free Languages Some slides are in courtesy.
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.
5. Context-Free Grammars and Languages
Closed book, closed notes
Normal Forms for CFG’s Eliminating Useless Variables Removing Epsilon
Context-Free Grammars: an overview
Chomsky Normal Form CYK Algorithm
Lecture 15 Pumping Lemma.
Natural Language Processing - Formal Language -
7. Properties of Context-Free Languages
Lecture 22 Pumping Lemma for Context Free Languages
FORMAL LANGUAGES AND AUTOMATA THEORY
Context Free Languages
Lecture 14 Grammars – Parse Trees– Normal Forms
More on Context Free Grammars
Context-Free Languages
Context-Free Grammars and Languages
Context Free Grammar: Simplification
Jaya Krishna, M.Tech, Assistant Professor
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
7. Properties of Context-Free Languages
CHAPTER 2 Context-Free Languages
فصل دوم Context-Free Languages
Finite Automata and Formal Languages
COSC 3340: Introduction to Theory of Computation
The Pumping Lemma for CFL’s
Pumping Lemma for Context-free Languages
Properties of Context-Free Languages
Department of Computer Science & Engineering
The Pumping Lemma for CFL’s
Cpt S 317: Spring 2009 Sampath Kumar S, AP/CSE, SECE
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Subject Name: Finite Automata & Formal Languages Subject Code 10CS56.
Chapter 2 Context-Free Language - 01
Chapter 2 Context-Free Language - 02
Key Answers for Homework #7
The Pumping Lemma for CFL’s
Applications of Regular Closure
The Pumping Lemma for CFL’s
Presentation transcript:

Jaya Krishna, M.Tech, Assistant Professor UNIT-V 9/22/2018 Jaya Krishna, M.Tech, Assistant Professor

Jaya Krishna, M.Tech, Assistant Professor AMBIGUITY IN CFG A grammar can generate the same string in several different ways. string is derived ambiguously in that grammar w Є L(G) is ambiguous ? Two or more derivation trees for w Two or more left most derivation trees form w E.g. Consider G = ({S}, {a, b, +, *}, P, S) Productions are S  S + S | S * S|a|b 9/22/2018 Jaya Krishna, M.Tech, Assistant Professor

AMBIGUITY IN CFG Two derivations trees for a + a * b Figure 5.1: Derivation trees for a + a * b 9/22/2018 Jaya Krishna, M.Tech, Assistant Professor

Jaya Krishna, M.Tech, Assistant Professor MINIMIZATION OF CFG CFG may not be necessary to use all the symbols in V U Σ may not be necessary to use all P for deriving sentences. 9/22/2018 Jaya Krishna, M.Tech, Assistant Professor

Jaya Krishna, M.Tech, Assistant Professor MINIMIZATION OF CFG Example: Consider the grammar G = ({S, A, B, C, E}, {a, b, c}, P, S) Where P = {S  AB, A a, B b, B  C, E  c | ε} L(G) = {ab} Let G’ = ({S, A, B}, {a, b}, P’, S) P’ = {S  AB, A  a, B  b} 9/22/2018 Jaya Krishna, M.Tech, Assistant Professor

Jaya Krishna, M.Tech, Assistant Professor MINIMIZATION OF CFG L(G) = L(G’) Eliminate C, E and c and the productions B  C, E  c | ε. Reduce the given grammar by eliminating or removing Useless symbols ε productions unit productions 9/22/2018 Jaya Krishna, M.Tech, Assistant Professor

Jaya Krishna, M.Tech, Assistant Professor MINIMIZATION OF CFG ELIMINATING USELESS SYMBOLS symbol is useful appears on right hand side & generates terminal. No such derivations Useless symbol and the production is useless production 9/22/2018 Jaya Krishna, M.Tech, Assistant Professor

Jaya Krishna, M.Tech, Assistant Professor MINIMIZATION OF CFG Consider G = (V, Σ, P, S) V = {S, T, X} Σ ={0, 1} Productions S  0T | 1T | X | 0 | 1 and T  00 Start symbol is S S  0T S  000 9/22/2018 Jaya Krishna, M.Tech, Assistant Professor

Jaya Krishna, M.Tech, Assistant Professor MINIMIZATION OF CFG Example: Eliminate the useless symbols from the following grammar S  aA | a | Bb |cC A  aB B  a |Aa C  cCD D  ddd 9/22/2018 Jaya Krishna, M.Tech, Assistant Professor

Jaya Krishna, M.Tech, Assistant Professor MINIMIZATION OF CFG consider all the productions that are giving terminal symbols S  a B  a D  ddd Now consider the following productions: S  cC C  cCD 9/22/2018 Jaya Krishna, M.Tech, Assistant Professor

Jaya Krishna, M.Tech, Assistant Professor MINIMIZATION OF CFG We will not get any terminal for C Thus C is Useless symbol To reach D Only rule is C Hence D is useless symbol Therefore reduced grammar is S  aA | a | Bb A  aB B  a |Aa 9/22/2018 Jaya Krishna, M.Tech, Assistant Professor

Jaya Krishna, M.Tech, Assistant Professor MINIMIZATION OF CFG ELIMINATING ε PRODUCTIONS Example: Given a Context Free Grammar with the following productions: S  aAb A  aAb | ε 9/22/2018 Jaya Krishna, M.Tech, Assistant Professor

Jaya Krishna, M.Tech, Assistant Professor MINIMIZATION OF CFG ε-production A  ε Consider S  aAb After substituting the ε for A we get S  aεb S  ab Similarly for A, finally we get S  aAb | ab A  aAb | ab 9/22/2018 Jaya Krishna, M.Tech, Assistant Professor

Jaya Krishna, M.Tech, Assistant Professor MINIMIZATION OF CFG ELIMINATING UNIT PRODUCTIONS Production of the form A  B {A, B} Є V complicate certain proof extra steps  not needed 9/22/2018 Jaya Krishna, M.Tech, Assistant Professor

Jaya Krishna, M.Tech, Assistant Professor MINIMIZATION OF CFG Eliminate unit productions from G given below: S  AB A  a B  C | b C  D D  E E  a A  a, B  b and E  a are the non unit productions. P’ Since B E and E  a is a non unit production, B  a is in P’. 9/22/2018 Jaya Krishna, M.Tech, Assistant Professor

Jaya Krishna, M.Tech, Assistant Professor MINIMIZATION OF CFG Similarly C  a and D  a is in P’. G’ = ({S, A, B, C, D, E}, {a, b}, P’, S) With P’ given by S  AB A  a B  b B  a C  a D  a 9/22/2018 Jaya Krishna, M.Tech, Assistant Professor

Jaya Krishna, M.Tech, Assistant Professor CHOMSKY NORMAL FORM Productions are of the form A  BC or A  a A, B and C are variables and a is a terminal  CNF To put G in CNF satisfies the restrictions i.e. G has No ε – productions No useless symbols No unit productions 9/22/2018 Jaya Krishna, M.Tech, Assistant Professor

Jaya Krishna, M.Tech, Assistant Professor CHOMSKY NORMAL FORM Our tasks are to: Arrange that all bodies of length 2 or more consist only of variables Break bodies of length 3 or more into a cascade of productions, each with a body consisting of two variables. 9/22/2018 Jaya Krishna, M.Tech, Assistant Professor

Jaya Krishna, M.Tech, Assistant Professor CHOMSKY NORMAL FORM Convert G in to CNF E  E + T | T * F | (E) | a | b | Ia | Ib | I0 | I1 T  T * F | (E) | a | b | Ia | Ib | I0 | I1 F  (E) | a | b | Ia | Ib | I0 | I1 I  a | b | Ia | Ib | I0 | I1 Solution: eight terminals a, b, 0, 1, +, *, (, and ) A  a B  b Z  0 O  1 P  + M  * L  ( R  ) 9/22/2018 Jaya Krishna, M.Tech, Assistant Professor

Jaya Krishna, M.Tech, Assistant Professor CHOMSKY NORMAL FORM E  EPT | TMF | LER | a | b| IA | IB | IZ | IO T  TMF | LER | a | b| IA | IB | IZ | IO F  LER | a | b| IA | IB | IZ | IO I  a | b| IA | IB | IZ | IO A  a B  b Z  0 O  1 P  + M  * L  ( R  ) 9/22/2018 Jaya Krishna, M.Tech, Assistant Professor

Jaya Krishna, M.Tech, Assistant Professor CHOMSKY NORMAL FORM Productions in CNF Length 3 EPT, TMF, and LER E  EC1 and C1  PT E  TC2, T  TC2, and C2  MF. E  LC3, T  LC3, F  LC3, and C3  ER. 9/22/2018 Jaya Krishna, M.Tech, Assistant Professor

Jaya Krishna, M.Tech, Assistant Professor CHOMSKY NORMAL FORM final grammar E  EC1 | TC2 | LC3 | a | b| IA | IB | IZ | IO T  TC2 | LC3 | a | b| IA | IB | IZ | IO F  LC3 | a | b| IA | IB | IZ | IO I  a | b| IA | IB | IZ | IO A  a B  b Z  0 O  1 P  + M  * L  ( R  ) C1  PT C2  MF C3  ER 9/22/2018 Jaya Krishna, M.Tech, Assistant Professor

Jaya Krishna, M.Tech, Assistant Professor PUMPING LEMMA FOR CFL pumping lemma says that in any sufficiently long string in a context free language, it is possible to find at most two short nearby substrings that we can pump in tandem. Break each string z in CFL 5 parts 9/22/2018 Jaya Krishna, M.Tech, Assistant Professor

Jaya Krishna, M.Tech, Assistant Professor PUMPING LEMMA FOR CFL Let L be a CFL Exists a constant i.e. n such that if z is any string in L |z| is at least n We write z = uvwxy  satisfies following conditions: |vwx| ≤ n (no long middle portion) vx ≠ ε (either v or x must not empty) For all i ≥ 0, uviwxiy is in L 9/22/2018 Jaya Krishna, M.Tech, Assistant Professor

ENUMERATION OF PROPERTIES OF CFL Many closure properties will parallel to regular languages. Substitution (operation) Let a Є Σ, now choose language La La can be over any alphabets, not necessarily Σ or same. This choice of languages defines a function s(a substitution) on Σ (i.e. s(a)) 9/22/2018 Jaya Krishna, M.Tech, Assistant Professor

ENUMERATION OF PROPERTIES OF CFL 9/22/2018 Jaya Krishna, M.Tech, Assistant Professor