Compiler Design MCQ Questions And Answers - Parsing
This section focuses on "Parsing" in Compiler Design. These Multiple Choice Questions (MCQ) should be practiced to improve the Compiler Design skills required for various interviews (campus interviews, walk-in interviews, company interviews), placements, entrance exams and other competitive examinations.
1. In how many types parsing is divided?
A. 2
B. 3
C. 4
D. 5
View Answer
Ans : A
Explanation: Syntax analyzers follow production rules defined by means of context-free grammar. The way the production rules are implemented (derivation) divides parsing into two types : top-down parsing and bottom-up parsing.
2. When the parser starts constructing the parse tree from the start symbol and then tries to transform the start symbol to the input, it is called?
A. bottom-up parsing
B. top-down parsing
C. Both A and B
D. None of the above
View Answer
Ans : B
Explanation: When the parser starts constructing the parse tree from the start symbol and then tries to transform the start symbol to the input, it is called top-down parsing.
3. In ___________________, if one derivation of a production fails, the syntax analyzer restarts the process using different rules of same production
A. Bottom-up Parsing
B. Recursive descent parsing
C. Backtracking
D. All of the above
View Answer
Ans : C
Explanation: Backtracking : It means, if one derivation of a production fails, the syntax analyzer restarts the process using different rules of same production. This technique may process the input string more than once to determine the right production.
4. A form of recursive-descent parsing that does not require any back-tracking is known as?
A. predictive parsing
B. non-predictive parsing
C. recursive parsing
D. non-recursive parsing
View Answer
Ans : A
Explanation: A form of recursive-descent parsing that does not require any back-tracking is known as predictive parsing.
5. Compute E.value for the root of the parse tree for the expression:2 # 3 & 5 # 6 &4.
A. 40
B. 80
C. 120
D. 160
View Answer
Ans : D
Explanation: Higher precedence operator will never produce an expression with operator with lower precedence.&># in terms of precedence order.
6. Assume that the SLR parser for a grammar G has n1 states and the LALR parser for G has n2 states.
A. n1 is necessarily less than n2
B. n1 is necessarily equal to n2
C. n1 is necessarily greater than n2
D. None of the above
View Answer
Ans : B
Explanation: SLR parser has less range of context free languages than LALR but still both n1 & n2 are same for SLR & LALR respectively.
7. the predictive parser puts some constraints on the grammar and accepts only a class of grammar known as LL(k) grammar.
A. TRUE
B. FALSE
C. Can be true or false
D. Can not say
View Answer
Ans : A
Explanation: To accomplish its tasks, the predictive parser uses a look-ahead pointer, which points to the next input symbols. To make the parser back-tracking free, the predictive parser puts some constraints on the grammar and accepts only a class of grammar known as LL(k) grammar.
8. Which of the following suffices to convert an arbitrary CFG to an LL(1) grammar?
A. Removing left recursion only
B. Factoring the grammar alone
C. Factoring & left recursion removal
D. None of the above
View Answer
Ans : D
Explanation: Factoring as well as left recursion removal do not suffice to convert an arbitrary CFG to LL(1) grammar.
9. Which of the following derivations does a top-down parser use while parsing an input string?
A. Leftmost derivation
B. Leftmost derivation in reverse
C. Rightmost derivation
D. Rightmost derivation in reverse
View Answer
Ans : A
Explanation: In top down parser takes input from Left to right constructing leftmost derivation of the sentence.
10. Relocation is the process of replacing symbolic references or names of libraries with actual usable addresses in memory before running a program.
A. TRUE
B. FALSE
C. Can be true or false
D. Can not say
View Answer
Ans : A
Explanation: Relocation is the process of replacing symbolic references or names of libraries with actual usable addresses in memory before running a program. Linker performs it during compilation.
Discussion