We are currently in the process of converting the website to the new design. Some pages, like this one, are still broken. We appreciate your patience.
Handmade Network»Forums
Dumitru Frunza
24 posts
Apprentice github.com/dfrunza/hoc
A study of compilers
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!
56 posts / 1 project
A study of compilers
I think it would be cool if you try to implement something other than a stack style. If your gonna do it and take it that far maybe you should experiment and do something different.

Just to see what comes of it.
Jeremiah Goerdt
208 posts / 1 project
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
A study of compilers

Must watch movie right here. Linked because of the book reference. Enjoy :-)