In syntax-directed definitions, what is the primary role of attributes associated with grammar symbols?
Think about what extra information is needed beyond just the structure of the language.
Attributes hold semantic information such as values or types that are computed during parsing to help understand the meaning of the input.
Which of the following correctly describes the difference between synthesized and inherited attributes?
Consider the direction of information flow in the parse tree.
Synthesized attributes flow upward from children to parent nodes, while inherited attributes flow downward from parent to children.
Given a syntax-directed definition with both synthesized and inherited attributes, which condition ensures that attribute evaluation can be done in a single bottom-up pass?
Think about which attribute type naturally fits bottom-up evaluation.
If all attributes are synthesized, they can be computed during a bottom-up traversal without needing information from parents, enabling a single pass.
Which statement correctly distinguishes S-attributed definitions from L-attributed definitions in syntax-directed definitions?
Focus on attribute types and evaluation order constraints.
S-attributed definitions have only synthesized attributes, making them easy to evaluate bottom-up. L-attributed definitions allow inherited attributes but restrict their use so evaluation can proceed in a single left-to-right pass.
Consider a syntax-directed definition designed to check type consistency in expressions. If the attribute rules fail to detect a type mismatch in an expression like a + true, what is the most likely cause?
Think about what part of the semantic rules enforces type correctness.
If the semantic rules lack checks for operator operand types, type mismatches like adding a boolean to a variable will not be detected.
