# Recent questions and answers in Compiler Design

1
Some code optimizations are carried out on the intermediate code because They enhance the portability of the compiler to the target processor Program analysis is more accurate on intermediate code than on machine code The information from dataflow analysis cannot otherwise be used for optimization The information from the front end cannot otherwise be used for optimization
2
A variable $x$ is said to be live at a statement $s_{i}$ in a program if the following three conditions hold simultaneously: There exists a statement $S_{j}$ that uses $x$ There is a path from $S_{i}$ to $S_{j}$ in the flow graph corresponding to the program The path has no intervening assignment ... of the above control flow graph are $\text{p, s, u}$ $\text{r, s, u}$ $\text{r, u}$ $\text{q, v}$
3
The minimum number of arithmetic operations required to evaluate the polynomial $P(X) = X^5+4X^3+6X+5$ for a given value of $X$, using only one temporary variable is ______.
4
The following code segment is executed on a processor which allows only register operands in its instructions. Each instruction can have atmost two source operands and one destination operand. Assume that all variables are dead after this code segment. c = a + b; d ... this code segment without any spill to memory? Do not apply any optimization other than optimizing register allocation. 3 4 5 6
5
The following program uses six different variables p, q, r, s, t and u. The code is: p=6 q=7 t=p*q s=t+p u=8 u=s*p s=p+u r=r*q t=t+p return t Assume that all operations take their operands from registers, the minimum number of registers needed to ... _____________? Given answer is 5, but my answer is 4. I think that the step u=8 can be skipped since 'u' is being reinitialized in the next step.
6
Definition of Static Single Assignment Static single-assignment form arranges for every value computed by a program to have a unique assignment (aka, “definition”) but p3 = a - b q4 = p3 * c p4 = u * v q5 = p4 + q4 is an valid example of SSA Now, tell me a,b,c,u,v are not assigned or previously recognized Then how this is a valid example of SSA? for ref see here
1 vote
7
Consider the following code segment: The minimum number of temporary variable required to convert the above code segment to static single assignment form is ________.
8
What is the maximum number of reduce moves that can be taken by a bottom-up parser for a grammar with no epsilon and unit-production (i.e., of type $A \rightarrow \epsilon$ and $A \rightarrow a$) to parse a string with $n$ tokens? $n/2$ $n-1$ $2n-1$ $2^{n}$
9
Make this grammer into unambiguous
1 vote
10
A canonical set of items is given below S→L.>R Q→R. On input symbol > the set has (a).a shift-reduce conflict and a reduce-reduce conflict. (b).a shift-reduce conflict but not a reduce-reduce conflict. (c).a reduce-reduce conflict but not a shift-reduce conflict. (d).neither a shift-reduce nor a reduce-reduce conflict.
11
An integer array $A[i, j]$ has index $i$ ranging from $1$ to $10$ and index $j$ ranging from $1$ to $20$. Integers take $4$ bytes each. Suppose array $A$ is stored starting at byte $0$. Find the location of: $A[4,5]$ $A[10,8]$ $A[3,17]$
12
The number of lexemes in the statement in FORTRAN DO 10 I = 100 is __________ .
1 vote
13
Which of the following is not an intermediate code form? Syntax trees Three address codes Quadrupules Post fix Notation
14
Which of the following are applications of symbol table? Storage allocation Checking type compatibility Suppressing duplicate error messages Choose the correct answer from the options given below: $(a)$ and $(b)$ only $(a)$ and $(c)$ only $(b)$ and $(c)$ only $(a)$ $(b)$ and $(c)$
15
Find the lexicographic ordering of the bit strings given below based on the ordering $0<1$. $001$ $010$ $011$ $0001$ $0101$ Choose the correct answer from the options given below: $001 < 010 < 011 < 0001 < 0101$ $0001 < 001 < 010 < 0101 < 011$ $0001 < 0101 < 001 < 010 < 011$ $001 < 010 < 0001 < 0101 < 011$
16
Which of the following can be accessed by transfer vector approach of linking? External data segments External subroutines Data located in other procedure All of these
17
18
The most powerful parser is $\text{SLR}$ $\text{LALR}$ Canonical $\text{LR}$ Operator-precedence
19
$\text{YACC}$ builds up $\text{SLR}$ parsing table Canonical $\text{LR}$ parsing table $\text{LALR}$ parsing table None of these
20
Context-free grammar can be recognized by finite state automation $2$- way linear bounded automata push down automata both (B) and (C)
21
Consider an $\varepsilon$-tree CFG. If for every pair of productions $A\rightarrow u$ and $A\rightarrow v$ If $\text{FIRST(u)} \cap \text{FIRST(v)}$ is empty then the CFG has to be $LL(1).$ If the CFG is $LL(1)$ then $\text{FIRST(u)} \cap \text{FIRST(v)}$ has to be empty. Both $(A)$ and $(B)$ None of the above
22
Synthesized attribute can easily be simulated by an LL grammar ambiguous grammar LR grammar none of the above
1 vote
23
In a single pass assembler, most of the forward references can be avoided by putting the restriction on the number of strings/lifereacts. that the data segment must be defined after the code segment. on unconditional rump. that the data segment be defined before the code segment.
24
A linker is given object module for a set of programs that were compiled separately. What information need not be included in an object module? Object mode Relocation bits Names and locations of all external symbols defined in the object module. Absolute addresses of internal symbols.
1 vote
25
The identification of common sub-expression and replacement of run time computations by compile-time computations is: Local optimization Constant folding Loop Optimization Data flow analysis
26
The structure or format of data is called Syntax Struct Semantic none of the above
27
The graph that shows basic blocks and their successor relationship is called: DAG Control graph Flow graph Hamiltonian graph
28
A top down parser generates Left most derivation Right most derivation Left most derivation in reverse Right most derivation in reverse
29
Syntax directed translation scheme is desirable because It is based on the syntax It is easy to modify Its description is independent of any implementation All of these
30
The output of lexical analyzer is: A set of regular expressions Strings of character Syntax tree Set of tokens
31
What is the maximum number of reduce moves that can be taken by a bottom-up parser for a grammar with no epsilon and unit production (i.e.,of type $A\to\epsilon$ and $A \to a)$ to parse a string with $n$ tokens? $n/2$ $n-1$ $2n-1$ $2^n$
32
In a compiler, keywords of a language are recognized during parsing of the program the code generation the lexical analysis of the program dataflow analysis
33
A system program that combines the separately complied modules of a program into a form suitable for execution assembler linking loader cross compiler load and go
1 vote
34
Which of the following is machine independent optimization? Loop optimization Redundancy Elimination Folding All of the option
35
The grammar $S\rightarrow aSb\mid bSa\mid SS\mid \varepsilon$ is: Unambiguous CFG Ambiguous CFG Not a CFG Deterministic CFG
1 vote
36
Which of the following statements is/are false? $S1$: $LR(0)$ grammar and $SLR(1)$ grammar are equivalent $S2$: $LR(1)$ grammar are subset of $LALR(1)$ grammars $S1$ only $S1$ and $S2$ both $S2$ only None of the options
37
The optimization phase in a compiler generally Reduces the space of the code Optimizes the code to reduce execution time Both (A) and (B) Neither (A) nor (B)
Which of the following statements is/are true in the context of interpreters? $S1$: Interpreters process program according to the logical flow of control through the program. $S2$: Interpreter translates and executes the error-free first instruction before it goes to the second. $S3$: Interpreter ... interpreted languages. Only $S1$ Only $S3$ Only $S1$, $S2$ and $S3$ Only $S1$, $S2$ and $S4$