GATE CSE
First time here? Checkout the FAQ!
x
+3 votes
1.1k views

Consider the following Syntax Directed Translation Scheme $( SDTS )$, with non-terminals $\{S,A \}$ and terminals $\{a,b \}$.

          $S \to aA  \quad \{\text{print }1\}$

          $S \to a    \quad   \{\text{print }2\}$

          $A \to Sb  \quad \{\text{print }3\}$

Using the above $SDTS$ , the output printed by a bottom-up parser, for the input $aab$ is:

  1.  $1 \ 3 \ 2 $ 
  2.  $2 \ 2 \ 3  $ 
  3.  $2 \ 3 \ 1 $ 
  4.  syntax error
asked in Compiler Design by Boss (8.9k points)  
edited by | 1.1k views

1 Answer

+25 votes
Best answer

aab could be derived as follows by the bottom up parser:

S->aA prints 1
A->aSb prints 3
A->aab  prints 2
Now since bottom up parser will work in reverse of right most derivation, so it will print in bottom up fashion i.e., 231 which is option C.

Note that this could also be visualized easily by drawing the derivation tree.
 

answered by Boss (7.9k points)  
edited by
Just a doubt... If the grammar given is not CLR(1) and the string is derivable will it be considered as parsable and sdt would be possible..??


Top Users Jun 2017
  1. Bikram

    3704 Points

  2. Hemant Parihar

    1484 Points

  3. junaid ahmad

    1432 Points

  4. Arnab Bhadra

    1408 Points

  5. Niraj Singh 2

    1311 Points

  6. Rupendra Choudhary

    1194 Points

  7. rahul sharma 5

    1120 Points

  8. Arjun

    930 Points

  9. srestha

    928 Points

  10. Debashish Deka

    896 Points

Monthly Topper: Rs. 500 gift card
Top Users 2017 Jun 19 - 25
  1. Bikram

    1960 Points

  2. Niraj Singh 2

    1306 Points

  3. junaid ahmad

    502 Points

  4. sudsho

    410 Points

  5. akankshadewangan24

    388 Points


23,355 questions
30,065 answers
67,365 comments
28,382 users