Lecture 12 Simplification of Context-Free Grammars and Normal Forms

Size: px
Start display at page:

Download "Lecture 12 Simplification of Context-Free Grammars and Normal Forms"

Transcription

1 Lecture 12 Simplification of Context-Free Grammars and Normal Forms COT 4420 Theory of Computation Chapter 6

2 Normal Forms for CFGs 1. Chomsky Normal Form CNF Productions of form A BC A, B, C V A a a T 2. Greibach Normal Form GNF Productions of form A ax A V, a T, X V*

3 λ-productions Any production of a CFG of the form A λ is called a λ-production. Any variable A for which the derivation A =>* λ is possible is called nullable.

4 Removing λ-productions Theorem: Given a grammar G with λ not in L(G), the set of nullable variables V N can be found using an algorithm. Proof: 1. For all productions A λ, put A into V N. 2. Repeat the following until no new variables are added to V N : For all productions B A 1 A 2 A n where A 1, A 2,, A n are in V N, put B into V N.

5 Removing λ-productions Theorem: Let G be any CFG with λ not in L(G), then there exists an equivalent G having no λ- productions. Algorithm: 1. Find the set V N of all nullable variables. 2. For all productions of the form A x 1 x 2 x m, m 1 where x i V T: We put this production in the new production set, as well as all those generated by replacing nullable variables with λ in all possible combinations. Exception: If all x i s are nullable, do not include A λ

6 Removing λ-productions Example Example: S ABaC A BC B b λ C D λ D d Nullable variables V N : A, B, C S ABaC BaC AaC ABa ac Ba Aa a A BC B C B b C D D d

7 Removing λ-productions Proof Proof: We need to show that: 1. If w λ and A =>* old w, then A =>* new w. 2. If A =>* new w then w λ and A =>* old w. Proof of (1): By induction on the number of steps by which A derives w in the old grammar. Basis: If in the old grammar, A derives w in one step, then A w must be a production. Since w λ, this production must appear in the new grammar as well. Therefore, A =>* new w.

8 Removing λ-productions Proof cont d Induction step: We assume the theorem is true for derivation steps of fewer than k. We show it for A =>* old w which has k steps. Let the first step be A => old X 1 X n, then w can be broken into w = w 1 w n, where X i =>* old w i, for all i, in fewer than k steps. Because of the induction hypothesis we have: X i =>* new w i The new grammar has a production A new X 1 X n, therefore A derives w in the new grammar.

9 Removing unit productions A unit production is one whose right-hand side has only one variable. A B Use a dependency graph: Whenever the grammar has a unit-production C D, create an edge (C,D) If E =>* F using only unit productions, whenever F α is a non-unit production, add E α. Remove unit productions

10 Original Grammar Removing unit productions S Aa B B A bb A a bc B Example Dependency Graph B S A New Grammar S Aa bb bc a B bb bc a A a bc bb S=>*B, S=>*A, A=>*B, B=>*A

11 Remove useless productions Variable A is useful if there exist some w L(G) such that: S =>* xay =>* w Otherwise it is useless. Example 1: S asb ab A A baa A does not derive terminal strings A is not reachable Example 2: S asb ab A baa ba

12 Useless productions The order is important! To remove useless productions:(follow these steps) 1. Eliminate variables that derive no terminal S aab A baa A is useless 2. Eliminate unreachable variables S AC C aab B Ab B is not reachable

13 Remove useless productions Example S as A C A a B aa C acb C is useless, so we remove variable C and its productions. After step (1), every remaining symbol derives some terminal.

14 Remove useless productions Example S as A A a B aa Dependency Graph S V = {S, A, B} B A Construct a dependency graph and determine the unreachable variables. (For every rule of the form C xdy, there is an edge from C to D. ) B is not reachable!

15 Cleaning up the grammar 1. Eliminate λ-productions 2. Eliminate unit productions 3. Eliminate useless variables The order is important because removing λ- productions, will introduce new unit productions or useless variables. Theorem: Let L be a CFL that does not contain λ. Then there exist a context-free grammar that generates L and does not have any useless productions, λ-productions, or unit-productions.

16 Converting to CNF A BC A a A, B, C V a T Theorem: Every context-free language L is generated by a Chomsky Normal Form (CNF) grammar. Proof: Let G be a CFG for generating L. Step1: First clean the grammar G. (remove λ-productions and unit-productions) Step2: For every production A x 1 x 2 x n, if n = 1, x 1 is a terminal (since there is no unit productions). If n 1, for every terminal a T, introduce a variable B a. Replace a with B a and add B a a to the set of productions.

17 Step 2 - Example A GcDe A GB c De B c c

18 Step 2 - Example A GcDe A GB c DB e B c c B e e

19 Converting to CNF Cont d Every production is of the form: A K 1 K 2 K 3 K n or A a a T A, K i V Step 3: Break right sides longer than 2 into chain of productions: A K 1 Z 1 A -> BCDE is replaced by Z 1 K 2 Z 2 A -> BF, F -> CG, and G -> DE.

20 Greibach Normal Form

21 A ax GNF A V a T X V* Theorem: Every context-free language L is generated by a Greibach Normal Form (GNF) grammar.

22 Lemma1 (theorem 6.1 in textbook): Let G=(V, T, S, P) be a CFG. Suppose P contains a production of the form A x 1 B x 2. Assume that A and B are different variables and that B y 1 y 2 y n is the set of all productions in P which have B as the left side. We can then remove A x 1 B x 2 from P and add A x 1 y 1 x 2 x 1 y 2 x 2 x 1 y n x 2 And have the same language.

23 A x 1 B x 2 A x 1 y 1 x 2 y 1 These derive the same sentential forms A ABa B AA b ZC A AAAa Aba AZCa

24 Lemma2, removing left recursion: Let G=(V, T, S, P) be a CFG. A Aα 1 Aα 2 Aα n be the set of A-productions that have A as the first symbol on the R.H.S. And let A β 1 β 2 β m be all the other A-productions. We can remove the left recursive A-productions and add: A β i 1 i m Z α i 1 i n A β i Z Z α i Z

25 A A A α i1 Β j Z A α i2 α ip Z A α ip α i2 Z Β j α i1

26 A ax Converting to GNF A V a T X V* Theorem: Every context-free language L is generated by a Greibach Normal Form (GNF) grammar. Step1: Rewrite the grammar into Chomsky Normal Form. Step2: Relabel all variables as A 1, A 2, A n Step3: Transform all productions into form: a. A i A j x j i < j and x j V* or b. A i a x j or c. Z i A j x j

27 Converting to GNF - Example S SS BC B CB a C SB b S = A 1, B = A 2, C =A 3 A 1 A 1 A 1 A 2 A 3 A 2 A 3 A 2 A 3 A 1 A 2 A 2 a A 3 b

28 Converting to GNF - Example A 1 A 1 A 1 apply lemma 2 to remove left recursion A 1 A 2 A 3 Z 1 A 1 A 1 A 2 A 3 Z 1 Z 1 A 1 Z 1 (a) (a) (b) (b) (a) (c) (c) A 1 A 1 A 1 A 1 A 2 A 3 A 2 A 3 A 2 A 3 A 1 A 2 A 2 a A 3 b A 1 A 2 A 3 Z 1 Z 1 A 1 Z 1 A 1 Z 1

