Professional Documents
Culture Documents
Compiler Construction 1
Language Processing System
Compiler Construction 2
Preprocessor
Compiler Construction 3
Assembler
Compiler Construction 4
Linker
Compiler Construction 5
Loader
Compiler Construction 6
Cross Compiler
Compiler Construction 7
Cross compilation Process
A cross compiler is a compiler capable of creating
executable code for a platform other than the one on
which the compiler is run.
Compiler Construction 8
Uses of Cross Compilers
The fundamental use of a cross compiler is to separate the build
environment from target environment. This is useful in a number
of situations:
Embedded computers where a device has extremely limited
resources.
For example, a microwave oven will have an extremely small
computer to read its touchpad and door sensor, provide output to
a digital display and speaker, and to control the machinery for
cooking food. This computer will not be powerful enough to run a
compiler, a file system, or a development environment.
Since debugging and testing may also require more resources
than are available on an embedded system, cross-compilation
can be less involved and less prone to errors than native
compilation.
Compiler Construction 9
Cross Compilers cont’d
Compiling for multiple machines.
For example, a company may wish to support several
different versions of an operating system or to support
several different operating systems. By using a cross
compiler, a single build environment can be set up to
compile for each of these targets.
Compiling on a server farm. Similar to compiling for
multiple machines, a complicated build that involves
many compile operations can be executed across any
machine that is free, regardless of its underlying
hardware or the operating system version that it is
running.
Compiler Construction 10
Source-to-source Compiler
Compiler Construction 11
Interpreter
•An interpreter is another common kind of language processor. Instead of
producing a target program as a translation, an interpreter appears to directly
execute the operations specified in the source program on inputs supplied by the
user
Compiler Construction 12
Interpreter cont’d
An interpreter, like a compiler, translates high-level
language into low-level machine language.
The difference lies in the way they read the source code
or input.
A compiler reads the whole source code at once,
creates tokens, checks semantics, generates
intermediate code, executes the whole program and
may involve many passes.
In contrast, an interpreter reads a statement from the
input, converts it to an intermediate code, executes it,
then takes the next statement in sequence. If an error
occurs, an interpreter stops execution and reports it.
whereas a compiler reads the whole program even if it
encounters several errors
Compiler Construction 13
Compilers and Interpreters
Compiler Construction 14
Overview of Compilers
Compilation Process:
Data
Source
Compiler Result
program
Compiler Construction 15
Example Of Combining Both Interpreter and Compiler
A Java source program may first be compiled into an intermediate form called
bytecodes.
The bytecodes are then interpreted by a virtual machine. A benefit of this
arrangement is that bytecodes compiled on one machine can be interpreted on
another machine, perhaps across a network.
In order to achieve faster processing of inputs to outputs, some Java compilers,
called just-in-time compilers, translate the bytecodes into machine language
immediately before they run the intermediate program to process the input.
Compiler Construction 16
Model of A Compiler
Compiler Construction 17
Compiling Passes
Compiler Construction 18
Cousins of Compilers
Preprocessors
Assemblers
Compiler may produce assembly code instead of
generating relocatable machine code directly.
Loaders and Linkers
Loader copies code and data into memory, allocates
storage, setting protection bits, mapping virtual
addresses, .. Etc
Linker handles relocation and resolves symbol
references.
Debugger
Compiler Construction 19
Tasks of Compilation Process and Its Output
Compiler Construction 20
Parse Tree and Symbol Table
Compiler Construction 21
Symbol Table
Compiler Construction 22