0% found this document useful (0 votes)
19 views

Compiler Design Lec1

Uploaded by

yasien202020
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Compiler Design Lec1

Uploaded by

yasien202020
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Ninevah university

College of Information Technology

Software Department

Third Class
Compiler Design
Lec1: Introduction to Compiler Design
Submitted By
Assistant Lecturer: Muneera Yousif

Tuesday, September 24, 2024


Learning and Teaching Resources
‫مصادر التعلم والتدريس‬
Text
Authors: Alfred V. Aho, Monica Lam, Ravi Sethi, and Jeffrey D. Ullman
Required Texts Title: Compilers: Principles, Techniques, and Tools, Second Edition
Publisher: Addison-Wesley, 2007, ISBN 978-0321486813
1. Aho, Lam, Sethi, Ullman. "Compilers: Principles, Techniques and Tools", 2nd edition.
(Aho2) The 1st edition (by Aho, Sethi, Ullman - Ahol), the "Dragon Book", has been a
classic for over 20 years.
Recommended
2. Cooper & Torczon. “Engineering a Compiler” – an earlier draft has been consulted when
Texts
preparing this module. The 2nd edition is now available and being assessed (pointers will
be provided to the 1st and hopefully to the 2nd edition).
3. Grune et al. "Modern Compiler Design" (Wiley)
4. Stephen Edward's CS4115 Web Page
Websites
http://www.cs.columbia.edu/~sedwards/classes/2012/w4115-fall/index.html
1- Introduction
Now we all know computer are an electronic
machine, or in the other word the understand
only 0,1. Therefore in early days of
computation instructions to the computers
were given using perforated paper card and
punched card in this presence of the hole is
representation of zero and absences mean one,
Let take punched card word if we convert in its equivalent binary using ASCII standard for
information interchange it becomes its
Now we have a machine that has immense
potential we can employ it to solve many of our
problems but on the other hand we are facing an
awful lot of trouble while communicating with it
so What are the solutions?
Since we are facing a communication barrier we
need language translator. It translates a high-level language program into a machine language
program that the central processing unit (CPU) can understand. It also detects errors in the
program.

language
punched card word translator 1010000…………

Internal architecture for language translator


Over the time computer scientists came up with various language translator:
1. Compiler
A compiler is a translator used to convert high-level
programming language to low-level programming
language.
It converts the whole program in one session and reports
errors detected after the conversion. The compiler takes
time to do its work as it translates high-level code to
lower-level code all at once and then saves it to memory.
Before choosing a compiler, the user has to identify first
the Instruction Set Architecture (ISA), the operating
system (OS), and the programming language that will be used to ensure that it will be
compatible.
The key differences between compilation and a compiler are:
• Compilation refers to the overall process of translating high-level code into executable
machine code. This involves several steps like parsing, optimization, and code
generation.
• A compiler is the specific software program that carries out this compilation process. It
takes the source code as input and outputs the executable machine code.

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.

2. The Structure of a Compiler


Up to this point we have treated a compiler as a single box that maps a source program into a
semantically equivalent target program. If we open up this box a little, we see that there are two
parts to this mapping:
a. Analysis (Machine Independent/Language Dependent)
b. Synthesis (Machine Dependent/Language Independent).
To translate code written in a programming language into code suitable for execution on some
target machine, a compiler runs through many steps.

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.

You might also like