Homework 01
Analyzing a Data Description Language
Out: Friday, August 29
Due: Friday, September 5, at 11:59 AM
Background
In order to write a compiler, we need to study the source language in some detail. Programming languages can be quite complex. Sometimes, it's good to practice on a smaller or simpler language first.
This assignment asks you to study a simple data description language and use it to think more deeply about the stages of a compiler that we learned about in Session 1 and Session 2.
Tasks
Study the DOT graph description language that we
encountered in Session 1.
There is a lot of documentation on DOT in the world. Here are
the three simple sources I'd like you study for this assignment:
- Making Diagrams with Graphviz
- a simple example of an unadorned digraph
- a simple example of a digraph with attributes
If you'd like to learn more about DOT (it's a cool and useful little language!), check out the DOT page at Wikipedia or search for more resources. For this assignment, though, you can limit your study to the three items listed here.
Now, do these tasks:
-
Use the DOT language to create your own version of this
"six stages of the compiler" diagram
we saw in Session 1:
Feel free to create a different layout for the figure, if you prefer.
To do this, create a plaintextsix-stages.dotfile with the DOT code you need. -
Download
Graphviz
for your computer and use it to create a graphic from your DOT
program. Save your image as a
six-stages.pngorsix-stages.jpgfile.
The Graphviz site offers downloadable binaries for Windows and source directories for Linux and OS X. If you use a Mac and would like to skip the process of building a binary from source, try downloading this zip file and expanding. It's the Mac binary I've been using happily for years.
If none of these work for you, you can use the command-line Dot compiler available onstudent.cs.uni.edu.Using Dot on
Here are instructions working at a command line in a shell. If you don't know how to do that in your environment, let me know, and we can discuss options.student.cs.uni.edu-
Copy your
six-stages.dottostudent:scp six-stages.dot [your-catid]@student.cs.uni.edu:
-
Log in to
student:ssh [your-catid]@student.cs.uni.edu
-
Run the Dot compiler:
dot six-stages.dot -Tpng > six-stages.png
-
Log out of
student:<ctrl-d>
-
Copy your
six-stages.dotimage fromstudent:scp [your-catid]@student.cs.uni.edu:six-stages.png .
-
Copy your
-
Describe how Graphviz might process DOT programs, in terms of
Session 1's six components of a compiler. (This is similar
to what I did for a hypothetical compiler working on the two
lines of pseudocode in the second half of Session 1.)
A few questions you might consider as you think about the DOT language and translating it to something else:- What output will each stage of the compiler produce?
- How might different target languages affect how the compiler works?
- Which parts of the compiler will be relatively easy to write?
- Which parts will be relatively hard to write?
six-stages.txt.
I realize that you are just beginning your study of compilers. I will take that into account as I read your analysis. However, as a CS student, you have used at least two different compilers, written programs in at least two different languages, and have one week of reading and lecture under your belt. This is a good time to begin applying what you know to think about a new language.
Two pages is a reasonable length for this analysis. If you really want to write more, let me know. If you really want to write less, you may not be thinking deeply enough about the issues.
Deliverables
By the due time and date, use the course submission system to submit the following files electronically:
six-stages.dot-
six-stages.pngorsix-stages.jpg -
six-stages.txtorsix-stages.pdf
six-stages.dot must be a plaintext file.
No hard copy is required.