Aptitude | GATE CS 1998 | Question 80
Let the attribute ‘val’ give the value of a binary number generated by S in the following grammar:
S → L.L | L
L→ LB | B
B → 0 | 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.
Answer:
Explanation: Given grammar is:-
SÂ -> L.L | L
L-> LB | B
BÂ -> 0 | 1
Now, syntax directed translation scheme using only synthesized attributes are:
SÂ -> L.L { S.val = L.Val + L.val / L.nb }
S -> L { S.val = L.val}
L -> LB { L.val = 2 * L.Val + B.val , L.nb = L.nb + B.nb }
L -> B { L.val = B.val , L.nb = B.nb}
BÂ -> 0 { B.val = 0 , B.nb = 1 }
BÂ -> 1 { B.val = 1 , B.nb = 1 }
where , val = decimal value , nb = number of bits
Quiz of this Question
Last Updated :
06 Feb, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...