Compiling with C# and Java - Errata and updates

P.D. Terry, Rhodes University

(Last updated 10 February 2009)

Compiling with C# and Java, an introductory text on compiler construction using C# and Java, was published by Pearson Education on 5th November 2004. Following standard publisher practice, the book carries a publication year of 2005, and the ISBN is 0-321-26360-X.

This page records errors found in in the material as originally published. The author would be grateful to have other errors brought to his attention.

Change log

22 August 2004 - pre-release

25 November 2004 - errors in the first printing (marked 25/11/2004)

9 June 2005 - further errors in the first printing (marked 9/06/2005) - pages 182-184

26 August 2006 - further errors in the first printing (marked 26/08/2006)

10 February 2009 - further errors in the first printing (marked 10/02/2009)


Errors and misprints found in the first printing

In describing these, we have used a convention where line numbers are counted positive from the top, or negative from the bottom of a page or section.

Preface

(25/11/2004) Page xiv, line -9, missing comma inserted to improve clarity:

small enough to understand thoroughly, yet large enough to provide considerable challenge


Chapter 2

(25/11/2004) Page 21, line 5, change "the knowledge" to "a knowledge", viz:

may have to make reference to Modula-2 syntax diagrams and a knowledge ...

(25/11/2004) Page 26, line 20, missing comma inserted to improve clarity:

team development, with different members of the team assuming responsibility

(10/02/2009) Page 30, Section 2.7, line 12, change "at' to "in"

one developed in Zürich known as the "Pascal-P" compiler (Nori et al. 1981).

(25/11/2004) Page 33, line 13, missing comma inserted to improve clarity:

has many facets, but common to them all is the idea that compilers for languages

(10/02/2009) Page 34, last line

Another list is currently at http://www.startvbdotnet.com/dotnet/languages.aspx


Chapter 4

(25/11/2004) Page 45, line 14, change parentheses

data itself on the data bus. This is illustrated in Figure 4.1 (after Wakerly (1981)).

(25/11/2004) Page 45, line 17, change subscript from "memSize - 1" to "memsize", viz:

     byte[] mem = new byte[memSize];

(25/11/2004) Page 63. While not incorrect, for consistency from line 16 onwards the code should all be indented a further two spaces, as shown in the following extract:

     ...
     // results are used for I/O.  Tracing at the code level may be
     // requested.

       int loop;                   // internal loops
       int tos;                    // value popped from stack
       ...


Chapter 5

(10/02/2009) Page 88, fifth bullet

It would be clearer to say that L(A.B) = {rt | r Î L(A) and t ÎL(B)}

(10/02/2009) Page 89, line 10 need a "dot"

A * · A * = A *                      (absorption for closure)

(25/11/2004) Page 103, section 5.9.1, lines 8, 10, 22 has some words in the wrong font.

"Non-terminals", "Terminals" and "spaces" should be in the normal proportional font.

(25/11/2004) Page 108, line 17 has spurious brackets [ and ]. It should read

     Expression  =  Term { "|" Term } .

(10/02/2009) Page 110. The first paragraph after the Cocol grammars might be more clearly expressed as

Actually they are not quite the same. Since Coco/R always ignores spaces (other than in strings), the second one would accept either of the inputs

BEGIN A C E := S P A D E END
BEGIN ACE := SPADE END

while the first would only accept the input

BEGIN ACE := SPADE END

(25/11/2004) Page 115, line 8 would read better with "distinguish" in place of "recognize", viz:

to be a piper to distinguish one tune from another.

(25/11/2004) Page 119, line 17 should be changed to read

extensions that are not covered by the specification at all, the possibilities for

(25/11/2004) Page 122, line -2 should read as follows (delete "the"):

The ISO standard for EBNF is available at


Chapter 6

(25/11/2004) Page 141, line 2, missing comma inserted to improve clarity:

average person parses with ease, discerning any necessary clues from within a

Chapter 7

(25/11/2004) Page 146, line 24, replace "(1)" by "(3)", viz:

which implies that we must be able to derive ac from B. If we apply (3) again we
(25/11/2004) Page 169, last line should be indented two further spaces, viz:
        END
      END Main.


Chapter 8

(26/08/2006) Page 176, the first line should read

     IGNORE CHR(0) .. CHR(31)

