Question
Consider the syntax directed translation given by the following grammar and semantic rules. Here and are non-terminals. is the starting non-terminal, and #, 0 and 1 are lexical tokens corresponding to input letters "#", "0" and "1", respectively. denotes the synthesized attribute (a numeric value) associated with a non-terminal . and denote occurrences of and on the right hand side of a production, respectively. For the tokens 0 and 1, and .
The value computed by the translation scheme for the input string
is _______. (Rounded off to three decimal places)
Official answer and solution
- Accepted answers
- 2.374 to 2.376
- From
- Official GATE 2023 answer key
Solution
Evaluate the synthesized attributes according to the syntax directed translation rules.
For input string 10#011:
-
Integer part () for
10:- .
- with .
-
Fractional part () for
011(evaluated right-to-left due to right recursion ):- Third bit (1): .
- Second bit (1): with .
- First bit (0): with .
-
Root rule :
2.375
Evaluating the fractional part left-to-right rather than following the right-recursive grammar derivation tree.
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2023 Computer Science and Information Technology (CS)
- Question
- 60 of 65
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.