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*
View Answer

Answer: b
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
View Answer

Answer: c
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*
View Answer

Answer: b
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.
advertisement
advertisement

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

Answer: d
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
b) adabcca
c) abcca
d) abababd
View Answer

Answer: a
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}
View Answer

Answer: a
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.
advertisement

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
View Answer

Answer: d
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
View Answer

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

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]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.