[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]
Back to A Quick Introduction to Pascal (1). On to Translation.
Held: Wednesday, 28 January 2004
Summary: Today we consider the main languages involved in a sample compiler: the output language (PAL) and the input language (STUPID).
Related Pages:
TestPAL.java, a sample program.Notes:
Homeworkor
Assignmentis your submission of the assignment. If you need help on the assignment, you should title your email
Help!or something similar.
to dolist just got insanely long. I probably won't respond to your surveys until early next week.
Overview:
treesof code (surprisingly useful to build during compilation).
import java.io.PrintWriter;
import rebelsky.pal.*;
public class TestPAL
{
public static void main(String[] args)
throws Exception
{
PrintWriter out = new PrintWriter(System.out,true);
Computer hal = new Computer(1000);
Temporary input = new Temporary();
Temporary result = new Temporary();
Label startLabel = new Label("START");
Label endLabel = new Label("END");
InstructionSequence convert = new InstructionSequence();
Temporary f = new Temporary();
convert.add(new Label("CONVERT"));
convert.add(new Comment("Experiments with Conversion"));
convert.add(new FWrite(input));
convert.add(new I2F(input,f));
convert.add(new FWrite(f));
InstructionSequence count = new InstructionSequence();
Label countloop = new Label("LOOP");
Label endcount = new Label("END");
Temporary counter = new Temporary();
count.add(new Comment("Print numbers from 1 to 10"));
count.add(new Label("COUNT"));
count.add(new Move(new IConstant(1), counter));
count.add(countloop);
count.add(new IWrite(counter));
count.add(new JumpLessEqual(new IConstant(10), counter, endcount));
count.add(new IAdd(new IConstant(1), counter, counter));
count.add(new Jump(countloop));
count.add(endcount);
InstructionSequence code = new InstructionSequence();
code.add(new Comment("Read values and test until 0 entered."));
code.add(startLabel);
code.add(new IRead(input));
code.add(new IWrite(input));
code.add(new IAdd(new IConstant(3), input, result));
code.add(new IWrite(result));
code.add(convert);
code.add(new JumpNotEqual(input, new IConstant(0), startLabel));
code.add(count);
code.add(endLabel);
code.add(new Halt());
hal.setCode(code);
out.println("----- DUMP -----");
hal.dump(out);
out.println("----- RUN ------");
hal.run(true);
} // main(String[])
} // class TestPAL
Sam's Totally Unintelligible Programming Instrution Doohickey.
Sam's Amazingly Minor Programming Language Example.
var x: integer; begin read(x); write(x+2); end
Back to A Quick Introduction to Pascal (1). On to Translation.
[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:56 2004.
The source to the document was last modified on Tue Jan 20 23:06:45 2004.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS362/2004S/Outlines/outline.04.html.
You may wish to
validate this document's HTML
;
;
Check with Bobby