Javatpoint Logo
Javatpoint Logo

Translation of Assignment Statements

In the syntax directed translation, assignment statement is mainly deals with expressions. The expression can be of type real, integer, array and records.

Consider the grammar

The translation scheme of above grammar is given below:

Production rule Semantic actions
S → id :=E {p = look_up(id.name);
 If p ≠ nil then
 Emit (p = E.place)
 Else
 Error;
}
E → E1 + E2 {E.place = newtemp();
 Emit (E.place = E1.place '+' E2.place)
}
E → E1 * E2 {E.place = newtemp();
 Emit (E.place = E1.place '*' E2.place)
}
E → (E1) {E.place = E1.place}
E → id {p = look_up(id.name);
 If p ≠ nil then
 Emit (p = E.place)
 Else
 Error;
}
  • The p returns the entry for id.name in the symbol table.
  • The Emit function is used for appending the three address code to the output file. Otherwise it will report an error.
  • The newtemp() is a function used to generate new temporary variables.
  • E.place holds the value of E.






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA