Compiler Design Lec1
Compiler Design Lec1
Software Department
Third Class
Compiler Design
Lec1: Introduction to Compiler Design
Submitted By
Assistant Lecturer: Muneera Yousif
language
punched card word translator 1010000…………
2. Interpreter
Just like a compiler, is a translator used to convert high-level programming language to low-
level programming language. It converts the
program one at a time and reports errors detected
at once while doing the conversion. With this, it
is easier to detect errors than in a compiler. An
interpreter is faster than a compiler as it
immediately executes the code upon reading the
code. It is often used as a debugging tool for
software development as it can execute a single
line of code at a time. An interpreter is also more
portable than a compiler as it is not processor-
dependent, you can work between hardware architectures. The machine-language target program
produced by a compiler is usually much faster than an interpreter at mapping inputs to outputs.
An interpreter, however, can usually give better error diagnostics than a compiler, because it
executes the source program statement by statement.
3. A hybrid compiler
Java language processors combine compilation and interpretation, as shown in figure a Java
source program may first be compiled into an intermediate form called bytecodes. The bytecodes
are then interpreted by a virtual machine. 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.
A hybrid compiler
4. Assembler
An assembler is a translator used to translate assembly language to machine language. It is like a
compiler for the assembly language but interactive like an interpreter. Assembly language is
difficult to understand as it is a low-level programming language. An assembler translates a low-
level language, an assembly language to an even lower-level language, which is the machine
code. The machine code can be directly understood by the CPU.
Components of a Compiler:
Front-End Back-End
Source Object
program program
Analysis synthesis
IR
Lexical Syntactic Semantic Code Code
analyzer analyzer analyzer generator optimizer
Tables
The front end must encode its knowledge of the source program in some intermediate
representation( IR )structure for later use by the back end. This (IR) a compiler uses some set of
data structures to represent the code that it processes.That form is called an intermediate
representation, or IR. becomes the compiler’s definitive representation for the code it is
translating. At each point in compilation, the compiler will have a definitive representation. It
may, in fact, use several different IRS as compilation progresses, but at each point, one
representation will be the definitive IR.