Professional Documents
Culture Documents
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]
Read RE
Select the strings that can be expressed by the above regular expression?
Answer: d. aabb
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
5. Which string does NOT belong to the language described by RE: (a | b)*ca*
Answer: c.aaaacbbbb
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:
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]*