29 Converting to GNF - Example A 3 A 1 A 2 apply lemma 1 to replace A 1 A 3 A 2 A 3 A 2 A 3 A 2 A 3 Z 1 A 2 Apply lemma 1 again A 3 A 3 A 2 A 3 A 2 A 3 aa 3 A 2 A 3 A 3 A 2 A 3 Z 1 A 2 A 3 aa 3 Z 1 A 2 (a) A 1 A 2 A 3 (a) A 2 A 3 A 2 A 3 A 1 A 2 (b) A 2 a (b) A 3 b (a) A 1 A 2 A 3 Z 1 (c) Z 1 A 1 (c) Z 1 A 1 Z 1 A 3 A 3 A 2 A 3 A 2 (b) A 3 aa 3 A 2 A 3 A 3 A 2 A 3 Z 1 A 2 (b) A 3 aa 3 Z 1 A 2

30 Converting to GNF - Example A 3 A 3 A 2 A 3 A 2 apply lemma2 to remove recursion A 3 A 3 A 2 A 3 Z 1 A 2 A 3 bz 2 aa 3 A 2 Z 2 aa 3 Z 1 A 2 Z 2 Z 2 A 2 A 3 A 2 A 2 A 3 Z 1 A 2 Z 2 A 2 A 3 A 2 Z 2 A 2 A 3 Z 1 A 2 Z 2 (a)a 1 A 2 A 3 (a) A 2 A 3 A 2 (b) A 2 a (b) A 3 b (a) A 1 A 2 A 3 Z 1 (c) Z 1 A 1 (c) Z 1 A 1 Z 1 A 3 A 3 A 2 A 3 A 2 (b) A 3 aa 3 A 2 A 3 A 3 A 2 A 3 Z 1 A 2 (b) A 3 aa 3 Z 1 A 2

31 Converting to GNF - Example (a) (a) (b) (b) (c) (c) A 1 A 2 A 3 A 2 A 3 Z 1 A 2 A 3 A 2 A 2 a A 3 b aa 3 A 2 aa 3 Z 1 A 2 bz 2 aa 3 A 2 Z 2 aa 3 Z 1 A 2 Z 2 Z 1 A 1 A 1 Z 1 Z 2 A 2 A 3 A 2 A 2 A 3 Z 1 A 2 A 2 A 3 A 2 Z 2 A 2 A 3 Z 1 A 2 Z 2 Now everything is in the form of step 3. Note that A n is in the form of GNF.

32 Converting to GNF Step4: For every production of the form A n- 1 A n x n use lemma 1 to convert to correct GNF form. Continue to A 1. For all Z-productions, use lemma 1 to convert to correct GNF form.

33 Example Cont d A 1 A 2 A 3 A 2 A 3 Z 1 A 2 A 3 A 2 A 2 a A 3 b aa 3 A 2 aa 3 Z 1 A 2 bz 2 aa 3 A 2 Z 2 aa 3 Z 1 A 2 Z 2 Z 1 A 1 A 1 Z 1 Z 2 A 2 A 3 A 2 A 2 A 3 Z 1 A 2 A 2 A 3 A 2 Z 2 A 2 A 3 Z 1 A 2 Z 2 For A 2 A 3 A 2 we write: A 2 ba 2 aa 3 A 2 A 2 aa 3 Z 1 A 2 A 2 bz 2 A 2 aa 3 A 2 Z 2 A 2 aa 3 Z 1 A 2 Z 2 A 2

34 For A 1 A 2 A 3 A 2 A 3 Z 1 we write: A 1 ba 2 A 3 aa 3 A 2 A 2 A 3 aa 3 Z 1 A 2 A 2 A 3 bz 2 A 2 A 3 aa 3 A 2 Z 2 A 2 A 3 aa 3 Z 1 A 2 Z 2 A 2 A 3 aa 3 A 1 ba 2 A 3 Z 1 aa 3 A 2 A 2 A 3 Z 1 aa 3 Z 1 A 2 A 2 A 3 Z 1 bz 2 A 2 A 3 Z 1 aa 3 A 2 Z 2 A 2 A 3 Z 1 aa 3 Z 1 A 2 Z 2 A 2 A 3 Z 1 aa 3 Z 1 Example Cont d A 1 A 2 A 3 A 2 A 3 Z 1 A 2 ba 2 aa 3 A 2 A 2 aa 3 Z 1 A 2 A 2 bz 2 A 2 aa 3 A 2 Z 2 A 2 aa 3 Z 1 A 2 Z 2 A 2 a A 3 b aa 3 A 2 aa 3 Z 1 A 2 bz 2 aa 3 A 2 Z 2 aa 3 Z 1 A 2 Z 2 Z 1 A 1 A 1 Z 1 Z 2 A 2 A 3 A 2 A 2 A 3 Z 1 A 2 A 2 A 3 A 2 Z 2 A 2 A 3 Z 1 A 2 Z 2

35 Example Cont d A 1 ba 2 A 3 aa 3 A 2 A 2 A 3 aa 3 Z 1 A 2 A 2 A 3 bz 2 A 2 A 3 aa 3 A 2 Z 2 A 2 A 3 aa 3 Z 1 A 2 Z 2 A 2 A 3 aa 3 ba 2 A 3 Z 1 aa 3 A 2 A 2 A 3 Z 1 aa 3 Z 1 A 2 A 2 A 3 Z 1 bz 2 A 2 A 3 Z 1 aa 3 A 2 Z 2 A 2 A 3 Z 1 aa 3 Z 1 A 2 Z 2 A 2 A 3 Z 1 aa 3 Z 1 A 2 ba 2 aa 3 A 2 A 2 aa 3 Z 1 A 2 A 2 bz 2 A 2 aa 3 A 2 Z 2 A 2 aa 3 Z 1 A 2 Z 2 A 2 a A 3 b aa 3 A 2 aa 3 Z 1 A 2 bz 2 aa 3 A 2 Z 2 aa 3 Z 1 A 2 Z 2 Z 1 A 1 A 1 Z 1 Z 2 A 2 A 3 A 2 A 2 A 3 Z 1 A 2 A 2 A 3 A 2 Z 2 A 2 A 3 Z 1 A 2 Z 2

36 Example Cont d A 1 ba 2 A 3 aa 3 A 2 A 2 A 3 aa 3 Z 1 A 2 A 2 A 3 bz 2 A 2 A 3 aa 3 A 2 Z 2 A 2 A 3 aa 3 Z 1 A 2 Z 2 A 2 A 3 aa 3 ba 2 A 3 Z 1 aa 3 A 2 A 2 A 3 Z 1 aa 3 Z 1 A 2 A 2 A 3 Z 1 bz 2 A 2 A 3 Z 1 aa 3 A 2 Z 2 A 2 A 3 Z 1 aa 3 Z 1 A 2 Z 2 A 2 A 3 Z 1 aa 3 Z 1 A 2 ba 2 aa 3 A 2 A 2 aa 3 Z 1 A 2 A 2 bz 2 A 2 aa 3 A 2 Z 2 A 2 aa 3 Z 1 A 2 Z 2 A 2 a A 3 b aa 3 A 2 aa 3 Z 1 A 2 bz 2 aa 3 A 2 Z 2 aa 3 Z 1 A 2 Z 2 Z 1 A 1 A 1 Z 1 Z 2 A 2 A 3 A 2 A 2 A 3 Z 1 A 2 A 2 A 3 A 2 Z 2 A 2 A 3 Z 1 A 2 Z 2

