Path: utzoo!attcan!uunet!mcsun!unido!mikros!mwtech!martin From: martin@mwtech.UUCP (Martin Weitzel) Newsgroups: comp.lang.c Subject: Re: lex & yacc - cupla questions Message-ID: <877@mwtech.UUCP> Date: 6 Aug 90 13:53:17 GMT References: <1990Jul26.175545.959@uicbert.eecs.uic.edu> <45960003@vantage.UUCP> Reply-To: martin@mwtech.UUCP (Martin Weitzel) Organization: MIKROS Systemware, Darmstadt/W-Germany Lines: 54 In article <45960003@vantage.UUCP> ray@vantage.UUCP (Ray Liere) writes: >I have found the book "Introduction to Compiler Construction with UNIX" >by Schreiner and Friedman (ISBN 0-13-474396-2) to be very helpful -- >they start with small projects and then work in to a good-sized compiler. This book has definetly its strengths and weakness. If you are completly new to compiler construction and have no plans to spend half your live reading the classical "Compilers - Principles, Techniques, and Tools" by Aho, Sethi, and Ullman, (ISBN 0-201-10088-6), the book of Schreiner and Friedman is surely an easier road to walk. But be aware that Schreiner+Friedmans book centers around writing a "Small-C"-Compiler, which is useful as a "Programming-Exercise", but not as a real product. (I'm not saying that the latter was intended or the book or promises this.) Sometimes they use programming conventions that are a little unportable, but what I allways appreciated from Schreiner+Friedmans book were the "cookbook-style" rules for `error' symbols in the grammar and `yyerrok' in the actions. What I definetely missed were the start conditions for lex. Instead they proposed and worked out at length how to recognize C-style comments using regular expressions only, which is not only much more difficult and less readable, but dangerous too, as yytext is limited to YYLMAX characters (usually 200). Explanations about how yyparse does its work are given in detail. If understanding this is not the problem (eg. if you have access to the lex+yacc tutorials which were printed in the "Unix Programmers Manual" in the days of V7-Unix), I'd rather recommend to start with "The Unix Programming Environment" by Kernighan+Pike (ISBN 0-13-937681-X). It has a large chapter where they describe the development of a small language called the "hoc" (similar to the UNIX "bc") in several steps, starting with an interpreter for expressions, later adding flow-control (if, while) and changing the whole thing to a "half-compiler". In my very personal opinion Kernighan+Pike gives you a better overview over the general techniques which must be mastered to write a compiler *and* you have less to read. Note that both books are only partially dedicated to lex + yacc, as are several other books, which contain small chapters about lex + yacc(%). Neither of each is sufficient if you want to develop a "product" and neither has much treatment of "other applications" (ie. if you want to write something different than a compiler with lex + yacc). For "real" compiler projects there are more complete books. The new book of Alan Holub, "Compiler Design in C" (ISBN: 0-13-155151-5) looks promising in this respect, but I haven't had the time for a closer look. %: If anybody has allready started a list of books which contain at least one chapter about lex + yacc, I'm willing to contribute what I know - pointers to such books as well as "personal opinion" about the quality or usefulnes of the material. Sorry that I don't have the time to start such a list myself within the next few weeks. -- Martin Weitzel, email: martin@mwtech.UUCP, voice: 49-(0)6151-6 56 83