|
Softpanorama |
||||||
| Contents | Bulletin | Scripting in shell and Perl | Network troubleshooting | History | Humor | |
| Peephole optimization | Program Graphs | Algorithms | Assembler | C | Random Findings | Humor | Etc |
Compiler construction (see also my page with the collection of links) stopped to be a black art approximately after publishing of famous David Gries' book. Now it's a pretty established field but the truth is that there are few good books on the topic. Widely praised Compilers Principles, Techniques, and Tools by Alfred V. Aho, Ravi Sethi, Jeffrey D. Ullman is in my opinion a weak book that stresses too much syntax parsing and obscures more then enlighten the design of compiler issues. The Dragon Book is way overhyped. It is confusing and a complete nightmare to understand. It have some value for instructors but almost none for students. Actually this book proves that Alfred Aho did not participated much in the development of the AWK interpreter and language :-).
One of the most underestimated books on compliers is probably the first volume of The Art Of Computer Programming, the book that should be on the shelf of any complier writer. Algorithms described in this book as well as MIX assembler are useful examples that compiler writer can use. Generally a book with a complete code of a simple compiler is a good start as theoretical methods exposed in books like Compilers Principles, Techniques, and Tools by Alfred V. Aho, Ravi Sethi, Jeffrey D. Ullman at the beginning looks incomprehensible. Paradoxically after a while you stat to understand how primitive thinking of all those "theorists" is and how detached they are from reality. In a sense there is no middle ground in appraising such books :-).
At the same time this is very interesting area because compilers represent an interesting paradigm for solving a very broad class of problems. In a way approach to construction of a program as a compiler from some specialized language. It is similar but at the same time is an alternative to now dominant OO approach. Separation of lexical aspects, syntactic aspects and semantic aspects of the task proved to be a very fruitful approach. Moreover OO technology can be to a certain extent considered as a rather primitive implementation of the compiler-compiler paradigm -- extending the language dynamically.
Lexical analysis phase should be IMHO better coded by hand and it can do some look ahead in order to simplify the next phase: syntax analysis. Actually even if you deal with the simple, regular lexical structure you do not need to use Lex of similar tools to generate lexical scanner. Hand written scanners are simpler, more powerful and more flexible. They can provide additional help to syntax analysis by looking forward for a particular lexical token Moreover usually lexical analyzers can use advanced instructions for a particular architecture (like tr) so mixture of C and assembler is the best way to go.
But as for syntactic analyzers, using something like YACC can improve reliability of parser and can be recommended. YACC has some debugging capabilities and you can ask questions and probably get answers in comp.compiler group. But for a simple languages a recursive decent is much better technology. It is not only simpler and better linked to generating code (which is the most difficult part of compiler) but also has better diagnostics. See for example LEPL 2.3
LEPL is a recursive descent parser library written in Python. It is based on parser combinator libraries popular in functional programming, but also exploits Python language features. Operators provide... a friendly syntax, and the consistent use of generators supports full backtracking and resource management. Backtracking implies that a wide variety of grammars are supported; appropriate memoisation ensures that even left-recursive grammars terminate
If it's your own language you almost always can tweak grammar to conform to recursive decent parser. Things like functions definition can always be moved to the front of the program by lexical scanner.
Also at the beginning you can start with an interpreter. That completely bypasses the problem of generating assembly code. This approach is especially useful if the language is flux. As you polish the language you can convert interpreter to a complier. First you can compile your language to C, then to assembler and then to object code. Such gradual approach is useful as you learn in the process.
One interesting possibility is to use XML as intermediary language then try to modify existing XML tools to convert it into C or assembler. XML captures nested structure of computer programs quite well and naturally suits to out of tuples which is the basic pre-generation form used in compliers. Using XML allows you using very common XML editors for viewing your intermediary representation. This alone simplify debugging immensely as good visibility of intermediate representation of the program is the key to success in compiler writing. You can also try to use XLST as a poor man code generator (see for example Xalan which is available in C++), at least at the beginning stages. And the knowledge you obtain in the process has millions other valuable applications. In other words additional time spent learning XML is time spend well. I highly recommend this approach as it make compiler more transparent from the very beginning.
As for syntax analysis the rule number one is not too spend too much time of syntax analysis. A lot of people hurt themselves and missed deadlines by overdoing this part of compilers instead of concentration of code generation. If you can mold you language into recursive decent parsing just do it and forget about the problem. It also can provide a very good error diagnostics (which is an Achilles spot of YACC).
If recursive decent parser is not suitable you can try to use YACC or something similar and also forget about the problem :-). Usually you can split your language into several simpler sublanguages which can be parsed more easily. For example some sublanguages can be parsable by regular expression parser. In this case you can use different parsing strategies for each of them. This approach can be implemented using Floyd-Evans language which is a specialized language for writing parsers. It operates with a stack of lexical tokens. This way you can combine recursive decent with bottom up approaches for parsing expressions.
Compilers does not exist as an isolated phenomenon -- a lot depends on hardware in hand and programming languages in hand. Those days most compilers are written in C, but scripting languages such as Python, if available, can be more productive. After all compiler is a text manipulating program. But always start simple: generate C-code or assembler code. You need to adapt to the target computer first and learn a lot before converting your compiler to generating object code. With modern speeds of CPU this might not be even necessary unless of language gain really wide acceptance. If you plan generating assembly code or object code, a good book on assembler should be added to your library.
Compiler writing produced several interesting algorithms including algorithms on directed graphs -- a very fascinating area. I hope that Donald Knuth will eventually write a volume devoted to compiler construction. This area definitely needs a giant. Meanwhile combination of Gries' book and Writing Compilers and Interpreters or Compiler Design in C (plus a couple of more advanced books like Muchnick's Advanced Compiler Design and Implementation) can probably serve you as a substitute of this inexistent volume of the Art of Programming.
If you want to create your own language a look like Programming Language Pragmatics can be a valuable help. Usually compiler writer already know three-four languages quite in depth (for example C, C++, Perl and Lisp) but if this is not the case self-education is a necessary step.
Although this area is semi-forgotten, one active software development paradigm related to compiler technologies is so called program generation and generator programming pattern ;-). There are several books related to this topic.
The last part and the most complex part of compiler writing is the code optimization and here a tree representation can be extremely useful. I strongly recommend to try peephole optimization as the first optimization method. It was introduced in the paper McKeeman, W.M. Peephole Optimization. CACM 8 (July 1965), p 443-444. See also Aho, Alfred V., Ravi Sethi, Jeffrey D. Ullman. "Compilers: Principles, Techniques, and Tools". Addison Wesley, 1986.
Peephole optimization is a method to improve the quality of the program by examining a short sequence of target instructions by applying to them pattern recognition technology such as regular expressions. The peephole is a small moving window on the target program. Instructions in the peephole are optimized only considering the local context present in the peephole. It can also be defined as the pattern matching and conditional replacement performed on small sections of code. (see Vicki H. Allan. Peephole Optimization as a Targeting and Coupling Tool, page 112-121 1989, ACM Proceedings of the 22nd annual international workshop on microprogramming and micro architecture). Among other things it includes (see Subject D1 Peephole Optimization and Optimal Code Generation):
redundant-instruction elimination like in
(1) MOV R0, a (2) MOV a, R0 # Whenever (2) is executed right after (1), it is redundant.
debug = 0;
if (debug) {
print debugging information
}
See Peter B. Kessler "Discovering Machine Specific Code Improvement", Sigplan Notices, July 1986. pp 249-254 and a related paper by Massalin in ASPLOS '87: Superoptimizer --- A look at the smallest program. Proceedings of the Second International Conference on Architectural Support for Programming Languages and Operating Systems (ASPLOS II), Oct. 1987, IEEE:
Abstract:
The superoptimizer is a tool that, given an instruction set, finds the shortest program to compute a function. Startling programs have been generated, many of them engaging in convoluted bit-fiddling bearing little resemblance to the source programs which defined the functions. The key idea in the superoptimizer is a probabilistic test that makes exhaustive searches practical for programs of useful size. The search space is defined by the processor's instruction set, which may include the whole set, but it is typically restricted to a subset. By constraining the instructions and observing the effect on the output program, it is possible to gain insight into the design of instruction sets. In addition, superoptimized programs may be used by peephole optimizers to improve the quality of generated code, or by assembly language programmers to improve manually written code
Nikolai Bezroukov
|
You can use Honor System to make a contribution, supporting this site |
Amazon.com
Andrew Kadatch(Redmond, WA United States) Excellent, December 12, 2001
This book is definitely _not_ for beginners, but compilers are not supposed to be written by novices -- if there is rocket science in computers, it is compiler development. Crystal clear style and language make this book easy reading, and LCC is the best non-optimizing compiler I've seen (and believe me, I've seen many compiler sources): orthogonal, easy to follow design, well-thought data structures and overall architecture.
I treat this book as a perfect collection of brilliant ideas, many of which you will find implemented in most commercial compilers.
Whether it helps to write your own compiler? -- sure. Are you thinking about IR (internal representation) that will be easy to create and, most important, walk through and manipulate? -- take a look how Fraser et al did it; they did it well. Think how to write a front end or code generator? -- it's all there. Sure, blind copying won't work -- optimizing compiler will call for way more sophisticated BURG-like technique (one of the best known code generation techniques by now), but, all in all, it'll be BURG-like, and it's in the book as well.
So, if you want to show your students (or learn yourself) how compilers should be written, you cannot find anything better than LCC accompanied by this book. Fraser's team did it right.
This is an updated version of an old book.
This exciting and practical book for compiler construction combines history and development of several early programming languages together with sufficient theory to develop a compiler for an extensive language. The book reflects the author's views that compiler construction can best be learned by the actual implementation of a compiler. A source language, equivalent to early translating languages, is developed. An object language consisting entirely of numbers is also developed. The student will learn to write programs in the developed source and object language. Using the language C++, the author gently leads the student through the steps which are necessary to complete a working compiler in a one-semester effort. Extensive exercises at the end of each chapter keep the student's focus on the big project - the implementation of a working compiler.
David Hunter 4.0 out of 5 stars Good, but repetative., January 12, 2002
Effectively, you purchase this text to learn how to write compilers and interpreters. This book does this well. The shadow of this, is the fact that 50-60% of this book is repetitious code. Hastily, you're thrown into concepts that help to define how a compiler works. Details covered range from functions of a compiler, down to function blocks of descrete code.
Exceptionally thorough, this book is written in a very linear fashion. Almost as if 'A to Z', you're taken from basic line indexing, through assembly output for x86. Providing you have the patience to properly work through this book, once you finish, you will definitely have the tools to write your own compiler.
Overall, this is a pretty good book. I would not say great because it does not keep a steady 'beat' with its steps. Fast and slow, it can be disorientating for some people. Rather than expending pages upon pages of code, I would like to see a CD included with the book. Code would be replaced by simplified function blocks to help speed the process. (To *really* grasp what the author is doing, you have to deciper the exact details of their code.)
Sean Osullivan 2.0 out of 5 stars Mak is useful, but do use it with caution, April 15, 2000
There are several things you should know about this book: 1) The book implements a top-down or recursive-descent parser, as opposed to a standard shift-reduce parser. This is *very* important, as lex/yacc, Visual Parse++, and other parsing tools are efficient shift-reduce machines. Thus, the parser isn't really portable. Even so, I did find the symbol table design that's used by the parser to be critical for what I needed.
2) The printed material is mostly (say 70%) code listings, thus even though the book is a whopping 838 pages, it would be much slimmer with fewer listings. The code is downloadable from the pusblisher's (Wiley) site.
3) The 30% of text and figures that are in the book could be much more insightful. For example, Chapter 11 - the interactive debugger should at least have some description (screenshots perhaps) of how to use the debugger. (Hint, the commands end with a semi-colon.)
4) Even though this book is C++ oriented, it doesn't use standard containers like linked lists, or trees (maps/sets). The classes have pointers in them that makes the class also act as a its own node in a list or whatever. This makes the design much more confusing than it needs to be.
5) The symbol table implementation has heavy circular dependencies. Quite honestly I don't know of a better implementation (yet). This does, however pose a problem if you'll need to extend the design (to use STL containers, to self-serialize, etc.)
The book has been a godsend, but I couldn't honestly let the 4 and 5 star reviews sit unchallenged. If I had known the above sooner, I could have saved quite a few weekends.
I think an Ideal Writing Compilers book would come bundled with a thirty day version of Visual Parse++ or Dr. Parse, and work from there.
Hugh K. Boyd 5.0 out of 5 stars Excellent Treatment of a Tough Subject, September 27, 2001
I bought this book in 1996 when I was a CS graduate student. The course text was the traditional "dragon book" which is a complete nigthmare to understand. I read this book in hopes of better understanding how compilers and interpreters are implemented and to this day I feel like I hit the jackpot. The book focuses primarily on the practical implementation of language interpreters and compilers and includes the code (C++) for a full featured Pascal interpreter (not just a minimal implementation that interprets a few statements). The author walks the reader through each class virtually line by line and presents the material in a way that any intermediate level C++ developer can easily understand.
Notwithstanding the pragmatic focus of this book, it also provides excellent treatment of the theory of compiler design. While it is at least 5 years old, I still keep this book in my library.
M. Cleary
- Hardcover: 592 pages
- Publisher: Course Technology; 1 edition (January 24, 1997)
- Language: English
- ISBN: 0534939724
- Average Customer Review:
based on 10 reviews. (Write a review)
- Amazon.com Sales Rank: #177,613 in Books
One of the best books, April 6, 2005
This book is outstanding! The Dragon Book is way overhyped. I have tried again and again to follow the dragon book, and each time I found it too difficult. On the other hand, Louden's book has answered many questions that I had in a clear, concise manner! I love this book! I have also flipped through almost all other compiler/interpreter books on the market in various bookstores, but none of them compare. This is *THE* book on introductory compiler design. Other books you might want if interested in writing your own programming language/compiler are "Programming Language Pragmatics", "Lex and Yacc", "Java Virtual Machine Specification" and "Virtual Machine Design and Implementation in C/C++".meerkat "Captain Meerkat"(Moscow, ID USA)
I taught from this book, May 6, 2003
This is an excellent basic book on compilers. Its strength is its strong practical approach combined with using YACC/LEX technology. It hand holds you through the development of a simple compiler. If I wanted to learn about compilers I would read this first. Its weakness is it is too narrow. There are plenty of features of languages that are not addressed but in passing. Its goal is to get a compiler built. For a compilers 101 class there is no better book.
by Keith Cooper, Linda Torczon
- Hardcover: 801 pages
- Publisher: Morgan Kaufmann (October 27, 2003)
- ISBN: 155860698X
- Average Customer Review:
based on 5 reviews. (Write a review)
- Amazon.com Sales Rank: #148,516 in Books
A classic, May 30, 2003
| Reviewer: SVENSSON KURT from Stockholm Sweden |
| Reviewer: A reader from Los Angeles |
| Reviewer: Cher-Wah Tan from Texas, SA USA |
Programming Language Pragmatics is one huge exception. None of the books I have read come close to the clarity that this book exhibits. On many occassions, the choice of words and presentation in this book has made me go 'Wow, I thought I already knew this stuff...'
Besides core topics, it has interesting discussion like concurrency, data-abstraction (object-oriented) and non-imperative programming models (functional and logic).
TOC (with my comments)
Ch. 1 Introduction
Ch. 2 Programming Language Syntax (theory of Regular Expression, Context-Free Grammars, Automata etc)
Ch. 3 Names, Scopes, and Bindings (binding, scope rules, closures etc)
Ch. 4 Semantic Analysis (attribute grammars, attribute flow, syntax tree etc)
Ch. 5 Assembly-Level Computer Architecture (keeping the pipeline full, register allocation etc)
Ch. 6 Control Flow
(expression evaluation, iteration, recursion, nondeterminacy etc)
Ch. 7 Data Types (type checking, pointers and recursive types etc)
Ch. 8 Subroutines and Control Abstraction (stack layout, calling sequences, parameter passing etc)
Ch. 9 Building a Runnable Program (back-end compiler structure, intermediate forms etc)
Ch. 10 Data Abstraction and Object Orientation (encapsulation, inheritance, dynamic method binding, multiple inheritance, the object model of smalltalk)
Ch. 11 Nonimperative Programming Models: Functional and Logic Languages
Ch. 12 Concurrency (shared memory, message passing etc)
Ch. 13 Code Improvement (peephole, redundancy elimination, data flow analysis, loop improvement, instruction scheduling, register allocation etc)
App. A Programming Languages Mentioned
App. B Language Design and Language Implementation
This is a very impressive book; truly one of my best investments in books so far.
5 Stars with caveats......., October 10, 2000
Reviewer: A reader from Vermont
Its hard to tell from the title of this book who will benefit from reading it
but from a practical standpoint, C++ library designers and those with an interest
in the "bleeding edge" of software engineering should find it very enlightening.
The primary focus of this book is speeding up the lifecycle of program design
by utilizing "Generative Programming". GP is a fancy name for programming
using domain specific notations and generating highly optimized code without
burdening the application programmer with low level details of domain libraries.
Chapter 1 "What is this book about?" - The authors describe GP. Short and sweet.....
Chapter 2 "Domain Engineering" - A rather dry, pedantic review of current Domain Engineering methods. This chapter reads like a PHD lit review. Boring....
Chapter 3 "Domain Engineering and OO Analysis and Design" - Why OO Analysis isn't appropriate for designing reusable libraries and analysis methods that are more suitable for the task. Quick and painless....
Chapter 4 "Feature Modeling" - One of the high points of the book. For those of you who have been stymied by the inflexibility of UML, the authors introduce the technique of "feature diagrams" which allow library designers to defer decisions like inheritance vs. aggregation until later in the design. Potentially very useful.
Chapter 5 "The Process of GP" - Describes how GP should work in an ideal world (which unfortunately doesn't exist yet). A bit too abstract.....
Chapter 6 "Generic Programming" - Describes type based programming (i.e. C++ templates) and various languages support for Generic Programming. Java programmers won't like this one!
Chapter 7 "Component-Oriented Template-Based C++ Programming Techniques" - The title pretty much says it all. Good introduction to C++ templates.
Chapter 8 "Aspect-Oriented Programming" - Aspects are portions of code that have little to do with the actual intent of the code. Examples are synchronization and error handling. This chapter describes how messy aspects can make code and how to separate aspects from core functionality. Good stuff....
Chapter 9 "Generators" - Describes how ideal code Generators should work. Good introduction to the topic.
Chapter 10 "Static Metaprogramming in C++" - For me this is the high point of the book. Compile time control structures such as IF<>, SWITCH<>, DO<> and WHILE<> are introduced. These can be used to generate configurable types as shown in later chapters. These structures are difficult to debug but if used conservatively are very powerful!
Chapter 11 "Intentional Programming" - A description of Microsoft's Intentional Programming environment. IP is the ideal GP development environment that allows library designers to enhance the main IDE with domain specific libraries. Developers interact directly with the source parse trees that are rendered to the IDE in a domain specific manner. The description is interesting but the IP Software is potential Vaporware and I'm kinda sick of reading about MS development tools that will change the world (C# anyone????)
Chapter 12-14 - The final chapters describe how to build template class generators that allow the application programming to specify functionality as a template parameter and the generator will build the type. It's as close to GP as we can get today. A list container class, bank account class and a highly optimized matrix library are designed using the GP methodology. It's nice to see the authors actually practicing what they preach.
Aside from the overly academic feel to the book and touting Microsoft fantasy-ware (which may become available... who knows?) this book offers much food for thought for system designers and C++ library implementers. The template tricks described are difficult to debug but with a little luck future compilers will provide better support for this style of compile time design. I look forward to the 2nd or 3rd edition of this book when this stuff matures.
Parser Design for the 21st century, February 7, 2002
Reviewer: Grant Steinfeld (see more about me) from New York, ny United States
I found this powerful parser framework easy to understand (with a little help from my friends) and a pleasure to incorporate into my programmers toolbox.Aho is for Computer Scientists and Mathematicians, while the organic nature of Steve's thinking and elegant application of Design Patterns to the problem of creating an extensible parser, is more up a Biologist turned webmaster alley.
In less that a few days we were able to convert IDL to WSDL, in less than 100 lines of code!
The only issue I had was the text sometimes could have benefited with some graphical depiction of the concepts, or even an accompanying flash animation / demo website. Maybe in the next edition?
Paperback - 448 pages Bk&Cd-Rom edition (February 7, 2001)
Prentice Hall PTR; ISBN: 0130258784 ; Dimensions (in inches): 1.21 x 9.22 x 6.99- Avg. Customer Rating:
![]()
A reader from San Jose, CA United States
Worth reading if you have interest in code generation, February 21, 2002
This book is definitely interesting in understanding how code generation works and how to utilize some of the newer technologies like XML and XSL to generate software.I am very impressed with some of the new, advanced code generators like CodeCharge, which utilize XML and XSL but do not give us insight to the internals of how it works.
While those tools prove that XML and XSL are great for generatng code, this book explains how it is done.
Soumen Sarkar (see more about me) from Fremont, CA United States
The ideas in the book are worth exploring, February 9, 2002
Agreed that XML may not be the best language to capture domain specification expressiveness. But use of XML/XSLT to do custom code generation has the benifit of rapid application prototyping and development. The crucial fact is that the domain specification is captured in XML only relatively few times and project software developers mainly use the generated code.A reader from Victoria, CanadaThe question is how many people in the project is exposed to 'ugliness' of XML and how many times. The advantages of 'neat' code generation far outweigh the disadvantages of 'ugliness' of domain specification in XML.
In a real Network Management Software development I achieved 60% of generated code (EJB, SNMP, Java utilities) by using custom code generation by XML/XSLT. Only myself dealt with XML other software developers happily used generated code. You can imagine the lead the project had and continues to have because of use of XML/XSLT in project specific custom code generation. The code generation system is stable now -- any new addition in EJB, SNMP model results in thousands of lines of Java/SQL/XML/SVG code without any additional effort.
I would, therefore, continue to recommend the book as worth exploring. This book really contributed new techniques in software development. More specically with XML/XSLT you have freely available tools to implement "model driven programming" in your software project.
Soso, January 15, 2002
While the book has interesting ideas, it ignores useful results of the domain-specific language community. More important, it preaches to use XML as a domain-specific language, which is in my opinion a disastrous idea.Terence Parr (jGuru.com) provides an excellent argument why this is the case in his article "Answers to the question 'When shouldn't you use XML?'", August 2001, IBM developerWorks : XML zone : XML zone articles:
"XML is a poor human interface: Humans have an innate ability to apply structure to a stream of characters (sentences), therefore, adding markup symbols can only make it harder for us to read and more laborious to type.
The problem is that most programmers have very little experience designing and parsing computer languages. Rather than spending the time to design and parse a human-friendly language, programmers are using the fastest path to providing a specification language and implementation: "Oh, use XML. Done." And that's OK, but I want programmers to recognize that they are providing an inferior interface when they take that easy route."
Besides, the book is poorly typeset. It appears that the font was increased until the book had more than 400 pages. I have never seen a bigger font in a computing book! I don't know why Prentice Hall endangers their good reputation with such a poorly typeset publication. Better try to borrow the book first before potentially wasting your money.
Mr James S Battle from
Good treatment of difficult material, December 23, 1999
authoritative, informative, and dull., November 28, 1999
Reviewer:
Ray Dillinger (see more about me) from Silicon Valley
This is a useful and highly informative text. It covers
technique and structures for the efficient compilation of OO, functional, and
Logic Programming Languages -- languages not well covered by the Dragon Book.
The code examples are sparse, and in pseudocode. The authors present
a lot of theory as mathematical formalisms -- one of the most precise and complete
ways to do it of course, but reading it is uphill work. They also cover technique
and give reasonable discussion of the complexity of various approaches. The
coverage of detail is absolutely superb.
However, to my eye and mind, the book is dreadfully dull. I find most compiler texts fun and engaging, inviting me to explore new ideas and make judgements about approaches. By contrast, this text is like being led by the hand (or by the nose) through every decision, idea, and comparison by someone who knows everything there is to know about it and doesn't care what you think or whether you get it. The technique is presented as an implementation of the theory, but real-world examples of situations requiring the application of that theory are scarce. Finally, the entire thing is written without a trace of wit or humor. I can't fault this book technically -- but I'm not confident of its ability to hold a student's attention.
Andrew W. Appel / Hardcover / Published 1998
I think it is recommended in the universities because of the support tools JLex and CUP, the documentation of which is again more pathetic!
M. Cleary
- Hardcover: 592 pages
- Publisher: Course Technology; 1 edition (January 24, 1997)
- Language: English
- ISBN: 0534939724
- Average Customer Review:
based on 10 reviews. (Write a review)
- Amazon.com Sales Rank: #177,613 in Books
One of the best books, April 6, 2005
This book is outstanding! The Dragon Book is way overhyped. I have tried again and again to follow the dragon book, and each time I found it too difficult.On the other hand, Louden's book has answered many questions that I had in a clear, concise manner! I love this book! I have also flipped through almost all other compiler/interpreter books on the market in various bookstores, but none of them compare.
This is *THE* book on introductory compiler design. Other books you might want if interested in writing your own programming language/compiler are "Programming Language Pragmatics", "Lex and Yacc", "Java Virtual Machine Specification" and "Virtual Machine Design and Implementation in C/C++".
meerkat "Captain Meerkat"(Moscow, ID USA)
I taught from this book, May 6, 2003
This is an excellent basic book on compilers. Its strength is its strong practical approach combined with using YACC/LEX technology. It hand holds you through the development of a simple compiler.If I wanted to learn about compilers I would read this first. Its weakness is it is too narrow. There are plenty of features of languages that are not addressed but in passing.
Its goal is to get a compiler built. For a compilers 101 class there is no better book.
Mak is useful, but do use it with caution., April 15, 2000
Reviewer:
Sean G. O'Sullivan (see more about me) from Fredericksburg, Va
There are several things you should know about this book:
1) The book implements a top-down or recursive-descent parser, as opposed to a standard shift-reduce parser. This is *very* important, as lex/yacc, Visual Parse++, and other parsing tools are efficient shift-reduce machines. Thus, the parser isn't really portable. Even so, I did find the the symbol table design that's used by the parser to be critical for what I needed.
2) The printed material is mostly (say 70%) code listings, thus even though the book is a whopping 838 pages, it would be much slimmer with fewer listings. The code is downloadable from the publisher's (Wiley) site.
3) The 30% of text and figures that are in the book could be much more insightful. For example, Chapter 11 - the interactive debugger should at least have some description (screenshots perhaps) of how to use the debugger. (Hint, the commands end with a semi-colon.)
4) Even though this book is C++ oriented, it doesn't use standard containers like linked lists, or trees (maps/sets). The classes have pointers in them that makes the class also act as a its own node in a list or whatever. This makes the design much more confusing than it needs to be.
5) The symbol table implementation has heavy circular dependencies. Quite honestly I don't know of a better implementation (yet). This does, however pose a problem if you'll need to extend the design (to use STL containers, to self-serialize, etc.)
The book has been a godsend, but I couldn't honestly let the 4 and 5 star reviews sit unchallenged. If I had known the above sooner, I could have saved quite a few weekends.
I think an Ideal Writing Compilers book would come bundled
with a thirty day version of Visual Parse++ or Dr. Parse, and work from there.
Great Introduction, March 22, 2000
Reviewer:
Kevin P. Albrecht (see more about me) from Tampa, Florida
This is a good introduction for people with no previous knowledge of writing
a compiler. I recommend good working knowledge of C++; and if you know Pascal,
you're even better off. Knowledge of basic data structures (Stacks, Linked Lists,
Binary Trees) is also important. The language that he implements is Pascal,
but it would be a simple task to implement another language.
A fine book on compiler construction using C++., August 30, 1999
Reviewer: Lee Carlson (globalmath@aol.com) from St.Louis, MO
This book gives a very detailed discussion of how to write a compiler using
C++. As such it could function as a supplementary textbook for a course in compilers
or as one for an advanced course in C++. The author describes in detail every
step of the way, and it makes interesting and fun reading. Buy it: it is well
worth the price.
Hardcover: 1919 pages Publisher: Prentice-Hall; 2nd edition (March 27, 1990) Language: English ISBN-10: 0131550454 ISBN-13: 978-0131550452
Olivier Langlois: My best compiler book, November 2, 2006
This book is more accessible than the Dragon book (Compilers: Principles, Techniques, and Tools) but is less complete. This book presents complete source code for parser generators tools and a C compiler. Even if this book is getting a little bit old and it targets a DOS platform, it should not stop you from acquiring this goldmine of very useful information for anyone interested in compilers for a very reasonable price.
Anonymous:
I have had this book for 8 years. It clearly describes compiler theories and examples. It is very useful when I develop very fast parser. (The code generated by lex isn't fast enough.) I am not in the compiler writing business. This book is perfect for me.
Paperback: 812 pages Publisher: Addison Wesley (July 11, 1991) Language: English ISBN-10: 0805321667 ISBN-13: 978-0805321661
eoi (see more about me) from LA CA
Crafting a Compiler with C offers an innovative approach to compiler design for students or professional programmers who use C. Through numerous examples and exercises, you'll learn how to design a working compiler from start to finish. The book also provides balanced coverage of both theoretical and implementation issues, with detailed discussions of standard compiler topics such as top-down and bottom- up parsing, semantic analysis, intermediate representations, and code generation. All the procedures in this book are presented in a readable, C-based notation. Features:
- Based on the best-selling Crafting a Compiler.
- Balances an excellent, readable introduction to compiler theory with a wealth of realistic compler design examples and exercises.
- Emphasizes the use of compiler tools that generate parsers and scanners.
- Discusses LR parsing and reduction techniques thoroughly.
- Introduces FLex and ScanGen early.
- Includes optional advanced topics at the end of each chapter.
Chapter 1 Introduction
An overview of the compilation process begins the text. The concept of constructing a compiler from a collection of components is emphasized. The idea of using tools to generate some of these components is introduced.
Chapter 2 A Simple Compiler
A very simple language, Micro, is presented, and each of the components of a compiler is discussed with respect to compiling Micro. Parts of the text of a compiler for Micro (written in Ada) are included in this chapter. The compilation of features of more comprehensive Ada subsets is the motivation for the techniques presented in the following chapters.
Chapter 3 Scanning Theory and Practice
The basic concepts and techniques for building the lexical analysis component of a compiler are presented. This discussion includes both the development of hand-coded scanners and the use of scanner generation tools for implementation of table-driven scanners.
Chapter 4 Grammars and Parsing
Fundamentals of formal language concepts and grammars are presented in this chapter, including context-free grammars, BNF notation, derivations, and parse trees. Since First and Follow sets are used in the definitions of both top- down and bottom-up parsing techniques, they are defined in this chapter. A discussion of language and grammar relationships is also included.
Chapter 5 LL(1) Grammars and Parsing
Top-down parsing is presented as the initial approach to syntax analysis. Both recursive descent and LL(1) are discussed, with an emphasis on the latter. Use of parser generators is a major focus of this chapter.
Chapter 6 LR Parsing
Bottom-up parsing is presented as an alternative approach to syntax analysis. LR, SLR and LALR parsing concepts are introduced and compared with LL techniques. Again, use of parser generators is a major focus of the chapter.
Chapter 7 Semantic Processing
The fundamentals of semantic processing in conjunction with top-down and bottom-up parsers are presented in this chapter. Topics include a comparison of alternative compiler organizations, addition of action symbols to a gram mar (for top-down parsing), rewriting grammars for "semantic hooks" (for bottom-up parsing), definition of semantic records and use of a semantic stack, checking semantic correctness, and producing intermediate code.
Chapter 8 Symbol Tables
This chapter stresses the use of a symbol table as an abstract component, utilized by the rest of the compiler through a precisely defined interface. Possible implementations are presented, followed by discussions of symbol tables for handling nested scopes and language features used to define names accessible from surrounding scopes (such as records and Ada packages).
Chapter 9 Run-time Storage Organization
Basic techniques for run-time storage management is presented, including discussions of static allocation, stack-based allocation and generalized dynamic (heap) allocation.
Chapter 10 Processing Declarations
Basic techniques for processing type, variable, and constant declarations are discussed. The organization of this material is based on semantic routines for handling specific language features.
Chapter 11 Processing Expressions and Data Structure References
Semantic routines for handling variable references and arithmetic and Boolean expressions are outlined. Address computation methods for array elements and record fields are included in the discussion of variables references. In this and the next two chapters, emphasis is placed on techniques for checking semantic correctness and generating intermediate code for use by a target code generator.
Chapter 12 Translating Control Structures
Compilation techniques for features such as if statements, case statements, and various looping constructs are the focus of this chapter. A point of emphasis is effective use of a semantic stack or syntax tree to simplify the job of handling these constructs, which can be nested and which can extend over arbitrary amounts of program text. Students should gain an understanding of the advantage of this general technique over ad hoc approaches.
Chapter 13 Translating Procedures and Functions
Techniques for processing both declarations and calls of subprograms are presented. Since much of the complexity of this topic involves parameters, considerable material is provided that deals with building parameter descriptions, checking for correctness of actual parameters in subprogram calls, and code-generation techniques required by various parameter modes. The concept of a run-time activation stack is discussed here, and the support routines necessary to implement one are outlined.
Chapter 14 Attribute Grammars and Multipass Translation
Multipass translation is modeled by traversal over an intermediate form. The attribute model of information flow receives particular emphasis.
Chapter 15 Code Generation and Local Code Optimization
The code generator is presented as a separate component that translates from the intermediate code generated by the semantic routines to the final target code of the compiler. Such topics as instruction selection, register management, and use of addressing modes are presented. Use of a code generator- generator is discussed. Discussion of basic block optimizations is included in this chapter.
Chapter 16 Global Optimization
The focus of this chapter is on practical techniques that yield useful improvements from a moderate amount of effort. Thus the main sections of the chapter include global data flow analysis, optimizing subprogram calls, and optimizing loops.
Chapter 17 Parsing in the Real World
This chapter includes material on two major topics necessary for implementing practical compilers: syntax-error handling and table compaction. The error-handling section presents error-recovery and error-repair techniques applicable to recursive descent, LL and LR parsers. The table compaction techniques included are applicable to both LL and LR parser tables, as well as to scanner tables and any other situation requiring efficient storage with fast access to elements of sparse tables.
Mr James S Battle
Good treatment of difficult material December 23, 1999
This book has a nice balance of theory and practical algorithms. There is enough detail to allow a (patient) reader to implement his own compiler tools, though like most other books on the subject, this book leaves you with the feeling that the area might have died about twenty years ago (no insult intended!); an update needed, to include OO languages, some treatment of the complexities associated with parsing modern languages, C++ etc. All things considered, still a great book, well worth the money
Luca Regini: 4.0 stars Good introduction, January 9, 2007
This book is quite dense and requires some serious work to be understood properly. It is quite complete even if it is a bit old compared with the latest twists in compiler theory. It is a mix between theory and pratical implementation. This is its main strength and its main weakness: it is not a comprehensive theorical work on compilers neither a complete "pratical" tutorial. Anyway it is a good introduction for the (college-level) student who is willing to do some serious work.
Dr R M. Siegfried: Handles a tough subject in a thorough and readable way, April 21, 2004
I teach compiler construction and I personally hate the "Dragon book" because it is beyond the level of many students. Fischer and LeBlanc present most of the same material and they make it readable. Theirs was the first book to devote an entire chapter to symbol tables, the central data structure that all components of a compiler use. There should be a law mandate that compiler courses should use either this book or Thomas Parsons'.
Paperback - 452 pages Book&Disk edition (August 15, 1994)
John Wiley & Sons; ISBN: 0471597546 ; Dimensions (in inches): 1.15 x 9.18 x
7.46
Other Editions:
Software
Amazon.com Sales Rank: 60,568
A good first step, April 20, 1999
Reviewer: A reader
from
This is a good, basic, "gateway" book on compiler and interpreter design and
implementation. It can easily provide the reader with the basic concepts of
this tricky topic in a way that will allow the reader to move on to more complicated
materials.
Having taken a compiler construction class in college using "Compilers : Principles, Techniques, and Tools", I can say that this book is much easier to understand and I wish we had spent the first 2-3 weeks of the course covering the material therein.
If you are new to compiler construction or are interested in producing a simple interpreter, this book is for you. If you already consider yourself well read in compiler technology, this book may be of questionable value.
Incomplete, poorly organized, and not very well written, April 6, 1999
Reviewer: A reader from
As with several other O'Reilly books, I found Lex & Yacc
to be maddeningly uneven. The approach is to give a too-brief synopsis of the
tool, then illustrate its use using a very specific example that, one suspects,
is merely the handiest project the authors had available.
I had a fair bit of programming experience when I bought the book, but none with Lex or Yacc. Some fundamental questions came up during the course of my muddling through, and these were left unanswered. I actually got more insight into these tools from a ~20-page web site on the topic.
The reference chapters are organized alphabetically ("ambiguities & conflicts", "bugs", ..., "%ident declaration"), and in a way that does not help someone who is looking for a specific answer (in trying to find out about the possibility of more than one parser in a program, who would think to look under 'v' for "variant and multiple grammars"?). These 'reference chapters' seemed more like a place to dump the information not discussed elsewhere.
Maybe it's a lost cause, finding a comprehensive, well-written introduction to such an arcane topic, but I'm still looking.
by David Watt, Deryck Brown
RaymondEasy to read and understand, August 15, 2003
The author has done a good job by presenting basic compiler theory and implementing a simple compiler using the java programming lauguage.A readerGood illustration of compiler concepts.
One of the better basic compiler books i have read so far.
Next book should be "Progamming language pragmatics" followed by "Advanced compiler design and implementation"
Best introduction ever written., September 22, 2001
I've purchased or borrowed 5 books on compiler design. There is no doubt that this book should be the choice for any introductory course. The authors explain everything tightly and provide a lot of actual examples in the text. All of it is in Java, of course. Don't worry if you don't use Java. It's very easy to understand if you have any experience with any OO language. I prefer Object Pascal and had no trouble whatsoever with the code.This book will not provide proofs or a lot in the way of choices for designing a compiler. This is good when you are starting out. The last thing you need if you actually want to learn about compiler design from front to back is a hundred different ways of doing the same thing. The text takes you through a small version of the "Triangle" language ("Mini-Triangle") - and the code for the entire Triangle language is available for download.
This book makes learning about compilers effortless for anyone with an OO background and a little knowledge of the most common algorithms learned in any into course on algorithms. If you can't learn from this text, then don't bother with any other.
The next book I'd recommend after reading this text is the Dragon Book. Then you can try on Advanced Compiler Design for size - which I am doing at present.
A great book to read along (or just before of after) this text is Programming Language Pragmatics. I read it in parallel. If I had to do it again, I'd probably read it first.
Excellent Introductory Compiler Text, September 28, 1999
Reviewer: A reader from St. Louis, MO, USA
This is a comprehensive and easy to understand text. It covers all the fundamental stages of compiler design, with plenty of explanation (both practical and theoretical). It doesn't exhaustively cover every conceivable topic, but it does leave you with a good taste of what's involved. Of course, it is not a book for beginning programmers, and there are very few code examples. Judging by the comments of some reviewers, I would suspect that they gave poor reviews because they lacked the prerequisite background (familiarity with a good HLL like C, data structures, mathematical background etc). As with any 'advanced' topic in computer science, there is quite a lot expected from you. Upon first reading, some topics occasionally seem overwhelming. Welcome to Earth. This is where your library card comes in. Do a little research and then come back to this text; you'll find that it is well organized and extremely clear. If you want a cookbook this book isn't for you. If you want a solid understanding of compiler fundamentals then this book is your best bet.
5 of 7 people found the following review helpful:
Great for hard-core compiler gurus, November 29, 1999
Reviewer: A reader from Dallas, TX
I picked this text up in anticipation for a compiler course at Georgia Tech. I have not read any other compiler books, so I have little to compare it to. However, I can definitely say that this is a book for people who are looking for "hard-core" compiler knowledge. It is a very dry and meticulous book. Contrary to the opinions of other reviewers, this is not an "easy to understand text". It will take quite a bit of determination to get the most out of it. If you don't love the stuff, you'll stop reading at page 100 or so. As for topics explained in this book, it seems to cover just about everything you will need to understand and write a full-blown compiler.
Dragon book is cool, but it is only for beginners. If you
are a beginner, always start with Dragon book, but don't abuse this classic
book.
The definitive compiler book for the 1990s, September 23, 1998
Reviewer: Paul Haahr (haahr@jivetech.com) from San Francisco, CA
This book is the comprehensive text for anyone working on an optimizing compiler
for uniprocessor systems. It gives good detail on all major approaches and is
up-to-date on important techniques like SSA form and partial redundancy information.
As someone working directly in the field, it's saved me the effort of
hunting up original research papers in many areas. One drawback for
this book as a practical tool: the pseudocode used to illustrate examples
is often pretty far from being suitable for real implementations.
A warning: this is not an introductory book,
and people who want to learn about the basics of building a compiler should
look elsewhere; perhaps Andrew Appel's ``Modern Compilers'' series. Muchnick's
book is for people who want to write compilers which generate high-performance
code
One of the first books on compiler construction. Outdated but still very important to read. The author can be considered as one of the "verification victims" -- despite being a very talented educator he did not produce any other book of equal significance: all other his books are overburdened with verification scholastic.
In the two years since I last worked directly with lcc, I've consulted the book on numerous occasions; Messrs. Fraser and Hanson have a clear writing and programming style that makes this book (and the awesome paper that they wrote with Todd Proebsting on lburg) one of my standard "how-to" books on simple IR and code generation issues.
I'd only like to see more information about lburg; in particular,
more about using lburg to do some simple optimizations. The writing style is
clear and reasonably concise, but the constraints of retrofitting literate programming
techniques onto an existing software project can make the code presentation
a little fragmented. Still, I always found what I wanted and usually found the
explanation to be quite good.
How they wrote *their* compiler, not how to write *yours*, April 5, 1999
Reviewer: A reader from USA
I did not like this book. First of all the authors are egotistical saying things
along the lines of "this compiler *must* be great, hundreds of people are using
it." Secondly, they wrote their compiler in pre-ANSI C, making it difficult
to read. Similarly, they use a hokey "hypertext" style format for presenting
the source code,also making it difficult to read. Thirdly, their techniques
are questionable - they don't use automatic tools for scanning or parser generation.
In fact their scanner is one big 'case' statment. Their parser is recursive
descent, hand-written. This is one of the least maintainable and most hard to
read parsing techniques. I do give them credit, though, for writing a compiler
with easily changeable back ends. This part is way cool, especially with such
diverse platforms as Sparc and x86. Finally, their writing is not easily read
- especially with the hokey code interspersed. I bought it wanting to learn
about their code generation but have decided to return it, and will probably
buy Advanced Compiler Design And Implementation; Muchnick, Steve instead.
Material below is partially based on The Teaching About Programming Languages Project. There is huge amount of this type of books and many are too scholastic and/or try to use (unnecessary) formalisms without justifying their usefulness.
Authors WEB page: Principles of Programming Languages: Design, Evaluation and Implementation by Bruce J. MacLennan (Oxford University Press), third edition, 1999).Courses that use this book:
Authors WEB page: Programming Language Concepts and Paradigms by David A. Watt (Prentice-Hall, 1990).
Authors WEB page: Programming Languages: An Interpreter-Based Approach by Samuel N. Kamin (Addison-Wesley Publishing Company, 1990).
If you use this text, you might also be interested in graduate courses that use this book.
Ravi Sethi, Tom Stone (Editor) / Hardcover / Published 1996
Amazon price: $51.95
Authors WEB page: Programming Languages: Concepts and Constructs by Ravi Sethi (Addison-Wesley Publishing Company, 1996)
Most popular humor pages:
Manifest of the Softpanorama IT Slacker Society : Ten Commandments of the IT Slackers Society : Computer Humor Collection : BSD Logo Story : The Cuckoo's Egg : C++ Humor : ARE YOU A BBS ADDICT? : Object oriented programmers of all nations : C Humor : Financial Humor : Financial Humor Bulletin, 2008 : Financial Humor Bulletin, 2010 : Richard Stallman Related Humor : Admin Humor : Perl-related Humor : Linus Torvalds Related humor : PseudoScience Related Humor : Networking Humor : Shell Humor: Financial Humor Bulletin, 2011 : Financial Humor Bulletin, 2012 : Financial Humor Bulletin, 2013 : Java Humor : Software Engineering Humor : Sun Solaris Related Humor : The Most Comprehensive Collection of Editor-related Humor : Microsoft plans to buy Catholic Church : Education Humor : IBM Humor : Assembler-related Humor : VIM Humor Computer Viruses Humor : Bright tomorrow is rescheduled to a day after tomorrow : Classic Computer Humor : Best Russian Programmer Humor : Russian Musical Humor : The Perl Purity Test : Politically Incorrect Humor : GPL-related Humor : OFM Humor : IDS Humor : Real Programmers Humor : Scripting Humor : Web Humor : Programming Language Humor : Goldman Sachs related humor : Greenspan humor :
Copyright © 1996-2013 by Dr. Nikolai Bezroukov. www.softpanorama.org was created as a service to the UN Sustainable Development Networking Programme (SDNP) in the author free time. This document is an industrial compilation designed and created exclusively for educational use and is distributed under the Softpanorama Content License. Site uses AdSense so you need to be aware of Google privacy policy. Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine. This is a Spartan WHYFF (We Help You For Free) site written by people for whom English is not a native language. Grammar and spelling errors should be expected. The site contain some broken links as it develops like a living tree...
|
|
You can use PayPal to make a contribution, supporting hosting of this site with different providers to distribute and speed up access. Currently there are two functional mirrors: softpanorama.info (the fastest) and softpanorama.net. |
Disclaimer:
The statements, views and opinions presented on this web page are those of the author and are not endorsed by, nor do they necessarily reflect, the opinions of the author present and former employers, SDNP or any other organization the author may be associated with. We do not warrant the correctness of the information provided or its fitness for any purpose.
Last modified: January 21, 2013