lex & yacc, 2nd Edition
Publisher: O'Reilly Media
Final Release Date: October 1992
Pages: 388

This book shows you how to use two Unix utilities, lex and yacc, in program development. These tools help programmers build compilers and interpreters, but they also have a wider range of applications.

The second edition contains completely revised tutorial sections for novice users and reference sections for advanced users. This edition is twice the size of the first and has an expanded index.

The following material has been added:

  • Each utility is explained in a chapter that covers basic usage and simple, stand-alone applications
  • How to implement a full SQL grammar, with full sample code
  • Major MS-DOS and Unix versions of lex and yacc are explored in depth, including AT&T lex and yacc, Berkeley yacc, Berkeley/GNU Flex, GNU Bison, MKS lex and yacc, and Abraxas PCYACC
Table of Contents
Product Details
About the Author
Colophon
Recommended for You
Customer Reviews

REVIEW SNAPSHOT®

by PowerReviews
oreillylex & yacc, 2nd Edition
 
3.3

(based on 9 reviews)

Ratings Distribution

  • 5 Stars

     

    (2)

  • 4 Stars

     

    (1)

  • 3 Stars

     

    (4)

  • 2 Stars

     

    (2)

  • 1 Stars

     

    (0)

Reviewed by 9 customers

Sort by

Displaying reviews 1-9

Back to top

 
5.0

Don't judge a book by its cover

By im the Runne

from San Jose

Pros

  • Accurate
  • Concise
  • Easy to understand
  • Well-written

