View Review Details


Book:   lex & yacc
Subject:   lex & yacc, 2nd Edition Review
Date:   1999-10-26 00:00:00
From:   Andreas H. Studer


The book is IMO well written, but misses some points. - I found out that calling tokens exactly the same name in YACC "like they are" can produce problems. YACC produces #define's out of the tokens and I wrote a C++-wrapper around the parser. So to make it easy, I first called all methods like the Tokens if they belongs to a token. But the Include of the C++-wrapper-header is after the defines, so if you'll have methods/variables/functions/whatever in this header with the same name like the tokens, you'll get in big troubles... and since it's a #define-problem, it's not that easy to find out... (in fact I thought first that the compiler has a serious problems with mixed C/C++-code :-) So my solution is: call all YACC Tokens with T_ something and nonterminals (to make it complete) NT_ something. Then you have less problems with this. - yyerror(...) and dislike functions are often in the book programmed like this: "void yyerror(...)". the problem is that compilers like Visual C++ expect for external binding functions a form like "int yyerror(...)". In fact if you'll look to the skeleton-sourcecode, you'll see exactly this. More than that: MSVC++ MUST have a return value for a function if it is declared that way. So you MUST include "return 0;" at the end. - the BISON-part is too small. Even if the documentation of BISON is well, I think it would be useful to have a closer look at this well prooven alternative to YACC. I think it's the most used YACC-alternative since Linux became so popular. A closer look to the "hairy-parser" and multi-threading ready parsers out of Bison would be helpful since it's not that well explained in the documentation of BISON. - It is really not a big problem to wrap a C++-class around a YACC-generated parser. I would include some thoughts in the book how to implement it. BISON is C++-compatible, but I don't know about the others. So to figure out which are would be helpful too. After all I had some problems with BISON on Windows, but the most-hard to figure out problems where solved by the book. It is also very well written, easy to understand and explains all important points well. It also helps the user to think the "yacc/lex"-way. Even if it is the only (?) book which describes this both Unix-tools, I can't imagine that it could be really alot better. Andreas H. Studer


See larger cover