# Compilers Questions and Answers – Regular Expression – 2

This set of Compilers Multiple Choice Questions & Answers (MCQs) focuses on “Regular Expression – 2”.

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*

Explanation: 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

Explanation: 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*

Explanation: 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

Explanation: abababab doesn’t end with bbab whereas the other 3 options satisfy the given regular expression.

5. String generated by following expression is?

S->aS/bA, A->d/ccA
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

a) aabccd
c) abcca
d) abababd

Explanation: 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}

Explanation: 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

Explanation: 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

Explanation: Here the non terminal that gives null will said to have a null production.

Sanfoundry Global Education & Learning Series – Compilers.

To practice all areas of Compilers, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]