Compiler Intro Lecture

Download as pdf or txt
Download as pdf or txt
You are on page 1of 18

CSC 401: Compiler Construction

2023/2024 Academic Year

1 / 18
Mode of Assessment

Three (3) major assignments – 20 Marks

Three Quizzes – 20 Marks

Mid – Semester Exams (1) – 15 marks + 5 marks from Quizzes

Attendance – 10 Marks

Main Exams – 30 Marks

Reading Material
– A Practical Approach to Compiler Construction. Des Watson (2017), Springer.
– Compilers Principles, Techniques, & Tools, by A.V. Aho, R.Sethi & J.D.Ullman, Pearson
Education
– Principle of Compiler Design, A.V.Aho and J.D. Ullman, Addition – Wesley
2 / 18
Course Outline

Module-I :
– Introduction to Compiling,
– A Simple One-Pass Compiler,
– Lexical analysis

Module-II:
– Syntax Analysis,
– Syntax-Directed Translation

Module-III
– Type Checking,
– Run-Time Environments

Module-IV
– Intermediate Code Generation,
– Code generation and Optimization
3 / 18
Module I
Introduction to Compiling

4 / 18
1.0 INTRODUCTION OF LANGUAGE PROCESSING SYSTEM

5 / 18
1.0 INTRODUCTION OF LANGUAGE PROCESSING SYSTEM
Preprocessor

A preprocessor produce input to compilers.

They may perform the following functions.
– Macro processing: A preprocessor may allow a user to define
macros that are short hands for longer constructs.
– File inclusion: A preprocessor may include header files into the
program text.
– Rational preprocessor: these preprocessors augment older
languages with more modern flow-of-control and data
structuring facilities.
– Language Extensions: These preprocessor attempts to add
capabilities to the language by certain amounts to build-in
macro. 6 / 18
1.0 INTRODUCTION OF LANGUAGE PROCESSING SYSTEM
Compiler

Compiler is a translator program that translates a program
written in a source program (HLL) into an equivalent program in
(MLL) the target program.

An important part of a compiler is the error messaging system.

Structure of a Compiler

7 / 18
1.0 INTRODUCTION OF LANGUAGE PROCESSING SYSTEM
Compiler

Executing a program written in HLL programming language is
basically of two parts:
– the source program must first be compiled/translated into an
object program.
– Then the resulting object program is loaded into a memory and
executed.

Execution process of source program in Compiler


8 / 18
1.0 INTRODUCTION OF LANGUAGE PROCESSING SYSTEM
Assembler

Because of the difficult in writing or reading programs in machine
language.

Programmers use a mnemonic (symbols) for each machine
instruction, which are subsequently translated into machine
language.

Such a mnemonic machine language is called an assembly
language.

Programs known as assemblers were written to automate the
translation of assembly language into machine language.

The input to an assembler program is called source program, the
output is a machine language translation (object program).
9 / 18
1.0 INTRODUCTION OF LANGUAGE PROCESSING SYSTEM
Interpreter

An interpreter is a program that appears to execute a source
program as if it were machine language.
– Languages such as BASIC, SNOBOL, LISP can be translated using
interpreters.
– JAVA also uses interpreter.

The process of interpretation can be carried out in following phases:
– Lexical analysis
– Synatx analysis
– Semantic analysis
– Direct Execution
10 / 18
1.0 INTRODUCTION OF LANGUAGE PROCESSING SYSTEM
Interpreter

Advantages:
– Modification of user program can be easily made and
implemented as execution proceeds.
– Type of object that denotes a variables may change dynamically.
– Debugging a program and finding errors is simplified for a
program used for interpretation.
– The interpreter for the language makes it machine independent.

Disadvantages:
– The execution of the program is slower.
– Memory consumption is more.
11 / 18
1.0 INTRODUCTION OF LANGUAGE PROCESSING SYSTEM


LOADER AND LINK-EDITOR: Write short notes on these.

12 / 18
1.0 INTRODUCTION OF LANGUAGE PROCESSING SYSTEM


LOADER AND LINK-EDITOR: Write short notes on these.

13 / 18
1.0 INTRODUCTION OF LANGUAGE PROCESSING SYSTEM


LIST OF COMPILERS – Common Lisp compilers
– Ada compilers – ECMAScript interpreters
– ALGOL compilers – Fortran compilers
– BASIC compilers – Java compilers
– C# compilers – Pascal compilers
– C compilers – PL/I compilers
– C++ compilers – Python compilers
– COBOL compilers – Smalltalk compilers

14 / 18
2.0 TRANSLATOR

A translator is a program that takes as input a program written in
one language and produces as output a program in another
language.

Beside program translation, the translator performs another very
important role, the error-detection.

Any violation of the HLL specification would be detected and
reported to the programmer.

Important role of translator are:
– Translating the HLL program input into an equivalent ml
program.
– Providing diagnostic messages wherever the programmer
violates specification of the HLL
15 / 18
16 / 18
17 / 18
18 / 18

You might also like