- Syntax trees resemble parse trees to an extent.
- In the syntax tree, interior nodes represent programming constructs while in the parse tree, the interior nodes represent nonterminals. Many nonterminals of a grammar represent programming constructs, but others are helpers of one sort of another, such as those representing terms, factors, or other variations of expressions.
- In syntax tree, these helpers typically are not needed and are hence dropped. To emphasize the contrast, a parse tree is sometimes called a concrete syntax tree, and underlying grammar is called a concrete syntax for the language.
- It is desirable for a translation scheme to be based on a grammar whose parse trees are as close to syntax trees as possible.
Define syntax-directed translation.
The syntax analyzer directs the whole process during the parsing of the whole code.
- Call the lexical analyzer, whenever syntax analyzer wants another token.
- Perform the action of semantic analyzer.
- Perform the action of intermediate code generator.
- The syntax directed translation makes user life easy by hiding many implementation detail and free the user from hiding to specify explicitly the order in which translation takes place.
Translation scheme basically indicates the order in which semantic rules are to be evaluated. The translation of token stream takes place by evaluating the semantic rules.
Basically the two notations, used to write semantic rules, are:
- Syntax Directed Definition
- Translation Scheme
Syntax directed definition is a high level notation and it hides the order in which the semantic rules are executed. Syntax directed definitions can be more readable, and hence more useful for specification.
The translation scheme specifies the order in which the semantic rules are executed. Translation scheme can be more efficient, and hence more useful for implementation.