Inherited attribute is a natural choice ina)Tracking declaration of a ...
Explanation: These attribute keep a check on variable declaration
View all questions of this test
Inherited attribute is a natural choice ina)Tracking declaration of a ...
Inherited Attribute in Compiler Design
In the field of compiler design, the concept of attribute is used to associate certain properties with the programming constructs like variables, expressions, statements, etc. An attribute is a property or characteristic of a construct that is used by the compiler to generate the target code. There are two types of attributes in compiler design - Inherited and Synthesized.
Inherited Attribute
An inherited attribute is a property or characteristic of a programming construct that is determined by its parent constructs in the parse tree. In other words, the value of an inherited attribute is passed from the parent construct to its child constructs during the parsing process. The child constructs can use this value to determine their own attributes and properties.
Examples of Inherited Attribute
Some common examples of inherited attributes in programming constructs are:
- The type of a variable is an inherited attribute of its declaration.
- The scope of a variable is an inherited attribute of its declaration.
- The access modifier of a method is an inherited attribute of its declaration.
Natural Choice for Tracking Declaration of a Variable
In the context of tracking the declaration of a variable, the inherited attribute is a natural choice. When a variable is declared in a program, its scope and other properties are determined by its parent constructs like a block, function, class, etc. These parent constructs can pass on the necessary information about the variable to its child constructs using inherited attributes. The child constructs can then use this information to resolve the references to the variable and generate the target code.
Conclusion
Inherited attributes are an essential concept in compiler design and are used extensively in the parsing and code generation processes. They are a natural choice for tracking the declaration of a variable and other properties of programming constructs.