Awesome q2a theme
0 votes

Can anyone tell how to solve the below question?

in Compiler Design by (804 points) | 137 views

@Shaik Masthan

plz tell me r u getting $a*a+a$??



What are we doing, is it for expression 

$E\rightarrow E\left \{ print "+" \right \}+T$


Is it for

$E\rightarrow E+T\left \{ print "+" \right \}$

I know SDD do postfix evaluation, but is it applicable here?



How much I got top-down parser is a subset of bottom-up parser.

So, SDD for both will be same and it will be in semantic analysis phase of any compiler.

Will be same for top-down and bottom-up compiler.

Plz. correct me if anything wrong in these words.


@Shaik Masthan @Satbir

Which one is correct between these two

one must be incorrect.

One printing from bottom to top and another top to bottom.

Though I havenot got any resource which is printing bottom to top.

So, I think @Mk Utkarsh ans is correct.


It will just printed when parser get it. right na??


1 Answer

+2 votes
Best answer

Ans will be C)

Rightmost derivation

$E\rightarrow E+T$           (+ printed)

$E\rightarrow E+T*F$      (* printed)

$E\rightarrow E+T*a$       (a printed)

$E\rightarrow E+F*a$

$E\rightarrow E+a*a$      (a printed)

$E\rightarrow F+a*a$       

$E\rightarrow a+a*a$       (a printed)

Now, do bottom-up parsing and find "handle"


$F+a*a$         Handle-$F$

$E+a*a$         Handle-$E$

$E+F*a$         Handle-$F$

$E+T*a$         Handle-$T$

$E+T*F$         Handle-$F$

$E+T$                Handle-$T$

$E$                        Handle-$E$

by (755 points)
selected by

Similar Question asked before

And there pdf link is given in which mention that :

 General rule: The actions are viewed as "dummy" terminals embedded in the parse tree. They are executed in the order of a preorder traversal of the tree. Thus, the result of the SDT is the same whether parsing is top-down, bottom-up, or something else.

What does it relly means???? 

@srestha I am not  able to understand the handle method can you explain it in a more elaborate way??

Thank you


In ur given link, isnot the grammar printing from last?

Check it again

@Pratyush Priyam Kuan

It is just reverse of rightmost derivation method. right?



See it

But i still in confusion which is correct and which is not!!


What I got still now, this SDT should be L-attributed, because semantic rules are in middle. So, cannot be evaluated in bottom-up parser. It can evaluated in top-down parser. So, nothing but DFS search is required.


Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
Welcome to GATE CSE Doubts, where you can ask questions and receive answers from other members of the community.
Top Users Jul 2020
  1. Shaik Masthan

    39 Points

  2. hiteshpujari

    9 Points

  3. fazin

    7 Points

  4. srestha

    7 Points

  5. gaurav2697

    6 Points

  6. Venkatesh Akhouri

    6 Points

  7. Meghana518

    6 Points

  8. beastincarnate

    6 Points

  9. athenahermes

    6 Points

  10. bittujash

    6 Points

7,561 questions
1,783 answers
90,493 users