Java Reference
In-Depth Information
Chapter1
Compilation
1.1 Compilers
A compiler is a program that translates a source program written in a high-level program-
ming language such as Java, C # , or C, into an equivalent target program in a lower, level
language such as machine code, which can be executed directly by a computer. This trans-
lation is illustrated in Figure 1.1.
FIGURE 1.1 Compilation.
By equivalent, we mean semantics preserving : the translation should have the same
behavior as the original. This process of translation is called compilation.
1.1.1 Programming Languages
A programming language is an artificial language in which a programmer (usually a person)
writes a program to control the behavior of a machine, particularly a computer. Of course,
a program has an audience other than the computer whose behavior it means to control;
other programmers may read a program to understand how it works, or why it causes
unexpected behavior. So, it must be designed so as to allow the programmer to precisely
specify what the computer is to do in a way that both the computer and other programmers
can understand.
Examples of programming languages are Java, C, C ++ , C # , and Ruby. There are hun-
dreds, if not thousands, of different programming languages. But at any one time, a much
smaller number are in popular use.
Like a natural language, a programming language is specified in three steps:
1. The tokens, or lexemes, are described. Examples are the keyword if , the operator + ,
constants such as 4 and `c' , and the identifier foo . Tokens in a programming language
are like words in a natural language.
2. One describes the syntax of programs and language constructs such as classes, meth-
ods, statements, and expressions. This is very much like the syntax of a natural lan-
guage but much less flexible.
3. One specifies the meaning, or semantics, of the various constructs. The semantics of
various constructs is usually described in English.
1
 
Search WWH ::




Custom Search