QB For Students
QB For Students
QB For Students
2. Consider the following Syntax Directed Translation Scheme (SDTS), with non-terminals
{S, A} and terminals {a,b}.
S→aA{print1} S→a{print2} S→Sb{print3}
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: (C)
9. How many descriptors are used for track both the registers (for availability) and addresses
(location of values) while generating the code?
(A) 2
(B) 3
(C) 4
(D) 5
Answer: (A)
12. Code generator uses ______ function to determine the status of available registers and the
location of name values.
(A) setReg
(B) cinReg
(C) pfReg
(D) getReg
Answer:(D)
13. Which of the following is not a form of Intermediate representation?
(A) Abstract Syntax Tree
(B) 3-address code
(C) Directed cyclic Graph
(D) Reverse Polish Notation
Answer: (C)
15. Some code optimizations are carried out on the intermediate code because
_______________
(A) They enhance the portability of the complier to other target processors
(B) Program analysis is name accurate on intermediate code than on machine code
(C) The information from data flow analysis cannot otherwise be used for optimization
(D) The information from the front end cannot otherwise be used for optimization
Answer: (B)
(A) p1 = a - b
q1 = p1 * c
p1 = u * c
q1 = p1 + q1
(B) p3 = a - b
q4 = p3 * c
p4 = u * c
q5 = p4 + q4
(C) p1 = a - b
q1 = p2 * c
p3 = u * c
q2 = p4 + q3
(D) p1 = a - b
q1 = p * c
p2 = u * c
q2 = p + q
Answer:(B)
PART-B
1. Open MPI is a Message Passing Interface library project combining technologies and
resources from several other projects that is developed and maintained by a consortium of
academic, research, and industry partners. In particular case, Intel C Compiler icc is used as
the backend compiler but we also have variants that use GCC. The following are the
packages that are involved in the versioning of OpenMPI model.
Fft= Numpy + Scipy + plot
Gsl = Scipy + plot
Python = Scikit + Matlib + Seaborn + plot + numpy
Gcc = Boost + atlas + hdf5 + plot
Torque = Fft + Gsl
OpenMPI = Torque + Python + Gcc
a) For the above hierarchy of the OpenMPI versioning, interpret the instruction and generate
Three Address Code for the same.
b) Create Directed Acyclic Graph for the Three Address Code generated from the above
Q.No (1a)
2. . For the code given below, determine the following : Constant propagation, live-variable
analysis.
(a) N = 10;
(b) k = 1;
(c) prod = 1;
(d) MAX = 99;
(e) while (k > N) {
(f) read(num);
(g) if (MAX/num < prod) {
(h) print("cannot compute prod");
(i) break;
(j) }
(k) prod = prod * num;
(l) k++;
(m) }
print(prod);
3. Construct Three address Code for the following Code and Explain different kinds of Three
address code representation.
begin
i := 1;
do begin
prod := prod + a[i] * b[i];
i = i+ 1;
end
while i <= 20
end
Note: Consider the type of array is integer.
3. Translate the conditional statement if a<b then 1 else 0 into three address code
4. Explain the following with example: i) Quadruples ii) Triples iii) Indirect triple
5. What are different intermediate code forms? Discuss different Three Address code types
and implementations of Three Address statements.
6.Explain the translation scheme to produce three address code for assignment statements.
7.Explain the Backpatching process for Boolean expression.
8.Explain the following terms: i) Register Descriptor ii) Address Descriptor iii) Instruction
Cost.
9.Explain various issues in the design of the code generation.
UNIT-V
1. Two standard storage-allocation strategies are
A. Stack Allocation and Queue Allocation
B. Stack Allocation and Static Allocation
C. Static Allocation and Queue Allocation
D. Simple Allocation and Static Allocation
ANSWER: B
4. Identify the synthesized and inherited attribute from the attributes: gen, kill, in, out
A. synthesized, inherited, inherited, synthesized
B. inherited, synthesized, synthesized, synthesized
C. synthesized, synthesized, inherited, inherited
D. synthesized, synthesized, inherited, synthesized
ANSWER: D
13. If an activation of procedure ‘A’ calls procedure ‘B’ then which one is TRUE?
A. Activation of B must end before the activation of A can end.
B. Activation of A must end before the activation of B can end.
C. Activation of A must end before the activation of B can start.
D. Activation of B must start after the activation of A can end.
ANSWER: A
14. Which of the following field of an activation record will point to the activation record of
the caller?
A. Retrned Values
B. Access Link
C. Temporaries
D. Control Link
ANSWER: D
15. Consider the following three address code. Identify the CORRECT collection of different
optimization can be performed? m = 3
j=n
v=2*n
limit = integer n / 2
L1: j = j – 1
t4 = 4 * j
t5 = a[t4]
if t5 > limit – v goto L1
A. Code Motion, Constant Folding, Induction Variable Elimination, Reduction in Strength
B. Copy Propagation , Code Motion, Deadcode Elimination, Reduction in Strength
C. Constant Folding, Copy Propagation, Deadcode Elimination, Reduction in Strength
D. Code Motion, Constant Folding, Copy Propagation, Induction Variable Elimination
ANSWER: A
18. The sequence of procedure calls of a program corresponds to which traversal of the
activation tree?
A. In order traversal
B. Pre order traversal
C. Post order traversal
D. Level-order travel
ANSWER: B
19. The ______ code must not, in any way, change the meaning of the program.
A. input
B. output
C. print
D. execute
ANSWER: A
20.Optimization should increase the _____ of the program and if possible, the program
should demand less number of resources.
A. length
B. count
C. speed
D. cost
ANSWER: C
PART-B
1) Write the code sequence for the d:=(a-b)+(a-c)+(a-c).
Apply code generation algorithm to generate a code sequence for the three address
statement.