Skip to main content

Week 1 Studio: Getting started

Toolchain setup, and a skeleton hand-rolled lexer that recognises integer literals — the smallest thing the course can call a running compiler

22 February 2027

Before the session

Arrive with an OCaml toolchain installed: an opam switch and dune for building. The setup page has the exact switch-creation steps and the versions this course’s own reference implementation was built against — follow it and confirm dune build runs before you arrive. If you have never set one up before, budget real time for this — a broken toolchain on day one costs you every week after it, and it is much cheaper to fix before the course needs it for anything.

If you’ve never written OCaml before, the OCaml crash course is a short, scoped-down read — let, pattern matching, and variant types, the three things this week’s lexer actually uses, with real code from it.

Skim the lecture’s naming-dispute aside again before you arrive. You will be asked, briefly, which account you’d trust and why.

In the session

Sample transcript

Genuine captured output from this course’s own week-1 reference lexer, run against a three-line file of bare integer literals:

$ dune exec bin/main.exe -- examples/digits.sno
INT 42
EOF
INT 7
EOF
INT 100
INT 200
EOF

The third line, 100 200, is the one worth tracing by hand: it holds two literals separated (and preceded) by blanks, and the only thing this week’s lexer has to get right is that a run of digits becomes one INT token while a blank is just a separator — the trace should show a single EOF closing that line, not one per literal.

This week’s real starter — the same lexer skeleton with the digit-recognition rule itself stubbed out — is downloadable at week-01-starter.zip.

Afterwards

What you build this week is the foundation the next three weeks extend directly — the arithmetic lexer in week 2, the parser in week 2–3, and the evaluator in week 4 all sit on top of this file rather than replacing it. Keep it; you’ll be growing it, not rewriting it.

The spec

What you bring to the session. Written so a reader can tell whether it has been met without asking you.

Teaching team