Labs

Lab 6.3: Generating Code

Rosetta Help

Print
References

The code generating part of our translator program starts with the parse tree1 for a statement, and uses it to produce a list of PIPPIN2 instructions that correspond to the original statement. Let's use Rosetta, now, to demonstrate code generation.

  1. Start as we did in the previous lab, by entering and setting the equation: W = X * (2 + Y) into Rosetta's equation window.

  2. Now, click on "Code Generation" in the control panel at the bottom of the program window. Notice that the parse tree is generated immediately, since that is the starting point for code generation.

  3. Then, click the "Play" button to watch Rosetta produce PIPPIN instructions as it works its way through the parse tree. Examine the PIPPIN code along the right side of the program window to convince yourself that it corresponds to the original statement.

  4. Hit the "Reset" button, and then "Step" through the code generation to see which PIPPIN statements correspond to which branches of the parse tree.

  5. Repeat steps 1-4 to generate code for the following equation:
    X = (3 * Y) + (2 /W)
    
  6. For each of the following statements, determine - without using Rosetta! - the PIPPIN code that would be generated for it. Then, use Rosetta to verify your answers.
    1. Y = Z * 3 - X
    2. X = (Y + 5) /2
    3. Z = (W * W) + (X * X)


  7. For each of the PIPPIN code segments below, find a statement that corresponds to it. Use Rosetta to confirm your suspicions.
    1.         LOD Z
              DVI #2
              STO X
      
    2.         LOD Z
              DVI #2
              MUL Y
              STO X
      
    3.         LDI #2
              MUL Y
              STO T1
              LOD Z
              DIV T1
              STO X
      
1pp. 223, 224–225, 306
2pp. 210–213, 215, 227–228, 260

Labs

MODULES:


Home Search Resources Objectives Feedback Order Form Credits

Copyright Notice
© 1998 PWS Publishing Company, All Rights Reserved.