Overview of the code

Code you will write or edit

asmparse.sml

Toy parser and unparser for assembly code. You will build a real unparser this week and a real parser next week.

Before looking at this file, look at and understand two sets of other files:

  • The language being parsed and unparses is defined by asm.sml and object-code.sml.

  • The parsing combinators are declared in producer-sig.sml.

Code you will look at and understand

asm.sml

The internal representation of assembly code.

object-code.sml

The internal representation of virtual object code, plus a module that unparses this representation to its on-disk form.

error-sig.sml

The interface to our version of the error monad.

producer-sig.sml

The interface to our library of parsing combinators.

escapes.sml

Exports function StringEscapes.quote, which will be useful for unparsing string literals.

impossible.sml

Defines function Impossible.impossible, which you’ll call if you ever need to signify an assertion failure.

Code you may look at, but not deeply

all.cm

This file lists, directly or by reference, all the ML code used to build the UFT, except main.sml. It’s worth looking at now because it will give you some sense of the pieces that make up the UFT.

asmlex.sml

My lexical analyzer for assembly language: it uses a combinator parser to convert a sequence of characters into a sequence of tokens. It may be worth looking at as an example of combinator parsing. And if you are ambitious, you may wish to modify it.

Code you will look at eventually, but not necessarily this week

assembler.sml

The heart of the assembler. Function Assembler.translate translates an assembly-language program into object code. Right now it’s just a stub: it extracts object-code instructions embedded in assembly language, and if it encounters anything else, it barfs. It will suffice to allow you to assemble code that doesn’t use labels.

Next week you will write a real version of Assembler.translate.

languages.sml

Lists all the languages the UFT will eventually understand.

uft.sml

The Universal Forward Translator. It is given a source language and a target language, and it figures out how to translate the source to the target.

env.sml

An environment abstraction. You’ll use it next week to save the meanings of assembly-language labels.

Code you may never look at

File error-module.sml implements the error monad, and producer-functor.sml implements our parsing combinators. You will have learned all the good stuff either in lab (parsing combinators) or preparing for lab (error monad).

File main.sml reads the command line and calls the UFT; main.cm builds it.

File impossible.cm works around an annoyance in Moscow ML’s build process.

File ioutil.sml defines a few convenience functions that I wish were in the Standard ML basis library, but aren’t.