Download Chapter 5

Transcript
w
py
o
C
n
242 Chapter 5
tio
a
lu
a
Compilation
Ev
n
o
i
at
py
o
C
lu
a
v
E
The source code is translated into executable code. The executable code can later be
executed without any need for the translator. Compilation is a batch process. The
input to this process is the high-level source code and the output is the executable file
or files. Errors encountered during the compilation process are normally relayed as a
series of messages to the programmer. All coding errors are reported at the end of an
unsuccessful compilation operation.
au
.
m
w
o
c
.
c
d
.pe
au
.
m
The operation of a compiler can be likened to a translator translating a book into a
foreign language. Imagine a translator is converting a novel written in German into
English. The translator will translate
the entire text of the novel. Once the
manuscript in English has been
produced in its entirety it is printed
and distributed. It is difficult for
The English translation is
The translator converts the entire
readers of the English version to
distributed separately to the
German novel into English.
original German version.
realise the language used in the
Fig 5.9
original German book. Let’s take our
Compilation
can
be
likened to the translation
analogy one step further. The
of a novel from German into English.
translator will no doubt find various
sentences in the original German difficult to translate into English. The translator
would make a note of these sentences. At the end of the translation process, these
sentences would be analysed and perhaps the original meaning would be acquired
from the author. The translator then goes back over the manuscript correcting their
translation. This is similar to a compiler listing all the errors found in the source code
and the programmer going back and correcting these errors. There is one important
difference however. A compiler does not produce any actual machine code until the
entire source code is known to be correct in terms of the syntax of the source code.
o
c
.
c
ed
p
.
w
w
w
y
p
n
o
i
at
Co
n
o
i
t
a
u
al
lu
a
v
Ev
E
o
c
.
c
Compilers are used to produce executable code for the majority of commercial
applications. Compiled programs generally run faster and more efficiently than
similar interpreted products. As a compiled program is made up of machine code
instructions, it is very difficult for the details of the original source code to be realised.
This protects the intellectual rights of the author of the software. As the source code is
not available to users, it is virtually impossible for them to make changes to the
product. This makes it easier for software companies to provide quality support for
their products, as they know precisely the workings of the application.
au
.
m
d
e
p
.
d
.pe
o
c
.
c
au
.
m
w
w
w
w
Executables created with compilers will
w always be machine specific. If a product is to
w
y
operate on a different processor p
oryoperating system, then the source code will need to
p
o
o
be recompiled using a compiler
that produces the appropriate machine code
C
C
instructions.
n
n
tioTASK Activity
tio
GROUP
a
a
lu translate the entire source code into an executable fileaorlufiles
Compilers
a
v later
no errors are found). These executables are run atEsome
Ev(assuming
stage separate to the compiler. Design a flowchart to describe the
operation of a compiler.
GROUP TASK Research
Make a list of programming languages which are generally compiled and
briefly outline the main use of each language.
o
c
.
dc
py
o
C
w
w
w
u
a
.
mSoftware Design and Development –The HSC Course
au
.
m
d
o
c
.
c