
h2wac
How to Write a Compiler #7 - Top Level Statements
C-minor's top-level statements are implemented by manipulating the AST before invoking the other compilation stages and are easy introduction to working with the AST.
A series of articles on "How to Write a Compiler" based on my experiences building C-minor: a strongly typed, garbage collected, direct to in-memory machine-code scripting language.
h2wac
C-minor's top-level statements are implemented by manipulating the AST before invoking the other compilation stages and are easy introduction to working with the AST.
h2wac
For language products typical unit testing doesn't work well long term. Instead I recommend sandboxing for early prototyping and a dedicated test case file runner for more end-to-end style testing.
h2wac
If ever there was a design pattern that's perfectly suited to a job, it's the visitor pattern for working with an abstract syntax tree. But what is the visitor pattern and why is it so well suited?
h2wac
The Parser takes a stream of tokens, checks the syntax is valid and produces an Abstract Syntax Tree.
h2wac
Ask anyone who's worked on a compiler, and they'll all agree that the Abstract Syntax Tree is the most important structure in the whole compiler. But what exactly is it and what is it used for?
h2wac
Tokenization is the process of reading source code and splitting it into meaningful symbols that describe the program's content. It's the first step of any compiler.
h2wac
C-minor is a strongly typed, garbage collected language that compiles to in-memory machine code for direct execution. Here's how I built it.