To start off, preprocessing replaces certain pieces of text by other text according to a system of macros. Next, compilation translates the source program into assembly instructions, which are then converted to machine instructions. Finally, the linking process establishes a connection to the operating system for primitives. This includes adding the runtime library, which mainly consists of memory management routines.
Source program preprocessing ¯ Source program compiling ¯ Assembly program assembling ¯ Machine instructions linking ¯ Executable code
Figure 7.1: Steps in the production of an executable.
The lexical analysis stage transforms a sequence of characters to a sequence of lexical elements. These lexical entities correspond principally to integers, floating point numbers, characters, strings of characters and identifiers. The message Illegal character might be generated by this analysis.
Sequence of characters lexical analysis ¯ Sequence of lexical elements parsing ¯ Syntax tree semantic analysis ¯ Annotated syntax tree generation of intermediate code ¯ Sequence of IL optimization of intermediate code ¯ Sequence of IL generation of pseudo code ¯ Assembly program
Figure 7.2: Compilation stages.
Syntax error
indicates that the phrase analyzed does not follow the grammar of the
language.Standard compiler graphical notation is used for describing the components in figure 7.3. A simple box represents a file written in the language indicated in the box. A double box represents the interpretation of a language by a program written in another language. A triple box indicates that a source language is compiled to a machine language by using a compiler written in a third language. Figure 7.4 gives the legend of each box.
The legend of figure 7.3 is as follows: