How can I find if an attribute is synthesized or inherited from the productions of a grammar?
I guess for that the attribute must be predefined in the problem -- if its value depends on child or parent nodes. But is there a way to analyse if an attribute is inherited or synthesized from grammar productions.
An attribute is said to be Synthesized attribute if its parse tree node value is determined by the attribute value at child nodes whereas 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.
Synthesized 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.
An inherited attribute is one that is inherited from a parent product class. You customize an inherited attribute domain by editing its definition at the subclass level. When you edit an inherited attribute definition, the changes propagate to all members of the subclass, including other subclasses under that subclass.
Syntax-directed translation rules use 1) lexical values of nodes, 2) constants & 3) attributes associated with the non-terminals in their definitions.
Synthesized Attribute: An attribute that gets its values from the attributes attached to the children of its non-terminal.
Inherited Attribute: An attribute that gets its values from the attributes attached to the parent (or siblings) of its non-terminal.
**PRODUCTION** **SEMANTIC RULES**
T->FT’ T’.inh=F.val
T.val=T’.syn
T’->*FT1’ T1’.inh=T’.inh*F.val
T’.syn=T1’.syn
T’->Ɛ T’.syn=T’.inh
F->id F.val=id.lexval
As you can see from the given grammar rules(productions), inh is an inherited attribute and syn is a synthesized attribute.
Further Read: Attribute Grammars.
The attribute which takes data values from its child nodes is called a synthesized attribute.
These are also called s-attributed production. The attribute which takes values from parents or sibling nodes is called inherited attributes. The production rule having inherited attribute(Each inherited attributes is restricted to inherit either from a parent or left sibling only) are called L-attributed productions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With