Re: _Compiler_Design_in_C_: is it a good book?

holub@violet.berkeley.edu
Tue, 13 Feb 90 10:12:19 PST

          From comp.compilers

Related articles
_Compiler_Design_in_C_: is it a good book? uucibg@swbatl.swbt.com (1990-01-25)
Re:_Compiler_Design_in_C_: is it a good book? jemarchese@srv.PacBell.COM (1990-01-31)
Re: _Compiler_Design_in_C_: is it a good book? holub@violet.berkeley.edu (1990-02-13)
Re: _Compiler_Design_in_C_: is it a good book? ken@minster.york.ac.uk (1990-03-07)
| List of all articles for this month |

Date: Tue, 13 Feb 90 10:12:19 PST
From: holub@violet.berkeley.edu
Newsgroups: comp.compilers
In-Reply-To: <1990Jan30.054651.17353@esegue.segue.boston.ma.us>
Organization: University of California, Berkeley

In article <1990Jan30.054651.17353@esegue.segue.boston.ma.us> Brian Gilstrap
writes:


>Does anyone know anything about ... _Compiler_Design_in_C_ by Allen I. Holub
>The blurb from Prentice says:
>"Using a new, easier-to-understand approach with less math, this handy guide
>covers all the topics you need for a full grasp of compilers. Author/expert
>Holub fully develops the functional versions of *lex* and *yacc*, and uses
>them to create a complete C compiler that includes parts of C normally left out
>of compiler design guidebooks. This version of *yacc* features [sic] error
>recovery and parser, which automatically produce a window-oriented debugging
>environment where the parse and value stacks are visible. Software and
>complete source code are included."
>


The blurb from Prentice is essentially correct, though it's long on hype and
short on content. The book is about 950 pages (not 500), and it will be in
stock at Prentice Hall on Feb. 21. In general, the book avoids greek letters
and and pedantic gobblygook in favor of (I hope) clear English prose. My
intention is to make everything in the book as understandable as possible.
There are lots of worked out examples, etc. All of the basic theory is
covered, but unlike most books, all of the theory is also implemented in C.


The book contains a complete implementation of lex and two versions of yacc
(one that builds a top-down parser and one that builds a bottom-up parser).
The yacc version, called occs (pronounced ox) for "the other compiler
compiler system" is a bit slower than the UNIX one, but it improves on UNIX
yacc in a couple of important ways: (1) the error recovery is dramatically
impoved and it's automatic (a panic-mode strategy is used and you don't have
to mess with error tokens and the like), and (2) when you compile the output
for debugging, you get a complete window-based debugging environment that
shows you the parse (and value) stack as it works. You can watch attributes
being synthesized, set breakpoints on reductions by specific productions,
tokens being input, log parse traces to a file, etc.


Lex and yacc are then used to build an almost-ANSI C compiler. I confess to
not implementing some of the small details (eg. no floating point,
initializations aren't done correctly, etc.), but all of the hard stuff is
there: all C types except float and double are supported, including
structures and enums. Arbitrarily complex declarations are supported
(pointers to arrays of pointers to functions that return structure
pointers--that kind of thing). All of the operators (including conditionals,
etc. && and || are done correctly). All of the control flow statments
(including switches and the for statement) are supported, etc.


The "software and complete source code" is not bundled with the book, but
it's available from me for $60. It runs now on the IBM/PC (Microsoft 5.1) and
BSD UNIX (4.3). The code is written in ANSI C, however, and I tried not to
use any functions that I thought were vendor specific, so it should port to
other environments with little difficulty. Curses is used for the debugger's
window output, and the book (and disk) includes sources for an IBM/PC curses
implementation. There's a tear-out postcard in the book that you can use to
order the software. I don't expect the code to be bug free, but I plan to
post regular updates to the net.


- Allen Holub
    holub@violet.berkeley.edu
    ...!ucbvax!violet!holub





Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.