Compiler Design GATE previous year questions with answer

Ques 27 GATE 2015 SET-2


Consider the intermediate code given below.
(1) i = 1
(2) j = 1
(3) t1 = 5 * i
(4) t2 = t1 + j
(5) t3 = 4 * t2
(6) t4 = t3
(7) a[t4] = -1
(8) j = j + 1
(9) if j ≤ 5 goto (3)
(10) i = i + 1
(11) if i < 5 goto (2)
The number of nodes and edges in the control-flow-graph constructed for the above code, respectively, are

A

5 and 7

B

6 and 7

C

5 and 5

D

7 and 8


(b) is the correct answer.

Ques 28 Gate 2015 Set-1


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.

Ques 29 GATE 2015 SET-1


A variable x is said to be live at a statement Si in a program if the following three conditions hold simultaneously:
i. There exists a statement Sj that uses x
ii. There is a path from Si to Sj in the flow graph corresponding to the program
iii. The path has no intervening assignment to x including at Si and Sj

The variables which are live both at the statement in basic block 2 and at the statement in basic block 3 of the above control flow graph are

A

p, s, u

B

r, s, u

C

r, u

D

q, v


(c) is the correct answer.

Ques 30 GATE 2015 SET-1


The least number of temporary variables required to create a three-address code in static single assignment form for the expression q + r / 3 + s - t * 5 + u * v / w is _______.


(8) is the correct answer.

Ques 31 GATE 2014 SET-3


The primary reason 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.


(c) is the correct answer.

Ques 32 GATE 2014 SET-3


Which of the following statements are CORRECT?
1) Static allocation of all data areas by a compiler makes it impossible to implement recursion.
2) Automatic garbage collection is essential to implement recursion.
3) Dynamic allocation of activation records is essential to implement recursion.
4) Both heap and stack are essential to implement recursion.

A

1 and 2 only

B

2 and 3 only

C

3 and 4 only

D

1 and 3 only


(d) is the correct answer.

Ques 33 GATE 2014 SET-3


Consider the basic block given below.
a = b + c
c = a + d
d = b + c
e = d – b
a = e + b
The minimum number of nodes and edges present in the DAG representation of the above basic block respectively are

A

6 and 6

B

8 and 10

C

9 and 12

D

4 and 4


(a) is the correct answer.

Ques 34 GATE 2014 SET-1


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.


(d) is the correct answer.

Unique Visitor Count

Total Unique Visitors

Loading......