Compilers Questions and Answers – Context Free Grammar – 1

This set of Compilers Multiple Choice Questions & Answers (MCQs) focuses on “Context free Grammar – 1”.

1. Assume the statements S1 and S2 given as:
S1: Given a context free grammar, there exists an algorithm for determining whether L (G) is infinite.
S2: There exists an algorithm to determine whether two context free grammars generate the same language.
Which of the following is true?
a) S1 is correct and S2 is not correct
b) Both S1 and S2 are correct
c) Both S1 and S2 are not correct
d) S1 is not correct and S2 is correct
View Answer

Answer: a
Explanation: The proof of S1 can be seen in various book of theory of computation but s2 is a problem of category undecidable so a contradiction to this assumption can be easily obtained.

2. If P & R are regular and also given that if PQ=R, then?
a) Q has to be regular
b) Q cannot be regular
c) Q need not be regular
d) Q has to be a CFL
View Answer

Answer: c
Explanation: If two regular languages when combined do not always produce a regular language.

3. Which of the following conversion is not possible (algorithmically)?
a) Regular grammar to CFG
b) NDFA to DFA
d) NDTM to DTM
View Answer

Answer: c
Explanation: Not every NDPDA has an equivalent deterministic PDA.

4. Consider the grammar given below E? E+E | E*E | E-E | E/E | E^E | (E) | id Assume that + and ^ have the same but least precedence, * and / have the next higher precedence but the same precedence and finally ^ has the highest precedence. Assume + and ^ associate to the left like * and / and that ^ associates to the right. Choose the correct for the ordered pairs (^,^), (-,-), (+,+), (*,*) in the operator precedence table constructed for the grammar.
a) All <
b) All >
c) < >, =
d) < > > >
View Answer

Answer: d
Explanation: This relation is established of basis of the precedence of operators.

5. Recursively enumerable languages are not closed under ______________
a) Union
b) Intersection
c) Complementation
d) Concatenation
View Answer

Answer: c
Explanation: Recursive languages are closed under the following operations.
The Kleene star L * of L
the concatenation L * o P of L and P
the union L U P
the intersection L ∩ P.
Note: Join free Sanfoundry classes at Telegram or Youtube

6. Grammar that produce more than one Parse tree for same sentence is ___________
a) Ambiguous
b) Unambiguous
c) Complementation
d) Concatenation Intersection
View Answer

Answer: a
Explanation: An ambiguous grammar is one for which there is more than one parse tree for a single sentence.

7. Automaton accepting the regular expression of any number of a’ s is ___________
a) a*
b) ab*
c) (a/b)*
d) a*b*c
View Answer

Answer: a
Explanation: It gives any number of a’s.

8. Grammars that can be translated to DFAs is ___________
a) Left linear grammar
b) Right linear grammar
c) Generic grammar
d) All of the mentioned
View Answer

Answer: b
Explanation: Right linear grammar can be translated to the DFAs.

9. Which of the following language accepted by a Push down Automata?
a) Type0
b) Type1
c) Type2
d) Type3
View Answer

Answer: c
Explanation: A known fact that type 2 grammar is accepted by PDA.

10. Given the following statements: (i) Recursive enumerable sets are closed under complementation. (ii) Recursive sets are closed under complements. Which is/are the correct statements?
a) I only
b) II only
c) Both I and II
d) Neither I nor II
View Answer

Answer: b
Explanation: Recursive languages are closed under the following operations.
The Kleene star L * of L
The concatenation L * o P of L and P
The union L U P
The intersection L ∩ P.

Sanfoundry Global Education & Learning Series – Compilers.

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

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.