Principles of Compiler Design: Gate Questions and Answers
Principles of Compiler Design: Gate Questions and Answers
Principles of Compiler Design: Gate Questions and Answers
GATE CS 2011
1)In a compiler, keywords of a language are recognized during
(A) parsing of the program
(B) the code generation
(C) the lexical analysis of the program
(D) dataflow analysis
OPTION C
GATE CS 2011
2)The lexical analysis for a modern computer languages such as Java
needs the power of which one of the following machine models is
necessary and sufficient sense.
(A) Finite state automata
(B) Deterministic pushdown automata
(C) Non-Deterministic pushdown automata
(D) Turing Machine
Option A
GATE CS 1998
4)Type checking is normally done during
(C) the information from dataflow analysis cannot otherwise be used for
optimization
(D) the information from the front end cannot otherwise be used for
optimization
Prof. C.NagaRaju YSREC of YVU
OPTION A
6/22/2020
9949218570
Question
GATE CS 1997
OPTION C
Prof. C.NagaRaju YSREC of YVU
6/22/2020
9949218570
Question
GATE-CS-2014-(Set-3)
7) One of the purposes of using intermediate code in compilers is
to
(A) make parsing and semantic analysis simpler.
(B) improve error recovery and error reporting.
(C) increase the chances of reusing the machine-independent
code optimizer in other compilers.
(D) improve the register allocation.
OPTION C
(A) 12
(B) 11
(C) 10
(D) 07
• OPTION A
OPTION B
OPTION A
A)Linear list
B) Search tree
C) Hash table
D) Self organization list
OPTION B
A.3
B.26
C.10
D.21
OPTION C
1)Printf 2) ( 3)"i = %d, &i = %x“ 4) , 5) I 6), 7) & 8) I 9) ) 10) ;
Answer is C
OPTION A
Option B
Option D
• option (A)
5. A CFG is ambiguous if
a) It has more than one rightmost derivations
b) It has more than one leftmost derivations
c) No parse tree can be generated for the CFG
d) a or b
OPTION D
Option A
Option D
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
Option D
Option (B)
option (C)
A. Shift/reduce conflict
B. Reduce /shift conflict
C. Shift conflict
D. Reduce conflict
Option A
Option (A)
When ß ( in the LR(1) item A -> ß.a,a ) is not empty, the look-
head
A. Will be affecting.
B. Does not have any affect.
C. Shift will take place.
D. Reduction will take place.
Option (B)
Option (D)
option C
Option D
Prof. C.NagaRaju YSREC of YVU
6/22/2020
9949218570
Explanation
• The question is asked with respect to the symbol ' < ' which is
not present in the given canonical set of items.
• Hence it is neither a shift-reduce conflict nor a reduce-reduce
conflict on symbol '<‘.
• So option D is correct choice
• But if the question would have asked with respect to the
symbol ' > ' then it would have been a shift-reduce conflict.
Option (C)
• Option (A)
Prof. C.NagaRaju YSREC of YVU
6/22/2020
9949218570
Explanation
A. Will be affecting.
B. Does not have any affect.
C. Shift will take place.
D. Reduction will take place.
Option (B)
Option (D)
option (B)
A. LL(1)
B. Canonical LR
C. SLR
D. LALR
Option B
Option C
Option A
• Option A is correct
• A grammar is ambiguous if there exists a string s such that the
grammar has more than one leftmost derivations for s. We
could also come up with more than one rightmost derivations
for a string to prove the above proposition, but not both of
right and leftmost. An unambiguous grammar can have
different rightmost and leftmost derivations.
Option A
OPTION A
OPTION C
OPTION D
OPTION D
7)The graph that shows basic blocks and their successor relationship is
called:
A)DAG
B)Control graph
C)Flow graph
D)Hamiltonian graph
• OPTION C
9)In _______, the bodies of the two loops are merged together
to form a single loop provided that they do not make any
references to each other.
A)Loop unrolling
B)Strength reduction
C)Loop concatenation
D)Loop jamming
OPTION D
OPTION A
A)Loop optimization
B)Local optimization
C)Constant folding
D)Data flow analysis
OPTION C
OPTION B
OPTION A
option (C)
OPTION B
Prof. C.NagaRaju YSREC of YVU
6/22/2020
9949218570
• Question 20 Explanation:
• E -> E1 - E2 Given that E1 and E2 don't share any sub expression,
most optimized usage of single user register for evaluation of this
production rule would come only when E2 is evaluated before E1.
This is because when we will have E1 evaluated in the register, E2
would have been already computed and stored at some memory
location. Hence we could just use subtraction operation to take
the user register as first operand, i.e. E1 and E2 value from
its memory location referenced using some index register or
some other form according to the instruction. Hence correct
answer should be (B) E2 should be evaluated first.
21)A grammar that is both left and right recursive for a non-
terminal is
A)Ambiguous
B)Unambiguous
C)Information is not sufficient to decide whether it is ambiguous or
Unambiguous.
D)None of the above
OPTION C
A.Local optimisation
B.Constant folding
C.Loop Optimisation
D.Data flow analysis
OPTION A
OPTION D
OPTION B
OPTION B
OPTION A
A. Syntax tree
B.semantic analyzer
C.Code optimizer
D.Lexical analyzer
Answer is B
OPTION D
Explanation
Question
OPTION B
Question
OPTION C
Question
OPTION B
Question
OPTION B
Question
OPTION D
Question
OPTION A
Question
OPTION A
Question
OPTION D
Question
OPTION A
Question
8
Question
OPTION C
Question
OPTION B
CODE OPTIMIZATION
C)Constant folding
Option D
A)DAG
B)Control graph
C)Flow graph
D)Hamiltonian graph
Flow graph
B)Local optimization
Answer is D
• Option is C
Answer: d
Explanation: All of these options are features of assembler
which are machine dependent
OPTION B
GATE2014
OPTION A
OPTION A
OPTION C
OPTION D
A.local optimization
B.loop optimization
C.constant folding
D.data flow analysis
Option: C