4 ms·
I'm thinking a lot of the complexity of writing a compiler stems from the usage of inappropriate tools. I.e. I would rather kill myself than write a lexer in C
by pka 10y ago
I'm thinking a lot of the complexity of writing a compiler stems from the usage of inappropriate tools. I.e. I would rather kill myself than write a lexer in C (without yacc / bison), but using parser combinators it's a rather trivial task.
Similarly, annotating, transforming, folding, pattern matching on, CPS transforming etc. the produced AST is pretty trivial in a language that supports these constructs. And again, a nightmare in C.
That leaves codegen, but using the right abstractions it turns into a very manageable task as well.
Here's a compiler written in Haskell for LLVM [0].
[0] http://www.stephendiehl.com/llvm http://www.stephendiehl.com/llvm
- TazeTSchnitzel 10y ago> I would rather kill myself than write a lexer in C I've written several lexers in C-like languages, it's not that painful. I wouldn't dare write a parser though.