37 Example Cont d A 1 ba 2 A 3 aa 3 A 2 A 2 A 3 aa 3 Z 1 A 2 A 2 A 3 bz 2 A 2 A 3 aa 3 A 2 Z 2 A 2 A 3 aa 3 Z 1 A 2 Z 2 A 2 A 3 aa 3 ba 2 A 3 Z 1 aa 3 A 2 A 2 A 3 Z 1 aa 3 Z 1 A 2 A 2 A 3 Z 1 bz 2 A 2 A 3 Z 1 aa 3 A 2 Z 2 A 2 A 3 Z 1 aa 3 Z 1 A 2 Z 2 A 2 A 3 Z 1 aa 3 Z 1 A 2 ba 2 aa 3 A 2 A 2 aa 3 Z 1 A 2 A 2 bz 2 A 2 aa 3 A 2 Z 2 A 2 Use lemma1 for all Z-productions aa 3 Z 1 A 2 Z 2 A 2 a A 3 b aa 3 A 2 aa 3 Z 1 A 2 bz 2 aa 3 A 2 Z 2 aa 3 Z 1 A 2 Z 2 Z 1 A 1 A 1 Z 1 Z 2 A 2 A 3 A 2 A 2 A 3 Z 1 A 2 A 2 A 3 A 2 Z 2 A 2 A 3 Z 1 A 2 Z 2

38 The CYK Parser

39 The CYK membership algorithm Input: Grammar G in Chomsky Normal Form String w = a 1 a 2.a n Output: find if w L(G)

40 The Algorithm Define: w ij : is a substring a i.a j V ij : { A V : A =>* w ij } A V ii if and only if G contains A a i A V ij if and only if G contains A BC, and B V ik, and C V k+1j, (k {i, i+1,, j-1})

41 The Algorithm 1. Compute V 11, V 22,,V nn 2. Compute V 12, V 23,,V n-1,n 3. Compute V 13, V 24,., V n-2,n 4. And so on. If S V 1n then w L(G), otherwise w L(G).

42 Example Grammar G and string w is given: S AB w = aabbb A BB A a B AB B b

43 Example 1. Compute V 11, V 22,,V 55 Note that: A V ii if and only if G contains A a i V 11 =? Is there a rule that directly derives a 1? V 11 = {A} V 22 =? Is there a rule that directly derives a 2? V 22 = {A} V 33 =? Is there a rule that directly derives a 3? V 33 = {B} V 44 = {B}, V 55 = {B}

44 Example 2. Compute V 12, V 23,,V 45 Note that: A V ij if and only if G contains A BC, and B V ik, and C V k+1j for all k s V 12 =? { A : A BC, B V 11, C V 22 } V 12 = {} V 23 =? { A : A BC, B V 22, C V 33 } V 23 = {S, B} V 34 =? { A : A BC, B V 33, C V 44 } V 34 = {A} V 45 =? { A : A BC, B V 44, C V 55 } V 45 = {A}? Variable AA? Variable AB? Variable BB? Variable BB

45 Example 3. Compute V 13, V 24,V 35? V 13 =? { A : A BC, B V 11, C V 23 } Variable AS, AB { A : A BC, B V 12, C V 33 } V 13 = {S, B} V 24 =? { A : A BC, B V 22, C V 34 } Variable AA? { A : A BC, B V 23, C V 44 } Variable SB, BB V 24 = {A}? V 35 =? { A : A BC, B V 33, C V 45 } Variable BA? { A : A BC, B V 34, C V 55 } Variable AB V 35 = {S, B}?

46 Example 4. Compute V 14, V 25 V 14 =? { A : A BC, B V 11, C V 24 } Variable AA { A : A BC, B V 12, C V 34 }? { A : A BC, B V 13, C V 44 } Variable SB, BB V 14 = {A} V 25 =? { A : A BC, B V 22, C V 35 } Variable AS, AB? { A : A BC, B V 23, C V 45 } Variable SA, BA? { A : A BC, B V 24, C V 55 } Variable AB V 25 = {S, B}??

47 Example 5. Compute V 15 V 15 =? { A : A BC, B V 11, C V 25 } Variable AS, AB { A : A BC, B V 12, C V 35 }? { A : A BC, B V 13, C V 45 } Variable SA, BA? { A : A BC, B V 14, C V 55 } Variable AB V 15 = {S, B}? S V 15, therefore w = aabbb L(G)

48 1 a 2 a 3 b 4 b 5 b 1 {A} 2 {A} 3 {B} 4 {B} 5 {B}

49 1 a 2 a 3 b 4 b 5 b 1 {A} {} 2 {A} {S, B} 3 {B} {A} 4 {B} {A} 5 {B}

50 1 a 2 a 3 b 1 {A} {} {S, B} 4 b 5 b 2 {A} {S, B} {A} 3 {B} {A} {S, B} 4 {B} {A} 5 {B}

51 1 a 2 a 1 {A} {} {S, B} {A} {S, B} 2 {A} {S, B} {A} {S, B} 3 {B} {A} {S, B} 4 {B} {A} 5 {B} 3 b 4 b 5 b

52 Approximate time complexity: 2 O ( w w ) = O( w 3 ) Number of V ij s to be computed If w = n n(n-1)/2 Number of evaluations in each V ij at most n

Simplification of CFG and Normal Forms. Wen-Guey Tzeng Computer Science Department National Chiao Tung University

Simplification of CFG and Normal Forms. Wen-Guey Tzeng Computer Science Department National Chiao Tung University Simplification of CFG and Normal Forms Wen-Guey Tzeng Computer Science Department National Chiao Tung University Normal Forms We want a cfg with either Chomsky or Greibach normal form Chomsky normal form

More information

Simplification of CFG and Normal Forms. Wen-Guey Tzeng Computer Science Department National Chiao Tung University

Simplification of CFG and Normal Forms. Wen-Guey Tzeng Computer Science Department National Chiao Tung University Simplification of CFG and Normal Forms Wen-Guey Tzeng Computer Science Department National Chiao Tung University Normal Forms We want a cfg with either Chomsky or Greibach normal form Chomsky normal form

More information

Context-Free Grammars: Normal Forms

Context-Free Grammars: Normal Forms Context-Free Grammars: Normal Forms Seungjin Choi Department of Computer Science and Engineering Pohang University of Science and Technology 77 Cheongam-ro, Nam-gu, Pohang 37673, Korea seungjin@postech.ac.kr

More information

CS 373: Theory of Computation. Fall 2010

