flex & bison

Errata for flex & bison

Submit your own errata for this product.


The errata list is a list of errors and their corrections that were found after the product was released. If the error was corrected in a later version or reprint the date of the correction will be displayed in the column titled "Date Corrected".

The following errata were submitted by our customers and approved as valid errors by the author or editor.

Color Key: Serious Technical Mistake Minor Technical Mistake Language or formatting error Typo Question Note Update



Version Location Description Submitted By Date Submitted Date Corrected
Safari Books Online
example2-3
top

The %option line is missing yylineno: /* fb2-3 skeleton for include files */ %option noyywrap %x IFILE ... should read /* fb2-3 skeleton for include files */ %option noyywrap yylineno %x IFILE

Note from the Author or Editor:
accept proposed change, which is in the middle of p.28

jjberry  Aug 11, 2009  Jul 19, 2013
Safari Books Online
xv
Middle of page

Lex was designed by Mike Lesk and Eric Schmidt (the same Eric Schmidt who now heads Google) to work with ***bison*** should be: Lex was designed by Mike Lesk and Eric Schmidt (the same Eric Schmidt who now heads Google) to work with ***yacc***

Note from the Author or Editor:
accept suggested correction

Anonymous  May 04, 2010  Jul 19, 2013
Other Digital Version
N/A
?

