retagged by
960 views

5 Answers

0 votes
0 votes

Ans is option : B only 

By shift reduce parser we can construct parse tree for Ambiguous grammar also...

For Ambiguous grammars, Shift- Reduce parser whenever RHS of a production is available, then it is immediately reduce it to LHS of the corresponding production.

           a        +      b          *           c

           E     ---------------------------------                    print a ----> output : a

           E        +     -------------------------- 

           E         +         E ----------------------               print b ----> output : a b

           E --------------------------------                         print + ----> output : a b +

           E                   *        ----------- 

           E                      *              E -------                print c ----> output : a b + c

           E ---------------------                                      print * ----> output : a b + c *

           E1 ------                                                      print \$ ----> output : a b + c * $

0 votes
0 votes

 The grammar for a shift-reduce parser must be unambiguous itself, or be augmented by tie-breaking precedence rules. This means there is only one correct way to apply the grammar to a given legal example of the language, resulting in a unique parse tree and a unique sequence of shift/reduce actions for that example ( source )

in the above question as we are assuming the shift reduce parser we have choice of making the tie-breaking precedence rules. 

Case1 : If we choose  precedence * > +  . we get answer a

Case 2 : If we choose precedence   + >  *  we get answer b

There fore depending upon  the precedence we are choosing in the compiler we get the answer c.

Related questions