Hey guys,
I'd like to share with you the results of my project to build a compiler from scratch. The main goal is to learn the internals of a compiler and to get a good understanding of the concepts involved, rather than to make a shippable product.
So I've been studying the famous "Dragon Book", 1st edition, for a while now, and I've gotten to a point where things start making sense :)
This is the first time since the beginning, when the compiler actually compiles something to "machine" code - and I'm excited!
Code on
GitHub
The main focus at this point is around generating code for a stack machine. The source language (which I've named "hoc") is rudimentary : it supports only one type - the 32-bit integer; variables can be declared and initialized; procedures can be declared and called, but without arguments; arithmetic expressions can be formed and evaluated; no control flow yet.
The stack machine has been implemented too, along with it's instruction set. Normally, the "hoc" source gets translated to VM code that's then written to a file, and is interpreted by launching the VM program with the path to the file as argument.
A nice trick, is to bake the code into the VM executable itself, as a Win32 resource, and run that instead of the external file.
I'm a fan of Casey's approach to programming, so the compiler is written and architected in a style following that philosophy.
Take a look and tell me what you think!