crop it then paste question is not clearly viewed

The Gateway to Computer Science Excellence

First time here? Checkout the FAQ!

x

+5 votes

Consider the following grammar to generate binary fractions:

If the above grammar with semantic rules calculate

and each non-terminal has synthesized attribute ‘val’ to store its value. Then the missing semantic rules will be _______.

**A**.

**B**.

**C.**

**D.**

0 votes

The answer is option D.

Reason::

Lets first understand the grammar .

1.It says that an binary fraction can be of the form decimal(.) followed by any number of binary bits.

2. Any binary bits can start with 0 followed by any number of binary bits or 1 followed by any number of binary bits.

3. Or it (B) can be a single bit 1 or 0.

4. Now if its 0 i.e 0.0 then the decimal value is $\frac{0}{2^{-1}}$ i.e. 0 .

5. And if its 1 i.e. 0.1 then the decimal value is $\frac{1}{2^{-1}}$ i.e. 1/2 . Therefore S3 :{B.val = 1/2 }

6. Now for S2 , its says that the 1st bit is 1 follwed by several number of binary bits.Also let those binary bits be $b_0b_1b_2......b_n$. Therefore the given binary number becomes 1 followed by $b_0b_1b_2......b_n$.Therefore , the decimal value is $\frac{1}{2^{-1}}+\frac{b_0}{2^{-2}}+\frac{b_1}{2^{-3}}+.......+\frac{b_n}{2^{-n}}$.

7. Now taking 1/2 common from the 2nd , 3rd........ terms we get $\frac{1}{2^{-1}}+\frac{1}{2}\left ( \frac{b_0}{2^{-1}}+\frac{b_1}{2^{-2}}+.......+\frac{b_n}{2^{-(n-1)}} \right) $ .

8. If we look clearly , it is nothing but 1/2+B.val/2. Therefore , S2: {B0.val=B1.val/2+1/2}.

9. Similarly, we can say for S1 :{B0.val=B1.val/2}.

I hope it helps.

Reason::

Lets first understand the grammar .

1.It says that an binary fraction can be of the form decimal(.) followed by any number of binary bits.

2. Any binary bits can start with 0 followed by any number of binary bits or 1 followed by any number of binary bits.

3. Or it (B) can be a single bit 1 or 0.

4. Now if its 0 i.e 0.0 then the decimal value is $\frac{0}{2^{-1}}$ i.e. 0 .

5. And if its 1 i.e. 0.1 then the decimal value is $\frac{1}{2^{-1}}$ i.e. 1/2 . Therefore S3 :{B.val = 1/2 }

6. Now for S2 , its says that the 1st bit is 1 follwed by several number of binary bits.Also let those binary bits be $b_0b_1b_2......b_n$. Therefore the given binary number becomes 1 followed by $b_0b_1b_2......b_n$.Therefore , the decimal value is $\frac{1}{2^{-1}}+\frac{b_0}{2^{-2}}+\frac{b_1}{2^{-3}}+.......+\frac{b_n}{2^{-n}}$.

7. Now taking 1/2 common from the 2nd , 3rd........ terms we get $\frac{1}{2^{-1}}+\frac{1}{2}\left ( \frac{b_0}{2^{-1}}+\frac{b_1}{2^{-2}}+.......+\frac{b_n}{2^{-(n-1)}} \right) $ .

8. If we look clearly , it is nothing but 1/2+B.val/2. Therefore , S2: {B0.val=B1.val/2+1/2}.

9. Similarly, we can say for S1 :{B0.val=B1.val/2}.

I hope it helps.

- All categories
- General Aptitude 1.8k
- Engineering Mathematics 7.3k
- Digital Logic 2.9k
- Programming & DS 4.9k
- Algorithms 4.3k
- Theory of Computation 6k
- Compiler Design 2k
- Databases 4.1k
- CO & Architecture 3.4k
- Computer Networks 4.1k
- Non GATE 1.4k
- Others 1.4k
- Admissions 596
- Exam Queries 577
- Tier 1 Placement Questions 23
- Job Queries 72
- Projects 18

49,532 questions

54,126 answers

187,326 comments

71,046 users