Syntax Directed Translation

In this class, We discuss Syntax Directed Translation.

For Complete YouTube Video: Click Here

The reader should have prior knowledge of semantic analysis basics. Click Here.

In this class, we understand the textbook terminology required for the next classes.

The below function shows the program for expression grammar discussed in our previous class.

Syntax Directed Translation:

Why does it get the name syntax-directed translation?

We are writing extra code during the syntax analysis phase to check the semantic conditions.

So we got the name syntax-directed translation.

Syntax Directed Definition:

We write the syntax-directed definition to check semantic conditions during syntax analysis.

Syntax directed Definition is CFG + Semantic rules.

Example:

Production ——– Semantic Rule

E – E + T ————-E.val = E1.val + T.val

E – T ——————-E.val = T.val

F – id —————— F.val = id.lexval

The semantic rule says the action taken during the expansion or reduction of the production.

lexval is the value obtained from the lexical analysis phase.

Attribute: E.va = T.val. Here val is called attribute.

From a programming perspective val is a variable to holds any value. The value may be an integer, Float, String, etc.

We implement the semantic rules mentioned in the program of syntax analysis.