What is the difference between S-attributed and L-attributed definitions?

March 27, 2024 · By Team EasyExamNotes · 1 min read (est.) · 0 comments

Share on WhatsApp
AspectS-attributed DefinitionsL-attributed Definitions
Order of attribute evaluationAttributes 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 restrictionsNo strict rules on attribute dependencies.Some rules limit where attributes can get their values from, especially for inherited attributes.
Evaluation strategyTypically uses bottom-up evaluation, computing synthesized attributes as we move up the tree.Typically uses top-down evaluation, passing inherited attributes down the tree.
ExampleIn 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.

Discussion

Ask a question, share your thoughts or report an error.

Sign in to participate in the discussion.

Join the discussion