Cons

    Best Uses

      Comments about oreilly lex & yacc, 2nd Edition:

      well

      (5 of 5 customers found this review helpful)

       
      3.0

      Nice book

      By dmkmil

      from Undisclosed

      Comments about oreilly lex & yacc, 2nd Edition:

      I bought the book back in 1993 and it pleases me each time a read it.

      If you have a project involving yacc and lex , this is the best source I have found the last years.

      However, a new edition would be nice !

      Notice : Take care as in certain examples memory is dynamically allocated but not freed.

      (1 of 7 customers found this review helpful)

       
      4.0

      Attractive Book

      By supersimha

      from Undisclosed

      Comments about oreilly lex & yacc, 2nd Edition:

      I have been refering the book for past three months which has helped me a lot in constructing a compiler(using c++,tool- vc++)as a part of my academic project. The book has helped in several stages of the process. The chapter 8(Yacc ambiguities and Conflicts) helped me in debugging several errors that i came across. I am very thankful to the author.

      Now the compiler is working as a win32 console based application. Currently i am trying to integrate lex and yacc with vc++(MFC)so that my compiler will have a very good user interface.I am facing problem with this integration process as c++ code snipet in the MFC application cannot call the parser(.y files).

      so i request your suggestion regarding this problem.

      Thanking You Narasimha.G

      (1 of 1 customers found this review helpful)

       
      5.0

      lex & yacc, 2nd Edition Review

      By Mike

      from Undisclosed

      Comments about oreilly lex & yacc, 2nd Edition:

      The book is full of code examples that show how to do things that may be very hard to re-invent. It is listed as a reference by yacc implementer. I find this book to be very interesting and detailed.

      ---------

      Mike

      (3 of 3 customers found this review helpful)

       
      2.0

      lex & yacc, 2nd Edition Review

      By Emmet Caulfield

      from Undisclosed

      Comments about oreilly lex & yacc, 2nd Edition:

      I have a copy of the 1st edition and recently downloaded the sample code.

      I have to concur with Andy Wong Man Boon, above, that the sample code is pretty crummy. I downloaded the code because I'd a particular interest in the SQL grammar, and found that the sql1 example didn't compile, complaining about being unable to resolve yywrap(). After fixing this problem (either by linking with -lfl or putting in a substitute yywrap()), I then found that the executable gave:



      1: syntax error at FROM

      SQL parse failed



      when fed SELECT foo FROM bar;!

      Now, I'm no expert (otherwise I wouldn't have the book), but it seems to me that simple queries like this aren't allowed by the grammar in sql1.y. I got it to work by putting the following into the grammar:



      sql: query_exp

      ;



      How trustworthy can the code, or the book, be when this kind of simple mistake is made?

      Emmet

       
      3.0

      lex & yacc, 2nd Edition Review

      By Philippe

      from Undisclosed

      Comments about oreilly lex & yacc, 2nd Edition:

      If you plan to update some of the sample code, in addition to what is explain in the previous message, I would recommend to use :

      static int add_word(int type, char *word);

      static int lookup_word(char *word);

      for the declaration of the functions used in the first sample.

      Regards, Philippe

      Feel free to visit http://perso.wanadoo.fr/philippe.baucour/

      (4 of 6 customers found this review helpful)

       
      3.0

      lex & yacc, 2nd Edition Review

      By Andy Wong Man Boon

      from Undisclosed

      Comments about oreilly lex & yacc, 2nd Edition:

      Well..it's time for a 3rd edition.

      After going through Chapter 1 to 7, I found

      that this is a good book on the subject "lex & yacc".

      Unfortunately, the examples in the book (Chap 1 to 5) do not

      compile and link properly. Even if an example happens to compiled and linked

      successfully, the executable will crash when executed :(

      (i.e. Example 1-7 (pg. 17))

      I felt that failure in compiling and linking the examples

      will discourage lex & yacc newbies from experimenting and learning lex & yacc.

      I've included some fixes below to make the examples compile and link properly.

      (I'm using Cygwin on W2K, flex 2.5.4 and bison 1.875)

      Hopefully, these fixes will help lex & yacc newbies who is reading

      this book and tinkering with the examples and exercises.

      -Andy Wong Man Boon

      if you want fixes for the other examples)

      {15} to {18}

      For ch1-05.l, add...

      %{

      ...

      int lookup_word(char *word);

      int add_word(int type, char *word);

      /* We do not require yyunput so do not define it to avoid

      'C' compiler warning */

      #define YY_NO_UNPUT

      %}

      %option noyywrap

      %%

      ...

      %%

      ...

      int add_word(int type, char *word) {...}

      int lookup_word(char *word) {...}

      For ch1-05.y, add..

      %{

      #include

      /* prototype for lexer function */

      int yylex(void);

      /* prototypes for error handling functions */

      int yyerror(char *s);

      %}

      ...

      %%

      ...

      %%

      ...

      int main(void)

      {

      yyin = stdin; /* Initialise yyin ! */

      ...

      return 0;

      }

      int yyerror(char *s)

      {

      fprintf(stderr, "yyerror: %s\n", s);

      return 1; /* Recovery not attempted */

      }

      Compile ch1-05.l and ch1-05.y as follows:-

      flex ch1-05.l

      bison -y -d ch1-05.y

      gcc -Wall -c lex.yy.c y.tab.c

      gcc -Wall -o ch1-05 lex.yy.o y.tab.o

      {24}

      For Ex1-10.l, the returning values from

      yylex() would be clearer if you add...

      %{

      #include

      ...

      #define YY_NO_UNPUT

      %}

      %option noyywrap

      %%

      ...

      \n { return '\n'; }

      "$" { return 0; /* end of input */ }

      %%

      int main(void)

      {

      int val;

      while( (val=yylex()) > 0) {

      printf("token is %d\n", val);

      }

      printf("token is %d\n", val);

      return 0;

      }

      Compile Ex1-10.l as follows:-

      flex Ex1-10.l

      gcc -Wall lex.yy.c -o Ex1-10

      {59}

      For ch3-01.y, the returning value of yyparse()

      would be clearer if you add to the main() the following:-

      int main(void)

      {

      ...

      bRet = yyparse();

      if( bRet != 0) {

      printf("yyparse() error: ret %d\n", bRet);

      } else {

      printf("yyparse() ok: ret %d\n", bRet);

      }

      return 0;

      }

      (3 of 3 customers found this review helpful)

       
      3.0

      lex & yacc, 2nd Edition Review

      By Fractal A.

      from Undisclosed

      Comments about oreilly lex & yacc, 2nd Edition:

      An informative and helpful source of information. The bits regarding the differences between yacc and flex are especially useful. More information about the errors generated by flex and bison would be useful. More explanations regarding the yylex, yyparse, yyparse_param, yyerror, and other yy functions are needed. Particularly, how are these functions attached to flex and bison? Also, how might a programmer manipulate these functions to obtain different results?

      (3 of 3 customers found this review helpful)

       
      2.0

      lex & yacc, 2nd Edition Review

      By Fabio Rotondo

      from Undisclosed

      Comments about oreilly lex & yacc, 2nd Edition:

      I bought this book because a very short article on a magazine excited me, but

      after I have read it completely, I still have a lot of questions and black holes

      in the way things work between Lex & Yacc.

      It is a good book, with lots of examples, but for somebody like me, with no

      background experience about these two tools, sometimes it went just too quickly.

      I think that some intermediate steps would do the trick.

      It is a good reference, anyway.

      Displaying reviews 1-9

      Back to top

       
      Buy 2 Get 1 Free Free Shipping Guarantee
      Buying Options
      Immediate Access - Go Digital what's this?
      Ebook: $23.99
      Formats:  DAISY, ePub, Mobi, PDF