You are on page 1of 2

Name: Nguyễn Đức Phi Hồng

ID : ITITIU17022
Principles of Programming Languages Exercises 1

Equivalent RE
1. Which regular expression is equivalent to the RE: a (a | b)* ?
a. a (a | b)(a | b)* b. (a | b)* c. aa|b* d.a(a*b*)*

Answer: d.a(a*b*)*
2. Which regular expression is equivalent to the RE: b*(ab | b)*(a | b)
a. b*(a?b)*[ab] b.b*[ab | b]*[a | b] c. b*[ab]*(a | b) d. b*[abb]*[ab]

Answer: None of the above

3. Which regular expression is equivalent to the RE: a?a+[bhmk]*[bhmk]*[xn]

a. a?a+[bhmk]+[xn] b. a+[bhmk]*[xn] c. a?a+[bhmk]*(xn) d. a+[bhmk]+[xn]

Answer: None of the above

Read RE

1. Given the following regular expression: (aa)+(ab)?(bb)+

Select the strings that can be expressed by the above regular expression?

a. aab b.  c. aaabb d. aabb

Answer: d. aabb

2. Given the following regular expression: (aa)*(ab)?(bb)*


Select the strings that can be expressed by the above regular expression?

a. abbb b. a c. aab d. 
Answer: d. 
3. Given the regular expression for a decimal integer literal in C language: 0|[1-9][0-9]*
Select the strings that can be expressed by the above regular expression?

a. 0 b. 102 c. -12 d. 00

Answer: a. 0

4. Which string belongs to the language described by RE: [^a-z][a-zA-Z0-9]*

a.Aa9# b.ma09 c. A d.kAM2


Answer: a. Aa9#

5. Which string does NOT belong to the language described by RE: (a | b)*ca*

a. abaac b.caaaa c.aaaacbbbb d.bbbcaaa

Answer: c.aaaacbbbb

6. Which string belongs to the language described by RE: (a | b)*ab*a


a.abbbbbab b.bbbbbba c.bbbbabbbbaa d.aaaaaaaaaab

Answer: c.bbbbabbbbaa

7. Which string does NOT belong to the language described by RE: [a-z]A[0-9]*
a. abA2 b.mA000 c.bA d.cA12

Answer: a. abA2

Select RE

1. Select the regular expression such that it can match the strings in MATCH set but NOT in
SKIP set:

MATCH SET: {3. , -255.34, 128e5, 1.9e10}

SKIP SET: {720, 4.e5}

a. -?[0-9,]+(\.[0-9]+(e[0-9]+)? | e[0-9]+)
b. [+-]?[0-9]([0-9][0-9]?)?(,[0-9][0-9][0-9])*( \.[0-9]*([eE][+-]?[0-9]+)? | [eE][+-]?[0-9]+)
c. [+-]?[0-9]([0-9][0-9]?)?(,[0-9][0-9][0-9])*(\.[0-9]+([eE][+-]?[0-9]+)?)?
d. -?([0-9,])+(\.[0-9]*)?(e[0-9]+)?
e. [+-]?[0-9]+(\.[0-9]+)?(e[0-9]+)?

Answer: d. -?([0-9,])+(\.[0-9]*)?(e[0-9]+)?

2. Select the regular expression such that it can match the strings in MATCH set but NOT in
SKIP set:
MATCH SET: {Chung, Cha, Chon, Chuoi, Chinh}
SKIP SET: {chung, Con, chi, Che}

a. Ch[aiuo][a-z]*
b. Ch[a-z]+
c. [a-zA-Z]+
d. C[a-z]+

Answer: a. Ch[aiuo][a-z]*

You might also like