# GATE Questions & Answers of Syntax-Directed Translation

## What is the Weightage of Syntax-Directed Translation in GATE Exam?

Total 4 Questions have been asked from Syntax-Directed Translation topic of Compiler Design subject in previous GATE papers. Average marks 1.75.

Consider the following Syntax Directed Translation Scheme (SDTS), with non-terminals {S, A} and terminals {a,b}.

$\style{font-family:Tahoma}{\begin{array}{l}\mathrm S\rightarrow\mathbf a\mathrm A\;\;\left\{\mathrm{print}\;1\right\}\\\mathrm S\rightarrow\mathbf a\boldsymbol\;\boldsymbol\;\boldsymbol\;\;\left\{\mathrm{print}\;2\right\}\\\mathrm S\rightarrow\mathrm S\mathbf b\;\;\left\{\mathrm{print}\;3\right\}\end{array}}$

Using the above SDTS, the output printed by a bottom-up parser, for the input aab is:

One of the purposes of using intermediate code in compilers is to

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

In a simplified computer the instructions are:

OP Rj, Ri   - Performs Rj OP Ri OP Ri and stores the result in register Ri.
OP m, Ri    - Performs val OP Ri and stores the result in Ri. val denotes the content of memory location m.
MOV, m Ri   - Moves the content of memory location m to register Ri.
MOV Ri, m   - Moves the content of register Ri to memory location m.

The computer has only to registers, and OP is either ADD or SUB. Consider the following basic block:

t1 = a + b
t2 = c + d
t3 = e - t2
t4 = t1 - t3

Assume that all operands are initially in memory. The final value of the computation should be in memory. What is the minimum number of MOV instructions in the code generated for this basic block?