Compiler Design

Compiler Design

25 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

Identify the odd one out.

  1. Global common subexpression
  2. Copy propagation
  3. Register allocation
  4. Code motion
Question 2 Multiple Choice (Single Answer)

Number of states for a grammar in SLR parser and LALR is

  1. double of the other
  2. somewhat dependent on each other
  3. independent
  4. dependent on grammar
Question 3 Multiple Choice (Single Answer)

Match the following.
(Choose the most appropriate option)
(A) S – Attributed Definition (i) Synthesized attribute
(B) L _ Attributed Definition (ii) Inherited attributed

  1. A – i, B – ii
  2. A – ii, B – i
  3. A – i, B – i, B – ii
  4. A – i, B – ii, A – ii
Question 4 Multiple Choice (Single Answer)

Consider the following grammar:A $\rightarrow$ BCC $\rightarrow$ +$A| \epsilon$B $\rightarrow$ id
In the predictive parser table, m, of grammar the entire M [A, id] and M [C, $] respectively, is

  1. {A $\rightarrow$ BC} and {C $\rightarrow$$\epsilon$}
  2. {A $\rightarrow$ BC} and { }
  3. {A $\rightarrow$ BC} and {C $\rightarrow$+A}
  4. {B $\rightarrow$ id} and {C $\rightarrow$ $\epsilon$}
Question 5 Multiple Choice (Single Answer)


Expression corresponding to this DAG is

  1. a + a * (b - c) + (b - c) *d
  2. a + a × (b - c) + (b - c) * (e/f)
  3. a*a + (b - c) + (b - c) * (e/f)
  4. a + a* (b - c) + (b + c) * (e/f)
Question 6 Multiple Choice (Single Answer)

The grammar
E $\rightarrow$E + E |E*E|(E)| id is

  1. left recursive
  2. ambiguous
  3. both (1) and (2)
  4. none of these
Question 7 Multiple Choice (Single Answer)

Which of the following statements is false about viable prefixes?

  1. SLR passing is based on the fact that LR(0) automata recognize viable prefixes.
  2. It is always possible to add terminal symbols to the end of a viable prefix to obtain a right- sentential form.
  3. Both (1) and (2)
  4. None of the above
Question 8 Multiple Choice (Single Answer)

Which of the following is generally not present in activation record?

  1. Access link
  2. List of all processes in system
  3. Saved machine status
  4. Control link
Question 9 Multiple Choice (Single Answer)

Match the following.

 
i. Token a. Character i, f, letter followed by latter and digits etc
ii. Pattern b. if, id, comparison
iii. Lexeme c. if, pi, < =
  1. i – b, ii – a, iii – c
  2. i – b, ii – c, iii – a
  3. i – c, ii – a, iii – b
  4. i – c, ii – b, iii - a
Question 10 Multiple Choice (Single Answer)

A$\rightarrow$BCC $\rightarrow$ + B {print ('+'); }C|$\epsilon$ B$\rightarrow$ D* B {print ('')i}|D D$\rightarrow$ (A)|id {print (id.value); }
For an input '5 + 6
7' this translation scheme prints

  1. 5 + 6 *7
  2. 5 + *6 7
  3. 5 6 + 7*
  4. 5 6 7 *+
Question 11 Multiple Choice (Single Answer)

Consider the following statements.
(i) Every SLR (1) grammar is unambiguous
(ii) There are many unambiguous grammars that are not SLR (1)

  1. i - True, ii - True
  2. i - True, ii - False
  3. i - False, ii - True
  4. i - False, ii - False
Question 12 Multiple Choice (Single Answer)

Eliminate left recursion
S $\rightarrow$ Aa|b
A $\rightarrow$Ac|Sd|f

  1. $S \rightarrow Aa | b \\\\ A \rightarrow bdA'| fA' \\\\A | \rightarrow cA'| adA'| \epsilon$
  2. $S \rightarrow Aa | b \\\\ A \rightarrow cdA'| dA' \\\\ A' \rightarrow bA'| adA' |\epsilon $
  3. $S\rightarrow Aa|b \\\\ A\rightarrow bdA'|fA'$
  4. $S \rightarrow Aa| b$ $A \rightarrow bdA'|fA'$ $A'\rightarrow cA'|adA'$
Question 13 Multiple Choice (Single Answer)

Computer value of 5 # 9 and 3 is

  1. 6
  2. 7
  3. 8
  4. 9
Question 14 Multiple Choice (Single Answer)