(26/08/2006) Page 180, there is a closing parenthesis missing in the third line of the second block of code, which should read

     if (acceptable.Contains(sym.kind)) GetSym();

(9/06/2005) Page 182, the methods Statement, IfStatement and OtherStatement should be marked static void.

(25/11/2004) Page 183, lines 19-22 should have "Designator" replaced by "Qualifier", viz:

DS(Qualifier, Subscript) = FIRST(Subscript) È FOLLOW(Qualifier)
   = { "[" , "]" }
DS(Qualifier, FieldSpecifier) = FIRST(FieldSpecifier) È FOLLOW(Qualifier)
   = { "." , "]" }

(9/06/2005) Page 183, the method Designator should be marked static void.

(9/06/2005) Page 184, the methods Qualifier, Subscript, FieldSpecifier and Designator should be marked static void.

(26/08/2006) Page 188, there is a semicolon in place of a comma at the end of the second line of the second block of code, which should start

     static SymSet
       FirstFactor = new SymSet(identSym, numSym, lParenSym),
       FirstAssignment = new SymSet(identSym);

(26/08/2006) Page 195, the last line should read

     IGNORE CHR(0) .. CHR(31)

(25/11/2004) Page 202, line 19-23 should have "state = 12" replaced by "state = 13", viz:

      case 12:
        if (ch == '|') state = 13; else {
          symKind = noSym; finished = true;
        }
        break;

(25/11/2004) Page 204, section 8.7, line 2, replace "incorporated" by "incorporate", viz:

often incorporate such tasks as the recognition of keywords (which usually

(25/11/2004) Page 212, line -2, "Goal" should be in italics

  12    reduce    1      Goal

(25/11/2004) Page 218, second last paragraph is misleading. It should be replaced by

Although the features are not exploited in this book, the version of Coco/R developed by Wöß, Löberbauer and Mössenböck (2003) (which is distributed in the Resource Kit) can deal with LL(1) conflicts by using extra lookahead. Together with a complete C# grammar, this can be obtained from http://www.ssw.uni-linz.ac.at/Research/Projects/Coco/


Chapter 9

(26/08/2006) Page 232, line 5 of section 9.43, replace "this is this" by "this is the", viz:

translator, such as code generation. If this is the case, then the order in which the

(25/11/2004) Page 233, line 3, replace "its" by "an", viz:

by conditions included in an attribute grammar, specifying relations that must be

(25/11/2004) Page 236, line 9, "BSc" is, of course, written as a single word, viz:

     Tawuya, Robyn, Melissa, Walter, Sam, Philani, Mark, Daniel : BSc .


Chapter 10

(25/11/2004) Page 241, Section 10.2.4, line 6, Replace "Comp.java" by "Calc.java", viz:

(25/11/2004) Page 245, line -5 has a period missing, and should read

     space   = CHR(32) .        // Familiar white space

(25/11/2004) Page 250, section 10.5.4, line 7, the word pointpoint-pointSym should not have a hyphen, viz:

"pointpointpointSym"). The UserNames section may be used to prefer user-

(25/11/2004) Page 250, section 10.5.4, line -2, the ellipsis should not have internal spaces, viz:

      ellipsis = "..." .

(25/11/2004) Page 255, third bulleted paragraph. The code is badly set out; it should read:

      Option =   "push" (. stack[++top] = item; .)
               | "pop"  (. item = stack[top--]; .)
               |        (. MonitorStack(); .) .


Chapter 11

(25/11/2004) Page 291, line 16. While the case study is all right as it stands, this code can be improved (made less "dangerous") if written

     public void Here() {
       if (defined) Parser.SemError("Label already defined");
       else {
         CodeGen.BackPatch(memAdr);
         memAdr = CodeGen.GetCodeLength();
         defined = true;
       }
     }
or, at least,
     public void Here() {
       if (!defined) CodeGen.BackPatch(memAdr);
       memAdr = CodeGen.GetCodeLength();
       defined = true;
     }


Chapter 12

(25/11/2004) Page 317, section 12.6.5, line -6. To make this correct the code should include a further // and read

     public Entry  nextInScope; // link to next entry in current
                                // scope
     public bool   declared;    // true for all except sentinel entry

