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

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

Lecture 12 Simplification of Context-Free Grammars and Normal Forms

Theory of Computation - Module 3

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

Automata Theory CS F-08 Context-Free Grammars

Concordia University Department of Computer Science & Software Engineering

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

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.

CS375: Logic and Theory of Computing

Theory of Computer Science

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

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

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

CS 133 : Automata Theory and Computability

ÖVNINGSUPPGIFTER I SAMMANHANGSFRIA SPRÅK. 17 april Classrum Edition

Theory of Computation

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

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

HW 3 Solutions. Tommy November 27, 2012

C1.1 Introduction. Theory of Computer Science. Theory of Computer Science. C1.1 Introduction. C1.2 Alphabets and Formal Languages. C1.

CSEP 590 Data Compression Autumn Arithmetic Coding

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

Solutions to Problem Set 3

SFWR ENG 2FA3. Solution to the Assignment #4

A Universal Turing Machine

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

Section 1 (closed-book) Total points 30

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.

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

CSCI 340: Computational Models. Regular Expressions. Department of Computer Science

INTRO TO I & CT. (Boolean Algebra and Logic Simplification.) Lecture # By: Department of CS & IT.

COSE212: Programming Languages. Lecture 1 Inductive Definitions (1)

Lecture 11 Context-Free Languages

INSTITUTE OF AERONAUTICAL ENGINEERING

REGular and Context-Free Grammars

FABER Formal Languages, Automata. Lecture 2. Mälardalen University

Semigroup presentations via boundaries in Cayley graphs 1

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

Properties of Context Free Languages

CS375 Midterm Exam Solution Set (Fall 2017)

COSE212: Programming Languages. Lecture 1 Inductive Definitions (1)

Author: Vivek Kulkarni ( )

1 Alphabets and Languages

Linear conjunctive languages are closed under complement

A B CDE F B FD D A C AF DC A F

CPSC 313 Introduction to Computability

AC68 FINITE AUTOMATA & FORMULA LANGUAGES JUNE 2014

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

Please give details of your answer. A direct answer without explanation is not counted.

Theory of Computation

Harvard CS 121 and CSCI E-207 Lecture 10: CFLs: PDAs, Closure Properties, and Non-CFLs

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Context-Free Grammars: Normal Forms

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

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

CMSC 330: Organization of Programming Languages

Harvard CS121 and CSCI E-121 Lecture 2: Mathematical Preliminaries

Talen en Compilers. Johan Jeuring , period 2. October 29, Department of Information and Computing Sciences Utrecht University

AC68 FINITE AUTOMATA & FORMULA LANGUAGES DEC 2013

Chapter 1. Introduction

(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},

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

Context Free Languages. Automata Theory and Formal Grammars: Lecture 6. Languages That Are Not Regular. Non-Regular Languages

Theory of Computation Turing Machine and Pushdown Automata

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Chapter 4. Regular Expressions. 4.1 Some Definitions

Section 1.3 Ordered Structures

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

CMSC 330: Organization of Programming Languages. Regular Expressions and Finite Automata

Developing a Distributed Java-based Speech Recognition Engine

In English, there are at least three different types of entities: letters, words, sentences.

Recursive descent for grammars with contexts

Fundamentele Informatica II

Context-Free Grammar

5/10/16. Grammar. Automata and Languages. Today s Topics. Grammars Definition A grammar G is defined as G = (V, T, P, S) where:

Properties of Context-free Languages. Reading: Chapter 7

Basic Principles of Lossless Coding. Universal Lossless coding. Lempel-Ziv Coding. 2. Exploit dependences between successive symbols.

CS 373: Theory of Computation. Fall 2010

CS500 Homework #2 Solutions

1. Draw a parse tree for the following derivation: S C A C C A b b b b A b b b b B b b b b a A a a b b b b a b a a b b 2. Show on your parse tree u,

Lecture 7 Properties of regular languages

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

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

CS375: Logic and Theory of Computing

Triangles. 3.In the following fig. AB = AC and BD = DC, then ADC = (A) 60 (B) 120 (C) 90 (D) none 4.In the Fig. given below, find Z.

Pentagonal quasigroups. 1. Introduction

Regular Expressions [1] Regular Expressions. Regular expressions can be seen as a system of notations for denoting ɛ-nfa

Properties of Context-Free Languages

The Probability of Winning a Series. Gregory Quenell

Dynamic Programming. Shuang Zhao. Microsoft Research Asia September 5, Dynamic Programming. Shuang Zhao. Outline. Introduction.

Theory of Computation (Classroom Practice Booklet Solutions)

The state numbers of a knot

