Compilers (CS362 2004S)

Exploring Translation

Summary: In today's lab, you will explore the translation of Stupid, Sam's Totally Unintelligble Program Instruction Doohicky, to PAL, the pseduo-assembly language that I've written (okay, started to write) as an intermediate language for your compilers.

Contents:

Warning: Stupid, the Stupid translator, PAL, and this lab are under development. All of them probably have many bugs. Let me know which ones you notice.

Collaboration: Feel free to work on this lab in pairs or trios.

Turning It In: You do not need to turn in this lab. It is intended primarily for your edification.

Grading: Since you're not going to turn it in, I'm not going to grade it (not that I usually grade things anyway).

Preparation:

Switch your current working directory to my stupid directory with

cd  /home/rebelsky/Web/Courses/CS362/2004S/Examples/stupid

Background

Stupid, Sam's Totally Unintelligible Programing Instruction Doohicky, is a sample programming language I've written as an example of various issues we've discussed in class. You've explored aspects of Stupid earlier this semester.

Today you will examine a translator that turns STUPID programs into PAL programs. You may want to review the lab on PAL for more details of PAL and Stupid.

Exercises

Exercise 1: Stupid Basics

The goal of exercise 1 is to have you consider the form of the generated code and how that code relates to the original program.

a. Scan through the programs in the Examples subdirectory. See if you can determine what each one should do.

b. Execute each in turn with

% java stupid.Stupid Examples/____.stupid

Exercise 2: Translating Boolean Expressions

The goal of exercise 2 is to have you look more closely at code generation.

a. Look at StupidTranslator.java. How does the translation of Boolean expressions differ from the translation discussed in class?

b. Consider the following two uses of the Boolean expression x <> y

i. How might the generated code differ between the two?

ii. What happens when you try to compile the two?

iii. Why do you get different results?

Exercise 3: Adding Operations

One purpose of this part is to have you think more about the steps in translation. A second is to give you experience extending the translator.

Update the translateExpression method in StupidTranslator.java to handle subtraction and division in addition to addition and multiplication.

Test your changes.

Exercise 4: Adding Comparison Operations

The purpose of this part is to have you think more carefully about the translation of Booleans.

In Exercise 2, you observed that the translator cannot handle comparisons used in assignment statements. Update translateExpression so that it handles comparisons.

Exercise 5: Adding Boolean Operations

The purpose of this part is to have you think more carefully about the translation of Booleans.

Update translateBooleanExpression to handle ands and ors.

 

History

Monday, 2 December 2002 [Samuel A. Rebelsky]

Tuesday, 3 December 2002 [Samuel A. Rebelsky]

Thursday, 22 April 2004 [Samuel A. Rebelsky]

 

Disclaimer: I usually create these pages on the fly, which means that I rarely proofread them and they may contain bad grammar and incorrect details. It also means that I tend to update them regularly (see the history for more details). Feel free to contact me with any suggestions for changes.

This document was generated by Siteweaver on Wed May 5 11:46:50 2004.
The source to the document was last modified on Thu Apr 22 13:56:31 2004.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS362/2004S/Labs/translate.html.

You may wish to validate this document's HTML ; Valid CSS! ; Check with Bobby

Samuel A. Rebelsky, rebelsky@grinnell.edu