
A micro compiler in Ocaml - joaobatalha
http://troydm.github.io/blog/2014/03/29/writing-micro-compiler-in-ocaml/
======
amirmc
As well as Real World OCaml (linked in the OP), there are also a number of
tutorials/exercises at
[http://ocaml.org/learn/tutorials/](http://ocaml.org/learn/tutorials/)

The most visited of these pages is 99 problems:
[http://ocaml.org/learn/tutorials/99problems.html](http://ocaml.org/learn/tutorials/99problems.html)

------
gsg
"Our program will preallocate 1000 bytes on stack for variables, since all of
our variables are static."

Oof, talk about cutting corners. Works well enough until you need function
calls, I guess.

Anybody who finds this intriguing might look at [http://esumii.github.io/min-
caml/index-e.html](http://esumii.github.io/min-caml/index-e.html), which is
also written in OCaml and goes into a bit more depth.

------
toolslive
I don't know what the purpose is here, but I think it would be a lot smaller
if the standard tools for lexing and parsing were used.
[http://caml.inria.fr/pub/docs/manual-
ocaml-400/manual026.htm...](http://caml.inria.fr/pub/docs/manual-
ocaml-400/manual026.html)

~~~
seanmcdirmid
Most real production compilers don't use lexer or parser generators.

~~~
reidrac
A "micro compiler" doesn't qualify as "real production compiler". I think
pointing out that a lexer/parser could have been used is relevant in this
case.

~~~
seanmcdirmid
Lexer/parser generators aren't used in practice even for hobbyists, so
pointing out standard tools could have been used is weird since the tools are
obviously not that popular.

~~~
mimog
In my experience lexers and parser generators are used extensively by
hobbyists. Tools such as Antlr, Boost.Spirit and Xtext come to mind.

~~~
coldtea
Xtext is very marginal compared to the far wider world of custom languages.
Antlr not so much, but still, tons of people write rec. des. parsers
themselves.

------
vrotaru
And more mini-languages which are implemented in Ocaml, here:

[https://github.com/andrejbauer/plzoo](https://github.com/andrejbauer/plzoo)

------
gtani
this reminds me of a neglected bookmark, the original rust compiler in ocaml
from 3 years ago
[http://www.reddit.com/r/rust/comments/18b808/is_the_original...](http://www.reddit.com/r/rust/comments/18b808/is_the_original_ocaml_compiler_still_available/)

