Consider the SDD P → QR { Q.val = R.val } A →*BC { A.val = B .val × C.val}…
Consider the SDD
P → QR { Q.val = R.val }
A →*BC { A.val = B .val × C.val}
Which of the following is true?
Answer: D. Q.val is inherited attribute and A.val is synthesized attribute. — Synthesized attribute: A synthesized attribute at node N is defined only in terms of attribute values at the children of N and at N itself. Inherited…
- A.
Q.val is synthesized attribute and A.val is inherited attribute.
- B.
Q.val is synthesized attribute but A.val is not an inherited attribute.
- C.
Q.val is inherited attribute but A.val is not a synthesized attribute.
- D.
Q.val is inherited attribute and A.val is synthesized attribute.
Attempted by 70 students.
Show answer & explanation
Correct answer: D
Synthesized attribute: A synthesized attribute at node N is defined only in terms of attribute values at the children of N and at N itself.
Inherited attribute: An inherited attribute at node N is defined only in terms of attribute values at N's parent, N itself, and N's siblings.
For the production P → Q R with the semantic rule Q.val = R.val: Q.val is an inherited attribute. This assignment defines Q.val using its sibling R (the rule is given at the parent), so Q.val depends on a sibling value and is therefore inherited.
For the production A → B C with the semantic rule A.val = B.val × C.val: A.val is a synthesized attribute. It is computed from the attribute values of its children B and C, so A.val is synthesized.
Conclusion: Q.val is an inherited attribute and A.val is a synthesized attribute.