2.5k views

Let the attribute ‘$val$’ give the value of a binary number generated by $S$ in the following grammar:

• $S \rightarrow L.L \mid L$
• $L \rightarrow LB \mid B$
• $B \rightarrow 0 \mid 1$

For example, an input $101.101$ gives $S.val = 5.625$

Construct a syntax directed translation scheme using only synthesized attributes, to determine $S.val$.

edited | 2.5k views

$S\to L.L \quad\{ S.val = L_1.val + L_2.val/2L_2.nb \}$

$\quad \quad \mid \; L \quad \{ S.val = L.val \}$

$L\to LB \quad \{ L.val = 2 * L_1.val + B.val,$
$\qquad \qquad \quad L.nb = L_1.nb + B.nb \}$

$\quad \quad \mid \; B\quad \{ L.val = B.val$
$\qquad\qquad \quad L.nb = B.nb \}$

$B \to 0 \quad \{ B.val = 0$
$\qquad\qquad B.nb = 1 \}$

$\quad \quad \mid \; 1 \quad \{ B.val = 1$
$\quad \quad \quad \qquad B.nb = 1 \}$

Here, $val =$ decimal value, $nb =$ number of bits.
edited by
0

L.dv = 2 * L1.dv + B.dv here why 2 is multiplied?

0

vnc in binary to decimal we multiply every time by 2

0
nice gate keeda

1
2