CS 373: Theory of Computation. Fall 2010 CS 373: Theory of Computation Gul Agha Mahesh Viswanathan Fall 2010 1 1 Normal Forms for CFG Normal Forms for Grammars It is typically easier to work with a context free language if given a CFG in a normal

More information

Parsing. Context-Free Grammars (CFG) Laura Kallmeyer. Winter 2017/18. Heinrich-Heine-Universität Düsseldorf 1 / 26

Parsing. Context-Free Grammars (CFG) Laura Kallmeyer. Winter 2017/18. Heinrich-Heine-Universität Düsseldorf 1 / 26 Parsing Context-Free Grammars (CFG) Laura Kallmeyer Heinrich-Heine-Universität Düsseldorf Winter 2017/18 1 / 26 Table of contents 1 Context-Free Grammars 2 Simplifying CFGs Removing useless symbols Eliminating

More information

Context-Free Grammar

Context-Free Grammar Context-Free Grammar CFGs are more powerful than regular expressions. They are more powerful in the sense that whatever can be expressed using regular expressions can be expressed using context-free grammars,

More information

Homework 4 Solutions. 2. Find context-free grammars for the language L = {a n b m c k : k n + m}. (with n 0,

Homework 4 Solutions. 2. Find context-free grammars for the language L = {a n b m c k : k n + m}. (with n 0, Introduction to Formal Language, Fall 2016 Due: 21-Apr-2016 (Thursday) Instructor: Prof. Wen-Guey Tzeng Homework 4 Solutions Scribe: Yi-Ruei Chen 1. Find context-free grammars for the language L = {a n

More information

CFG Simplification. (simplify) 1. Eliminate useless symbols 2. Eliminate -productions 3. Eliminate unit productions

CFG Simplification. (simplify) 1. Eliminate useless symbols 2. Eliminate -productions 3. Eliminate unit productions CFG Simplification (simplify) 1. Eliminate useless symbols 2. Eliminate -productions 3. Eliminate unit productions 1 Eliminating useless symbols 1. A symbol X is generating if there exists: X * w, for

More information

Theory of Computation - Module 3

Theory of Computation - Module 3 Theory of Computation - Module 3 Syllabus Context Free Grammar Simplification of CFG- Normal forms-chomsky Normal form and Greibach Normal formpumping lemma for Context free languages- Applications of

More information

Finite Automata and Formal Languages TMV026/DIT321 LP Useful, Useless, Generating and Reachable Symbols

Finite Automata and Formal Languages TMV026/DIT321 LP Useful, Useless, Generating and Reachable Symbols Finite Automata and Formal Languages TMV026/DIT321 LP4 2012 Lecture 13 Ana Bove May 7th 2012 Overview of today s lecture: Normal Forms for Context-Free Languages Pumping Lemma for Context-Free Languages

More information

TAFL 1 (ECS-403) Unit- III. 3.1 Definition of CFG (Context Free Grammar) and problems. 3.2 Derivation. 3.3 Ambiguity in Grammar

TAFL 1 (ECS-403) Unit- III. 3.1 Definition of CFG (Context Free Grammar) and problems. 3.2 Derivation. 3.3 Ambiguity in Grammar TAFL 1 (ECS-403) Unit- III 3.1 Definition of CFG (Context Free Grammar) and problems 3.2 Derivation 3.3 Ambiguity in Grammar 3.3.1 Inherent Ambiguity 3.3.2 Ambiguous to Unambiguous CFG 3.4 Simplification

More information

CS375: Logic and Theory of Computing

CS375: Logic and Theory of Computing CS375: Logic and Theory of Computing Fuhua (Frank) Cheng Department of Computer Science University of Kentucky 1 Table of Contents: Week 1: Preliminaries (set algebra, relations, functions) (read Chapters

More information

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018 Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018 Lecture 14 Ana Bove May 14th 2018 Recap: Context-free Grammars Simplification of grammars: Elimination of ǫ-productions; Elimination of

More information

CPSC 313 Introduction to Computability

CPSC 313 Introduction to Computability CPSC 313 Introduction to Computability Grammars in Chomsky Normal Form (Cont d) (Sipser, pages 109-111 (3 rd ed) and 107-109 (2 nd ed)) Renate Scheidler Fall 2018 Chomsky Normal Form A context-free grammar

More information

MTH401A Theory of Computation. Lecture 17

MTH401A Theory of Computation. Lecture 17 MTH401A Theory of Computation Lecture 17 Chomsky Normal Form for CFG s Chomsky Normal Form for CFG s For every context free language, L, the language L {ε} has a grammar in which every production looks

More information

Plan for 2 nd half. Just when you thought it was safe. Just when you thought it was safe. Theory Hall of Fame. Chomsky Normal Form

Plan for 2 nd half. Just when you thought it was safe. Just when you thought it was safe. Theory Hall of Fame. Chomsky Normal Form Plan for 2 nd half Pumping Lemma for CFLs The Return of the Pumping Lemma Just when you thought it was safe Return of the Pumping Lemma Recall: With Regular Languages The Pumping Lemma showed that if a

More information

Note: In any grammar here, the meaning and usage of P (productions) is equivalent to R (rules).

Note: In any grammar here, the meaning and usage of P (productions) is equivalent to R (rules). Note: In any grammar here, the meaning and usage of P (productions) is equivalent to R (rules). 1a) G = ({R, S, T}, {0,1}, P, S) where P is: S R0R R R0R1R R1R0R T T 0T ε (S generates the first 0. R generates

More information

NPDA, CFG equivalence

NPDA, CFG equivalence NPDA, CFG equivalence Theorem A language L is recognized by a NPDA iff L is described by a CFG. Must prove two directions: ( ) L is recognized by a NPDA implies L is described by a CFG. ( ) L is described

More information

Properties of Context-free Languages. Reading: Chapter 7

Properties of Context-free Languages. Reading: Chapter 7 Properties of Context-free Languages Reading: Chapter 7 1 Topics 1) Simplifying CFGs, Normal forms 2) Pumping lemma for CFLs 3) Closure and decision properties of CFLs 2 How to simplify CFGs? 3 Three ways

More information

Chap. 7 Properties of Context-free Languages

Chap. 7 Properties of Context-free Languages Chap. 7 Properties of Context-free Languages 7.1 Normal Forms for Context-free Grammars Context-free grammars A where A N, (N T). 0. Chomsky Normal Form A BC or A a except S where A, B, C N, a T. 1. Eliminating

More information

Properties of context-free Languages

Properties of context-free Languages Properties of context-free Languages We simplify CFL s. Greibach Normal Form Chomsky Normal Form We prove pumping lemma for CFL s. We study closure properties and decision properties. Some of them remain,

More information

EXAMPLE CFG. L = {a 2n : n 1 } L = {a 2n : n 0 } S asa aa. L = {a n b : n 0 } L = {a n b : n 1 } S asb ab S 1S00 S 1S00 100

EXAMPLE CFG. L = {a 2n : n 1 } L = {a 2n : n 0 } S asa aa. L = {a n b : n 0 } L = {a n b : n 1 } S asb ab S 1S00 S 1S00 100 EXAMPLE CFG L = {a 2n : n 1 } L = {a 2n : n 0 } S asa aa S asa L = {a n b : n 0 } L = {a n b : n 1 } S as b S as ab L { a b : n 0} L { a b : n 1} S asb S asb ab n 2n n 2n L {1 0 : n 0} L {1 0 : n 1} S

More information

Recitation 4: Converting Grammars to Chomsky Normal Form, Simulation of Context Free Languages with Push-Down Automata, Semirings

Recitation 4: Converting Grammars to Chomsky Normal Form, Simulation of Context Free Languages with Push-Down Automata, Semirings Recitation 4: Converting Grammars to Chomsky Normal Form, Simulation of Context Free Languages with Push-Down Automata, Semirings 11-711: Algorithms for NLP October 10, 2014 Conversion to CNF Example grammar

More information

Ogden s Lemma for CFLs

Ogden s Lemma for CFLs Ogden s Lemma for CFLs Theorem If L is a context-free language, then there exists an integer l such that for any u L with at least l positions marked, u can be written as u = vwxyz such that 1 x and at

More information

Problem Session 5 (CFGs) Talk about the building blocks of CFGs: S 0S 1S ε - everything. S 0S0 1S1 A - waw R. S 0S0 0S1 1S0 1S1 A - xay, where x = y.

Problem Session 5 (CFGs) Talk about the building blocks of CFGs: S 0S 1S ε - everything. S 0S0 1S1 A - waw R. S 0S0 0S1 1S0 1S1 A - xay, where x = y. CSE2001, Fall 2006 1 Problem Session 5 (CFGs) Talk about the building blocks of CFGs: S 0S 1S ε - everything. S 0S0 1S1 A - waw R. S 0S0 0S1 1S0 1S1 A - xay, where x = y. S 00S1 A - xay, where x = 2 y.

More information

Context Free Grammars

Context Free Grammars Automata and Formal Languages Context Free Grammars Sipser pages 101-111 Lecture 11 Tim Sheard 1 Formal Languages 1. Context free languages provide a convenient notation for recursive description of languages.

More information

CSCI Compiler Construction

CSCI Compiler Construction CSCI 742 - Compiler Construction Lecture 12 Cocke-Younger-Kasami (CYK) Algorithm Instructor: Hossein Hojjat February 20, 2017 Recap: Chomsky Normal Form (CNF) A CFG is in Chomsky Normal Form if each rule

More information

Context Free Grammars: Introduction. Context Free Grammars: Simplifying CFGs

Context Free Grammars: Introduction. Context Free Grammars: Simplifying CFGs Context Free Grammars: Introduction CFGs are more powerful than RGs because of the following 2 properties: 1. Recursion Rule is recursive if it is of the form X w 1 Y w 2, where Y w 3 Xw 4 and w 1, w 2,

More information

This lecture covers Chapter 7 of HMU: Properties of CFLs

This lecture covers Chapter 7 of HMU: Properties of CFLs This lecture covers Chapter 7 of HMU: Properties of CFLs Chomsky Normal Form Pumping Lemma for CFs Closure Properties of CFLs Decision Properties of CFLs Additional Reading: Chapter 7 of HMU. Chomsky Normal

More information

Properties of Context-Free Languages

Properties of Context-Free Languages Properties of Context-Free Languages Seungjin Choi Department of Computer Science and Engineering Pohang University of Science and Technology 77 Cheongam-ro, Nam-gu, Pohang 37673, Korea seungjin@postech.ac.kr

More information

Automata Theory CS F-08 Context-Free Grammars

Automata Theory CS F-08 Context-Free Grammars Automata Theory CS411-2015F-08 Context-Free Grammars David Galles Department of Computer Science University of San Francisco 08-0: Context-Free Grammars Set of Terminals (Σ) Set of Non-Terminals Set of

More information

Non-context-Free Languages. CS215, Lecture 5 c

Non-context-Free Languages. CS215, Lecture 5 c Non-context-Free Languages CS215, Lecture 5 c 2007 1 The Pumping Lemma Theorem. (Pumping Lemma) Let be context-free. There exists a positive integer divided into five pieces, Proof for for each, and..

More information

Solution. S ABc Ab c Bc Ac b A ABa Ba Aa a B Bbc bc.

Solution. S ABc Ab c Bc Ac b A ABa Ba Aa a B Bbc bc. Section 12.4 Context-Free Language Topics Algorithm. Remove Λ-productions from grammars for langauges without Λ. 1. Find nonterminals that derive Λ. 2. For each production A w construct all productions

More information

Einführung in die Computerlinguistik

Einführung in die Computerlinguistik Einführung in die Computerlinguistik Context-Free Grammars formal properties Laura Kallmeyer Heinrich-Heine-Universität Düsseldorf Summer 2018 1 / 20 Normal forms (1) Hopcroft and Ullman (1979) A normal

More information

AC68 FINITE AUTOMATA & FORMULA LANGUAGES JUNE 2014

AC68 FINITE AUTOMATA & FORMULA LANGUAGES JUNE 2014 Q.2 a. Show by using Mathematical Induction that n i= 1 i 2 n = ( n + 1) ( 2 n + 1) 6 b. Define language. Let = {0; 1} denote an alphabet. Enumerate five elements of the following languages: (i) Even binary

More information

Simplification and Normalization of Context-Free Grammars

Simplification and Normalization of Context-Free Grammars implification and Normalization, of Context-Free Grammars 20100927 Slide 1 of 23 Simplification and Normalization of Context-Free Grammars 5DV037 Fundamentals of Computer Science Umeå University Department

More information

Definition: A grammar G = (V, T, P,S) is a context free grammar (cfg) if all productions in P have the form A x where

Definition: A grammar G = (V, T, P,S) is a context free grammar (cfg) if all productions in P have the form A x where Recitation 11 Notes Context Free Grammars Definition: A grammar G = (V, T, P,S) is a context free grammar (cfg) if all productions in P have the form A x A V, and x (V T)*. Examples Problem 1. Given the

More information

Notes for Comp 497 (Comp 454) Week 10 4/5/05

Notes for Comp 497 (Comp 454) Week 10 4/5/05 Notes for Comp 497 (Comp 454) Week 10 4/5/05 Today look at the last two chapters in Part II. Cohen presents some results concerning context-free languages (CFL) and regular languages (RL) also some decidability

More information

The Pumping Lemma for Context Free Grammars

The Pumping Lemma for Context Free Grammars 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 is in the form A BC A a Where a is any terminal

More information

Concordia University Department of Computer Science & Software Engineering

Concordia University Department of Computer Science & Software Engineering Concordia University Department of Computer Science & Software Engineering COMP 335/4 Theoretical Computer Science Winter 2015 Assignment 3 1. In each case, what language is generated by CFG s below. Justify

More information

AC68 FINITE AUTOMATA & FORMULA LANGUAGES DEC 2013

AC68 FINITE AUTOMATA & FORMULA LANGUAGES DEC 2013 Q.2 a. Prove by mathematical induction n 4 4n 2 is divisible by 3 for n 0. Basic step: For n = 0, n 3 n = 0 which is divisible by 3. Induction hypothesis: Let p(n) = n 3 n is divisible by 3. Induction

More information

Notes for Comp 497 (454) Week 10

Notes for Comp 497 (454) Week 10 Notes for Comp 497 (454) Week 10 Today we look at the last two chapters in Part II. Cohen presents some results concerning the two categories of language we have seen so far: Regular languages (RL). Context-free

More information

Harvard CS 121 and CSCI E-207 Lecture 12: General Context-Free Recognition

Harvard CS 121 and CSCI E-207 Lecture 12: General Context-Free Recognition Harvard CS 121 and CSCI E-207 Lecture 12: General Context-Free Recognition Salil Vadhan October 11, 2012 Reading: Sipser, Section 2.3 and Section 2.1 (material on Chomsky Normal Form). Pumping Lemma for

More information

SFWR ENG 2FA3. Solution to the Assignment #4

SFWR ENG 2FA3. Solution to the Assignment #4 SFWR ENG 2FA3. Solution to the Assignment #4 Total = 131, 100%= 115 The solutions below are often very detailed on purpose. Such level of details is not required from students solutions. Some questions

More information

CDM Parsing and Decidability

CDM Parsing and Decidability CDM Parsing and Decidability 1 Parsing Klaus Sutner Carnegie Mellon Universality 65-parsing 2017/12/15 23:17 CFGs and Decidability Pushdown Automata The Recognition Problem 3 What Could Go Wrong? 4 Problem:

More information

Chomsky and Greibach Normal Forms

Chomsky and Greibach Normal Forms Chomsky and Greibach Normal Forms Teodor Rus rus@cs.uiowa.edu The University of Iowa, Department of Computer Science Computation Theory p.1/25 Simplifying a CFG It is often convenient to simplify CFG One

More information

Theory Of Computation UNIT-II

Theory Of Computation UNIT-II Regular Expressions and Context Free Grammars: Regular expression formalism- equivalence with finite automata-regular sets and closure properties- pumping lemma for regular languages- decision algorithms

More information

Finite Automata Theory and Formal Languages TMV026/TMV027/DIT321 Responsible: Ana Bove

Finite Automata Theory and Formal Languages TMV026/TMV027/DIT321 Responsible: Ana Bove Finite Automata Theory and Formal Languages TMV026/TMV027/DIT321 Responsible: Ana Bove Tuesday 28 of May 2013 Total: 60 points TMV027/DIT321 registration VT13 TMV026/DIT321 registration before VT13 Exam

More information

INSTITUTE OF AERONAUTICAL ENGINEERING

INSTITUTE OF AERONAUTICAL ENGINEERING INSTITUTE OF AERONAUTICAL ENGINEERING DUNDIGAL 500 043, HYDERABAD COMPUTER SCIENCE AND ENGINEERING TUTORIAL QUESTION BANK Course Name : FORMAL LANGUAGES AND AUTOMATA THEORY Course Code : A40509 Class :

More information

Address for Correspondence

Address for Correspondence Proceedings of BITCON-2015 Innovations For National Development National Conference on : Research and Development in Computer Science and Applications Research Paper SUBSTRING MATCHING IN CONTEXT FREE

More information

Foundations of Informatics: a Bridging Course

Foundations of Informatics: a Bridging Course Foundations of Informatics: a Bridging Course Week 3: Formal Languages and Semantics Thomas Noll Lehrstuhl für Informatik 2 RWTH Aachen University noll@cs.rwth-aachen.de http://www.b-it-center.de/wob/en/view/class211_id948.html

More information

Computational Models - Lecture 5 1

Computational Models - Lecture 5 1 Computational Models - Lecture 5 1 Handout Mode Iftach Haitner. Tel Aviv University. November 28, 2016 1 Based on frames by Benny Chor, Tel Aviv University, modifying frames by Maurice Herlihy, Brown University.

More information

Sheet 1-8 Dr. Mostafa Aref Format By : Mostafa Sayed

Sheet 1-8 Dr. Mostafa Aref Format By : Mostafa Sayed Sheet -8 Dr. Mostafa Aref Format By : Mostafa Sayed 09 Introduction Assignment. For = {a, } a) Write 0 strings of the following languages i) All strings with no more than one a,,, a, a, a, a, a, a, a ii)

