Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

GATE | GATE CS 1999 | Question 57

  • Last Updated : 30 Sep, 2020

[5 Marks question]

Let synthesized attribute val  give the value of the binary number generated by S in the following grammar. For example, on output 101.101, S.val=5.625

Attention reader! Don’t stop learning now.  Practice GATE exam well before the actual exam with the subject-wise and overall quizzes available in GATE Test Series Course.

Learn all GATE CS concepts with Free Live Classes on our youtube channel.

S → LL | L



L → LB | B

B → 0 | 1

Write S-attributed values corresponding to each of the productions to find S.val.


Answer:

Explanation: For the above grammar, the S-attributed values corresponding to each of the productions to find S.val is given below.

Here, val represents value and nb represents number of bit.

S → L.L   { S.val=L1.val  + L2.val / 2^L2.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 }  


Quiz of this Question

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!