Synthesized vs Inherited Attributes

user2047167 picture user2047167 · Apr 11, 2015 · Viewed 25k times · Source

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.

Answer

Am_I_Helpful picture Am_I_Helpful · Apr 11, 2015

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.