More information

download instant at Assume that (w R ) R = w for all strings w Σ of length n or less.

download instant at  Assume that (w R ) R = w for all strings w Σ of length n or less. Chapter 2 Languages 3. We prove, by induction on the length of the string, that w = (w R ) R for every string w Σ. Basis: The basis consists of the null string. In this case, (λ R ) R = (λ) R = λ as desired.

More information

Einführung in die Computerlinguistik Kontextfreie Grammatiken - Formale Eigenschaften

Einführung in die Computerlinguistik Kontextfreie Grammatiken - Formale Eigenschaften Normal forms (1) Einführung in die Computerlinguistik Kontextfreie Grammatiken - Formale Eigenschaften Laura Heinrich-Heine-Universität Düsseldorf Sommersemester 2013 normal form of a grammar formalism

More information

CPS 220 Theory of Computation

CPS 220 Theory of Computation CPS 22 Theory of Computation Review - Regular Languages RL - a simple class of languages that can be represented in two ways: 1 Machine description: Finite Automata are machines with a finite number of

More information

Homework #7. True False. d. Given a CFG, G, and a string w, it is decidable whether w ε L(G) True False

Homework #7. True False. d. Given a CFG, G, and a string w, it is decidable whether w ε L(G) True False Hmewrk #7 #1. True/ False a. The Pumping Lemma fr CFL s can be used t shw a language is cntext-free b. The string z = a k b k+1 c k can be used t shw {a n b n c n } is nt cntext free c. The string z =

