Skip to content
Related Articles

Related Articles

Improve Article

GATE | GATE-CS-2006 | Question 59

  • Difficulty Level : Easy
  • Last Updated : 15 Sep, 2021

Consider the following translation scheme.
S → ER
R → *E{print(“*”);}R | ε
E → F + E {print(“+”);} | F
F → (S) | id {print(id.value);}
Here id is a token that represents an integer and id.value represents the corresponding integer value. For an input ‘2 * 3 + 4’, this translation scheme prints
(A) 2 * 3 + 4
(B) 2 * +3 4
(C) 2 3 * 4 +
(D) 2 3 4+*


Answer: (D)

Explanation: Background Required to solve the question – Syntax Directed Translation and
Parse Tree Construction.

Explanation : We are given L-Attributed Syntax Directed Translation as
semantic actions like printf statements are inserted anywhere on the 
RHS of production (R → *E{print(“*”);}R). After constructing the parse tree 
as shown below from the given grammar, we will follow depth first order left 
to right evaluation in order to generate the final output.

Parse Tree:
parse-tree

Attention reader! Don’t stop learning now.  Practice GATE exam well before the actual exam with the subject-wise and overall quizzes available in GATE Test Series Course.

Learn all GATE CS concepts with Free Live Classes on our youtube channel.

Just follow the arrows in the picture (This is actually Depth first 
left to right evaluation ) and the moment we take exit from any child 
which is printf statement in this question, we print that symbol which 
can be a integer value or ‘*’ or ‘+’.

Evaluation :
syntax-directed-translation

This explanation has been contributed by Pranjul Ahuja.



Quiz of this Question

My Personal Notes arrow_drop_up
Recommended Articles
Page :