Find the false statement.

  1. No left recursive or ambiguous grammar can be LL(1)
  2. The class of grammars that can be parsed using LR methods is a proper subset of the class of grammars that can be the passed by LL method
  3. LR parsing is non - back tracking method
  4. LR methods can describe more languages than LL - grammars
Question 15 Multiple Choice (Single Answer)

Follow (E) is

  1. { )}
  2. {$}
  3. both (1) and (2)
  4. none of the above
Question 16 Multiple Choice (Single Answer)

The grammar

  1. is ambiguous
  2. is unambiguous
  3. cannot be decided
  4. generates two parse trees for one input string
Question 17 Multiple Choice (Single Answer)

The grammar
$S \rightarrow SA|A$
$A \rightarrow a$

  1. SLR (1) but not LL (1)
  2. SLR (1) and LL (1)
  3. Not SLR (1), not LL (1)
  4. Not SLR (1), but LL (1)
Question 18 Multiple Choice (Single Answer)

The value printed by the following is
$ (( A + B ) * C + ( D * E) + ( F *G)) $

  1. $ ++\*+ABC\*DE\*FG $
  2. $ +\*++ABC\*DE\*FG $
  3. $AB+C\*DE\*+FG\*+$
  4. $ABC+\*DE\*+FD\*+$
Question 19 Multiple Choice (Single Answer)

While (i < = limit - 2) statement becomes
$
\begin{cases}
t=\text{limit - 2} \\
\text{While } (i \Leftarrow t)
\end{cases}
$
This optimization is caused by

  1. copy propagation
  2. code motion
  3. dead code elimination
  4. insufficient information
Question 20 Multiple Choice (Single Answer)

Consider the grammar.
T$\rightarrow$T*F|F
F $\rightarrow$ id
For a sentence id1 *id2, the handlers in the right sequential form of the reduction are

  1. id1, F, id2, T *F
  2. id1, id2, T *F
  3. id1, F, T *F
  4. id1, F, id2
Question 21 Multiple Choice (Single Answer)

Consider the grammar with transition rule and E is the start symbol.

E $\rightarrow$ E1 $\ne$ T {E1.value = E1.value + T.value}
|T {E.value = T.value}
T $\rightarrow$ T1 & F {T.value = T1.value / F.value}
|F {T.value = F.value}
F $\rightarrow$ num {F.value = num.value}
Concept E. The value for the root of the parse tree for expression 6 # 4 and 2 # 16 and 4 is

  1. 16
  2. 12
  3. 8
  4. 6
Question 22 Multiple Choice (Single Answer)

Consider the grammar.

First ( E' ) and first ( E ) are respectively

  1. {+, $\epsilon$}, { , id }
  2. {+ , $\epsilon$}, { *, $\epsilon$}
  3. {*, $\epsilon$}, {C, id}
  4. none of these
Question 23 Multiple Choice (Single Answer)

Choose the most appropriate option.
(i) Indirect triples is advantageous than triples.
(ii) With indirect triple, an optimizing compiler can move an instruction by reordering the instruction list, without affecting the triples themselves.

  1. i is true but ii is false.
  2. i and ii are true and ii is the cause of i.
  3. i and ii are true but ii is not the cause of i.
  4. Both of them are false.
Question 24 Multiple Choice (Single Answer)

Left factor the grammar.
$A \rightarrow ad|a|ab|abc|b$

  1. $A \rightarrow aA'|b\\\\A' \rightarrow d| \epsilon |b|bc$
  2. $A \rightarrow aA'| b\\\\A'\rightarrow d |\epsilon| bA\\\\A'\rightarrow \epsilon| c$
  3. $A \rightarrow aA'| b\\\\A'\rightarrow d | bA'\\\\A\rightarrow c $
  4. $A \rightarrow aA' | b\\\\A' \rightarrow d | b | bc$
Question 25 Multiple Choice (Single Answer)

Following are the production and the action.

  1. $L\rightarrow E \eta$
  2. $E \rightarrow \{ print('+'); \}E_1 + T$
  3. $E \rightarrow R$
  4. $E \rightarrow \{ print('+'); \}T_1 + F$
  5. $T\rightarrow F$
  6. $F\rightarrow (E)$
  7. $F\rightarrow \text{digit \{print (digit lexval)\} }$
    This is syntax directed translation for
  1. prefix to infix
  2. infix to prefix
  3. postfix to infix
  4. infix to postfix