Skip to content
Related Articles

Related Articles

Improve Article

GATE | GATE-CS-2003 | Question 58

  • Last Updated : 28 Jun, 2021

Consider the translation scheme shown below

S → T R
R → + T {print ('+');} R | ε
T → num {print (num.val);} 

Here num is a token that represents an integer and num.val represents the corresponding integer value. For an input string ‘9 + 5 + 2’, this translation scheme will print
(A) 9 + 5 + 2
(B) 9 5 + 2 +
(C) 9 5 2 + +
(D) + + 9 5 2


Answer: (B)

Explanation: Let us make the parse tree for 9+5+2 in top down manner, left first derivation.

Steps:
1) Exapnd S->TR
2) apply T->Num...
3) apply R -> +T...
4) appy T->Num...
5) apply R-> +T..
6) apply T-> Num..
7) apply R-> epsilon 

After printing through the print statement in the parse tree formed you will get the answer as 95+2+

Quiz of this Question

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.

My Personal Notes arrow_drop_up
Recommended Articles
Page :