Compiler Design GATE CS and IT previous year questions with answer


Ques 1 Gate 2022


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.



Ques 2 GATE 2021 SET-2


In the context of compilers, which of the following is/are NOT an intermediate representation of the source program?

A

Three address code

B

Abstract Syntax Tree (AST)

C

Control Flow Graph (CFG)

D

Symbol table



Ques 3 Gate 2020


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



Ques 4 Gate 2020


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 Ⅲ



Ques 5 Gate 2020


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 6 Gate 2019


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



Ques 7 Gate 2019


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 8 Gate 2017 Set-2


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



Ques 9 Gate 2017 Set-2


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)



Ques 10 Gate 2016 Set-2


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