Learning Resources on Parsers, Interpreters, and Compilers [closed]

被刻印的时光 ゝ 提交于 2019-11-26 15:47:19

The best paper I ever read on compilers is dated 1964 "META II a syntax-oriented compiler writing language" by Val Schorre. (http://doi.acm.org/10.1145/800257.808896)

In 10 pages, he shows you how to build an astoundingly simple but very effective compiler-compiler, provides you with with the compiler-compiler grammar and provides you with enough details for you to hand implement it in an afternoon (with one astonishing conceptual moment when you realize how it recurses), and just for grins implements an ALGOL-like language. The paper is a complete gas and really should be required reading for anybody working with compiler technology.

Here's a link to play with an great tutorial on metacompiling, based on the paper. http://www.bayfronttechnologies.com/mc_tutorial.html

Aho's "Dragon book" is the standard reference, but another good choice is Andrew Appel's Modern Compiler Implementation in Java (also available in ML and C flavors). It walks you step-by-step through each of the necessary components of a compiler/interpreter and provides a lot of useful source code.

This highly-entertaining blog post by Steve Yegge (Rich Programmer Food) won't tell you everything you need to know about how to build a compiler (although it does include a fair amount of good insight), but it does a great job of explaining why you want to understand compliers.

Heck, that post almost got me to start studying compilers, and I have a full-time job, a 3-year-old at home, and about -1.5 free hours per day on average.

Not very easy, but exhaustive: the dragon book

Compiler Construction: Principles and Practice is a best book on the subject.

The MIT OpenCourseWare(OCW) site has a class whose project is to build a complier...they refer to the Dragon book and Appel's book, but in addition, there are also class notes and lectures available. The class is 6.035 - Computer Language Engineering.

I found the class notes very useful for explaining recursive-descent parsers.

I've found "Let's build a compiler" - the tutorial by Jack Crenshaw, very easy to follow and understand. Jack builds a compiler for Pascal, from the ground up, with very detailed explanations of every step.

I recently read Programming Language Processors in Java and would recommend it to you as it starts with basic concepts and then takes you through the implementation of a recursive-descent compiler including code generation with plenty of discussion of alternative approaches. I've not read the other suggested books in this thread though, so can't offer a comparison with those. Don't be put off by the In Java part, if you don't know java, as the concepts and their implementation are well enough explained that you get the gist without needing a detailed understanding of Java.

I recommend Compiler Design in C which you would have to find in a used book site unfortunately. The only real problem with the book is that it was written back when speed of compilation was an important factor so the compiler is written in C. That's enough of a low level language that sometimes the implementation theory is buried under the implementation code.

You mentioned both Interpreters and Compilers. I'd actually recommend starting with an Interpreter rather than a Compiler. It's much easier to get started with an Interpreter and they tend to be more fun to work on because you can get immediate feedback on how you're doing.

Just in case you:

  • Are willing to play
  • Like the chance to build something quicker, then go deeper
  • Are ok with using .NET at an underlying platform

...then I'd recommend you to check Microsoft's Dynamic Language Runtime, which is provided as source code inside the whole Dynamic Silverlight SDK.

http://www.codeplex.com/sdlsdk

Some nice things about it is that it provides lots of ready-to-use features like a console, a common type system, a generic abstract syntax tree, etc. And the package includes three implementations: Python, Ruby and Javascript.

Maybe it is a good chance to implement a short language other the DLR, then start checking the actual DLR code, and then start building the basic stuff on your own.

In any case, best luck from another language freak!

RE: lex, yacc, bison

Do you mean you don't need pointers to them or that you aren't interested in using them? I don't recommend writing a lexer or parser by hand.

EDIT: You may have an exaggerated sense of what a "compiler-compiler" can accomplish: the really hard part of compilation begins after you've built the AST. The Aho, Louden, and Appel books are all quite good.

It's an old book, and rather dated, but I've found Brinch Hansen on Pascal Compilers to be a very practical introduction to creating a language and building the elements of a compiler. Despite the name, it's not specific to Pascal. It's very worthwhile if you can find a copy.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!