(25/11/2004) Page 326, lines 14 - 18. To match the code given earlier, replace "boolean" with "bool", viz:

       6   while (x) {
    ****          ^ bool expression needed
       7     int y, z;
    ****         ^ earlier declaration of y still in scope
       8     y = true || 4;
    ****                 ^ bool operands needed

(26/08/2006) Page 340, Exercise E12.37. The first production should, of course, use the terminal "switch", not "case", and so should read

     SwitchStatement   = "switch" "(" Expression ")" "{"
                           { OneSwitch }
                         "}" .


Chapter 13

(25/11/2004) Page 355, line 21, replace "any constructs" by "such constructs", viz:

same number of implicit labels for each instance of such constructs. These

(25/11/2004) Page 374, line 3, insert a comma to clarify the sense, viz:

which involved a carry bit, which consequently required unsetting before SBC

(25/11/2004) Page 379, Figure 13.1(b). The pieces on the right hand end have been joined up in error. This part should resemble something more like

        Expression
             |
             |

       ----  /  -----------.
                           |
                           |

       --------<--------   -   -------

(25/11/2004) Page 389, line 13, "cmp" should be in upper case, viz:

     MOV  [249],  [252]  ;   d := CMP


Chapter 14

(26/08/2006) Page 396, delete the spurious 10th line of code, viz:

      boolType = 6;
which already appears as line 9.

(25/11/2004) Page 426, section 14.6.3, line 2, replace "CAL" by "CALL", viz:

We would replace the LDA and CALL opcodes suggested earlier with alternatives

(25/11/2004) Page 426, section 14.6.3, line 7, replace "CAL" by "CALL", viz:

CALL L A Call and enter a function whose code commences at address A and

(25/11/2004) Page 426, section 14.6.3, line 22, replace "PVM.cal" by "PVM.call", viz:

     case PVM.call:                   // function entry

(25/11/2004) Page 430, section 14.6.5, line 2, replace "CAL" by "CALL", viz:

registers, modelled in an interpreter as a small array, display. The ADR, CALL,

(25/11/2004) Page 431, line -4, replace "CAL" by "CALL", viz:

CALL L A Call and enter a function whose identifier was declared at static level L,

(25/11/2004) Page 432, line 9, replace "PVM.cal" by "PVM.call", viz:

     case PVM.call:                   // function entry

(25/11/2004) Pages 434 - 436. The various components of Figures 14.7 and 14.8 all have the same error - the character in the rightmost cell should be a lowercase z, not an uppercase Z.


Chapter 15

(25/11/2004) Page 466, line 29, the parameter "isPublic" should be written as one word, and not as "is Public", viz:

     public static Entry Insert(int kind, string name, string
                                ASMName, Type type, bool isStatic,
                                bool isPublic, Entry owner)
     // Creates a new entry with the given kind, name and type and
     // other properties

(25/11/2004) Page 482, line -17, "InaccessibleMember" and not "Inaccessible Member", viz:

     Entry m = Table.FindMember(name, d.type);
     if (InaccessibleMember(m))
       SemError("inaccessible in this context");
     if (m.isStatic && m.kind != Entry.Con)
       d = new IdentNode(m);

(25/11/2004) Page 484, line 6. The line is better indented; code would be clearer set out as follows:

     case CodeGen.mul:
       return new ConstNode(Type.intType,
                            left.value * right.value);
     case CodeGen.div:
       if (right.value == 0)
         Parser.SemError("division by zero");
       else return new ConstNode(Type.intType,
                                 left.value / right.value);
       break;


Appendix A

(25/11/2004) Page 551, line 3. Insert "the name", viz:

assembler source is to prefix the name with a bracket [. In ILASM/CIL the CIL name is


Appendix D

(25/11/2004) Page 588, line 12, the URL should be in Courier font, viz:

     http://www.softwareautomata.com


Disclaimer

While every attempt has been made to ensure that the material in this distribution performs properly, the author can accept no liability for any damage or loss, including special, incidental, or consequential, caused by the use of the software, directly or indirectly.

However, please bring any problems that you may experience to the attention of the author.

Pat Terry
Computer Science Department
Rhodes University
GRAHAMSTOWN 6140
South Africa
Tel: +27-46-603-8292
FAX: +27-46-636-1915
e-mail: p.terry@ru.ac.za