Professional Documents
Culture Documents
Nguyễn Đức Phi Hồng ITITIU 17022- Principles of Programming Languages- Excercise 2
Nguyễn Đức Phi Hồng ITITIU 17022- Principles of Programming Languages- Excercise 2
ID : ITITIU17022
Principles of Programming Languages Exercises 2
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.14159, -255.34, 128e5, 1.9e10, 123,340.00}
SKIP SET: {720, 4.e5}
Answer: d. -?([0-9,])+(\.[0-9]*)?(e[0-9]+)?
Write RE
1. Which regular expression describes all strings on {a,b} containing an odd number of a's?
a. b*ab*(ab*ab*)*
b. b*a*b*a*b*a*b*
c. a(aa)+
d. b*a(b*ab*a)* b*
Answer: c
2. Which regular expression describes all strings on {a,b} containing an even number (>0) of a's?
a. (b*ab*a)+b*
b. b*a*b*a*b*
c. b*(ab*ab*)+
d. b*(ab*a)+b*
Answer: a
3. Which regular expression(s) describes an integer literal in Pascal language? Remind that an integer
literal in Pascal language is a non-empty sequence of digits.
a. 0 | [1-9][0-9]*
b. [0-9]*
c. (+|-)?[0-9]+
d. [0-9]+
Answer: c
4. Select the regular expressions that describe the following comparison operators in C language: >=,
>, <= ?
b. ((< | >)*=)*
c. (< | >)=?
d. ()(=)*
Answer: a
5. Which regular expression describes all non-empty strings on {a,b} NOT including two consecutive
a's ?
a. (abb*)+
b. (a | b)*
c. b*(ab | b)*(a | b)
d. b*(abb*)
Answer: a
6. Which RE describes all non-empty strings on {a,b} including only one appearance of aa ? a.
[ab]*aa[ab]*
b. [ab]+
c. [aab]+
d. (aa | b)+
Answer: d
1.
a) a*b{2,}
b) (ab|ba|aa|bb)*
c) (aaa)*b