Compiler Design Gate Previous Year Questions



Ques 1Compiler

Which one of the following statements is TRUE?

a) The LALR(1) parser for a grammar G cannot have a reduce-reduce conflict if the LR(1) parser for G does not have reduce-reduce conflict.
b) The symbol table is accessed only during the lexical analysis phase.
c) Data flow analysis is necessary for run-time memory management.
d) LR(1) parsing is sufficient for deterministic context-free languages.


d is the correct answer.




Ques 2Compiler

Consider the productions A → PQ and A → XY. Each of the five non-terminals A,P,Q,X, and Y has two attributes: s is a synthesized attribute, and i is an inherited attribute. Consider the following rules.

Rule 1: P.i=A.i+2, Q.i=P.i+A.i, and A.s=P.s+Q.s
Rule 2: X.i=A.i+Y.s and Y.i=X.s+A.i

Which one of the following is TRUE ?

a) Both Rule 1 and Rule 2 are L-attributed
b) Only Rule 1 is L-attributed
c) Only Rule 2 is L-attributed
d) Neither Rule 1 nor Rule 2 is L-attributed


b is the correct answer.




Ques 3Compiler

Consider the following statements.
I. Symbol table is accessed only during lexical analysis and syntax analysis.
II. Compilers for programming languages that support recursion necessarily need heap storage for memory allocation in the run-time environment.
III. Errors violating the condition ‘any variable must be declared before its use’ are detected during syntax analysis.
Which of the above statements is/are TRUE ?

a) I only
b) I and III only
c) Ⅱ only
d) None of Ⅰ, Ⅱ and Ⅲ


d is the correct answer.




Ques 4Compiler

Consider the following grammar.

S → aSB ∣ d
B → b

The number of reduction steps taken by a bottom-up parser while accepting the string aaadbbb is ________ .


7 is the correct answer.




Ques 5Compiler

Which one of the following kinds of derivation is used by LR parsers?

a) Leftmost
b) Leftmost in reverse
c) Rightmost
d) Rightmost in reverse


d is the correct answer.




Ques 6Compiler

Consider the augmented grammar given below:

S′ → S
S → ⏐id
L → L, S⏐S
Let I0= CLOSURE ({[S′ → S]}).

The number of items in the set GOTO (I0, <) is __________.


5 is the correct answer.




Ques 7Compiler

Which of the following statements about the 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


Parsing is the correct answer.




Ques 8Compiler

Match the following according to input(from the left column) to the compiler phase(in the right column) that process it:

(P)Syntax Tree (i)Code generator
(Q)Character Stream (ii)Syntax analyser
(R)Intermediate representation (iii)Semantic analyser
(S)Token stream (iv)Lexical analyser

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)


Compiler Design is the correct answer.




Ques 9Compiler

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


Phase of Compiler is the correct answer.




Ques 10Compiler

Consider the following code segment.

x = u - t;
y = x * v;
x = y + w;
y = t - z;
y = x * y;


The minimum number of total variables required to convert the above code segment to static single assignment form is ____


a is the correct answer.




Ques 11Compiler

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


SDT is the correct answer.




Ques 12Compiler

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 statement(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 and S2


Parser is the correct answer.




Ques 13Compiler

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) SLR, canonical LR
d) LALR, canonical LR


Parser is the correct answer.




Ques 14Compiler

In the context of abstract-syntax-tree (AST) and control-flow-graph (CFG), which one of the following is True?

a) In both AST and CFG, let node N2 be the successor of node N1. In the input program, the code corresponding to N2 is present after the code corresponding to N1.
b) For any input program, neither AST nor CFG will contain a cycle.
c) The maximum number of successors of a node in an AST and a CFG depends on the input program.
d) Each node in AST and CFG corresponds to at most one statement in the input program.


CFG is the correct answer.




Ques 15Compiler

Which one of the following is True at any valid state in shift-reduce parsing?

a) Viable prefixes appear only at the bottom of the stack and not inside
b) Viable prefixes appear only at the top of the stack and not inside
c) The stack contains only a set of viable prefixes
d) The stack never contains viable prefixes


Parsing is the correct answer.