PU Paper 2022
PU Paper 2022
Question #4:
Translation Scheme:
Grammar Rules:
Translation Rules:
Attributed Grammar:
Grammar Rules:
In this attributed grammar, the attribute val is calculated for each non-terminal and terminal symbol
based on the production rules. The val attribute for a floating-point string (R) is calculated as the
sum of the integer part (N1) and the fractional part (N2) divided by 10 raised to the power of the
number of digits in the fractional part ( k).
2. Semantic Rules:
R.val represents the numeric value of the floating-point string generated by the
production R -> N.N.
N.val represents the numeric value of the integer part of the floating-point string
generated by the production N -> N1 D.
N.val1 and N.val2 represent the numeric values of the integer parts of the left and
right sides of the decimal point in the floating-point string generated by the production
R -> N.N.
D.val represents the numeric value of a single digit in the floating-point string
generated by the productions N -> D and D -> 0|1|2|3|4|...|9.
Example:
R.val = N.val1 + N.val2 / 10.0 = 123.0 + 45.6 / 10.0 = 123.0 + 4.56 = 127.56