You are on page 1of 35

Compiler Design

Lecture 1: Introduction to Compilers


Prerequisites
 Computer Architecture
 Analysis and Design of Algorithms
 Concepts of Programming Languages
 Theory of Computation

A little refreshment for those courses would help you


progress well in our course 

CSCI415 | Compiler Design Lecture 1 2


Course Information
 Lecture
 Office Hours
 Grading Criteria

CSCI415 | Compiler Design Lecture 1 3


Lectures
Dr. Zeinab Abd El Haliem
(eng.zeina.fci@gmail.com)
 Lecture (2 hrs/week)
 Tuesday 2:30 – 4:30
 Theoretical and Scientific Background
 Office Hours
 Tuesday 10:30 – 12:30

CSCI415 | Compiler Design Lecture 1 4


Course Grading
Total score 100 degrees
Category Total
Final exam 25
Midterm 20
Lecture Contribution 5
Quizzes 15 (3) Percentages are
subject to changes
Assignments 10 (2)
depending on
Lab Tasks 5 circumstances at the
Project 20 (2) time

CSCI415 | Compiler Design Lecture 1 6


Course Objectives
 Develop a fundamental understanding of the
issues that arise in program translation.
 including syntax analysis, translation, and basics of
program optimization
 Learn the Science behind building up a Compiler

CSCI415 | Compiler Design Lecture 1 7


Course Learning Objectives
 Studythe basic concepts, theories and principles for writing
compilers
 Build lexical analyzer, scanner, starting from regular expression
 Get students acquainted with programming language’s definition
(Syntax and Semantics)
 Identify
and describe syntax of programming language by
Context-Free Grammars
 Implement Techniques for Efficient Parsing
 Writesyntax-directed translation schemes of Language
constructs
 Learn optimization methods for better performance, maximum
execution, efficiency and Minimum code size
CSCI415 | Compiler Design Lecture 1 8
Suggested Books

CSCI415 | Compiler Design Lecture 1 9


Course Outline
 Lexical analysis
 Syntax analysis
 Top-down parsing
 Bottom-up parsing
 Semantic analysis
 Runtime environment
 Code generation

CSCI415 | Compiler Design Lecture 1 10


Lecture Agenda
 Introduction to Compilers Theory
 Language Processing System
 Programs related to A Compiler
 Compiler versus Interpreter

CSCI415 | Compiler Design Lecture 1 11


Introduction to Compilers Theory

CSCI415 | Compiler Design Lecture 1


High-level versus low-level
languages

CSCI415 | Compiler Design Lecture 1 13


What’s a compiler?

CSCI415 | Compiler Design Lecture 1 14


Execution process of C Program

CSCI415 | Compiler Design Lecture 1 15


Language Processing System

CSCI415 | Compiler Design Lecture 1 21


Language Processing System
Source Program

Pre-processor
Pre-processed code

Compiler
Target assembly code

Assembler
Relocatable machine code
Library Files/
Relocatable Linker
modules
Executable machine code

Loader

Target Machine Code


CSCI415 | Compiler Design Lecture 1 22
1. Preprocessors
Source Program

 Delete comments, include other


Pre-processor
files, and perform macro
Compiler substitutions.
 Requiredby a language (as in C)
Assembler
or can be later add-ons that
Linker provide additional facilities

Loader

Target Machine Code


CSCI415 | Compiler Design Lecture 1 23
2. Compiler
Source Program

A compiler translates the input


Pre-processor
pre-processed code and
Compiler generate assembly language as
its target language.
Assembler
 It reveals any bugs or errors.
Linker  Itoutputs target assembly
code.
Loader

Target Machine Code


CSCI415 | Compiler Design Lecture 1 24
3. Assemblers
Source Program

 Anassembler translates assembly


Pre-processor
language programs into machine
Compiler code.
 The output of an assembler is
Assembler
called an object file, which contains
a combination of machine
Linker
instructions as well as the data
Loader
required to place these instructions
in memory.
Target Machine Code
CSCI415 | Compiler Design Lecture 1 25
4. Linkers
Source Program

Pre-processor

Compiler
 Linker is a computer program that links and
merges various object files together in order to
Assembler make an executable file.
 It searches and locates referenced
Linker module/routines in a program and determines
the memory location where these codes will be
Loader loaded, making the program instruction to have
absolute references.
Target Machine Code
CSCI415 | Compiler Design Lecture 1 26
5. Loaders
Source Program

A part of an operating system that


Pre-processor
is responsible for loading
Compiler programs and libraries.
 It calculates the size of a program
Assembler
(instructions and data) and creates
Linker memory space for it.
 Itinitializes various registers to
Loader
initiate execution.
Target Machine Code
CSCI415 | Compiler Design Lecture 1 27
Programs related to a Compiler

CSCI415 | Compiler Design Lecture 1


Other Programs: Editors
 Compiler have been bundled together with
editor and other programs into an integrated
development environment (IDE)
 Oriented towards the format or structure of
the programming language, called structure-
based
 May include some operations of a compiler
like reporting about some errors.

CSCI415 | Compiler Design Lecture 1 29


Other Programs: Debuggers
 Used to determine execution error in a compiled
program
 Keeps track of most or all the source code
information
 Halt execution at pre-specified locations called
breakpoints
 Must be supplied with appropriate symbolic
information by the compiler

CSCI415 | Compiler Design Lecture 1 30


Other Programs: Profiles
 Collect statistics on the behavior of an object
program during execution
 Called Times for each procedures
 Percentage of execution time
 Used to improve the execution speed of the
program

CSCI415 | Compiler Design Lecture 1 31


Click icon to add picture

Compiler versus Interpreter

CSCI415 | Compiler Design Lecture 1 32


Compilers Vs Interpreters

CSCI415 | Compiler Design Lecture 1 33


Interpreter Compiler
Translates a program one Scans the entire program and
statement at a time translates it into machine code

Interpreters usually take less Compilers usually take a large


amount of time to analyze the amount of time to analyze the
source code. However, the overall source code. However, the overall
execution time is comparatively execution time is comparatively
slower than compilers faster than interpreters

No intermediate object code is Generates intermediate object


generated, hence are memory code which further requires linking,
efficient hence requires more memory
Programming languages like
Programming languages like C, C++,
JavaScript, Python, Ruby use
Java use compilers
interpreters

CSCI415 | Compiler Design Lecture 1 34


Next Lecture

CSCI415 | Compiler Design Lecture 1 35


See you next lecture

CSCI415 | Compiler Design Lecture 1 36


Copyright. Vaidehi Joshi,
CSCI415 | Compiler DesignA Deeper Inspection Into Compilation
Lecture And
1 Interpretation. 37
Copyright. Vaidehi Joshi,
CSCI415 | Compiler DesignA Deeper Inspection Into Compilation
Lecture And
1 Interpretation. 38
Copyright. Vaidehi Joshi,
CSCI415 | Compiler DesignA Deeper Inspection Into Compilation
Lecture And
1 Interpretation. 39
Copyright. Vaidehi Joshi,
CSCI415 | Compiler DesignA Deeper Inspection Into Compilation
Lecture And
1 Interpretation. 40
Copyright. Vaidehi Joshi,
CSCI415 | Compiler DesignA Deeper Inspection Into Compilation
Lecture And
1 Interpretation. 41

You might also like