Isolation and Contentment in Segregation Games with Three Types

D EFB B E B EAB ABC DEF C A F C D C DEF C AD C AEC D D E C D EF B ABC AB CD A EFD AD D E

Notes for Comp 497 (454) Week 10

Regularity-preserving letter selections

Context Free Languages and Grammars

CSE 105 Homework 1 Due: Monday October 9, Instructions. should be on each page of the submission.

CS 341 Homework 16 Languages that Are and Are Not Context-Free

Transcription:

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 1S00 S 1S00 100 L = { ww R : w { a, b}*} L = { ww R : w { a, b} } asa bsb S S asa bsb aa bb n m k L { a b c : n 0, m 0, k 0} C A aa B bb C cc L { a b : n 0} { b a : n 0} S S S S S 1 2 1 as b 1 bs 2 2 a L { a b b : n 0} S Ab L = { a n b n c k : n, k 0 } S AC C cc L = {a n b n c i : n 1, i 0} A aab ab B cb

L = {a j b n c n : n 1, j 0} A aa B bbc bc L = {a n b n+m c m n, m 0} L = {a n b n+m c m n, m 1} A aab ab B bbc B bbc bc L = {a n ba n : n 0} S asa B B b L = {a n b m c n : n, m 0} L = {a n b m c n : n, m 1} S asc A S asc aac A ba A ba b L { ab cd f : n 0} S aaf A bad c L={a i b j c k d l a l b k c j d i i, j, k, l 0} S asd A A bac B B cbb C C dca L = {a n b m c 2n+m : n, m > 0} Here a n b m c 2n+m = a n b m c m c 2n S ascc A A bac bc L = { (ab} i (cd )j (ba) j (dc) i i, j 0 } S absdc A A cdaba L = {a n b m a m b n : n, m 0} S asb A A baa L = {a n b m a m b n : n, m 1} S asb aab A baa ba

R L = { wc * w : w { a, b}*} S C asa bsb C Cc L = {a i b j c k i = j+k } a i b j c k = a j+k b j c k = a k a j b j c k S asc A L = {a i b j c k j = i+k } a i b j c k = a i b i+k c k = a i b i b k c k B bac L = {a i b j c k k = i+j } a i b j c k = a i b j c i+j = a i b j c j c i S asc A A bac L = {a i b j c k j=i or j=k} Here the language is union of two language L 1 = {a i b j c k j=i} and L 2 = {a i b j c k j=k} L 1 = {a i b j c k j=i} a i b j c k = a i b i c k A CD D cd L 1 = {a i b j c k j=k} a i b j c k = a i b k c k B EF E ae F bfc The grammar for L is S A B A CD D cd B EF E ae F bfc L = {a i b j c k i=j or i=k} Here the language is union of two language L 1 = {a i b j c k i=j} and L 2 = {a i b j c k i=k}

L 1 = {a i b j c k i=j} a i b j c k = a j b j c k A CD D cd L 1 = {a i b j c k i=k} a i b j c k = a k b j c k B abc E E be The grammar for L is S A B A CD D cd B abc E E be L = {a i b j c k k=i or k=j} Here the language is union of two language L 1 = {a i b j c k k=i } and L 2 = {a i b j c k k=j } L 1 = {a i b j c k k=i } a i b j c k = a i b j c i A aac C C bc L 1 = {a i b j c k k=j} a i b j c k = a i b j c j B EF E ae F bfc The grammar for L is S A B A aac C C bc B EF E ae F bfc L = {0 i 1 j 0 k j > i+k, i. k 0} Let j = i+k+m where m > 0 0 i 1 j 0 k = 0 i 1 i+m+k 0 k = 0 i 1 i 1 m 1 k 0 k L = L 1 L 2 L 3 L 1 = {0 i 1 i : i 0 } L 2 = {1 m : m > 0 } L 3 = {1 k 0 k : k 0 } C A 0A1 B 1B 1 C 1C0

L = {a i b j c k i < j or i> k} Here the language is union of two language L 1 = {a i b j c k i<j} and L 2 = {a i b j c k i>k} L 1 = {a i b j c k i < j} Let j = i+m where m 1 a i b j c k = a i b i+m c i = a i b i b m c k A CDE D bd b E ce L 1 = {a i b j c k i>k } Let i= k+m where where m 1 a i b j c k = a k+m b j c k = a m a k b j c k B FG F af a G agc H H bh The grammar is S A B A CDE D bd b E ce B FG F af a G agc H H bh L = {a n b m 2n m 3n} S asbb asbbb L = {a n b m : n 2, m 3} S asb as Sb aabbb i j L { a b : i j} S X Y ( L = L(x) L(y)) X axb ax a ( L(x)= { a i b j ; i>j }) Y ayb Yb b ( L(y)= { a i b j ; i<j }) m n L { 0 1 : m n, n, m 1} S 0A1 0B1 A 0A1 0A 0 B 0B1 1B 1 n m L { a b : m n, m, n 1} S asb aa bb a b A aa a B bb b n m p L { a b c : n m p} S Sc asc Ac aac A Ab aab

