News for hackers. Stuff that matters.
Re:A micro compiler in Ocaml by toolslive on Tuesday April 01, 2014 @02:11AM (#7506451)
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...
Re:A micro compiler in Ocaml by seanmcdirmid on Tuesday April 01, 2014 @03:47AM (#7506703)
Most real production compilers don't use lexer or parser generators.
Re:A micro compiler in Ocaml by whenc on Tuesday April 01, 2014 @05:30AM (#7507049)
Re:A micro compiler in Ocaml by reidrac on Tuesday April 01, 2014 @05:06AM (#7506961)
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.
Re:A micro compiler in Ocaml by seanmcdirmid on Tuesday April 01, 2014 @05:08AM (#7506968)
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.
Re:A micro compiler in Ocaml by mimog on Tuesday April 01, 2014 @06:24AM (#7507172)
In my experience lexers and parser generators are used extensively by hobbyists. Tools such as Antlr, Boost.Spirit and Xtext come to mind.
Re:A micro compiler in Ocaml by coldtea on Tuesday April 01, 2014 @03:17PM (#7510956)
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.
Re:A micro compiler in Ocaml by p4bl0 on Tuesday April 01, 2014 @06:59AM (#7507253)
Is that true? At least in the OCaml ecosystem (where there is many many compilers), ocamllex and menhir seems to be used quite often.
Re:A micro compiler in Ocaml by seanmcdirmid on Tuesday April 01, 2014 @07:13AM (#7507283)
I 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.
Re:A micro compiler in Ocaml by patmcguire on Tuesday April 01, 2014 @09:13AM (#7507812)
The main compilers for PHP, Ruby, and Go all do, although gcc uses a handwritten one now http://en.m.wikipedia.org/wiki/GNU_bison

Do those not count? What are the tradeoffs to doing it from scratch?

Re:A micro compiler in Ocaml by seanmcdirmid on Tuesday April 01, 2014 @10:23AM (#7508365)
Scala and C# are by hand. I imagine C++ is also since there is no other way to do it. Java uses JavaCC, Lua is by hand

Using tools is often more complicated than just writing code, it isn't that hard to write a recursive descent parser, and you have the flexibility if loading it with all the error recovery you want. What tools give you is potentially better parser performance and more theoretic assurances (useful for tricky grammars).

Re:A micro compiler in Ocaml by platz on Tuesday April 01, 2014 @12:21PM (#7509437)
After the comments I've seen from paulp, I'd hardly believe that way Scala did this was optimal, although I'm not sure there were any issues with lexing & parsing
Re:A micro compiler in Ocaml by seanmcdirmid on Tuesday April 01, 2014 @04:19PM (#7511376)
It's not optimal and it doesn't matter considering parsing overhead is just noise compared to type system computations.
Re:A micro compiler in Ocaml by kristianp on Tuesday April 01, 2014 @03:11AM (#7506608)
Informative comment, but surely the purpose of the article is to teach ocaml, not the lexing&parsing tools, which require more ocaml knowledge?
Re:A micro compiler in Ocaml by toolslive on Tuesday April 01, 2014 @06:11PM (#7512100)
The 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.

Re:A micro compiler in Ocaml by greyfade on Wednesday April 02, 2014 @11:28PM (#7520764)
I 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?
Re:A micro compiler in Ocaml by viciousplant on Tuesday April 01, 2014 @02:31AM (#7506496)
don't you see the purpose is purely the anime?
Re:A micro compiler in Ocaml by jzelinskie on Tuesday April 01, 2014 @02:58AM (#7506565)
I'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.