More information

Chapter 4: Context-Free Grammars

Chapter 4: Context-Free Grammars Chapter 4: Context-Free Grammars 4.1 Basics of Context-Free Grammars Definition A context-free grammars, or CFG, G is specified by a quadruple (N, Σ, P, S), where N is the nonterminal or variable alphabet;

More information

Chapter 5: Context-Free Languages

Chapter 5: Context-Free Languages Chapter 5: Context-Free Languages Peter Cappello Department of Computer Science University of California, Santa Barbara Santa Barbara, CA 93106 cappello@cs.ucsb.edu Please read the corresponding chapter

More information

Context Free Grammars: Introduction

Context Free Grammars: Introduction Context Free Grammars: Introduction Context free grammar (CFG) G = (V, Σ, R, S), where V is a set of grammar symbols Σ V is a set of terminal symbols R is a set of rules, where R (V Σ) V S is a distinguished

More information

VTU QUESTION BANK. Unit 1. Introduction to Finite Automata. 1. Obtain DFAs to accept strings of a s and b s having exactly one a.

VTU QUESTION BANK. Unit 1. Introduction to Finite Automata. 1. Obtain DFAs to accept strings of a s and b s having exactly one a. VTU QUESTION BANK Unit 1 Introduction to Finite Automata 1. Obtain DFAs to accept strings of a s and b s having exactly one a.(5m )( Dec-2014) 2. Obtain a DFA to accept strings of a s and b s having even

