7

Possible Duplicate:
Learning to write a compiler

I know this is a broad question to ask, but where could I start learning how compilers actually work, how programming languages are made, I mean not how you use Java or Ruby but how people actually are making them. I will not try to replicate these languages in any ways but I want to understand the concepts and theory behind it. So what I need is either some directions on what I should search for, or even better and more appriciated are book recommendations.

Regards,

Jonathan Nash.

Community
  • 1
  • 1

4 Answers4

3

You could take a look at the Dragon Book:

LukeH
  • 263,068
  • 57
  • 365
  • 409
  • 2
    Note that the Dragon Book is not an introductory text, but a very good reference book. See http://www.billthelizard.com/2008/12/books-programmers-dont-really-read.html for comments. – Thorbjørn Ravn Andersen Jun 15 '11 at 17:07
  • Thank you but the link does not work. – Johnathan Nash Jun 15 '11 at 17:21
  • @Johnathan: Stackoverflow was converting my amazon link into a corrupt affiliate link for some reason. I've edited and it now seems to be working properly. – LukeH Jun 15 '11 at 19:22
3

You might find Lets Build a Compiler by by Jack Crenshaw an interesting introduction.

Kept very simple and focussed on building actual functionality.

Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347
  • I second this. The dragon book is the definitive text but definitely not the place to start. Lets Build a Compiler helped me out big time when I had to write a compiler. – Jeremy Jun 15 '11 at 17:35
  • +1 Great place to start if you actually want to build one – tylermac Jun 15 '11 at 18:11
3
  • Compiler Constrution by Niklaus Wirth is pretty good and available for free from the link I provided (yes, legally). It's a bit old and uses Oberon for the examples but is easy to follow.

  • Create Your Own Programming Language by Marc-André Cournoyer is available online for USD 40 and consists of an eBook (including exercises and solutions), source code for two example languages (one in Ruby and one in Java) and a screencast on extending the JVM based language. This is probably the most newbie-friendly introduction you can find on the topic and afterwards you should have a pretty good idea about the steps involved (tokenizing, parsing, lexing etc.) and can continue your research with the provided links. It's a bit expensive, but IMHO it's worth it.

  • While not primarily a learning resource, the CoffeeScript web site has a section called "Annotated Source", which is really helpful in seeing how a programming language works. CoffeeScript's author started working on it after he read the book I mentioned in the previous bullet point btw.

Michael Kohl
  • 66,324
  • 14
  • 138
  • 158
1

I've greatly enjoyed Language Implementation Patterns and learned a bunch. I wish I had read it before trying to implement a DSL some years ago.

Jim Blizard
  • 4,255
  • 28
  • 37