Professional Documents
Culture Documents
Compiler Design
CS224
Course Description:
Course Title and Code - Compiler Design CS224
Pre-requisite: CS213: Course Level: 6, Credit Hours: 3(3+0)
Compiler introduction and background. Phases and cousins of compiler
Lexical analysis: regular expressions, finite automata and its implementation. مبادئ وتقنيات وأدوات هو كتاب شهير في مجال علوم الحاسوب من تأليف الفريد:المترجمات
يعرف أيضا الكتاب. رافي سيتي وجيفري المان يختص بشرح كيفية بناء المترجمات،فينو اهو
Syntax analysis: top-down and bottom up parsing. Derivation trees. Writing ( نظرا للصورة الموجودة على غالفه التي تحتويDragon Book) باسم كتاب التنين
context-free grammar of a sample computer language. Recursive descent يسمى اإلصدار األول من الكتاب باسم كتاب التنين األحمر،على فارسيحمل سيفا ويقاتل تنين
parsing. LL parsing. Non-recursive predictive parsing. SLR parsing. )بينما يسمى الجزء الثاني باسم كتاب التنين االرجواني (حسب لون الغالف
Syntax-directed translation. S-attributed and L-attributed grammars. Abstract
syntax trees. :مواضيع الكتاب
Semantic analysis. Type checking. بنية المترجمات
Runtime environments. Activation trees, activation records, calling sequence. النحوي التحليل +الداللي التحليل + الصرفي التحليل :المفردات تحليل
) تجزئة (لغة
Intermediate code generation. Three-address code. Flow-of-control statements
الترجمة الموجهة نحو بناء الجملة
translation. ) توليد الكود (توضيح
Code generation and optimization. Register allocation, basic block and أمثلة البرمجيات
peephole optimizations.
About the Textbook: Will be available in PDF format on the LMS for you to download for free. (QU Blackboard)
Text: = Compilers: Principles, techniques and tools. Aho, Lam, Sethi and Ullman
Ref: = Introduction to Compiler Design. T. Mogensen
Marks distribution: About Me
50 Marks Final Exam Name : Dr. Galal Eldin Abbas Eltayb (Sudan)
20 Marks First Midterm B.Sc., M.Sc.: Computer science , Ph.D.: Information technology
20 Marks Second Midterm University Staff since 1995 (Khartoum, Sudan Tech, Nile valley, Qassim)
10 Marks Quizzes an assignments
Chapter 1: Introduction
Computer Language
A language is consider as a finite set of strings over
some finite set of alphabets. Computer languages are
consider as finite sets, and mathematically set
operations can be perform on them. Finite languages
can be describe by means of regular expressions.
Compiler1
A compiler is a special program that processes statements written in a particular programming
language and turns them into machine language or "code" that a
computer's processor uses. Typically, a programmer writes
language statements in a language such as Pascal or C one line at a
time using an editor. The file has been created contains what are called the source statements. The
programmer then runs the appropriate language compiler, specifying the name of the file that
contains the source statements.
1
https://searchdatacenter.techtarget.com/answer/What-is-the-difference-between-a-compiler-and-an-interpreter
https://www.thefreecountry.com/compilers/
When executing (running), the compiler first parses (or analyzes) all of the language statements
syntactically one after the other and then, in one or more successive stages or "passes", builds the
output code, making sure that statements that refer to other statements are referred to correctly in
the final code. Traditionally, the output of
the compilation has been called object code
or sometimes an object module. (Note that
the term "object" here is not related to
object-oriented programming.) The object
code is machine code that the processor can
execute one instruction at a time.
History of Compiler
Compiler name
The original meaning of “to compile” is “to select representative material and add it to a
collection”; makers of compilation CDs use the term in its proper meaning. In its early days
programming language translation was viewed in the same way: when the input contained for
example “a + b”, a prefabricated code fragment “load a in register; add b to register” was selected
and added to the output. A compiler compiled a list of code fragments to be added to the translated
program. Today’s compilers, especially those for the non-imperative programming paradigms,
often perform much more radical transformations on the input program.
Features of Compilers
Types of Compiler
Single Pass Compilers Two Pass Compilers Multipass Compilers
Multipass Compilers
The multipass compiler processes the source code or syntax tree of a program several times. It
divided a large program into multiple small programs and process them. It develops multiple
intermediate codes. All of these multipass take the output of the previous phase as an input. So it
requires less memory. It is also known as 'Wide Compiler'.
Tasks of Compiler
Role of Compiler
Application of Compilers
Interpreter
An interpreter is a computer program that is used to directly execute program instructions written
using one of the many high-level programming languages. The interpreter transforms the high-
level program into an intermediate language that it then executes, or it could parse the high-level
source code and then performs the commands directly, which is done line by line or statement by
statement.
Role of Interpreter
The interpreter converts the source code line-by-line during RUN Time.
Interpret completely translates a program written in a high-level language into machine level
language.
Interpreter allows evaluation and modification of the program while it is executing.
Relatively less time spent for analyzing and processing the program
Program execution is relatively slow compared to compiler
No Compiler Interpreter
1 Performs the translation of a program as a Performs statement by statement translation.
whole.
2 Execution is faster. Execution is slower.
3 Requires more memory as linking is Memory usage is efficient as no intermediate
needed for the generated intermediate object code is generated.
object code.
4 Debugging is hard as the error messages It stops translation when the first error is met.
are generated after scanning the entire Hence, debugging is easy.
program only.
5 Programming languages like C, C++ uses Programming languages like Python, BASIC, and
compilers. Ruby uses interpreters.
o We can build a new front-end for an existing back end (so a new machine can quickly get a
set of compilers for different source languages).
o We only have to write 2n2n half-compilers instead of n(n−1)n(n−1) full compilers. (Though
this might be a bit of an exaggeration in practice!)
4. To perform machine independent optimizations.
Synthesis part
• Synthesis part takes the intermediate representation as input and transforms it to the target
program.
• It is also termed as back end of compiler.
The design of compiler can be decomposed into several phases, each of which converts one form of
source program into another.