Syntax-directed Translations

1. What is syntax-directed translation? Explain.

Ans: Syntax-directed translation (SDT) is an extension of context-free grammar (CFG) which acts as a notational framework for the generation of intermediate code. It embeds program fragments (called semantic actions) within the production bodies. For example, as in

A → A1 * B {print ‘*’}

In SDT, by convention, we use curly braces to enclose semantic actions. If the grammar symbols contain curly braces, then we enclose them in single quotes as ‘{’ and ‘}’. The order of execution of semantic actions is determined by the position of a semantic action in a production body. Here, in the above example, the action occurs at the end, that is, after all the grammar symbols. ...

Get Express Learning: Principles of Compiler Design now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.