1 votes 1 votes Consider the SDT , where S ->TR, R-> +TR|empty {print ("+")} , And T-> num {print(num)} And if the input is given "9+5+2" What is output ? Compiler Design compiler-design syntax-directed-translation + – spriti1991 asked Mar 18, 2015 spriti1991 2.3k views answer comment Share Follow See 1 comment See all 1 1 comment reply Shiva Sagar Rao commented Feb 4, 2021 i edited by Shiva Sagar Rao Feb 4, 2021 reply Follow Share This question is change of 2nd production in the previous GATE question GATE2003-58 0 votes 0 votes Please log in or register to add a comment.
Best answer 1 votes 1 votes Input 952++ S-> TR -> 9 R (print 9 by T -> num) -> 9 +TR (R -> +TR) -> 9 + 5 R (print 5 by T -> num) -> 9 + 5 + TR (R -> +TR ) -> 9 + 5 + 2 R (print 2 by T-> num) -> 9 + 5 + 2 (print + by R -> empty) -> 9 + 5 + 2 (print + by R -> empty) So, answer is 952++. Arjun answered Mar 18, 2015 selected Aug 20, 2015 by Pooja Palod Arjun comment Share Follow See all 10 Comments See all 10 10 Comments reply Show 7 previous comments Digvijay Pandey commented May 2, 2015 reply Follow Share @Arjun sir : S ->TR, R-> +TR|empty {print ("+")} T -> num {print(num)} sir meaning of production no 2 is : R-> +TR R-> empty {print ("+")} or R-> +TR {print ("+")} R-> empty {print ("+")} if 1st one one then 952+ and for 2nd one anwer would b 952+++ .. ryt ??? 0 votes 0 votes Arjun commented May 2, 2015 reply Follow Share Meaning is second. And 952++ should be correct. It was my mistake. 0 votes 0 votes Digvijay Pandey commented May 2, 2015 reply Follow Share sir in production of 9+5+2 we are using production R--> +TR two times and one more R ---> empty .. so total three + sign should be in output na ?? 0 votes 0 votes Please log in or register to add a comment.
2 votes 2 votes Answer is 95+2+ See this - Ankish answered Mar 19, 2015 Ankish comment Share Follow See all 4 Comments See all 4 4 Comments reply spriti1991 commented Mar 19, 2015 reply Follow Share Hi i an doing excatly in same way by making SDT. but i am keeping ("print(+)) later that is a for a node R i am placing first + then T then R and then print (+) so i am ending with the diff answer . why did you kept print(+) before R in a tree ? (Taling about the child of R ) haan 0 votes 0 votes Ankish commented Mar 19, 2015 reply Follow Share I think your question is incorrect.It is one of the GATE question.Correct grammar should be - S → T R R → + T {print ('+');} R | ε T → num {print (num.val);} In the above grammar, print(+) is after T and before R. Got it? 0 votes 0 votes spriti1991 commented Mar 19, 2015 reply Follow Share Okay it might be . the book from which i am referring is hand written notes so this may be the reason . I got it :) However this would be a L attribute SDT. Because in That SDT only we are allowed to put semantic rules in between or end or start . Thank you Ankish :D 0 votes 0 votes saket nandan commented May 1, 2015 reply Follow Share answer is 9+5+2+ according to above question rather than gatew question 0 votes 0 votes Please log in or register to add a comment.
0 votes 0 votes according to given question answer will be according to above parse tree will be 952+ saket nandan answered May 1, 2015 saket nandan comment Share Follow See all 0 reply Please log in or register to add a comment.