250+ TOP MCQs on Regular Expression and Answers

Compilers Multiple Choice Questions & Answers (MCQs) on “Regular Expression”.

1. The RE in which any number of 0′s is followed by any number of 1′s followed by any number of 2′s is?
a) (0+1+2)*
b) 0*1*2*
c) 0* + 1 + 2
d) (0+1)*2*

Answer: b
Clarification: The order for the desired string is 012 and for any number of 0s we write 0* for any number of 1s we denote it by 1* and similarly for 2*.Thus 0*1*2*.

2. The regular expression have all strings of 0′s and 1′s with no two consecutive 0′s is?
a) (0+1)
b) (0+1)*
c) (0+∈) (1+10)*
d) (0+1)* 011

Answer: c
Clarification: From the former bracket we choose 0 or epsilon. Then from the latter part 1 or 10 which can be followed by 1 or 10.

3. The regular expression with all strings of 0′s and 1′s with at least two consecutive 0′s is?
a) 1 + (10)*
b) (0+1)*00(0+1)*
c) (0+1)*011
d) 0*1*2*

Answer: b
Clarification: The expression (0+1)*00(0+1)* is where either it initially takes 0 or 1 or 00 followed by string of combination of 0 and 1.

4. Which of the following is NOT the set of regular expression R = (ab + abb)* bbab?
a) ababbbbab
b) abbbab
c) ababbabbbab
d) abababab

Answer: a
Clarification: ab followed by abb which is followed by bbab.

5. String generated by following expression is?

S->aS/bA, A->d/ccA

a) aabccd
b) adabcca
c) abcca
d) abababd

Answer: a
Clarification: S->aS (substitute S->aS)
S->aaS (substitute S->bA)
S->aabA (substitute A->ccA)
S->aabccA (substitute A->d)
S->aabccd.

6. Consider the production of the grammar S->AA A->aa A->bb Describe the language specified by the production grammar.
a) L = {aaaa,aabb,bbaa,bbbb}
b) L = {abab,abaa,aaab,baaa}
c) L = {aaab,baba,bbaa,bbbb}
d) L = {aaaa,abab,bbaa,aaab}

Answer: a
Clarification: S->AA (substitute A->aa)
S->aaaa
S->AA (substitute A->aa )
S->aaA (substitute A->bb)
S->aabb
S->AA (substitute A->bb the A->aa)
S->bbaa
S->AA (substitute A->bb)
S->bbbb.

7. If R is regular language and Q is any language (regular/ non regular), then Pref (Q in R) is _____________
a) Non-regular
b) Equal
c) Infinite
d) Regular

Answer: d
Clarification: So says the definition of Regular Grammar.

8. The production of the form no terminal → Λ is said to be null production.
a) False
b) True

Answer: b
Clarification: Here the non terminal that gives null will said to have a null production.

Leave a Reply

Your email address will not be published. Required fields are marked *