Overview
In the third part of the course, you’ll take the first steps towards creating a programming language. You’ll learn the basics of creating an interpreter for BASIC (Beginner’s All-purpose Symbolic Instruction Code), which was introduced in 1964. BASIC was one of the first high-level programming languages with a design goal of being easy to learn and use.
The manual for the original Dartmouth BASIC, which was developed at Dartmouth College, is available here. As you notice, there’s a lot to BASIC — thus, we will only focus on a subset of BASIC interpreter.
The structure of this part is as follows.
-
BASIC Basics introduces the BASIC programming language, covering the structure and syntax of BASIC programs, from producing output and using variables to control flow structures.
-
Building an Interpreter: Architecture and Design explains what an interpreter is, the stages of interpretation (lexing, parsing, and execution), and sets up the project structure for our BASIC interpreter.
-
Tokens and Lexing covers how to define token types using enums and build a lexer that transforms raw text into tokens using peekable iterators.
-
Parsing Tokens to Expressions and Statements shows how to define expressions and statements, and how to build a parser that transforms tokens into a structured representation of the program.
-
Interpreting Programs implements the interpreter itself, including expression evaluation, variable storage, and the main execution loop with support for control flow.
-
Read-Eval-Print Loop (REPL) and User Interface builds an interactive command-line interface for the interpreter, with commands for running, listing, saving, and loading programs.
-
Testing and Test Coverage discusses the difference between unit tests and integration tests, and introduces tools for measuring test coverage in Rust.
-
Go To Statement Considered Harmful explores the historical context of the GOTO statement, Dijkstra’s famous critique, and the Böhm-Jacopini theorem that showed GOTO is not necessary for computation.
-
FUN with Functions extends the interpreter with subroutines (GOSUB/RETURN) using a call stack, and implements simple single-expression functions with DEF FN.
-
Recap and Feedback summarizes what we’ve built and provides an opportunity for feedback.
By the end of this part, you will have built a working BASIC interpreter in Rust that supports variables, arithmetic expressions, control flow with IF and GOTO, subroutines, and simple functions.