0 votes 0 votes Compiler Design compiler-design syntax-directed-translation testbook-test-series + – Na462 asked Oct 5, 2018 • edited Mar 12, 2019 by ajaysoni1924 Na462 1.6k views answer comment Share Follow See all 19 Comments See all 19 19 Comments reply Na462 commented Oct 5, 2018 reply Follow Share What will be the output if instead of bottom up it were a top down parser ? 0 votes 0 votes Na462 commented Oct 5, 2018 reply Follow Share Please explain the rule for solving such question in both the case. I basically solve it by creating annotated parse tree but still need a good approach for both top and bottom up parser. 0 votes 0 votes himgta commented Oct 5, 2018 reply Follow Share C) 231 1 votes 1 votes Shaik Masthan commented Oct 5, 2018 reply Follow Share I basically solve it by creating annotated parse tree it is good method. What will be the output if instead of bottom up it were a top down parser ? For bottom-up parser, use RMD, then create annoted parse tree For top-down parser, use LMD, then create annoted parse tree This example, there is no change in the answer, however answer is 2 3 1 1 votes 1 votes himgta commented Oct 6, 2018 reply Follow Share @Shaik Masthan brother in all the cases output produced by top down or bottom up is same....or in this example it is so happened? 0 votes 0 votes Shaik Masthan commented Oct 6, 2018 reply Follow Share i didn't know exactly ! But it seems to be equal in any case( ambiguous or unambiguous grammars with either Top-Down or Bottom-Up ) 0 votes 0 votes Na462 commented Oct 8, 2018 reply Follow Share @Shaik, Brother see this one here : 0 votes 0 votes Na462 commented Oct 8, 2018 reply Follow Share Please can you solve for both using top down and bottom up. My answer is A but correct answer is B. 0 votes 0 votes Na462 commented Oct 8, 2018 reply Follow Share I created the annotated Syntax tree correctly only when should i execute the print. I am confused at that. Is it the case that in top down parser :- The first time when i will hit the production at that moment only i should print. In bottom up :- When the reduction will take place then i should print. I am confused here :( Can u solve for both top down and bottom up and generate the output Please 0 votes 0 votes Dharmendra Verma commented Nov 3, 2018 reply Follow Share Yes you are thinking the correct way. 0 votes 0 votes Shaik Masthan commented Dec 10, 2018 reply Follow Share brother in all the cases output produced by top down or bottom up is same....or in this example it is so happened? let take it is s-attributed grammar.... For unambiguous grammars, there is only one parse tree for each string which is belong to the language generated by the grammar. Top-down parser ultimately generates a parse tree which is equal to Bottom-Up parser generates ! Top-down parser follow post order, where Bottom-up parser follow DFS from left to right due to when reduction takes place it is evaluated ! Now our question turned into is POST ORDER = Depth First Search from left to right ? if yes, then output is equal, otherwise not equal ! POST ORDER = Depth First Search from left to right ? ===> this is true, therefore in all the cases output produced by top down or bottom up is same Please can you solve for both using top down and bottom up. My answer is A but correct answer is B. option A is correct 0 votes 0 votes Na462 commented Dec 13, 2018 reply Follow Share Brother No offense but, I think in top-down parser the moment u hit the rule execute it but in the bottom-up parser, the moment reduction occurs execute the rule. Can u please give any reference of what u saying? thats why the correct answer should be indeed B :) 0 votes 0 votes Na462 commented Dec 13, 2018 reply Follow Share I have asked to my university teacher and too discussed with @Mk Utkarsh Example : Suppose brother Productions are given as : S->aA {pf("I")} A->bB {pf("am")} B -> b {pf("Cool")} What will be the output for the string 'abb' in top down and bottom up parser ? Ans. According to the method i stated below if i follow that then:- Top down : I am Cool Bottom Up: Cool am I 0 votes 0 votes Na462 commented Dec 13, 2018 reply Follow Share Please verify once :) 0 votes 0 votes Shaik Masthan commented Dec 13, 2018 reply Follow Share I think in top-down parser the moment u hit the rule execute it S ---> aA {print("I")} it means after completing a, and A then print "I" 0 votes 0 votes Na462 commented Dec 13, 2018 reply Follow Share So brother why output in all the cases output produced by top down or bottom up is same ? as for above the outputs are I am cool and cool am i are correct right ? and they are different 0 votes 0 votes Deepanshu commented Dec 13, 2018 reply Follow Share i think both top down and bottom up should be cool am i there 0 votes 0 votes Na462 commented Dec 13, 2018 reply Follow Share Any reference ? 0 votes 0 votes srestha commented Nov 16, 2019 i edited by srestha Nov 16, 2019 reply Follow Share @Shaik Masthan Now our question turned into is POST ORDER = Depth First Search from left to right ? if yes, then output is equal, otherwise not equal ! If not equal then what will happen? I got http://cse.iitkgp.ac.in/~bivasm/notes/SDD.pdf reference. But nothing mentioned like that Another ref 0 votes 0 votes Please log in or register to add a comment.