Site icon i2tutorials

Compiler Design-Postfix Notation

Postfix Notation

 

It is a linear representation of syntax tree

Example:

      1. A * ( b + c )

Sol: abc + *

      2. ( a * b ) + ( c / d )

Sol: a b * c d ? +

      3.  a * ( b * c ) + d

Sol: a b * c d + / e *

      4. ( a * b ) / ( c + d ) * e

Sol: a b * c d + / e * 

5.  A + ( ( b * c ) ) ( e ↑ f ) ) + ( b * c )

Sol: a b c * e f ↑ / + b c * +

 

Three Address Code Representation

Example: 

S = ( x + y ) * ( a / b )

T1 = x + y

T2 = a/b

T3 = T1 * T2  (or)  S + T1 * T2

S = T3

 

Each instruction contains utmost 3 arrdesses 2 on right hand side of expression & 1 on left hand side utmost 1 operator on RHS.

3 add code can be represented in 3 ways:

  1. Quadruple
  2. Triple
  3. Indirect triple

 

Reference Link

Postfix Notation

Exit mobile version