6.1 Attributes and attribute Grammars
6.1 Attributes and Attribute Grammars
Attributes Any property of a programming language construct such as The data type of a variable The value of an expression The location of a variable in memory The object code of a procedure The number of significant digits in a number Binding of the attribute The process of computing an attribute and associating its computed value with the language construct in question Binding time The time during the compilation/execution process when the binding of an attribute occurs Based on the difference of the binding time, attributes is divided nto Static attributes (be bound prior to execution and dynamic attributes (be bound during execution)
• Attributes – Any property of a programming language construct such as • The data type of a variable • The value of an expression • The location of a variable in memory • The object code of a procedure • The number of significant digits in a number • Binding of the attribute – The process of computing an attribute and associating its computed value with the language construct in question • Binding time – The time during the compilation/execution process when the binding of an attribute occurs – Based on the difference of the binding time, attributes is divided into Static attributes (be bound prior to execution) and Dynamic attributes (be bound during execution)
Example: The binding time and significance during compilation of the attributes Attribute computations are extremely varied ype checker In a language like C or Pascal, is an important part of semantic analysis While in a language like LiSP, data types are dynamic, LISP compiler must generate code to compute types and perform type checking during program execution The values of expressions Usually dynamic and the be computed during execution But sometime can also be evaluated during compilation (constant folding)
• Example: The binding time and significance during compilation of the attributes. – Attribute computations are extremely varied – Type checker • In a language like C or Pascal, is an important part of semantic analysis; • While in a language like LISP , data types are dynamic, LISP compiler must generate code to compute types and perform type checking during program execution. – The values of expressions • Usually dynamic and the be computed during execution; • But sometime can also be evaluated during compilation (constant folding)
Example: the binding time and significance during compilation of the attributes Attribute computations are extremely varied The allocation of a variable Either static(such as in FORTRAN77)or dynamic(such as in LISP) Sometimes it is a mixture of static and dynamic(such as in C and Pascal) depending on the language and properties of the variable itself. Object code of a procedure A static attribute, which is computed by the code generator Number of significant digits in a number Often not explicitly treated during compilation
• Example: the binding time and significance during compilation of the attributes. – Attribute computations are extremely varied – The allocation of a variable: • Either static (such as in FORTRAN77 ) or dynamic (such as in LISP), • Sometimes it is a mixture of static and dynamic (such as in C and Pascal) depending on the language and properties of the variable itself. – Object code of a procedure: • A static attribute, which is computed by the code generator – Number of significant digits in a number: • Often not explicitly treated during compilation
6.1.1 Attribute grammars
6.1.1 Attribute Grammars