250+ TOP MCQs on Context Free Grammar and Answers

Compilers Multiple Choice Questions & Answers (MCQs) on “Context free Grammar”.

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

Answer: a
Clarification: 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

Answer: c
Clarification: 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
c) NDPDA to DPDA
d) NDTM to DTM

Answer: c
Clarification: 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) < > > >

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

Answer: c
Clarification: 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.

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

Answer: a
Clarification: 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

Answer: a
Clarification: 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

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

Answer: c
Clarification: 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

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

Leave a Reply

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