Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Synthesized vs Inherited Attributes

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.

like image 353
user2047167 Avatar asked Apr 11 '15 10:04

user2047167


People also ask

What is synthesized and Inherited attributes?

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.

What are synthesized attributes?

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.

What is attribute inheritance?

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.

What are the two types of attributes for syntax directed translation?

Syntax-directed translation rules use 1) lexical values of nodes, 2) constants & 3) attributes associated with the non-terminals in their definitions.


2 Answers

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.

like image 136
Am_I_Helpful Avatar answered Sep 19 '22 11:09

Am_I_Helpful


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.

like image 20
Adnan Lodhi Avatar answered Sep 19 '22 11:09

Adnan Lodhi