Java Reference
In-Depth Information
Some programming languages, like Java, also specify various static type rules, that a
program and its constructs must obey. These additional rules are usually specified as part
of the semantics.
Programming language designers go to great lengths to precisely specify the structure
of tokens, the syntax, and the semantics. The tokens and the syntax are often described
using formal notations, for example, regular expressions and context-free grammars. The
semantics are usually described in a natural language such as English 1 . A good example
of a programming language specification is the Java Language Specification [Gosling et al.,
2005].
1.1.2 Machine Languages
A computer's machine language or, equivalently, its instruction set is designed so as to
be easily interpreted by the computer itself. A machine language program consists of a
sequence of instructions and operands, usually organized so that each instruction and each
operand occupies one or more bytes and so is easily accessed and interpreted. On the other
hand, people are not expected to read a machine code program 2 . A machine's instruction
set and its behavior are often referred to as its architecture.
Examples of machine languages are the instruction sets for both the Intel i386 family
of architectures and the MIPS computer. The Intel i386 is known as a complex instruction
set computer (CISC) because many of its instructions are both powerful and complex. The
MIPS is known as a reduced instruction set computer (RISC) because its instructions are
relatively simple; it may often require several RISC instructions to carry out the same oper-
ation as a single CISC instruction. RISC machines often have at least thirty-two registers,
while CISC machines often have as few as eight registers. Fetching data from, and storing
data in, registers are much faster than accessing memory locations because registers are part
of the computer processing unit (CPU) that does the actual computation. For this reason,
a compiler tries to keep as many variables and partial results in registers as possible.
Another example is the machine language for Oracle's Java Virtual Machine (JVM)
architecture. The JVM is said to be virtual not because it does not exist, but because it is
not necessarily implemented in hardware 3 ; rather, it is implemented as a software program.
We discuss the implementation of the JVM in greater detail in Chapter 7. But as compiler
writers, we are interested in its instruction set rather than its implementation.
Hence the compiler: the compiler transforms a program written in the high-level pro-
gramming language into a semantically equivalent machine code program.
Traditionally, a compiler analyzes the input program to produce (or synthesize) the
output program,
Mapping names to memory addresses, stack frame offsets, and registers;
Generating a linear sequence of machine code instructions; and
Detecting any errors in the program that can be detected in compilation.
Compilation is often contrasted with interpretation, where the high-level language pro-
gram is executed directly. That is, the high-level program is first loaded into the interpreter
1 Although formal notations have been proposed for describing both the type rules and semantics of
programming languages, these are not popularly used.
2 But one can. Tools often exist for displaying the machine code in mnemonic form, which is more readable
than a sequence of binary byte values. The Java toolset provides javap for displaying the contents of class
files. 3 Although Oracle has experimented with designing a JVM implemented in hardware, it never took off.
Computers designed for implementing particular programming languages rarely succeed.
 
Search WWH ::




Custom Search