Lesson 0.2
Setting Up
Install Go, create the project, run a test. Five minutes, then we start building.
5 min exercise
Install Go
Go 1.22 or later. Check if you already have it:
go version
# go1.22.0 or higher If not: go.dev/dl — download, install, done. One binary, no dependencies.
Create the project
mkdir monk-lang && cd monk-lang
go mod init github.com/yourname/monk-lang This creates go.mod — Go's dependency file. That's the entire setup. No build config, no bundler, no package manager ceremony.
Write the first test
Create syntax/scanner_test.go:
package syntax
import "testing"
func TestPlaceholder(t *testing.T) {
// This test exists to verify your setup works.
// It gets replaced in Phase 1.
if 1+1 != 2 {
t.Fatal("math is broken")
}
} Run it:
go test ./syntax/
# ok github.com/yourname/monk-lang/syntax 0.001s This is the TDD loop you'll use for the entire compiler. Write a failing test. Make it pass. Refactor. Every phase starts with a test file.
Project structure
The compiler will grow into this shape:
go.modModule definition
syntax/Phases 1-2: lexer, parser, AST, tokens
codegen/Phase 4: AST to C source
main.goPhase 5: CLI entry point (monk build/run/check)
runtime/Phase 3: C library linked into every binary
Each directory is a Go package. Tests live next to the code they test (syntax/scanner_test.go). No separate test directory.
Checkpoint
Go 1.22+ installed and on your PATH
go test ./syntax/ passes You understand the project structure
You're ready for Phase 1. Next: the lexer.