Explore topic-wise MCQs in Compiler Design.

This section includes 65 Mcqs, each offering curated multiple-choice questions to sharpen your Compiler Design knowledge and support exam preparation. Choose a topic below to get started.

51.

Assume the conflicts in Part (a) of this question are resolved and an LALR(1) parser is generated for parsing arithmetic expressions as per the given associativity properties does the generated parser realize?

A. Equal precedence and left associativity; expression is evaluated to 7
B. Equal precedence and left associativity; expression is evaluated to 9
C. Precedence of x is higher than that of + and both operators are left associative; expression is evaluated to 7
D. Precedence of + is higher than that of and both operators are left associative; expression is evaluated to 9
Answer» C. Precedence of x is higher than that of + and both operators are left associative; expression is evaluated to 7
52.

The above grammar and the semantic rules are fed to a yacc tool (which is an LALR (1) parser generator) for parsing and evaluating arithmetic expressions. Which one of the following is true about the action of yacc for the given grammar?

A. It detects recursion and eliminates recursion
B. It detects reduce-reduce conflict and resolves
C. It detects shift-reduce conflict and resolves the conflict in favour of a shift over a reduce action
D. It detects shift reduce conflict, and resolves the conflict in favour of a reduce over a shift action
Answer» D. It detects shift reduce conflict, and resolves the conflict in favour of a reduce over a shift action
53.

In the correct grammar above, what is the length of the derivation (number of steps starting from S) to generate the string a

A. max (l, m) + 2
B. l + m + 2
C. l + m + 3
D. max (l, m) + 3
Answer» B. l + m + 2
54.

Consider the following two statements :

A. Both P and Q are true
B. P is true and Q is false
C. P is false and Q is true
D. Both P and Q are false
Answer» D. Both P and Q are false
55.

Consider the grammar with non-terminals N = {S, C, S

A. it is left recursive
B. it is right recursive
C. it is ambiguous
D. it is not context-free
Answer» D. it is not context-free
56.

For the correct answer strings to Q. above, how many derivation trees are there?

A. 1
B. 2
C. 3
D. 4
Answer» C. 3
57.

Which of the following strings is generated by the grammar?

A. aaaabb
B. aabbbb
C. aabbab
D. abbbba
Answer» D. abbbba
58.

An LALR(1) parser for a grammar G can have shift-reduce (S-R) conflicts, if and only, if

A. the SLR (1) parser for G has S-R conflicts
B. the LR (1) parser for G has S-R conflicts
C. the LR (0) parser for G has S-R conflicts
D. the LALR (1) parser for G has reduce-reduce conflicts
Answer» C. the LR (0) parser for G has S-R conflicts
59.

Consider two binary operators and with the precedence of operator being lower than that of operator . Operator is right associative while operator is left associative. Which one of the following represents the parse tree for expression (7 3 4 3 2)?

A. <img src="http://images.interviewmania.com/wp-content/uploads/2019/11/as-47.jpg">
B. <img src="http://images.interviewmania.com/wp-content/uploads/2019/11/as-48.jpg">
C. <img src="http://images.interviewmania.com/wp-content/uploads/2019/11/as-49.jpg">
D. None of these
Answer» C. <img src="http://images.interviewmania.com/wp-content/uploads/2019/11/as-49.jpg">
60.

Match the following according to input (from the left column) to the compiler phase (in the right column) that processes it :

A. P (ii), Q (iii), R (iv), S (i)
B. P (ii), Q (i), R (iii), S (iv)
C. P (iii), Q (iv), R (i), S (ii)
D. P (i), Q (iv), R (ii), S (iii)
Answer» D. P (i), Q (iv), R (ii), S (iii)
61.

Which of the following statements about parser is/are CORRECT?

A. I only
B. II only
C. III only
D. II and III only
Answer» B. II only
62.

What is the maximum number of reduce moves that can be taken by a bottom-up parser for a grammer with no epsilon-and unit-production (i.e. of type A and A a) to parse a string with n tokens?

A. n / 2
B. n 1
C. 2n 1
D. 2
E. <sup>n</sup>
Answer» C. 2n 1
63.

In a simplified computer, the instructions are

A. 2
B. 3
C. 5
D. 6
Answer» C. 5
64.

Consider the following C code segment :

A. The code contains loop invariant computation.
B. There is scope of common sub-expression elimination in this code
C. There is scope of strength reduction in this code
D. There is scope of dead code elimination in this code
Answer» E.
65.

The grammar S aSa | bS| c is

A. LL (1) but not LR (1)
B. LR (1) but not LL (1)
C. Both LL (1) and LR (1)
D. Neither LL (1) and LR (1)
Answer» D. Neither LL (1) and LR (1)