The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+13 votes
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$.

in Compiler Design by Veteran (52.1k points)
edited by | 2.5k views

1 Answer

+21 votes
Best answer
$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.
by Boss (19.9k points)
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

Related questions

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
49,984 questions
55,138 answers
190,495 comments
85,159 users