Errata for Compiler Construction - Principles and Practice
by Kenneth C. Louden

Second and Third Printings

Last modified Friday, 22-Jul-2005 21:47:39 PDT

In addition to the Errata for the 4th and Higher Printings, the following errors:

Page 4

Paragraph 2, line 6: "Unix system studied in Chapter 5." should appear as "Unix system. Yacc is studied in Chapter 5."

Page 10

Figure in the middle of page: The syntax tree root node has the wrong label. It should be "assign-expression", not "assign-statement".

Page 11

Figure at the top of page: The syntax tree root node has the wrong label. It should be "assign-expression", not "assign-statement".

Page 20

Paragraph 1, lines 1-2: "--where the compiler of language B runs on a different machine, which results in a cross compiler for A" should appear as "where the compiler of language B generates code for (and runs on) a different machine, resulting in a cross compiler for A"

Page 77

12th line from the bottom: "bookkeeping tokens EOF" should appear as "bookkeeping tokens ENDFILE"

Page 106

Example 3.7: In the second line (the grammar rule for stmt-sequence), the semicolon should be Courier bold:

stmt-sequence ® stmt ; stmt-sequence | stmt

Page 111

Middle of page, 2nd line of code: This code should appear as

typedef enum {OpK,ConstK} ExpKind;

Page 113

Figures of Example 3.9: In the first figure (the parse tree), the third node labeled stmt should be in the same font as the other two stmt nodes (Roman italic). In the second figure, the second node labeled with a semicolon should be in the same font as the other node (Courier bold).

Page 127

Figure 3.4: In the syntax diagram for mulop, an arrow is missing, and in the syntax diagram for factor, three of the arrows on the right point in the wrong direction. A corrected version of Figure 3.4 is as follows:

Page 140

Exercise 3.14(a): "Write C-type declarations..." should appear as "Write C type declarations...."

Page 141

Exercise 3.18: Delete part (a) of this exercise (it requires more knowledge of context-sensitive grammars than is covered in the text). Replace part (b) with the following wording: "Is it possible to write a context-free grammar for the strings of the form xcx, where x is a string of a's and b's? Explain."

Exercise 3.22(a): "Show that a cyclic grammar is ambiguous." should appear as "Explain why a cyclic grammar is likely to be ambiguous."

Page 153

Line 7: The right-hand dollar sign should line up with the right-hand dollar sign on line 4.

Page 157

Table 4.3: Delete the 10th line of the table, which reads

$ L L S )E( i            i(1)o e o $           I ® i( E )S L

and after the 13th line, which reads

$ L L S )E                 1)o e o $               E ® 1

insert the following line:

$ L L S )1               1)o e o $               match

Page 159

Figure 4.3: Change n to m in the first line of the algorithm.

Page 161

Top of page: The parse tree figure is missing three branches involving e-productions for term' (the labels for the interior nodes are also in the wrong font). The correct parse tree is as follows:

Page 163

Table 4.4: The grammar rule in the table entry for term' and + is missing its arrow. It should appear as term' ® e .

Page 164

Figure 4.5: Change the word language to grammar in the first line of the algorithm.

Page 170

10th line from the bottom: "Rule 6 adds * to First(mulop)" should appear as "Rule 7 adds * to First(mulop)".

Page 177

First line: Change if-stmt to else-part at the beginning of the line.

Page 178

Top of page: Rule 2 is incorrectly stated and should be replaced by the correct rule, given on page 154.

Page 191

Line 3: The comma on the right-hand side of the grammar rule for var-list should be Courier bold:

var-list ® identifier , var-list | identifier

Page 205

Figure 5.3: The caption should appear as "The DFA of sets of LR(0) items...."

Page 207

Definition, item 2: Change a to g in lines 1, 2, 5, 6, 8, and 9 of this item.

Page 208

Figure 5.5: The caption should appear as "The DFA of sets of LR(0) items...."

Page 210

Definition, item 2, line 5: "Remove the string a and all of its corresponding states" should appear as "Remove the string g and all of its corresponding states."

Definition, item 2, line 7: "which the construction of a began." should appear as "which the construction of g began."

Definition, item 2, line 8: "item of the form B ® g .A b ." should appear as "item of the form B ® a .A b ."

Page 213

Table 5.8, line 3: The input is missing a right parenthesis and should appear as ")()$".

Page 216

Line 15 (middle of page): The end of this line ("because of the rule V ® V :=") should appear as " because of the rule S ® V :=".

Page 220

Figure 5.7: The transition from state 5 to itself on left parenthesis is missing its arrowhead.

Page 221

Middle of page: In condition 1 of the two conditions for a grammar to be LR(1), the item [B ® b ., X] in the second line of the condition should appear as [B ® g ., X].

Page 223

Lines 4 and 5: These lines should appear as follows:

State 2:      [S ® id ., $]
                  [V ® id ., :=]

Figure 5.8: The right square bracket in the last item listed in State 0 should be in regular font, not code font.

Page 228

Figure 5.10: The last three lines of code should be replaced by the following:

int yyerror(char * s)
{ fprintf(stderr,"%s\n",s);
  return 0;
} /* allows for printing of an error message */

Page 238

Last paragraph, lines 4-5: Replace the beginning of this sentence by the following text:

#define YYDEBUG 1

at the beginning of the Yacc specification file, just after the #includes) and by setting ...

Page 241

Yacc code at the top of the page: The last lines of this code (the rules for op) have actions that are missing the assignment symbols; thus, the last three lines of this code should be replaced by the following:

