Figure 1.7. Translation of an assignment statement

 

p = x + v * 60

 

Lexical Analysis

 

<id,1> <=> <id,2> <+> <id,3> <*> <60>

 

Syntax Analysis

 

assn

/    |    \

id   =   expr

  /         /    |    \

      p     expr  +  expr

               |         /    |    \

                 id    expr   *  expr

                |        |            |

                    x      id        const

                         |            |

                          v          60

 

Semantic Analysis

 

=

  /         \

<id,1>        +

                  /      \

          <id,2>         *

                          /       \

                        <id,3>    int2float

                                     |

                                    60

 

Intermediate Code

 

t1   = int2float(60)

t2   = id3 * t1

t3   = id2 + t2

id1 = t3

 

Code Optimization

 

t1   = id3 * 60.0

id1 = id2 + t1

 

Code Generator

 

LDF  R2,  id3

MULF R2,  R2, #60.0

LDF  R1,  id2

ADDF R1,  R1, R2

STF  id1, R1