S-Attributed Definitions

An SDD is S-attributed if every attribute is synthesized. Attributes of an S-attributed SDD can be evaluated in bottom-up order of the nodes of parse tree. Evaluation is simple using post-order traversal.

postorder(N) {
for (each child C of N, from the left)
postorder(C);
evaluate attributes associated with node N;
}

S-attributed definitions can be implemented during bottom-up parsing as
– bottom-up parse corresponds to a postorder traversal
– postorder corresponds to the order in which an LR parser reduces a production body to its head

0 comments