The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+11 votes
1.4k 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$.
asked in Compiler Design by Veteran (59.6k points)
edited by | 1.4k views

1 Answer

+18 votes
Best answer

S-- > L.L  { S.dv = L1.dv + L2.dv/2L2.nb }

         | L   { S.dv = L.dv }

L-- > LB   { L.dv = 2 * L1.dv + B.dv

                  L.nb = L1.nb + B.nb }}

        | B   { L.dv = B.dv

                 L.nb = B.nb }

B-- > 0    { B.dv = 0

                 B.nb = 1 }

       | 1    { B.dv = 1

                 B.nb = 1 }

here dv = decimal value

        nb = number of bits.

answered by Boss (19.7k points)
selected 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


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

40,855 questions
47,520 answers
145,896 comments
62,279 users