Home » Syntax directed Translation

Syntax directed Translation

by Online Tutorials Library

Syntax directed translation

In syntax directed translation, along with the grammar we associate some informal notations and these notations are called as semantic rules.

So we can say that

  • In syntax directed translation, every non-terminal can get one or more than one attribute or sometimes 0 attribute depending on the type of the attribute. The value of these attributes is evaluated by the semantic rules associated with the production rule.
  • In the semantic rule, attribute is VAL and an attribute may hold anything like a string, a number, a memory location and a complex record
  • In Syntax directed translation, whenever a construct encounters in the programming language then it is translated according to the semantic rules define in that particular programming language.

Example

Production Semantic Rules
E → E + T E.val := E.val + T.val
E → T E.val := T.val
T → T * F T.val := T.val + F.val
T → F T.val := F.val
F → (F) F.val := F.val
F → num F.val := num.lexval

E.val is one of the attributes of E.

num.lexval is the attribute returned by the lexical analyzer.

You may also like