What is assignment statements with Integer types in compiler design?


Assignment statements consist of an expression. It involves only integer variables.

Abstract Translation Scheme

Consider the grammar, which consists of an assignment statement.

S → id = E

E → E + E

E → E ∗ E

E → −E

E → (E)

E → id

Here Translation of E can have two attributes −

  • 𝐄. 𝐏𝐋𝐀𝐂𝐄− It tells about the name that will hold the value of the expression.
  • 𝐄. 𝐂𝐎𝐃𝐄− It represents a sequence of three address statements evaluating the expression E in grammar represents an Assignment statement. E. CODE represents the three address codes of the statement. CODE for non-terminals on the left is the concatenation of CODE for each non-terminal on the right of Production.


                                                    Abstract Translation Scheme

ProductionSemantic Action
S → id = E{S. CODE = E. CODE| |id. PLACE| | '=. '||E. PLACE}
E → E(1) + E(2){T = newtemp( );
E. PLACE = T;
E. CODE = E(1). CODE | |E(2). CODE| |
E. PLACE
| | '=' | |E(1). PLACE | | '+' | |E(2). PLACE }
E → E(1) ∗ E(2){T = newtemp( );
 E. PLACE = T;
E. CODE = E(1). CODE | |E(2). CODE | |
E. PLACE | | '=' | |E(1). PLACE
| | '*' | |E(2). PLACE }
E → −E(1){T = newtemp( );
E. PLACE = T;
E. CODE = E(1). CODE
| |E. PLACE | | '=−' | |E(1). PLACE
 }
E → (E(1)){E. PLACE = E(1). PLACE;
E. CODE = E(1). CODE }
E → id{E. PLACE = id. PLACE;
 E. CODE = null; }

In the first production S → id = E,

id. PLACE| | '=' | | E. PLACE is a string which follows S. CODE = E. CODE.

In the second production E → E(1) + E(2),

E. PLACE| | '=' | | E(1). PLACE | | '+' | | E(2). PLACE is a string which is appended with E. CODE = E(1). CODE ||E(2). CODE.

In the fifth production, i.e., E → (E(1)) does not have any string which follows E. CODE = E(1). CODE. This is because it does not have any operator on its R.H.S of the production.

Similarly, the sixth production also does not have any string appended after E. CODE = null. The sixth production contains null because there is no expression appears on R.H.S of production. So, no CODE attribute will exist as no expression exists, because CODE represents a sequence of Three Address Statements evaluating the expression.

It consists of id in its R.H.S, which is the terminal symbol but not an expression. We can also use a procedure GEN (Statement) in place of S. CODE & E. CODE, As the GEN procedure will automatically generate three address statements.

So, the GEN statement will replace the CODE Statements.

GEN Statements replacing CODE definitions

ProductionSemantic Action
S → id = EGEN(id. PLACE = E. PLACE)
E → E(1) + E(2)GEN(E. PLACE = E(1). PLACE + E(2). PLACE
E → E(1) ∗ E(2)GEN(E. PLACE = E(1). PLACE ∗ E(2). PLACE
E → −E(1)GEN(E. PLACE = −E(1). PLACE)
E → (E(1))None
E → idNone

Updated on: 05-Nov-2021

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements