edited by
1,413 views
5 votes
5 votes
$\begin{align*} &E\rightarrow E+E \qquad {\color{red}{\text{E.val} = \text{E}_1\text{.val} { \;\;\large + \;\; } \text{E}_2\text{.val}}} \\ &E\rightarrow E*E \; \qquad {\color{red}{\text{E.val} = \text{E}_1\text{.val} { \;\;\large - \;\; } \text{E}_2\text{.val}}} \\ &E\rightarrow E - E \qquad {\color{red}{\text{E.val} = \text{E}_1\text{.val} { \;\;\large * \;\; } \text{E}_2\text{.val}}} \\ &E\rightarrow \left ( E \right ) \;\;\; \; \qquad {\color{red}{\text{E.val} = \text{E}_1\text{.val}}} \\ &E\rightarrow \text{id} \;\;\; \; \;\;\; \qquad {\color{red}{\text{E.val} = \text{id}\text{.val}}} \\ \\ &\text{What is that value of the attribute comupted at the root when the expression} \\ &{\large\color{blue}{\left [ \left ( 3*3 \right )+\left ( 3*5 \right ) - 6 \right ]+7}} \quad \text{is evaluated using above SDT ?} \\ \end{align*}$
edited by

2 Answers

Best answer
3 votes
3 votes
$\begin{align*} &\text{Operator priority order } \\ &\rightarrow 1st \quad {\large \color{blue}{-}} \\ &\rightarrow 2nd \quad {\large \color{blue}{*}} \\ &\rightarrow 3rd \quad {\large \color{blue}{+}} \\ \\ \hline \\ &\text{While reducing to a production corresponding SDT is evaluated} \\ \\ &\Rightarrow \left ( {\color{red}{\left ( 3*3 \right )}}+{\color{red}{\left ( 3*5 \right )}} - 6 \right )+7 \\\\ &\Rightarrow \left ( 0 \;\;{\large \color{blue}{+}} \;\; {\color{red}{(- 2) \;\;{\large \color{red}{-}}\;\; 6}} \right ) + 7 \\\\ &\Rightarrow \left ( 0 \;\;{\large \color{blue}{+}} \;\; (-12) \right ) + 7 \\ \\ &\Rightarrow \left ( -12 \right ) + 7 \\ \\ &\Rightarrow -5 \\ \end{align*}$
selected by
1 votes
1 votes

see this one..little bit messy though..!

Related questions

1 votes
1 votes
1 answer
1
Na462 asked Jan 13, 2019
1,235 views
Consider the following Translation rules for the Grammar G :What will be the output for input string abebebe for bottom up parser ?CBBPBPBPCBBBPPBBCBPBPBPBCBPBBPPB