Creating a Compiler: Explore OCaml or Stick with Java / C / C ++

I need to create a new language and compiler for this language for the class that I occupy this semester - this means that the period is about 3.5 months. I read that OCaml is one of the best languages ​​for writing a compiler, but I have no experience with this. My question is this: would it be a better idea for me to try to create a compiler with languages ​​that I already know well (Java, C, C ++), or to devote some time to learning OCaml and use it instead?

+4
source share
1 answer

It depends on how you rate the interest of each choice.

If your goal is to complete your project as quickly as possible, sticking to a tool that you already know well is probably the best choice. The language is important, and I believe that ML languages ​​are best suited for compilers, but in a short time, convenient with the language, tools, error messages, and common idioms are likely to exceed the performance benefits associated with the language. Or at least among garbage collectors; you can be effective with C, but you should know the language well (and in this case, you probably won’t compile it among C ++ and Java).

If you are interested in creating compilers and, more generally, language tools or learning programming languages ​​after completing a course, learning a statically typed functional language is definitely worth the investment, and a compiler course is a great reason to do that.

Edit: some pointers

rgrinberg a useful comment reminds me to tell you MinCaml as one of the possible sources of inspiration.

My first thought was that Andrew Appel "Implementing the Compiler in {C, Java, ML}" was written by Andrew Appel, but, as Amazon commented, this book is too advanced to be used as an introduction to both compilers and and for ML.

Andrej Bauer The Zoo programming language is also an excellent resource, but it is more focused on discovering a wide range of programming languages ​​using an interpreter than compilation on its own (although some zoo animals are compiled for abstract machines).

+10
source

All Articles