Order of attribute evaluation | Attributes are calculated as we traverse the parse tree from leaves to root, allowing attributes to depend on children and siblings. | Attributes are evaluated in a single pass from root to leaves, with restrictions on which attributes can depend on each other. |
Dependency restrictions | No strict rules on attribute dependencies. | Some rules limit where attributes can get their values from, especially for inherited attributes. |
Evaluation strategy | Typically uses bottom-up evaluation, computing synthesized attributes as we move up the tree. | Typically uses top-down evaluation, passing inherited attributes down the tree. |
Example | In arithmetic expressions, the value of an expression depends on the values of its parts, so it’s S-attributed. | In type checking, the type of an expression might depend on its context, so it’s often L-attributed. |