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.

1.

Consider a program P that consists of two source modules M1 and M2 contained in two different files. If M1 contains a reference to a function defined in M2, the reference will be resolved at

A. edit time
B. compile time
C. link time
D. load time
Answer» D. load time
2.

Consider the basic block given below. a = b + c c = a + d d = b + c e = d - b a = e + b The minimum number of nodes and edges present in the DAG representation of the above basic block respectively are

A. 6 and 6
B. 8 and 10
C. 9 and 12
D. 4 and 4
Answer» B. 8 and 10
3.

Given the following expression grammar E E * F | F + E | F E F | id Which of the following is true?

A. * has higher precedence than +
B. has higher precedence than *
C. + and have same precedence
D. + has higher precedence than *
Answer» C. + and have same precedence
4.

Consider the following translation scheme: S FR R *E{print ( * ); R | E F + E {print ( + ); |F F (S)| id {print (id. value);} Here, id is a token that represents an integer and id value represents, the corresponding integer value. For an input 2 * 3 + 4 , this translation scheme prints.

A. 2 * 3 + 4
B. 2 * + 3 4
C. 2 3 * 4 +
D. 2 3 4 + *
Answer» E.
5.

Consider the syntax directed translation scheme (SDTS) given in the following. Assume attribute evaluation with bottom-up parsing, i.e., attributes are evaluated immediately after a reduction. E E1 * T {E.val = E1 .val * T. val} E T {E.val = T. val} T F T1 {T.val = F.val T1. val} T F {T.val = F. val} F 2 {F.val = 2} F 4 {F.val = 4} (a) Using this SDTS, construct a parse tree for the expression 4 2 4 * 2 and also compute its E.val. (b) It is required to compute the total number of reductions performed to parse a given input. Using synthesized attributes only, modify the SDTS given, without changing the grammar, to find E.red, the number of reductions performed while reducing an input to E.

A. E.val = 12 ; E.red = T.red + 1
B. E.val = 2 ; E.red = T.red + 1
C. E.val = 10 ; E.red = T.red - 1
D. All of these
Answer» B. E.val = 2 ; E.red = T.red + 1
6.

Consider the translation scheme shown below: S RT R + T {print ( + :) R/ T num {print (num. val);} Here, num is a taken that represents an integer and num. val represents the corresponding integer value. For an input string 9 + 5 + 2 , this translation scheme will print

A. 9 + 5 + 2
B. 95 + 2 +
C. 952 + +
D. + + 952
Answer» C. 952 + +
7.

Which of the following statements are CORRECT? (1) Static allocation of all data areas by a compiler makes it impossible to implement recursion. (2) Automatic garbage collection is essential to implement recursion. (3) Dynamic allocation of activation records is essential to implement recursion. (4) Both heap and stack are essential to implement recursion.

A. 1 and 2 only
B. 2 and 3 only
C. 3 and 4 only
D. 1 and 3 only
Answer» E.
8.

Consider the grammar shonws below :S CC C cc/ d This grammar is

A. LL (1)
B. SLR (1) but not LL (1)
C. LALR (1) but not SLR (1)
D. LR (1) but not LALR (1)
Answer» B. SLR (1) but not LL (1)
9.

Consider the following C code segment : for (i = 0, i < n; i ++) { for (j = 0, j < n; j ++) { if (i % 2){ x + = (4 * j + 5 * i); Y + = (7 + 4 * j);}}} Which one of the following is false?

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.
10.

In a simplified computer, the instructions are OP Rj, Ri Performs Rj OP Ri and stores the result in register Ri . OP m, Rj Performs val OP Ri and stores the result in Rj. val denotes the content of memory location m. MOV m, Ri Moves the content of memory location m to register Ri. MOV, Ri, m Moves the content of the register Ri to memory location m. The computer has only two registers, and OP is either ADD or SUB. Consider the following basic block: t1 = a + b t2 = c + d t3 = e t2 t4 = t1 t3Assume that all operands are initially in memory. The final value of the computation should be in memory. What is the minimum number of MOV instructions in the code generated for this basic block?

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

For a C program accessing X[i][j][k], the following intermediate code is generated by a compiler. Assume that the size of an integer is 32 bits and the size of a character is 8 bits. t0 = i * 1024 t1 = j * 32 t2 = k * 4 t3 = t1 + t0 t4 = t3 + t2 t5 = X[t4]Which one of the following statements about the source code for the C program is

A. X is declared as int X[32][32][8] .
B. X is declared as int X[4][1024][32] .
C. X is declared as char X[4][32][8] .
D. X is declared as char X[32][16][2] .
Answer» B. X is declared as int X[4][1024][32] .
12.

Consider the grammar shown below: S i E t S S / a S e S I E b In the predictive parser table, M of this grammar, the entire M[S , e] and M [S ,$] respectively are

A. {S e S} and {S }
B. {S e S} and {}
C. {S } and {S }
D. {S e S, S } and {S }
Answer» E.
13.

Consider the grammar E E + n | E n | n For a sentence n + n n, the handles in the right-sentential form of the reduction are

A. n, E + n and E + n n
B. n, E + n and E + E n
C. n, n + n and n + n n
D. n, E + n and E n
Answer» E.
14.

Which of the following grammar rules violate the requirement of an operator grammar? P, Q, R are non terminals, and r, s, t are terminals. 1. P Q R 2. P Q S R 3. P 4. P Q t R r

A. 1 only
B. 1 and 3
C. 2 and 3
D. 3 and 4
Answer» C. 2 and 3
15.

Consider the grammar with the following translation rules and E as the start symbol: E E #T {E. value = E1 value * T. value} | T {E. value = T. value} T T1 & F {T. value = T1 value F. value} | F {T. value =F. value} F num {F. value = num. value} Compute E value for the root ofthe parser tree for the expression 2 # 3 & 5 # 6 & 4.

A. 200
B. 180
C. 160
D. 40
Answer» E.
16.

Consider the grammar defined by the following production rules, with two operators * and + S T * P T U | T * U P Q + P | Q Q Id U Id Which one of the following is TRUE?

A. + is left associative, while * is right associative
B. + is right associative, while * is left associative
C. Both + and * are right associative
D. Both + and * are left associative
Answer» C. Both + and * are right associative
17.

Consider the following grammar. S S * E S E E F + E E F F id Consider the following LR (0) items corresponding to the grammar above. 1. S S * E 2. E F. + E 3. E F + .E Given the items above, which two of them will appear in the same set in the canonical sets-of-items for the grammar?

A. 1 and 2
B. 2 and 3
C. 1 and 3
D. None of these
Answer» E.
18.

Consider the following grammar G S F | H F p | c H d | c Where S, F, and H are non terminal symbols, p, d, and c are terminal symbols. Which of the following statements (s) is/ are correct? S1 : LL(1) can parse all strings that are generated using grammar G S2 : LR(1) can parse all strings that are generated using grammar G

A. Only S1
B. Only S2
C. Both S1 and S2
D. Neither S1 nor S2
Answer» E.
19.

Consider the following Syntax Directed Translation Scheme (SDTS), with non-terminals {S, A} and terminals{a, b}. S aA {print 1} S a {print 2} A Sb {print 3} Using the above SDTS, the output printed by a bottom up parser, for the input aab is :

A. 1 3 2
B. 2 2 3
C. 2 3 1
D. syntax error
Answer» D. syntax error
20.

Which of the following statements about parser is/are CORRECT? I. Canonical LR is more powerful than SLR. II. SLR is more powerful than LALR. III. SLR is more powerful than Canonical LR.

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

Consider the following two statements : P : Every regular grammar is LL (1). Q : Every regular set has a LR (1) grammar. Which of the following is true?

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
22.

Consider the grammar with non-terminals N = {S, C, S1}, terminals T = {a, b, i, t, e} with S as the start symbol and the following set of rules S iCtSS1 | a S1 eS | C b The grammar is not LL(1) because

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
23.

Which of the following statements are true? 1. There exist parsing algorithms for some programming languages whose complexities ar less than (n3). 2. A programming language which allows recursive can be implemented with static storage allocation. 3. No L-attributed definition can be evaluated in the framework of bottom-up parsing. 4. Code improving transformations can be performed at both source language and intermediate code level.

A. 1 and 2
B. 1 and 4
C. 3 and 4
D. 1, 3 and 4
Answer» C. 3 and 4
24.

Match the following : List I List II P. Lexical analysis 1. Graph coloring Q. Parsing 2. DFA minimization R. Register allocation 3. Post-order traversal S. Expression evaluation 4. Production tree

A. P-2, Q-3, R-1, S-4
B. P-2, Q-1, R-4, S-3
C. P-2, Q-4, R-1, S-3
D. P-2, Q-3, R-4, S-1
Answer» D. P-2, Q-3, R-4, S-1
25.

Match the following : (P) Lexical analysis (i) Leftmost derivation (Q) Top down parsing (ii) Type checking (R) Semantic analysis (iii) Regular expressions (S) Runtime environments (iv) Activation records

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

Consider the following two sets of LR(1) items of an LR(1) grammar. X c.X, c/d X c.X, $ X .cX, c/d X .cX, $ X .d, c/d X .d, $ Which of the following statements related to merging of the two sets in the corresponding LALR parser is/are false? 1. Cannot be merged since look aheads are different. 2. Can be merged but will result in S-R conflict. 3. Can be merged but will result in R-R conflict. 4. Cannot be merged since goto on c will lead to two different sets.

A. 1 only
B. 2 only
C. 1 and 4 only
D. All of these
Answer» E.
27.

Match the following according to input (from the left column) to the compiler phase (in the right column) that processes it : (P) Syntax tree (i) Code generator (Q) Character stream (ii) Syntax analyzer (R) Intermediate (iii) Semantic analyzer representation (S) Token stream (iv) Lexical analyzer

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)
28.

Consider the following grammar: S FR R *S| F id In the predictive parser table, M, of the grammar the entries M [S, id] and M[R, $] respectively.

A. {S FR} and {R ]
B. {S FR} and { }
C. {S FR} and {R *S}
D. {F id} and {R }
Answer» B. {S FR} and { }
29.

In the correct grammar above, what is the length of the derivation (number of steps starting from S) to generate the string albm with l m?

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

For a C program accessing X[i][j][k], the following intermediate code is generated by a compiler. Assume that the size of an integer is 32 bits and the size of a character is 8 bits.

A. X is declared as int X[32][32][8] .
B. X is declared as int X[4][1024][32] .
C. X is declared as char X[4][32][8] .
D. X is declared as char X[32][16][2] .
Answer» B. X is declared as int X[4][1024][32] .
31.

The least number of temporary variables required to create three-address code in static single assignment form for the expression q + r /3 + s t*5 + u*v /w is ______.

A. 0
B. 3
C. 1
D. 2
Answer» C. 1
32.

Consider the translation scheme shown below:

A. 9 + 5 + 2
B. 95 + 2 +
C. 952 + +
D. + + 952
Answer» C. 952 + +
33.

Consider the following translation scheme:

A. 2 * 3 + 4
B. 2 * + 3 4
C. 2 3 * 4 +
D. 2 3 4 + *
Answer» E.
34.

Consider a program P that consists of two source modules M

A. edit time
B. compile time
C. link time
D. load time
Answer» D. load time
35.

Consider the basic block given below.

A. 6 and 6
B. 8 and 10
C. 9 and 12
D. 4 and 4
Answer» B. 8 and 10
36.

Consider the syntax directed translation scheme (SDTS) given in the following. Assume attribute evaluation with bottom-up parsing, i.e., attributes are evaluated immediately after a reduction.

A. E.val = 12 ; E.red = T.red + 1
B. E.val = 2 ; E.red = T.red + 1
C. E.val = 10 ; E.red = T.red - 1
D. All of these
Answer» B. E.val = 2 ; E.red = T.red + 1
37.

In a compiler, keyboards of a language are recognized during

A. parsing of the program
B. the code generation
C. the lexical analysis of the program
D. data flow analysis
Answer» D. data flow analysis
38.

Which of the following derivations does a top-down parser use while parsing an input string? The input is assumed to be scanned in left to right order.

A. Leftmost derivation
B. Leftmost derivation traced out in reverse
C. Rightmost derivation
D. Rightmost derivation traced out in reverse
Answer» B. Leftmost derivation traced out in reverse
39.

Given the following expression grammar

A. * has higher precedence than +
B. has higher precedence than *
C. + and have same precedence
D. + has higher precedence than *
Answer» C. + and have same precedence
40.

Consider the grammar shonws below :

A. LL (1)
B. SLR (1) but not LL (1)
C. LALR (1) but not SLR (1)
D. LR (1) but not LALR (1)
Answer» B. SLR (1) but not LL (1)
41.

Consider the grammar shown below:

A. {S e S} and {S }
B. {S e S} and {}
C. {S } and {S }
D. {S e S, S } and {S }
Answer» E.
42.

Consider the grammar defined by the following production rules, with two operators * and +

A. + is left associative, while * is right associative
B. + is right associative, while * is left associative
C. Both + and * are right associative
D. Both + and * are left associative
Answer» C. Both + and * are right associative
43.

Consider the following grammar G

A. Only S1
B. Only S2
C. Both S1 and S2
D. Neither S1 nor S2
Answer» E.
44.

Among simple LR (SLR), canonical LR, and look ahead LR (LALR), which of the following pairs identify the method that is very easy to implement and the method that is the most powerful, in that order

A. SLR, LALR
B. Canonical LR, LALR
C. LSR, canonical LR
D. LALR, canonical LR
Answer» D. LALR, canonical LR
45.

Consider the following Syntax Directed Translation Scheme (SDTS), with non-terminals {S, A} and terminals{a, b}.

A. 1 3 2
B. 2 2 3
C. 2 3 1
D. syntax error
Answer» D. syntax error
46.

Which of the following suffices to convert an arbitrary CFG to an LL (1) grammar?

A. Removing left recursion alone
B. Factoring the grammar alone
C. Removing left recursion and factoring the grammar
D. None of the above
Answer» E.
47.

Which of the following grammar rules violate the requirement of an operator grammar? P, Q, R are non terminals, and r, s, t are terminals.

A. 1 only
B. 1 and 3
C. 2 and 3
D. 3 and 4
Answer» C. 2 and 3
48.

Consider the grammar with the following translation rules and E as the start symbol:

A. 200
B. 180
C. 160
D. 40
Answer» E.
49.

The grammar A AA | (A) | is not suitable for predictive parsing because the grammar is

A. ambiguous
B. left-recursive
C. right-recursive
D. an operator grammar
Answer» C. right-recursive
50.

Consider the grammar

A. n, E + n and E + n n
B. n, E + n and E + E n
C. n, n + n and n + n n
D. n, E + n and E n
Answer» E.