This project is an implementation of a PL/0 compiler written in Common Lisp. The goal is to study compiler construction by following Wirth’s classic PL/0 language, while exploring modern backends such as WebAssembly (WASM).
PL/0 is a small teaching language introduced by Niklaus Wirth in Algorithms + Data Structures = Programs (1976).
It has:
- Constants, variables, and procedures
- Arithmetic expressions and conditions
- Control flow with
if
andwhile
- Structured blocks using
begin ... end
It is deliberately minimal, making it ideal for educational compiler projects.
- The language has been updated with comments (//) and types.
- The language supports explicit 32-bit integer delcarations.
// Example pl0 program
const int max = 10;
int x, y, sum;
// Procedure 'add' adds 2 integers
procedure add;
begin
sum := x + y;
end;
// Main program block
begin
x := 3;
y := 5;
call add;
end.
src/
lexer.lisp ; Tokenizer for PL/0 source code
ast.lisp ; Abstract syntax tree (AST) definitions
parser.lisp ; Recursive-descent parser for PL/0 grammar
analyzer.lisp : Symbol table generator and symantic checking
emitter.lisp ; Code generator for IR / WASM
main.lisp ; Main program driver
tests/
*.pl0 ; Example PL/0 programs for testing
- Common Lisp implementation (tested with SBCL and CCL)
- Quicklisp package manager
- SLIME for Emacs integration (recommended)
Clone the repository:
git clone https://github.com/asuttles/andy.git
cd andy
(ql:quickload :andy)
(andy.main:compile-source "tests/test1.pl0")
Niklaus Wirth, Algorithms + Data Structures = Programs, 1976
The PL/0 Grammar
For more information about the project, see Project Notes.
MIT License. See LICENSE for details.