5 ms·
Ask HN: What is a good language to learn/use for writing compilers/interpreters?
I would really like to learn how to write compilers/interpreters in depth.
What are the best languages to concentrate on to write compilers or interpreters in?
Do the basic concepts transfer easily from one base language to another? That is, how much difference conceptually is there going to be between say writing a compiler/interpreter in C or Java vs Haskell, OCaml or Lisp (for example).
- tomh- 16y agoI say Haskell, the way you can build abstract syntax tree's as data types and do pattern matching on them is a very natural way to write a compiler, it is almost a one-to-one match with a language definition.
- hga 16y agoScheme has traditionally been a if not the major language for doing this, but it was established in this niche well before Haskell got big (Scheme had a decade and half head start on Haskell, three decades if you want to go back to the invention of LISP). On the other hand there's a tradition of dogfooding in this area, one argument being that if your (general purpose, let's assume) language isn't good for building a compiler, what use is it? If you believe in your language....
- sea6ear 16y agoThanks, this seems like a good argument that I hadn't considered. I like pattern matching a lot so this appeals to me.
- starkfist 16y agoML. Because the best compiler book these days uses ML. If you are going to sell your compiler to you will have to write it in C++.