L = { a n b m : n m+3 } S asb A B A a aa aaa B bb L = { a n b m : n m-1 } S asb A B A aa B bb bb L = {0 n 1 m 0 n : n+m 2} case I: case II: case III: n a = n b in L 3 n a - n b 0 in L n a < n b in L Here L is union of 111*, 011*0 and L= {0 n 1*0 n : n 1} S S 1 S 2 S 3 S 1 1 S 1 11 A 1A S 2 01A0 S 3 0 S 3 0 0A0 The set of all string over alphabet {a,b} with exactly twice as many a s as b s S SaSbSaS SaSaSbS SbSaSaS The set of all string over alphabet {a,b} not of the form WW for some string W. S aba bab as bs A ba b B ab a The set of all string over alphabet {0,1} with at least three 1s S A1A1A1A A 0A 1A 0 1 The set of all string over alphabet {0,1} which starts and ends with same symbol S 0A0 1A1 A 0A 1A 0 1 The set of all string over alphabet {0,1} which length is odd RE = ((0+1) (0+1))*(0+1) The grammar is S CA A 0 1 (RE : (0+1) ) B AA (RE : (0+1)(0+1)) C BC (RE: ((0+1)(0+1))*) The set of odd length strings in {a,b}* with middle symbol a. S asa bsb asb bsa a

The set of even length strings in {a,b}* with two middle symbols equal S asa bsb asb bsa aa bb The set of odd length strings in {a,b}* whose first, middle and last symbols are all the same. S aaa bbb A aaa bab aab baa a B aba bbb abb bba b Construct grammar which generates all integers S DS D D 0 1 2 3 4 5 6 7 8 9 Construct grammar which generates all even integers up to 998 S 0 2 4 6 8 AS 1 AAS 1 A 1 2 3 4 5 6 7 8 9 S 1 0 2 4 6 8 L = { a i b j c k d l i+k=j+l } S asd ABC A aab B bbc C ccd L = { a i b j c k d l i+j=k+l } S asd B C B abc A C bcd A A bac A represent {b j c j j > 0} B represent {a i b j c k i+j = k & i,j,k > 0} a i b j c j c i C represent {b j c k d l k+l=j & i,j,k > 0} b l b k c k d l L = {a i b j c k : i j or i k or j k } Here given language is union of following three languages L = {a i b j c k : i j, k 0 } {a i b j c k : i k, j 0 } {a i b j c k : j k, i 0 } The first language {a i b j c k : i j, k 0 } is the concatenation of {a i b j : i j } with {c k : k 0 } S 1 S 11 S 12 S 11 X Y ( L = L(x) L(y)) X axb ax a ( L(x)= { a i b j ; i>j }) Y ayb Yb b ( L(y)= { a i b j ; i<j }) S 12 cs 12

The third language {a i b j c k : j k, k 0 } is the concatenation of {a i : i 0 } with {b j c k : j k } S 3 S 31 S 32 S 31 as 31 S 32 W Z ( L = L(w) L(z)) W bwc bw b ( L(w)= { b j c k ; j>k }) Z bzc Zc c ( L(z)= { b j c k j<k}) The second language {a i b j c k : i k, j 0 }, may be written as: L 1 L 2 L 2 L 3 where L 1 = {a n : n 1}, L 2 = {a n b m c n : n, m 0 }, and L 3 = {c n : n 1}. S 2 S 21 S 22 S 21 AB A aa a B abc B B bb S 22 BC C cc c The CFG of the language {a i b j c k : i j, k 0 } {a i b j c k : i k, j 0 } {a i b j c k : j k, i 0 } is S S 1 S 2 S 3 S 1 S 11 S 12 S 11 X Y ( L = L(x) L(y)) X axb ax a ( L(x)= { a i b j ; i>j }) Y ayb Yb b ( L(y)= { a i b j ; i<j }) S 12 cs 12 S 2 S 21 S 22 S 21 AB A aa a B abc B B bb S 22 BC C cc c S 3 S 31 S 32 S 31 as 31 S 32 W Z ( L = L(w) L(z)) W bwc bw b ( L(w)= { b j c k ; j>k }) Z bzc Zc c ( L(z)= { b j c k j<k})