Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Introduction to compiler, Slides of Compilers

Introduction to compiling Definition of compiler, translator, interpreter Analysis of the source program The phases of a compiler Compiler construction tools Programming language basics Lexical analysis Role of lexical analyzer Input buffering Specification of tokens Recognition of tokens using finite automata Regular expressions and finite automata From NFA to DFA Regular expression to an NFA

Typology: Slides

2019/2020

Available from 11/05/2023

soorya-merin-tom
soorya-merin-tom 🇮🇳

1 document

1 / 191

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
PRINCIPLES
OF COMPILERS
PRINCIPLES
OF COMPILERS
1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

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