Comments on the Tucker and Noonan book:
Page 131: The Java array declarations shown on this page all
initialize the array variables to newly created arrays. This is not
necessary. Declaring an array variable, creating an array, and
initializing an array variable are all three separate actions, any one
of which can be done without the others. In class we can work
examples where they are separated. Also, it is worth noting that the
Java arrays described as two-dimensional (or three-dimensional) are
actually one-dimensional arrays of one-dimensional arrays (of
one-dimensional arrays). For example, the array referred to by the
variable C
is a four-element array, each element of which
refers to a three-element array, each element of which is a value of
type char
. We can work some examples showing why this
matters, and how other languages differ.
Page 132: Keep in mind that the Jay syntax shown here differs from Java not only by requiring array variable declaration, array creation, and array variable initialization to all go together, but also by requiring the size of each newly created array to be specified by an integer constant, rather than an arbitrary expression that evaluates to an integer.
Also, the concrete syntax shown here defines the nonterminal Variable but makes no use of it; nor is it used in the pre-existing parts of the grammar. The abstract syntax has its own problem: the Variable in a Declaration could be an ArrayVariable, which surely isn't intended. Further difficulties arise if this extension of Jay to include arrays is used together with the earlier extension of Jay to include procedures.
Page 133: The rule stated for Jay that all array sizes need to be greater than 0 differs from Java. In Java, an array can be created with size 0. Also, the validity rules on this page (that is, the rules for V) are incomplete. We should talk a bit about the type checking and semantics for selecting and updating array elements, but also about assignments to array variables. I'm not so worried about the fact that Jay has been underspecified, but you ought to understand the issues that arise in real languages, including particularly Java.
Page 134: The footnote at the bottom of this page should be associated with the reference to Figure 5.7, not Figure 5.8. Also, in a language where all array sizes are known at compile time (which seems to be the intention for Jay), there is no need for dope vectors.
Pages 134-135: The information shown on these pages regarding
two-dimensional array indexing is not relevant to Java. As menioned
earlier, the Java array referred to by C
is a four-element array, each element of which
refers to a three-element array, each element of which is a value of
type char
. We can draw a picture of this, as an
alternative to Figure 5.8, and work out how the address of an element
such as C[2][1]
would be computed. The version shown in
the book is more relevant to languages like C and C++.