Docsity

Introduction to compiler, Slides of Compilers

Partial preview of the text

Download Introduction to compiler and more Slides Compilers in PDF only on Docsity!

PRINCIPLES

OF COMPILERS

PRINCIPLES

OF COMPILERS

Introduction to compiling 1.^

Definition of compiler, translator, interpreter

2.^

Analysis of the source program

3.^

The phases of a compiler

4.^

Compiler construction tools

2.

Programming language basics 3.

Lexical

analysis

Lexical

analysis

1.^

Role of lexical analyzer

2.^

Input buffering

3.^

Specification of tokens

4.^

Recognition of tokens using finite automata

5.^

Regular expressions and finite automata

6.^

From NFA to DFA

7.^

Regular expression to an NFA

Definition Of Compiler, Translator, Interpreter:

a)

Definition Of Compiler: ^

Compiler

is^

a^

software(translator/program)

which

converts a program written in high level language(sourcelanguage) to low level language (object/target/machine language)

language)

It converts the whole program in one session and reportserrors detected after the conversion. 

A

compiler

is^

processor

dependent

and

platform

dependent. 

Example: GCC(GNU compiler collection)

Types of compiler(Based on compiler passes):^ 

A compiler pass refers to the traversal of a compilerthrough the entire program.  Compiler pass are two types:

Single

pass

compiler

Single

pass

compiler

Two pass compiler or Multi pass Compiler

Single pass compiler: ^

If we combine or group all the phases of compilerdesign

in

a

single

module

known

as

single

pass

compiler. 

Example : Pascal ,C

There are two parts to compilation:^ 1.

Analysis:

The analysis part breaks up the source program intoconstituent

pieces

and

creates

an

intermediate

representation of the source program. 2.

Synthesis:

The

synthesis

part

constructs

the

desired

target

program from the intermediate representation.

The context of a compiler: A language processing system:^ 

A language processor is a software program designed orused to perform tasks such as processing program code tomachine code. 

There

are

two

main

types

of

language

processors:

Interpreter

and

translator(Compiler

and

assembler)

Interpreter

and

translator(Compiler

and

assembler)

The difference between an interpreter and a translator isthat an interpreter is telling the computer what to do. Atranslator

takes

the

program’s

code

and converts

it

to

machine code, allowing the computer to read it.

We have learnt that any computer system is made ofhardware

and

software.

The

hardware

understands

a

language, which humans cannot understand. So we writeprograms in high level language, which is easier for us to understand and remember. These programs are then fedinto a series of tools and OS component to get the desiredcode that can be used by the machine. This is known as language processing system.

Preprocessor:

A preprocessor, generally considered as a

part of compiler, is a tool that produces input for compilers.It deals with macro processing,augmentation,file inclusion,language extension etc. 

Compiler:

Compile the preprocessed code and translates it

to assembly

code

to assembly

code

Assembler:

An assembler translates assembly language

into machine code. The output of an assembler is called anobject

file,

which

contains

a

combination

of

machine

instructions as well as the data required to place theseinstructions in memory.

Linker:

Linker

is

a

computer

program

that

links

and

merges various object files together in order to make anexecutable file. 

Loader:

It is a part of OS and is responsible for loading

executable

files

into

memory

and

execute

them.

It

calculates the size of a program(instructions and data) andcreates memory space for it. It initializes various register toinitiate execution.

b)

Translator: ^

It is a programming language processor that converts a computerprogram from one language to another. It takes a program writtenin source code and converts it into machine code. It discovers andidentifies the error during translation. ^

Purpose:

It translates high level language program into a machinelanguage program that the CPU can understand. It also detectserrors in the program.

^

Types 1.^

Compiler

2.^

Interpreter

3.^

Assembler

c)^

Interpreter: ^

It is a translator used to convert high level programminglanguage to low level programming language. ^

It^

converts

the program one at

a time and

reports

errors

detected at once, while doing the conversion. ^

An interpreter is faster than a compiler as it immediately executes

the

code

upon

reading

the

code

.

executes

the

code

upon

reading

the

code

.

^

It used as a debugging tool for software development as it canexecute a single line of code at a time. ^

An interpreter is also more portable than a compiler as it is notprocessor dependent. ^

Example : Python