You are on page 1of 27

Compiler

Design
Assoc. Prof. Ahmed Moustafa Elmahalawy
Communication and Computer Engineering Department
‫ميثاق المحاضرة‬

‫األحترام المتبادل‬ ‫إغالق المحمول‬ ‫تحديد الهدف‬ ‫المشاركة‬ ‫اإللتزام بالوقت‬


Outlines
1- Introduction.

2- Model of a Compiler.

3- Language Specification.

4- Grammars and Their Classification.


1- Reports / sheets = 3 Marks.

2- Attendance = 3 Marks.

3-MarksQuiz 1,2= 18 Marks.

4- Mid Term exam = 36 Marks.

6- Final Exam = 40 Marks.


References
1- Jean-Paul Tremblay and Paul G. Sorenson “The
Theory and Practice of Compiler Writing” BS
Publications 4-4-309, Giriraj Lane, Sultan Bazar,
Hyderabad - 500 095 A.P. 2008.

2- Torben Ægidius Mogensen “Basics of Compiler


Design”, Published through lulu.com.
http://www.diku.dk/ torbenm/Basics, 2000-2010.
ISBN 978-87-993154-0-6

3- Andrew W. “Modern Compiler Implementation in


Java” Appel and Jens Palsberg, Cambridge
University Press © 2002. ISBN:052182060x
Chapter 1
Introduction
Compiler Design Chapter 1: Introduction

Contents:-

1- Programming Languages

2- Translators

3- Why learn about compilers?


Compiler Design Chapter 1: Introduction

Users of modern computing systems


can be divided into two broad categories.

_There are those who never develop their


own programs, but simply use ones
developed by others.

_There are those who are concerned as


much with the development of programs as
with their subsequent use.
Compiler Design Chapter 1: Introduction

1.1 Programming Languages


In computer programming, a
programming language serves as a means
of communication between the person with a
problem and the computer used to help
solve it.
Compiler Design Chapter 1: Introduction

An effective programming language


enhances both the development and the
expression of computer programs.

It must bridge the gap between the


often unstructured nature of human thought
and the precision required for computer
execution.
Compiler Design Chapter 1: Introduction

A program solution to a given problem


will be easier and more natural to obtain if
the programming language used is close to
the problem.

Such a programming language is


usually high-level.
Compiler Design Chapter 1: Introduction

Digital computers accept and


understand only their own special low-level
language, consisting typically of long
sequences of zeros and ones.

These sequences are generally


unintelligible to humans.
Compiler Design Chapter 1: Introduction

Programmers use tools as compilers,


editors and operating systems to remove all
burdens, or all possibilities for error, as the
reader will be well aware.

Much program development was done


in machine language where programs
written as almost meaningless collections of
binary or hexadecimal digits.
Compiler Design Chapter 1: Introduction

However, in order for high-level


languages to be usable, one must be able to
convert programs written in them into the
binary or hexadecimal digits and bit strings
that a machine will understand.
Compiler Design Chapter 1: Introduction

At an early stage, the development of


translators or compilers - programs which
accept (as data) a textual representation of
an algorithm expressed in a source
language, and which produce (as primary
output) a representation of the same
algorithm expressed in another language,
the object or target language.
Compiler Design Chapter 1: Introduction

A hierarchy of programming languages


based on increasing machine independence
includes the following:

1. Machine-level languages.

2. Assembly languages.

3. Higher-level or user-oriented
languages.

4. Problem-oriented language.
Compiler Design Chapter 1: Introduction

1. Machine-level languages are the lowest


form of computer language.

Each instruction in a program is


represented by a numeric code, and
numerical addresses are used throughout
the program to refer to memory locations in
the computer's memory.
Compiler Design Chapter 1: Introduction

Also included as machine-level


programs are programs written in microcode
(i.e., microprograms).

Microcode allows for the expression of


some of the more powerful machine-level
instructions in terms of a set of basic
machine instructions.
Compiler Design Chapter 1: Introduction

2. Assembly languages are essentially a


symbolic version of a machine-level
language.

Each operation code is given a


symbolic code such as ADD for addition and
MUL for multiplication.

Moreover, memory locations are given


symbolic names such as PAY and RATE.
Compiler Design Chapter 1: Introduction

Some assembly languages contain


macroinstructions which are at a higher level
than assembly-languages instructions.

Assembly language systems offer


certain diagnostic and debugging assistance
that is normally not available at the machine
level.
Compiler Design Chapter 1: Introduction

3- Higher-level or user-oriented languages


such as FORTRAN, PASCAL, or PL/I offers
most of the features of an assembly language.
While some facilities for accessing system
level features may not be provided, a high-level
language offers a more enriched set of language
features such as structured control constructs,
nested statements, blocks, and procedures.
Compiler Design Chapter 1: Introduction

4- Problem-oriented language provides for the


expression of problems in a specific application
or problem area.

Examples of such languages are SEQUEL


for database retrieval applications and COGO for
civil engineering applications.
Compiler Design Chapter 1: Introduction

Advantages of high-level languages over


low-level languages such as machine and
assembly languages include the following:

1. High-level languages are easier to learn than


their lower-level counterparts.

2. These languages are closer to their problem


areas than lower-level languages.
Compiler Design Chapter 1: Introduction

3. The learning of many high-level languages


requires little or no computer hardware
background because such languages are
relatively machine-independent.

4. The programmer does not have to be


concerned with clerical tasks involving
numerical or symbolic references to
instructions, memory locations, constants etc.
Compiler Design Chapter 1: Introduction

5. A programmer is not required to know how to


convert data from external forms to various
internal forms within the memory of a
computer.

6. Most high-level languages offer a programmer


a variety of control 'structures which are not
available in low-level languages.
Compiler Design Chapter 1: Introduction

High-level languages offer several of the


following language constructs:

• Conditional statements (such as IF-THEN-


ELSE and CASE statements)

• Looping statements (for both counted and


conditional loops)

• Nested statements

• Block structures

You might also like