23 23 votes Consider the syntax directed translation scheme $\textsf{(SDTS)}$ given in the following. Assume attribute evaluation with bottom-up parsing, i.e., attributes are evaluated immediately after a reduction. $E\rightarrow E_{1} * T \qquad \{E.val = E_{1}.val * T.val\}$ $E\rightarrow T \qquad \qquad \{E.val = T.val\}$ $T\rightarrow F - T_{1}\qquad \{T.val = F.val - T_{1}.val\}$ $T\rightarrow F \qquad \qquad \{T.val = F.val\}$ $F\rightarrow 2 \qquad \qquad \{F.val = 2\}$ $F\rightarrow 4 \qquad \qquad \{F.val = 4\}$ Using this $\textsf{SDTS},$ construct a parse tree for the expression $4 - 2 - 4 * 2$ and also compute its $E.val$. It is required to compute the total number of reductions performed to parse a given input. Using synthesized attributes only, modify the $\textsf{SDTS}$ given, without changing the grammar, to find $E.red$, the number of reductions performed while reducing an input to $E$. Compiler Design gatecse-2000 compiler-design syntax-directed-translation normal descriptive + – Kathleen 12.0k views answer comment Share Follow Print See all 5 Comments 5 5 Comments reply chauhansunil20th commented Nov 30, 2018 reply Follow flag $-$ is farthest from the start symbol, and $*$ is nearest to the start symbol, therefore, $-$ has higher precedence than $*$. $-$ is right associative as if an expression contains more than one $-$ then tree will grow towards right side, and $-$ present at the lower part of the tree towards right side will be evaluated before the $-$ present at the upper part of the tree towards left side, as Production T is right recursive. So, expression will evaluate to 12. 0 0 replyShare Nitesh Singh 2 commented Jan 20, 2019 reply Follow flag Dont assume precedence of operator by yourself always take care of precedence and associativity given in question. 0 0 replyShare Yashdeep2000 commented Jan 30, 2024 reply Follow flag I wonder what would have been different in B section if, instead of using “Synthesized Attribute” we use inherited attribute? 0 0 replyShare ritiksri8 commented Nov 4, 2024 reply Follow flag Solve by the help of precednce and associativity parse tree is time taking 0 0 replyShare chidambareswar23 commented Jan 29 i edited by chidambareswar23 Jan 29 reply Follow flag All questions related to Syntax Directed Translation Scheme(SDTS):Compiler Design: GATE CSE 1995 | Question: 2.10Compiler Design: GATE CSE 1996 | Question: 20Compiler Design: GATE CSE 2000 | Question: 19Compiler Design: GATE CSE 2016 Set 1 | Question: 46Compiler Design: GATE CSE 2021 Set 1 | Question: 26Compiler Design: GATE CSE 2022 | Question: 55Compiler Design: GATE CSE 2023 | Question: 50Compiler Design: GATE CSE 2003 | Question: 58Compiler Design: GATE CSE 2004 | Question: 45Compiler Design: GATE CSE 2006 | Question: 59 0 0 replyShare Please log in or register to add a comment.
Best answer 35 35 votes Given expression $4-2-4*2$Total reductions = 10Expression value, $E.val = 12$Total number of reductions performed, $E.red = 10$ (number of non-leaf nodes in the parse tree)Part B Explanation: https://gateoverflow.in/690/gate-cse-2000-question-19?show=136436#a136436 Prateek kumar answered Aug 30, 2016 • edited Jan 16 by Deepak Poonia 1 flag: ✌ Low quality (Amitesh Patra “Incomplete, lacks part b. of the question”) Prateek kumar comment Share Follow See all 3 Comments 3 3 Comments reply Vicky rix commented Dec 31, 2017 reply Follow flag number of reductions is nothing but the number of non-leaves in the parse tree ... 21 21 replyShare Hira Thakur commented Sep 11, 2022 reply Follow flag Please explain part B of the question. 0 0 replyShare Thadymademe commented Oct 24, 2022 i edited by Thadymademe Aug 26, 2024 reply Follow flag @Hira Thakur From the perspective of parsing the input its not necessary to compute the total number of reductions. 1 1 replyShare Please log in or register to add a comment.
48 48 votes SDTS to find the number of reductions:: E→ E1 * T {E.red = E1.red+ T.red+1} E→T {E.red = T.red+1} T→F - T1 {T.red = F.red + T1.red+1} T→F {T.red = F.red+1} F→2 {F.red = 1} F→4 {F.red = 1} VS answered Jul 6, 2017 VS comment Share Follow See 1 comment 1 1 comment reply rahul sharma 5 commented Jan 23, 2018 reply Follow flag @VS ,you can edit the selected answer to include this as part b answer. 1 1 replyShare Please log in or register to add a comment.
11 11 votes A. Given Expression is 4 - 2 - 4 * 2 , which can be rewritten as ((4 - (2 - 4))* 2) which is equal to 12. Aditya answered Aug 12, 2015 Aditya comment Share Follow See all 2 Comments 2 2 Comments reply Purple commented Jan 24, 2016 reply Follow flag how do we know that minus '-' is right to left? 0 0 replyShare shivanisrivarshini commented Jan 24, 2016 reply Follow flag second minus is at lower level than 1st minus so first 2-4=-2 then 4-(-2)=6 then 6*2 since is at higher level 1 1 replyShare Please log in or register to add a comment.