3
Compiler Design Spring 2010 (CSE344) Practice Questions on Regular Expressions Instructor: Asma Sanam Larik 1. Write a regular expression for each of the following sets of binary strings. Use only the basic operations. a. b. all binary strings except empty string _______________________ c. begins with 1 and ends with a 1 ____________________________ d. ends with 00 ___________________________________________ e. contains at least three 1s _________________________________ 2. Write a regular expression to describe inputs over the alphabet {a, b, c} a. that are in sorted order _________________________________ b. containing at least one a and at least one b__________________ 3. Write a regular expression for each of the following sets of binary strings. Use only the basic operations. a. b. contains the substring 110 _____________________________ c. doesn't contain the substring 110 ________________________

Exercise on Regular Expressions

Embed Size (px)

DESCRIPTION

REGEX

Citation preview

Page 1: Exercise on Regular Expressions

Compiler Design Spring 2010 (CSE344)Practice Questions on Regular Expressions

Instructor: Asma Sanam Larik1. Write a regular expression for each of the following sets of binary strings.

Use only the basic operations.

a.

b. all binary strings except empty string _______________________

c. begins with 1 and ends with a 1 ____________________________

d. ends with 00 ___________________________________________

e. contains at least three 1s _________________________________

2. Write a regular expression to describe inputs over the alphabet {a, b, c}

a. that are in sorted order _________________________________

b. containing at least one a and at least one b__________________

3. Write a regular expression for each of the following sets of binary strings.

Use only the basic operations.

a.

b. contains the substring 110 _____________________________

c. doesn't contain the substring 110 ________________________

d. whose tenth symbol from the right is 1_____________________

e. not containing 101 as a substring

2. Write a regular expression for each of the following sets of binary strings.

Use only the basic operations.

a.

b. number of 0s is a multiple of 3 _____________________________

c. has at least 3 characters, and the third character is 0 ___________

d. starts and ends with the same character _____________________

e. length is at least 1 and at most 3 ___________________________

2. Write a Regular Expression for the following language

a. L= { an bm | n>=4, m<=3}

Page 2: Exercise on Regular Expressions

Compiler Design Spring 2010 (CSE344)Practice Questions on Regular Expressions

b. L= { an bm | (n +m) is even }c. L={w Є {0,1}* | w has at least one pair of consecutive zeros}d. L={w Є {0,1}* | w has no pair of consecutive zeros}

3. What is the language denoted by the following RE

a. R= (a+b)*(a+bb) __________________________________________________

b. R= (aa)* (bb)*b __________________________________________________

Answers:1)

a. (0+1)(0+1)*b. 1(0+1)*1c. (0+1)*00d. (0+1)*1(0+1)*1(0+1)*1(0+1)*

2)a. a*b*c*b. (a+b+c)*a(a+b+c)*b(a+b+c)* +

(a+b+c)* b(a+b+c)*a(a+b+c)*

3)a. (0+1)*110(0+1)*b. (0+10)*1*c. (0+1)*1(0+1)9

d. (0*1*00)* 0*1*

4) a. (0+1)(0+1)0(0+1)* b. 1* + (1*01*01*01*)+

c. 1(0+1)*1 + 0(0+1)*0 +0 + 1

d. (0+1) + (0+1)(0+1) + (0+1)(0+1)(0+1)

5) a. a4 a*+ a4 a*b + a4 a*b2 + a4 a*b3 = a4 a*(Є+b+b2 + b3 ) b. (aa)* (bb)* + (aa)* a (bb)* b c. (0+1)* 00 (0+1)* d. (1* 011*)*0+ 1*0

6) a. set of strings terminated by a or bb b. even number of a’s followed by odd number of b’s