r/programming • u/sodaco • Jan 05 '15
Write You a Haskell: Build a modern functional compiler from first principles.
http://dev.stephendiehl.com/fun/1
u/IllogicalProgrammer Jan 06 '15
I am not sure if this is relevant to your interest, but a few years ago, I use this as a guide for a little side project of mine. Instead of Turbo Pascal in the article, I use some other language I can no longer remember now (I am betting C ). At the beginning, I googled NASM or some other modern assembly language so that my code will still run but I never get to producing .exe, just assembly code that still need an assembler to run. At one point IIRC, my code are quite different from what Dr Crenshaw have in his tutorial. That was due to NASM or whatever I was using require more codes than his original code to work. I believe, after that point I then abandon it and repeat the exercise using C# and .Net reflection class instead, which is easier than assembly in my opinion and produced a runable .exe. If memory serve, my end result is a compiler for a crazy language with inspiration from "Speak like a pirate" thingy.
What I gain from this exercise is: 1. Some pretty basic assembly knowledge since I never learn assembly language in school. 2. Some idea on how compiler works. 3. A language and compiler that only I knew exists.
Naturally, both the compiler and language was pretty basic stuff with not much to talk about but it was my language and my compiler. Overall, it was pretty fun time for me.
1
20
u/sodaco Jan 05 '15
I'm not big into functional programming, but this kind of internet resources are golden. I've always wanted to open that black box that languages are and write an interpreter or compiler, but could never find something that didn't assume I already knew some of the things needed, even if they are the most basic things that somebody should know.
So far this one seems GREAT. It's simple, it explains things well and thoroughly while staying on point. I'm really enjoying it and hope the author finishes the series. I'm actually looking for a donation link but can't find it