What are good resources on compilation? [duplicate]

こ雲淡風輕ζ 提交于 2020-01-11 19:51:57

问题


Summary for the impatient: I'm searching for good references on generating code for common language constructs but not parsing.

I am interested in programming languages and try to read the literature as much as possible. But most of them covers the topic in a functional and theoretical perspective that, I find them hard to understand let alone implement the ideas.

So the question is; Which resources do you suggest about programming language implementations that covers the topic in a more imperative and practical fashion?

For example, I find "The Implementation of Lua 5.0" paper very instructive.

Note that, I am not seeking articles about parsing or tokenizing.


回答1:


Here are a bunch of good textbooks:

Modern Compiler Implementation in Java (Tiger book) A.W. Appel Cambridge University Press, 1998 ISBN 0-52158-388-8 A textbook tutorial on compiler implementation, including techniques for many language features

Compilers: Principles, Techniques and Tools (Dragon book) Aho, Lam, Sethi and Ullman Addison-Wesley, 2006 ISBN 0321486811 The classic compilers textbook, although its front-end emphasis reflects its age.

Advanced Compiler Design and Implementation (Whale book) Steven Muchnick Morgan Kaufman Publishers, 1997 ISBN 1-55860-320-4 Essentially a recipe book of optimizations; very complete and suited for industrial practitioners and researchers.

Engineering a Compiler (Ark book) Keith D. Cooper, Linda Torczon Morgan Kaufman Publishers, 2003 ISBN 1-55860-698-X A modern classroom textbook, with increased emphasis on the back-end and implementation techniques.

Optimizing Compilers for Modern Architectures Randy Allen and Ken Kennedy Morgan Kaufman Publishers, 2001 ISBN 1-55860-286-0 A modern textbook that focuses on optimizations including parallelization and memory hierarchy optimizations.

Programming Languages Pragmatics Michael L. Scott Morgan Kaufmann Publishers, 2005 ISBN 0126339511




回答2:


Supposedly (I read through it, but haven't done it), An Incremental Approach to Compiler Construction is excellent. It describes how the author teaches his compilers course.

From the abstract:

Compilers are perceived to be magical artifacts, carefully crafted by the wizards, and unfathomable by the mere mortals. Books on compilers are better described as wizard-talk: written by and for a clique of all-knowing practitioners. Real-life compilers are too complex to serve as an educational tool. And the gap between real-life compilers and the educational toy compilers is too wide. The novice compiler writer stands puzzled facing an impenetrable barrier, “better write an interpreter instead.”

The goal of this paper is to break that barrier. We show that building a compiler can be as easy as building an interpreter. The compiler we construct accepts a large subset of the Scheme programming language and produces assembly code for the Intel-x86 architecture, the dominant architecture of personal computing. The development of the compiler is broken into many small incremental steps. Every step yields a fully working compiler for a progressively expanding subset of Scheme. Every compiler step produces real assembly code that can be assembled then executed directly by the hardware. We assume that the reader is familiar with the basic computer architecture: its components and execution model. Detailed knowledge of the Intel-x86 architecture is not required.

The development of the compiler is described in detail in an extended tutorial. Supporting material for the tutorial such as an automated testing facility coupled with a comprehensive test suite are provided with the tutorial. It is our hope that current and future implementors of Scheme find in this paper the motivation for developing high-performance compilers and the means for achieving that goal.




回答3:


I suggest playing with ANTLR. I used it awhile back and found it very easy to use.




回答4:


The "Dragon" and "Tiger" books (see above) are both excellent, though I find the "Tiger" (Appel) book a bit dense. I also quite like Modern Compiler Design by David Galles. As for tools and utilities to help you understand, I recommend taking a look at one or more of the following:

  • JavaaCC for lex and parser generation
  • Grammatica for lex and parser generation
  • Jasmin and Jasper for code generation



回答5:


My favourite is "Building an Optimizing Compiler" by Robert Morgan. Very practical, covers static single assignment.




回答6:


Another hint: do not start digging into GCC; it is way too complicated. You want something more researchy and simple to start with, I would suggest looking into something like a Java compiler written in Java or the Erlang compilers written in Erlang.




回答7:


The Design and Evolution of C++ by Bjarne Stroustrup, which has fairly little code, but mostly discusses the trade-offs and other concerns in designing the language.




回答8:


Try to look at the LLVM project and their publications and tutorials.




回答9:


I like Compiler Construction by Nicolas Wirth, but maybe that's because learning (Turbo) Pascal was what made me decide to go into Computer Science.

http://www-old.oberon.ethz.ch/WirthPubl/CBEAll.pdf




回答10:


The Purple Dragon Book is the best ever.



来源:https://stackoverflow.com/questions/153330/what-are-good-resources-on-compilation

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