Difference between Synthesized and Inherited Attributes


Both Synthesized and Inherited Attribute are the part of semantics of a language that provide meaning to its constructs, like tokens and syntax structure. Semantics help interpret symbols, their types, and their relations with each other and its analysis judges whether the syntax structure constructed in the source program derives any meaning or not. Now on the basis of features of attributes we can distinguish between Synthesized and Inherited Attributes

Following are the important differences between Synthesized and Inherited Attributes.

Sr. No.KeySynthesized AttributeInherited Attribute
1DefinitionSynthesized attribute is an attribute whose parse tree node value is determined by the attribute value at child nodes.To illustrate, assume the following production S → ABC if S is taking values from its child nodes (A, B, C), then it is said to be a synthesized attribute, as the values of ABC are synthesized to S.On other hand an attribute is said to be Inherited attribute if its parse tree node value is determined by the attribute value at parent and/or siblings node. In case of S → ABC if A can get values from S, B and C. B can take values from S, A, and C. Likewise, C can take values from S, A, and B then S is said to be Inherited Attribute.
2DesignAs mentioned above in case of Synthesized attribute the production must have non-terminal as its head.On other hand in case of Inherited attribute the production must have non-terminal as a symbol in its body.
3EvaluationSynthesized attribute can be evaluated during a single bottom-up traversal of parse tree.While on other hand Inherited attribute can be evaluated during a single top-down and sideways traversal of parse tree.
4TerminalBoth terminal and Non terminals can contain the Synthesized attribute.On other hand only Non terminals can contain the Inherited attribute.
5UsageSynthesized attribute is used by both S-attributed SDT and L-attributed STD.On other hand Inherited attribute is used by only L-attributed SDT.

Updated on: 09-Jun-2020

16K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements