[Skip to Body]
Primary:
[Front Door]
[Current]
[Glance]
-
[Honesty]
[Instructions]
[Links]
[Search]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Project]
[Readings]
[Reference]
Misc:
[2001S]
[2002F]
[SamR]
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
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.
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
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
b := x <> y
if (x <> y) then b := true else b:= false;
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?
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.
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.
The purpose of this part is to have you think more carefully about the translation of Booleans.
Update translateBooleanExpression
to handle ands and ors.
Monday, 2 December 2002 [Samuel A. Rebelsky]
Tuesday, 3 December 2002 [Samuel A. Rebelsky]
Thursday, 22 April 2004 [Samuel A. Rebelsky]
[Skip to Body]
Primary:
[Front Door]
[Current]
[Glance]
-
[Honesty]
[Instructions]
[Links]
[Search]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Project]
[Readings]
[Reference]
Misc:
[2001S]
[2002F]
[SamR]
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
;
;
Check with Bobby