0% found this document useful (0 votes)
12 views4 pages

Lecture01

The document provides an overview of compiler design, explaining key concepts such as programming languages, compilers, interpreters, and the roles of linkers and preprocessors. It distinguishes between high-level and low-level programming languages, as well as the differences between object files and executable files. Additionally, it outlines the process of compiling a source program into an object program and the subsequent linking to create an executable file.

Uploaded by

Abdallah Ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views4 pages

Lecture01

The document provides an overview of compiler design, explaining key concepts such as programming languages, compilers, interpreters, and the roles of linkers and preprocessors. It distinguishes between high-level and low-level programming languages, as well as the differences between object files and executable files. Additionally, it outlines the process of compiling a source program into an object program and the subsequent linking to create an executable file.

Uploaded by

Abdallah Ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

1

Compilers Design
1 - Introduction
Reference
Introduction to Compiler Design, Mogensen, Torben Ægidius
A preview of this book is available at Google-Books:
https://books.google.com.eg/books?id=KvDustn1eikC&printsec=frontcover&sourc
e=gbs_ge_summary_r&cad=0#v=onepage&q&f=false

1.1 What is a programming language?


A programming language is a set of commands that you use to write programs (give
instructions to the computer).

1.2 Types of programming languages


1.2.1 High level programming languages
Closer to human languages (Human-like or English-like) and further from machine
languages.
Examples: Java, Python, and C++.

1.2.2 Low level programming languages


Low-level programming language used to interface with computer hardware.
Machine Language
The computer only understands combinations of 0 and 1 code, a language which we
call machine language.
Machine language is extremely difficult for human.
Assembly Language
Assembly language uses symbolic commands (MOV, ADD, SUB, CMP … etc.)
instead of binary numbers allowing humans to read the code easily.
Assembler
An assembler translates an assembly language program to machine language.

1.3 What is a source program?


A source program is a program written in high-level programming language.
2

1.4 What is an object program?


An object program is a program written in machine language.

1.5 What is a compiler?


A compiler is a computer programs that translates a source program (a program
written in high-level language) to an equivalent object program (a program written in
machine language). For example: C++ compiler.

1.6 Compilers versus Interpreters


The compiler (like C++ compiler) translates the entire source program to another
object program (if and only if the source program has NO syntax errors).
An interpreter translates the program line by line; it takes one line, checks it for syntax
errors, translates it into machine language and then executes it. This means that after the
program runs, it may stop because of a syntax error. Example: Matlab.

1.7 Using intermediate languages


Some compilers do NOT generate machine code directly; they generate a program in
an intermediate language that is translated by a part of the compiler called "back end" into
machine language. The intermediate language may be assembly language and the back end
may be an assembler.

1.7.1 The back end


The back end, translates the intermediate code to machine language.

1.8 Linkers
A linker collects different object files into an executable file. A linker also connects
an object program to the code for standard library functions.
3

Example
Consider the following C++ program:
Saved as "test.cpp"

#include <stdio.h>
int main()
{
int x = 2;
int y = 3;
int z = x + y;
printf("z = %d\n",z);
double a = 2.5;
return 0;
}

When you make (build) the program (run it), the following things happens:
• The source file "test.cpp" is compiled to an object file "test.obj"
• The linker collects the object file "test.obj" with the code in the library file "stdio.h",
the part of "stdio.h" that contains "printf" is compiled and added to "test.obj"

1.9 Object file (.obj) versus Executable (.exe) file


Both object file (.obj) and executable file (.exe) are written in machine code
Differences:
1. We can execute an executable file (by double clicking it) while we cannot execute an
object file.
2. An object file is a file that has not yet been linked to the libraries, so some function
definitions are not yet determined which exist in the libraries, and that is why we cannot
execute it. Once an object file is linked with the library by the compiler, then all function
definitions are determined and we get an executable file, which can be executed.

1.10 The parts of a compiler


A compiler is divided into passes; each pass may be divided into phases.
4

1.10.1 The Preprocessor


A preprocessor is a program that processes its input data (the source program) to
produce output; the output of a processor is used as input to the compiler.
The C preprocessor responsible for handling preprocessor directives: #include and
#define.

You might also like