(troydm.github.io) Writing Micro Compiler in OCaml - Troydm's Blog
ROAM_REFS: https://troydm.github.io/blog/2014/03/29/writing-micro-compiler-in-ocaml/
- Writing Micro Compiler in OCaml
Mar 29th, 2014
TL;DR Writing micro compiler in OCaml
At one point or another every single software developer in the world comes to a realization in his career when the time is ripe and it's time to write your own super cool programming language.
However the subject of creating your own programming language with an compiler is quite a complex one and can't be tackled without some pre-research. That's how I've started reading Crafting Compiler in C, an aged but really comprehensive book about developing your own compiler for an Ada-like programming language. Second chapter describes writing a really simple micro language targeting pseudo assembly-like output in order to explain the core concepts of developing your own compiler and writing an LL(1) parser.
Let's try rewriting this micro compiler in OCaml, a language better suited for writing compilers that is becoming quite popular due to it's clean syntax and strict evaluation semantics combined with functional and object-oriented programming styles. If you are not familiar with OCaml try reading Real World OCaml first. Instead of outputting pseudo assembly our micro compiler will output a real nasm source code which will be automatically compiled into a binary executable file.