op : '+' { $$ = '+'; }
   : '-' { $$ = '-'; }
   ;

Page 247

Section 5.7.3, line 2: "...contains the pseudotoken error as the only symbol on its right-hand side." should appear as "...contains the pseudotoken error on its right-hand side."

Page 251

Exercise 5.3, line 2: The grammar rule "A® A ( A ) | e" should appear as "S ® S ( S ) | e" .

Page 253

Exercise 5.22(a): "...as described in Section 5.7.1,..." should appear as "...as described in Section 5.7.2,..."

Exercise 5.24(a): The replacement rule should appear as:

command : exp {printf("%d\n",$1);}
        | exp error {printf("%d\n",$1);}
        ;

Exercise 5.24(b): The replacement rule should appear as:

command : exp {printf("%d\n",$1);}
        | error exp {printf("%d\n",$2);}
        ;

Page 255

Exercise 5.36: Parts (a) and (b) of this exercise cannot be done simultaneously in Yacc, and should be considered as separate exercises. The comment about the use of the %union declaration applies to part (b) only.

Page 265

Example 6.3: In the fourth line (the grammar rule for var-list), the comma should be Courier bold:

var-list ® id , var-list | id

Page 272

Example 6.7: In the fourth line the attribute equation is missing a period on the left hand side, and should appear as:

id.dtype = var-list1.dtype

Page 278

Figure 6.8: The third line of code should appear as

if (t->kind == OpKind)

and the thirteenth line of code should appear as

case Times:

Page 284

Table 6.7: In the first semantic rule, the word "int" should be in italics:

Page 294

Example 6.18: In the attribute grammar table, the second and third semantic rules (for the grammar rule var-list1 ® var-list2 id ,) should appear as

var-list1 .dtype = var-list2 .dtype
id
.dtype = var-list1 .dtype

Page 311

Table 6.9: The last semantic rule in the right-hand column has a missing left parenthesis before the call to lookup. The correct rule should appear as:

decl.outtab =
        if (decl.intab = errtab) or exp.err
        then errtab
        else if (lookup(decl.intab,id.name) =
                decl.nestlevel)
        then errtab
        else insert(decl.intab,id.name, decl.nestlevel)

Page 341

Exercise 6.14, last line: "when reductions to a var-list occur." should appear as "when reductions by the rule var-list ® id occur."

Page 354

Figure 7.4: The three appearances of god should be gcd instead.

Page 355

Figure 7.5: The first line of code of the function g should appear as follows:

{ int y = m-1;

Page 367

Figure 7.10: The activation record of the call to r has two arrows from the access link field to the activation record of p. The left arrow should come from the control link field instead of the access link field. The correct figure is as follows:

Page 370

Figure 7.13, second activation record of p (fifth box down): "<access link>" should appear as "<no access link>".

Page 381

Line 7: "it is possible that memory is still so " should appear as "it is possible that memory is so ".

Line 9: "Hence, a garbage collection" should appear as "Hence, garbage collection".

Page 419

Last line: This line of code should appear as follows:

a[t4] = t3

Page 425

Second paragraph, line 5: Change "simi-lar" to "similar" at the end of the line.

Page 453

Footnote 16, last line: "Sparc.architecture." should appear as "Sparc architecture."

Page 474

Figure in the middle of the page: An arrow is missing that should point into the nonbasic block box from the right, just before the text "jump from elsewhere". The correct figure is as follows:

gif figure

Page 476

Figure 8.18: Line 6 of basic block B3 should appear as "t4 = x == 0".

Page 477

Figure 8.19: The topmost node (with label t4) should contain == rather than =.

Page 482

Section 8.10.2, line 7: "Variables that are references during loops" should appear as "Variables that are referenced during loops".

Page 493

Line 13: "a function declaration with the name main." should appear as "a function declaration of the form void main(void)."

Page 503

Code Line 51: This line of code should appear as follows:

char pgm[120]; /* source code file name */

Page 504

Code Line 100: Insert the following line of code before this line:

fclose(source);

Page 511

Code Line 510: This line of code should appear as follows:

fprintf(listing,"Const: %d\n",tree->attr.val);

Page 512

Code Line 626: Insert the following line of code at this point:

static int EOF_Flag = FALSE;

Code Line 630: Replace this line of code by the following code:

static int getNextChar(void)

Code Line 639: Replace this line of code by the following code:

else
{ EOF_flag = TRUE;
  return EOF;
}

Code Line 647: Replace this line of code by the following code:

{ if (!EOF_flag) linepos-- ;}

Page 513

Code Line 684: Replace this line of code by the following code:

{ int c = getNextChar();

Page 514

Code Line 742: Replace this line of code by the following code:

if (c == EOF) 
{ state = DONE; 
  currentToken = ENDFILE; 
}
else if (c == '}') state = START;

Page 515

Code Line 781: Replace this line of code by the following code:

tokenString[tokenStringIndex++] = (char) c;

Page 526

Code lines 1453 and 1454 should be interchanged, and code lines 1468 and 1469 should be interchanged.

Page 538

Code Line 3049: Insert the following line of code before this line:

if (c == EOF) break;

Page 552

6th line from the bottom: The code line gets(in_Line); should have an additional line of code before it, and an additional line of code after it, as follows:

fflush(stdout); 
gets(in_Line);  
lineLen = strlen(in_Line);

Page 553

2nd line from the bottom: The code line gets(in_Line); should have an additional line of code before it, and an additional line of code after it, as follows:

fflush(stdout); 
gets(in_Line);  
lineLen = strlen(in_Line);