Re: Compiler Books? (Henry Spencer)
1 Nov 2003 12:02:25 -0500

          From comp.compilers

Related articles
Compiler Books? (2003-10-27)
Re: Compiler Books? (2003-10-31)
Re: Compiler Books? (2003-11-01)
Re: Compiler Books? (Jeff Kenton) (2003-11-21)
| List of all articles for this month |

From: (Henry Spencer)
Newsgroups: comp.compilers
Date: 1 Nov 2003 12:02:25 -0500
Organization: SP Systems, Toronto, Canada
References: 03-10-113 03-10-145
Keywords: books, C
Posted-Date: 01 Nov 2003 12:02:25 EST

VBDis <> wrote:
>IMO top-down parsers are easier to understand than bottom-up
>parsers. Even if both types can be used for C and Pascal, bottom-up
>parsers are commonly described and used for C, and top-down parsers
>for Pascal and other "Wirthian" languages.
>...if your language has to be somewhat compatible with C,
>you have to go the harder way.

Sorry, not so. C was designed for top-down parsing; the first C
compiler, Dennis Ritchie's own, used recursive descent with some

Even ANSI C is not that hard to parse top-down. It requires some work
and thought, not just a mechanical transcription of the standard's
grammar. There are a few places where it helps to peek ahead one
extra token, to decide which way to go in a timely way. And of course
you need some interaction with the symbol table to get typedefs right.
Some of this is annoying but none of it is prohibitive; I've done it.

Incidentally, Bjarne Stroustrup is on record as saying that letting
Aho and Johnson talk him out of writing a recursive-descent parser for
the early C++ was a major mistake. C++ is extremely difficult to
parse using pure bottom-up techniques, and needs a lot of kludges,
while doing it top-down is fairly straightforward and is common in
production compilers.
MOST launched 30 June; first light, 29 July; 5arcsec | Henry Spencer
pointing, 10 Sept; first science, early Oct; all well. |

Post a followup to this message

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