4 ms·
A micro compiler in Ocaml
- toolslive 13y agoI 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.html http://caml.inria.fr/pub/docs/manual-ocaml-400/manual026.htm...
- viciousplant 13y agodon't you see the purpose is purely the anime?
- jzelinskie 13y agoI'm a pretty big fan of anime, but I still don't see the point in randomly sprinkling internet memes or other random television screenshots in blog posts. At first, I thought it might be a refreshing change of pace, but now I just feel like it detracts from the article.
- kristianp 13y agoInformative comment, but surely the purpose of the article is to teach ocaml, not the lexing&parsing tools, which require more ocaml knowledge?
- toolslive 13y agoThe author doesn't appear to be an experienced OCaml programmer, and misses lots of opportunities for simpler code. For example let is_digit c = let code = Char.code c in code >= Char.code('0') && code <= Char.code('9') Could have been written: let is_digit = function '0'..'9' -> true | _ -> false So the purpose probably wasn't to teach OCaml.
- seanmcdirmid 13y agoMost real production compilers don't use lexer or parser generators.
- reidrac 13y agoA "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 13y agoLexer/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 13y agoIn my experience lexers and parser generators are used extensively by hobbyists. Tools such as Antlr, Boost.Spirit and Xtext come to mind.
- coldtea 13y agoXtext 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.
- p4bl0 13y agoIs that true? At least in the OCaml ecosystem (where there is many many compilers), ocamllex and menhir seems to be used quite often.
- seanmcdirmid 13y agoI know a lit of hobbyists and professionals who just roll recursive decent parsers given the reduced complexity and better error recovery. Using these tools, they don't necessarily help unless you have icky syntax to deal with or really care about that last ounce of performance.
- greyfade 13y agoI hate this suggestion. What's the point of writing a toy compiler if you skip learning how to write one of its most critical parts?
- amirmc 13y agoAs 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
- vrotaru 13y agoAnd more mini-languages which are implemented in Ocaml, here: https://github.com/andrejbauer/plzoo https://github.com/andrejbauer/plzoo
- gsg 13y ago"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.
- gtani 13y agothis 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_ocaml_compiler_still_available/ http://www.reddit.com/r/rust/comments/18b808/is_the_original...