Thursday, March 24, 2016

Define different types of translation with example


A translation is an input/output mapping. Generally three types of translation scheme are used -

  • Three Address Statements
  • Quadruples &
  • Triples

Three Address Statements : Three address statements are a sequence of statements.
Typically, the general form A : B op C, where A, & C are either programmer defined names. Constants or compiler - generated temporary names. Op stands for any operator, such as a fixed or floating -point arithmatic operator or a logical operator on Boolean -valued data. Three address statements usually contain  three addresses, two for the operands & one for the result.

Example : Let us consider the expression A : = -B*(C+D).

We get the following three-address code from the expression : 

T1 : = -B
T2 : = C+D
T3 : = T1+T2
A : = T3

Quardruples : Quadruples representation the three - address code by using four fields
These are -
                    OP, ARG1, ARG2 & RESULT.
Implementation of quadruples : Let us consider the following three - address code : 
T1 : = -B
T2 : = C+D
T3 : = T1+T2
A : = T3
These statement are represented by quadruples as shown in fig . (a) 

SL NO OP ARG1 ARG2 RESULT
(0) Uminus B - T1
(1) + C D T2
(2) * T1 T2 T3
(3) := T3 - A

Fig. (a) quadruple representation of three -address statements.


Triple : Triple representation the three address code by using three fields. 
These are -
                    OP, ARG1, ARG2.
So, we use parenthesized number to represent pointer into the triple structure.while symbol-table pointers are represented by names themselves.
Implementation of quadruples : Let us consider the following three - address code : 
T1 : = -B
T2 : = C+D
T3 : = T1+T2
A : = T3
 These statement are represented by quadruples as shown in fig . (a) 


SL NO OP ARG1 ARG2
(0) Uminus B -
(1) + C D
(2) * (0) (1)
(3) := A (2)

Fig. (b) triple representation of three -address statements.


                                       
 
If You want to learn about the technology, computer science & engineering, web programming, freelancing, earning please click here :CSE SOLVE

0 comments:

Post a Comment