More information

St.MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad

St.MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad St.MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad-500 014 Subject: FORMAL LANGUAGES AND AUTOMATA THEORY Class : CSE II PART A (SHORT ANSWER QUESTIONS) UNIT- I 1 Explain transition diagram, transition

More information

CS A Term 2009: Foundations of Computer Science. Homework 2. By Li Feng, Shweta Srivastava, and Carolina Ruiz.

CS A Term 2009: Foundations of Computer Science. Homework 2. By Li Feng, Shweta Srivastava, and Carolina Ruiz. CS3133 - A Term 2009: Foundations of Computer Science Prof. Carolina Ruiz Homework 2 WPI By Li Feng, Shweta Srivastava, and Carolina Ruiz Chapter 4 Problem 1: (10 Points) Exercise 4.3 Solution 1: S is

More information

Introduction to Formal Languages, Automata and Computability p.1/42

Introduction to Formal Languages, Automata and Computability p.1/42 Introduction to Formal Languages, Automata and Computability Pushdown Automata K. Krithivasan and R. Rama Introduction to Formal Languages, Automata and Computability p.1/42 Introduction We have considered

More information

Context-free Grammars and Languages

Context-free Grammars and Languages Context-free Grammars and Languages COMP 455 002, Spring 2019 Jim Anderson (modified by Nathan Otterness) 1 Context-free Grammars Context-free grammars provide another way to specify languages. Example:

More information

(b) If G=({S}, {a}, {S SS}, S) find the language generated by G. [8+8] 2. Convert the following grammar to Greibach Normal Form G = ({A1, A2, A3},

(b) If G=({S}, {a}, {S SS}, S) find the language generated by G. [8+8] 2. Convert the following grammar to Greibach Normal Form G = ({A1, A2, A3}, Code No: 07A50501 R07 Set No. 2 III B.Tech I Semester Examinations,MAY 2011 FORMAL LANGUAGES AND AUTOMATA THEORY Computer Science And Engineering Time: 3 hours Max Marks: 80 Answer any FIVE Questions All

More information

Lecture 11 Context-Free Languages

Lecture 11 Context-Free Languages Lecture 11 Context-Free Languages COT 4420 Theory of Computation Chapter 5 Context-Free Languages n { a b : n n { ww } 0} R Regular Languages a *b* ( a + b) * Example 1 G = ({S}, {a, b}, S, P) Derivations:

More information

CS5371 Theory of Computation. Lecture 7: Automata Theory V (CFG, CFL, CNF)

CS5371 Theory of Computation. Lecture 7: Automata Theory V (CFG, CFL, CNF) CS5371 Theory of Computation Lecture 7: Automata Theory V (CFG, CFL, CNF) Announcement Homework 2 will be given soon (before Tue) Due date: Oct 31 (Tue), before class Midterm: Nov 3, (Fri), first hour

More information

Automata Theory Final Exam Solution 08:10-10:00 am Friday, June 13, 2008

Automata Theory Final Exam Solution 08:10-10:00 am Friday, June 13, 2008 Automata Theory Final Exam Solution 08:10-10:00 am Friday, June 13, 2008 Name: ID #: This is a Close Book examination. Only an A4 cheating sheet belonging to you is acceptable. You can write your answers

More information

where A, B, C N, a Σ, S ϵ is in P iff ϵ L(G), and S does not occur on the right-hand side of any production. 3.6 The Greibach Normal Form

where A, B, C N, a Σ, S ϵ is in P iff ϵ L(G), and S does not occur on the right-hand side of any production. 3.6 The Greibach Normal Form 262 CHAPTER 3. CONTEXT-FREE LANGUAGES AND PDA S 3.6 The Greibach Normal Form Every CFG G can also be converted to an equivalent grammar in Greibach Normal Form (for short, GNF). Acontext-freegrammarG =(V,Σ,P,S)

More information

An automaton with a finite number of states is called a Finite Automaton (FA) or Finite State Machine (FSM).

An automaton with a finite number of states is called a Finite Automaton (FA) or Finite State Machine (FSM). Automata The term "Automata" is derived from the Greek word "αὐτόματα" which means "self-acting". An automaton (Automata in plural) is an abstract self-propelled computing device which follows a predetermined

More information

Solutions to Problem Set 3

Solutions to Problem Set 3 V22.0453-001 Theory of Computation October 8, 2003 TA: Nelly Fazio Solutions to Problem Set 3 Problem 1 We have seen that a grammar where all productions are of the form: A ab, A c (where A, B non-terminals,

More information

60-354, Theory of Computation Fall Asish Mukhopadhyay School of Computer Science University of Windsor

60-354, Theory of Computation Fall Asish Mukhopadhyay School of Computer Science University of Windsor 60-354, Theory of Computation Fall 2013 Asish Mukhopadhyay School of Computer Science University of Windsor Pushdown Automata (PDA) PDA = ε-nfa + stack Acceptance ε-nfa enters a final state or Stack is

More information

6.1 The Pumping Lemma for CFLs 6.2 Intersections and Complements of CFLs

6.1 The Pumping Lemma for CFLs 6.2 Intersections and Complements of CFLs CSC4510/6510 AUTOMATA 6.1 The Pumping Lemma for CFLs 6.2 Intersections and Complements of CFLs The Pumping Lemma for Context Free Languages One way to prove AnBn is not regular is to use the pumping lemma

More information

Computational Models - Lecture 4 1

Computational Models - Lecture 4 1 Computational Models - Lecture 4 1 Handout Mode Iftach Haitner and Yishay Mansour. Tel Aviv University. April 3/8, 2013 1 Based on frames by Benny Chor, Tel Aviv University, modifying frames by Maurice

More information

5.A Examples of Context-Free Grammars 3.1 and 3.2 of Du & Ko s book(pp )

5.A Examples of Context-Free Grammars 3.1 and 3.2 of Du & Ko s book(pp ) 5.A Examples of Context-Free Grammars 3.1 and 3.2 of Du & Ko s book(pp. 91-108) Example 3.1 Consider S ε asb. What is L(S)? Solution S asb aasbb a n Sb n a n b n. L(S) = {a n b n n 0} Example 3.2 Consider

More information

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY REVIEW for MIDTERM 1 THURSDAY Feb 6 Midterm 1 will cover everything we have seen so far The PROBLEMS will be from Sipser, Chapters 1, 2, 3 It will be

More information

Chomsky Normal Form and TURING MACHINES. TUESDAY Feb 4

Chomsky Normal Form and TURING MACHINES. TUESDAY Feb 4 Chomsky Normal Form and TURING MACHINES TUESDAY Feb 4 CHOMSKY NORMAL FORM A context-free grammar is in Chomsky normal form if every rule is of the form: A BC A a S ε B and C aren t start variables a is

More information

Syntax Analysis: Context-free Grammars, Pushdown Automata and Parsing Part - 3. Y.N. Srikant

Syntax Analysis: Context-free Grammars, Pushdown Automata and Parsing Part - 3. Y.N. Srikant Syntax Analysis: Context-free Grammars, Pushdown Automata and Part - 3 Department of Computer Science and Automation Indian Institute of Science Bangalore 560 012 NPTEL Course on Principles of Compiler

More information

MA/CSSE 474 Theory of Computation

MA/CSSE 474 Theory of Computation MA/CSSE 474 Theory of Computation CFL Hierarchy CFL Decision Problems Your Questions? Previous class days' material Reading Assignments HW 12 or 13 problems Anything else I have included some slides online

More information

CS20a: summary (Oct 24, 2002)

CS20a: summary (Oct 24, 2002) CS20a: summary (Oct 24, 2002) Context-free languages Grammars G = (V, T, P, S) Pushdown automata N-PDA = CFG D-PDA < CFG Today What languages are context-free? Pumping lemma (similar to pumping lemma for

More information

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY Chomsky Normal Form and TURING MACHINES TUESDAY Feb 4 CHOMSKY NORMAL FORM A context-free grammar is in Chomsky normal form if every rule is of the form:

More information

Context-Free Grammars (and Languages) Lecture 7

Context-Free Grammars (and Languages) Lecture 7 Context-Free Grammars (and Languages) Lecture 7 1 Today Beyond regular expressions: Context-Free Grammars (CFGs) What is a CFG? What is the language associated with a CFG? Creating CFGs. Reasoning about

More information

Question Bank UNIT I

Question Bank UNIT I Siddhivinayak Technical Campus School of Engineering & Research Technology Department of computer science and Engineering Session 2016-2017 Subject Name- Theory of Computation Subject Code-4KS05 Sr No.

More information

Computational Models - Lecture 3

Computational Models - Lecture 3 Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. p. 1 Computational Models - Lecture 3 Equivalence of regular expressions and regular languages (lukewarm leftover

More information

Properties of Context-Free Languages. Closure Properties Decision Properties

Properties of Context-Free Languages. Closure Properties Decision Properties Properties of Context-Free Languages Closure Properties Decision Properties 1 Closure Properties of CFL s CFL s are closed under union, concatenation, and Kleene closure. Also, under reversal, homomorphisms

More information

Context-Free Languages (Pre Lecture)

Context-Free Languages (Pre Lecture) Context-Free Languages (Pre Lecture) Dr. Neil T. Dantam CSCI-561, Colorado School of Mines Fall 2017 Dantam (Mines CSCI-561) Context-Free Languages (Pre Lecture) Fall 2017 1 / 34 Outline Pumping Lemma

More information

CS311 Computational Structures More about PDAs & Context-Free Languages. Lecture 9. Andrew P. Black Andrew Tolmach

CS311 Computational Structures More about PDAs & Context-Free Languages. Lecture 9. Andrew P. Black Andrew Tolmach CS311 Computational Structures More about PDAs & Context-Free Languages Lecture 9 Andrew P. Black Andrew Tolmach 1 Three important results 1. Any CFG can be simulated by a PDA 2. Any PDA can be simulated

More information

Pushdown Automata. Reading: Chapter 6

Pushdown Automata. Reading: Chapter 6 Pushdown Automata Reading: Chapter 6 1 Pushdown Automata (PDA) Informally: A PDA is an NFA-ε with a infinite stack. Transitions are modified to accommodate stack operations. Questions: What is a stack?

More information

CS481F01 Prelim 2 Solutions

CS481F01 Prelim 2 Solutions CS481F01 Prelim 2 Solutions A. Demers 7 Nov 2001 1 (30 pts = 4 pts each part + 2 free points). For this question we use the following notation: x y means x is a prefix of y m k n means m n k For each of

More information

1. (a) Explain the procedure to convert Context Free Grammar to Push Down Automata.

1. (a) Explain the procedure to convert Context Free Grammar to Push Down Automata. Code No: R09220504 R09 Set No. 2 II B.Tech II Semester Examinations,December-January, 2011-2012 FORMAL LANGUAGES AND AUTOMATA THEORY Computer Science And Engineering Time: 3 hours Max Marks: 75 Answer

More information

Part 4 out of 5 DFA NFA REX. Automata & languages. A primer on the Theory of Computation. Last week, we showed the equivalence of DFA, NFA and REX

Part 4 out of 5 DFA NFA REX. Automata & languages. A primer on the Theory of Computation. Last week, we showed the equivalence of DFA, NFA and REX Automata & languages A primer on the Theory of Computation Laurent Vanbever www.vanbever.eu Part 4 out of 5 ETH Zürich (D-ITET) October, 12 2017 Last week, we showed the equivalence of DFA, NFA and REX

More information

Testing Emptiness of a CFL. Testing Finiteness of a CFL. Testing Membership in a CFL. CYK Algorithm

Testing Emptiness of a CFL. Testing Finiteness of a CFL. Testing Membership in a CFL. CYK Algorithm Testing Emptiness of a CFL As for regular languages, we really take a representation of some language and ask whether it represents φ Can use either CFG or PDA Our choice, since there are algorithms to

More information

The View Over The Horizon

The View Over The Horizon The View Over The Horizon enumerable decidable context free regular Context-Free Grammars An example of a context free grammar, G 1 : A 0A1 A B B # Terminology: Each line is a substitution rule or production.

More information

Theory of Computation Turing Machine and Pushdown Automata

Theory of Computation Turing Machine and Pushdown Automata Theory of Computation Turing Machine and Pushdown Automata 1. What is a Turing Machine? A Turing Machine is an accepting device which accepts the languages (recursively enumerable set) generated by type

More information

CSE 468, Fall 2006 Homework solutions 1

CSE 468, Fall 2006 Homework solutions 1 CSE 468, Fall 2006 Homework solutions 1 Homework 1 Problem 1. (a) To accept digit strings that contain 481: Q ={λ,4,48, 481}, Σ ={0,1,...,9}, q 0 = λ, A ={481}. To define δ, weuse a for all letters (well,

More information

Context-Free Grammars. 2IT70 Finite Automata and Process Theory

Context-Free Grammars. 2IT70 Finite Automata and Process Theory Context-Free Grammars 2IT70 Finite Automata and Process Theory Technische Universiteit Eindhoven May 18, 2016 Generating strings language L 1 = {a n b n n > 0} ab L 1 if w L 1 then awb L 1 production rules

More information

Chapter 16: Non-Context-Free Languages

Chapter 16: Non-Context-Free Languages Chapter 16: Non-Context-Free Languages Peter Cappello Department of Computer Science University of California, Santa Barbara Santa Barbara, CA 93106 cappello@cs.ucsb.edu Please read the corresponding chapter

More information

Introduction to Theory of Computing

Introduction to Theory of Computing CSCI 2670, Fall 2012 Introduction to Theory of Computing Department of Computer Science University of Georgia Athens, GA 30602 Instructor: Liming Cai www.cs.uga.edu/ cai 0 Lecture Note 3 Context-Free Languages

More information

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska LECTURE 14 SMALL REVIEW FOR FINAL SOME Y/N QUESTIONS Q1 Given Σ =, there is L over Σ Yes: = {e} and L = {e} Σ Q2 There are uncountably

More information