Where others have reported error in first bison example: I have to agree. In my case I get 32767 as the answer consistently if input is valid. Changing from $1 to $2 (as everyone has suggested) fixes this. (I'd love to know why 0,1 and 32767 are the values people get.)

Note from the Author or Editor:
on page 11, in line starting | calclist exp EOL in the printf call change $1 to $2

Martin Packer  Apr 14, 2012  Jul 19, 2013
Safari Books Online
3.6
para 9

We can add these lines to the definition section to tell it how to resolve the conflicts: Previously referred to as 'declarations' section? And referred to as such in the next text para? "We can add these lines to the definition section to tell it how to resolve the conflicts:"

Note from the Author or Editor:
yes, change definitions to declarations in last para on p. 59

dpawson  Aug 30, 2009  Jul 19, 2013
Printed
Page 10
bottom

CFG is a Type 2 language, not a Type 3 as stated in the book

Note from the Author or Editor:
change 3 to 2 in two places in the footnote on page 10

Anonymous  Jan 19, 2012  Jul 19, 2013
PDF
Page 12
5th paragraph

The text in the 5th paragraph of page 12 mentions a "calcset" start symbol, but what we have in the previous page is a grammar whose start symbol is named "calclist".

Note from the Author or Editor:
yes, "calcset" should be "calclist". Oops.

Fernando Carrijo  May 11, 2010  Jul 19, 2013
Printed
Page 25
last lines of example 2-2

The last test reads: if (argc > 1) /* print total if more than one file */ It should really be: if (argc > 2)

Note from the Author or Editor:
accept suggested change

Anonymous  Apr 16, 2010  Jul 19, 2013
PDF
Page 28
first pattern in example 2-3

The pattern is in error. The pattern ^"#"[ \t]*include[ \t]*\[\"<] must instead be ^"#"[ \t]*include[ \t]*[\"<] if the scanner is to match any #include files at all. Note the extra and erroneous backslash in the published text.

Note from the Author or Editor:
In the example on the last line of the page, delete the \ between * and [ as suggested.

Kyle Ferrio  Dec 11, 2010  Jul 19, 2013
Printed
Page 30
Example 2-3

The end of the first comment in the popfile function is missing: /* get rid of current entry */ fclose(bs->f); ^^^^

Note from the Author or Editor:
accept suggested change

craie  Aug 07, 2010  Jul 19, 2013
Printed
Page 30
Example 2-3

Near the end of the newfile function, the fn parameter (a character pointer which originated from yytext) is copied into both bs->filename and curfilename. Although this happened beforehand, the author even warns against this type of activity on page 36 (first paragraph). Therefore I believe it should be strdup'd instead (at least the first and then you can copy it). Otherwise, by the time you take this record off the stack, it won't be pointing to the same information.

Note from the Author or Editor:
p. 30, second line, change fn to strdup(fn) change sixth line to curfilename = bs->filename in middle of example, below the line fclose(bs->f); add new line free(bs->fn);

craie  Aug 07, 2010  Jul 19, 2013
Printed
Page 34
middle of the code example

The call of perror in the code uses argv[1]. It should be: perror(argv[i]);

Note from the Author or Editor:
accept suggested correction argv[1] should be argv[i]

Anonymous  Apr 17, 2010  Jul 19, 2013
Printed
Page 35
5th paragraph

The lookup function uses strcmp (case sensitive string comparison) even though the author points out on page 33 that the yytext is not case folded in this case-insensitive example. Perhaps stricmp or strcasecmp was meant? Otherwise the symbol table will not reflect the case-insensitivity intended (and the instrumented statistics may be suspect). This problem is repeated in the symcompare function on page 37.

Note from the Author or Editor:
In the code about 2/3 of the way down on page 35, change strcmp to strcasecmp

craie  Aug 07, 2010  Jul 19, 2013
PDF
Page 42
punctuators declaration

At the punctuators declaration pattern: "="|"*="|"/="|"%="|"+="|"-="|"<<="|">>="|"&="|"^=""|=" I think that needs to be: "="|"*="|"/="|"%="|"+="|"-="|"<<="|">>="|"&="|"^="|"|=" ^ needs an extra `|' symbol

Note from the Author or Editor:
Suggested change is correct. Thanks.

crosvera  Jul 05, 2012  Jul 19, 2013
Printed
Page 44
last paragraph

For example 2-5, popfile() function should not be the same as the ones earlier in chapter 2. It should be modified a little, or a segment fault will raise, when parsing more than one C source files from command line. Snippet of popfile() from example 2-3: /* switch back to previous */ prevbs = bs->prev; free(bs); if (!prevbs) return 0; /* switch to previous */ yy_switch_to_buffer(prevbs->bs); curbs = prevbs; yylineno = curbs->lineno; curfilename = curbs->filename; return 1; For this version, when a second C source file from command line is open, newfile() function will see non-null curbs, and no space will be allocated for curbs, but curbs has been freed by popfile() already. So, for example 2-5, the code should be changed to: /* switch back to previous */ prevbs = bs->prev; free(bs); /* current bs should be restored, before returning */ curbs = prevbs; if (!prevbs) return 0; /* switch to previous */ yy_switch_to_buffer(prevbs->bs); yylineno = curbs->lineno; curfilename = curbs->filename; return 1;

Note from the Author or Editor:
Yes, it's an error, don't immediately see how to change the book so it fits on the page.

Hz Song  May 09, 2011 
PDF
Page 50
para. 1

The reader had to be pretty alert to realize that the shift/reduce sequence is correct for the grammar including expression : NUMBER '+' NUMBER | NUMBER '-' NUMBER but not the "extended" grammar expression : NUMBER NUMBER '+' NUMBER | NUMBER '-' NUMBER A rearrangement of pp 48-50 would do a lot to clarify and avoid confusing the reader encountering LR grammar for the first time. N.B. that the really alert reader will notice that the 'extended' grammar is missing the single quotes around the operator tokens.

Note from the Author or Editor:
On p.48 in the example in the middle, put single quotes around '+' and '-'

Kyle Ferrio  Dec 12, 2010  Jul 19, 2013
PDF
Page 63
bottom quarter of page

The following block of code correctly appears at the top of page 61 and is erroneously repeated near the bottom of page 63, both within Example 3-5 (fb3-2.h). It should appear exactly once: /* interface to lexer */ extern int yylineno; void yyerror(char *s, ...);

Note from the Author or Editor:
Yes, delete those three lines from page 63.

Kyle Ferrio  Dec 21, 2010  Jul 19, 2013
PDF
Page 77
bottom quarter (Example 3-8, fb3-2func.c)

The call yyerror("call to undefined function", fn->name); will not write the intended diagnostic, unless changed to yyerror("call to undefined function %s", fn->name); for example.

Note from the Author or Editor:
Proposed change is correct.

Kyle Ferrio  Dec 21, 2010  Jul 19, 2013
Printed
Page 216
purecalc.l

It's probably better practice to explicitly declare %option extra-type="struct pcdata*" somewhere in the first section of purecalc.l; doing so would at least be consistent with the pure scanner word count program given earlier in the chapter.

Note from the Author or Editor:
at bottom of p.216 insert suggested line below the %option header line

Anonymous  Apr 13, 2010  Jul 19, 2013