edited by
10,500 views
26 votes
26 votes

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
edited by

2 Answers

Best answer
59 votes
59 votes

$\bf{aab}$ could be derived as follows by the bottom up parser:

$S \rightarrow a$$\color{blue}{\mathbf A}$ prints $\color{blue}{1}$
$\quad \rightarrow a$$\color{blue}{\mathbf S}$$b$ prints $\color{blue}{3}$
$\quad \rightarrow aab$  prints $\color{blue}{2}$
Now since the bottom-up parser will work in reverse of rightmost derivation, so it will print in bottom-up fashion i.e., $231$ which is option C.

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

edited by
Answer:

Related questions

35 votes
35 votes
4 answers
1
Sandeep Singh asked Feb 12, 2016
10,027 views
The attribute of three arithmetic operators in some programming language are given below.$$\begin{array}{|c|l|}\hline \textbf{OPERATOR} & \textbf{PRECEDENCE} & \textbf{...
69 votes
69 votes
12 answers
2
69 votes
69 votes
4 answers
3