Inherited Attributes
. an inherited attribute is one whose value is defined in terms of attributes at the parent and/or siblings
. Used for finding out the context in which it appears
. possible to use only S-attributes but more natural to use inherited attributes
D T L |
L.in = T.type
|
T real |
T.type = real
|
T int |
T.type = int
|
L L1 , id |
L1 .in = L.in; addtype(id.entry, L.in)
|
L id |
addtype (id.entry,L.in)
|
Inherited attributes help to find the context (type, scope etc.) of a token e.g., the type of a token or scope when the same variable name is used multiple times in a program in different functions. An inherited attribute system may be replaced by an S -attribute system but it is more natural to use inherited attributes in some cases like the example given above.
Here addtype(a, b) functions adds a symbol table entry for the id a and attaches to it the type of b .
|