Open In App

Aptitude | GATE CS 1998 | Question 80

Improve
Improve
Like Article
Like
Save
Share
Report

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
Previous
Next
Share your thoughts in the comments
Similar Reads