I built a compiler in C from scratch with lexer, parser, and C codegen

3 Pandaadir 1 7/23/2025, 9:51:13 AM github.com ↗

Comments (1)

Pandaadir · 7h ago
A couple of days ago, I set out to understand how compilers work by building one myself in C. It implements a full 3-phase pipeline (lexing → parsing → code generation) and emits valid C code.

It handles variables, arithmetic, comments, strings, number formats, and compiles most programs in ~1ms.

Arena allocation ensures zero memory leaks. Interactive mode and benchmarking tools are built-in.

Would love feedback or suggestions — especially around codegen strategies.