Java Reference
In-Depth Information
Exercises
1. The model of compilation we introduced is essentially batch-oriented.
In particular, it assumes that an entire source program has been written
and that the program will be fully compiled before the programmer
can execute the program or make any changes. An interesting and
important alternative is an interactive compiler . An interactive compiler,
usually part of an integrated programdevelopment environment, allows
a programmer to interactively create andmodify a program, fixing errors
as they are detected. It also allows a program to be tested before it is fully
written, thereby providing for stepwise implementation and testing.
Redesign the compiler structure of Figure 1.4 to allow incremental com-
pilation. (The key idea is to allow individual phases of a compiler to be
run or rerun without necessarily doing a full compilation.)
2. Most programming languages, such as C and C
, are compiled directly
into the machine language of a “real” microprocessor (for example, an
Intel x86 or Sparc).
++
erent approach. It is commonly
compiled into the machine language of the JVM. The JVM is not imple-
mented in its own microprocessor, but is instead interpreted on some
existing processor. This allows Java to be run on a wide variety of ma-
chines, thereby making it highly platform independent.
Explain why building an interpreter for a virtual machine like the JVM
is easier and faster than building a complete Java compiler. What are the
disadvantages of this virtual machine approach?
Java takes a di
ff
3. C compilers are almost always written in C. This raises something of a
“chicken and egg” problem—howwas the first C compiler for a particular
system created? If you need to create the first compiler for language X on
system Y, one approach is to create a cross-compiler . A cross-compiler
runs on system Z but generates code for system Y.
Explain how, starting with a compiler for language X that runs on system
Z, you might use cross-compilation to create a compiler for language X,
written in X, that runs on system Y and generates code for system Y.
What extra problems arise if systemY is “bare”—that is, has no operating
system or compilers for any language? (Recall that Unix R
is written in
C and thus must be compiled before its facilities can be used.)
 
 
Search WWH ::




Custom Search