Syntax Directed Translation


Use attribute grammars, where productions are supplemented with information to control semantic analysis and translation.

Associate attributes with each grammar symbol to describe its properties.

For each production add semantic rules (aka semantic actions) to compute attribute values.

dig 0 { dig.val = 0 } 1 { dig.val = 1} … 9 { dig.val = 9}

Decorated Syntax of a Digit

dig { .val = dig.val } | dig { .val = .val * 10 + dig.val }

decorated-parse-tree

See Also