On this page:
1.1 A Bit of History
1.2 What does a Compiler look like?
1.3 What is CMSC 430?
1.4 How to write a Compiler?
1.5 Mechanics
1.6 What will we do?
1.7 What will you learn?
1.8 What do you need to know?
1.9 A few words on the medium of instruction
7.4

1 What is a Compiler?

A function that maps an input string to an output string.

compiler : String -> String

Typically, the input and output strings are “programs”

compiler : SourceProgram -> TargetProgram

For example, here are some well known compilers:

gcc, clang : C          -> Binary          (* a.out, .exe *)

ghc        : Haskell    -> Binary

javac      : Java       -> JvmByteCode     (* .class *)

scalac     : Scala      -> JvmByteCode

ocamlc     : Ocaml      -> OcamlByteCode   (* .cmo *)

ocamlopt   : Ocaml      -> Binary

gwt        : Java       -> JavaScript      (* .js *)

v8         : JavaScript -> Binary

nasm       : X86        -> Binary

pdftex     : LaTeX      -> PDF

pandoc     : Markdown   -> PDF | Html | Doc

Key Requirements on output program:

  1. Has the same meaning (“semantics”) as input,

  2. Is executable in relevant context (VM, microprocessor, web browser).

1.1 A Bit of History

Compilers were invented to avoid writing machine code by hand.

From Binary to FORTRAN

Richard Hamming – The Art of Doing Science and Engineering, p25:

In the beginning we programmed in absolute binary… Finally, a Symbolic Assembly Program was devised – after more years than you are apt to believe during which most programmers continued their heroic absolute binary programming. At the time [the assembler] first appeared I would guess about 1% of the older programmers were interested in it – using [assembly] was “sissy stuff”, and a real programmer would not stoop to wasting machine capacity to do the assembly.

John A.N. Lee, Dept of Computer Science, Virginia Polytechnical Institute

One of von Neumann’s students at Princeton recalled that graduate students were being used to hand assemble programs into binary for their early machine. This student took time out to build an assembler, but when von Neumann found out about it he was very angry, saying that it was a waste of a valuable scientific computing instrument to use it to do clerical work.

1.2 What does a Compiler look like?

Compiler Pipeline

An input source program is converted to an executable binary in many stages:

1.3 What is CMSC 430?

A sequel to both those classes.

1.4 How to write a Compiler?

General recipe, applies to any large system

We will

(Yes, loops forever, but we will hit Ctrl-C in 15 weeks...)

1.5 Mechanics

See Syllabus.

1.6 What will we do?

Write a compiler for NanoML -> X86

But Rome wasn’t built in a day … and neither is any serious software.

Rome wasn’t built in a day

So we will write many compilers:

1.7 What will you learn?

Core principles of compiler construction

Several new languages

More importantly how to write a large program

1.8 What do you need to know?

This 430 depends very heavily on CMSC 330.

Also depends on CMSC 216

1.9 A few words on the medium of instruction

We will use Racket which, for our purposes is like Ocaml but with nicer syntax.1To start a good flamewar just post this anywhere online where Haskell and OCaml folks can see it.

Racket has many advanced features beyond what you saw in 330, but we won’t be using them; in the few cases we do, I’ll explain them as we go.

1To start a good flamewar just post this anywhere online where Haskell and OCaml folks can see it.