0% found this document useful (0 votes)
18 views7 pages

Introduction of Compiler Design Compiler

The document provides an overview of compiler design, explaining that a compiler translates high-level programming languages into low-level machine code through various stages. It details the properties of compilers, the role of language processing systems, and the differences between compilers, assemblers, and interpreters. Additionally, it highlights the advantages and disadvantages of interpreters compared to compilers, emphasizing the importance of language processors in programming.

Uploaded by

Adarsh Gaonkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views7 pages

Introduction of Compiler Design Compiler

The document provides an overview of compiler design, explaining that a compiler translates high-level programming languages into low-level machine code through various stages. It details the properties of compilers, the role of language processing systems, and the differences between compilers, assemblers, and interpreters. Additionally, it highlights the advantages and disadvantages of interpreters compared to compilers, emphasizing the importance of language processors in programming.

Uploaded by

Adarsh Gaonkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Introduction of Compiler Design

 The compiler is software that converts a program written in a high-level


language (Source Language) to a low-level language
(Object/Target/Machine Language/0, 1’s).
 A translator or language processor is a program that translates an input
program written in a programming language into an equivalent program
in another language.
 The compiler is a type of translator, which takes a program written in a
high-level programming language as input and translates it into an
equivalent program in low-level languages such as machine language or
assembly language.
 The program written in a high-level language is known as a source
program, and the program converted into a low-level language is known
as an object (or target) program.
 The process of translating the source code into machine code involves
several stages, including lexical analysis, syntax analysis, semantic
analysis, code generation, and optimization.

Properties of Compilers
 Compiler verifies all types of limits, ranges, errors , etc.
 Compiler program takes more time to run and it occupies huge amount
of memory space.
 The speed of compiler is slower than other system software. It takes
time because it enters through the program and then does translation of
the full program.
 A Compiler is a software that typically takes a high level language (Like
C++ and Java) code as input and converts the input to a lower level
language at once.
 It lists all the errors if the input code does not follow the rules of its
language. This process is much faster than interpreter but it becomes
difficult to debug all the errors together in a program.
 Compiler itself must run fast
 Compiler must be portable
 Must give good diagnostics and error messages
 Generated code must work well with existing debuggers
 Must have consistent optimization
self compiler or resident compiler: When compiler runs on same machine and
produces machine code for the same machine on which it is running
Compiler may run on one machine and produces the machine codes for other
computer then in that case it is called as cross compiler.

A high-level programming language is a language that has an abstraction of


attributes of the computer. High-level programming is more convenient to the
user in writing a program.
A low-Level Programming language is a language that doesn’t require
programming ideas and concepts.

Language Processing Systems

Programs in HLL go through a series of transformations so that they can


readily be used by machines. This is where language procedure systems come
in handy.
 High-Level Language: If a program contains pre-processor
directives such as #include or #define it is called HLL. They are
closer to humans but far from machines. These (#) tags are
called preprocessor directives. They direct the pre-processor about
what to do.
 Pre-Processor: The pre-processor removes all the #include
directives by including the files called file inclusion and all the
#define directives using macro expansion. It performs file inclusion,
augmentation, macro-processing, etc.
 Assembly Language: It’s neither in binary form nor high level. It is
an intermediate state that is a combination of machine instructions
and some other useful data needed for execution.
 Assembler: For every platform (Hardware + OS) we will have an
assembler. They are not universal since for each platform we have
one. The output of the assembler is called an object file. Its translates
assembly language to machine code.
 Interpreter:
 The Compiler in one go reads the inputs, does the processing,
and executes the source code whereas the interpreter does the
same line by line. A compiler scans the entire program and
translates it as a whole into machine code whereas an
interpreter translates the program one statement at a time.
 Interpreted programs are usually slower concerning compiled
ones. For example: Let in the source program, it is written
#include “Stdio. h”. Pre-Processor replaces this file with its
contents in the produced output.
 The basic work of a linker is to merge object codes (that have
not even been connected), produced by the compiler,
assembler, standard library function, and operating system
resources.
 The codes generated by the compiler, assembler, and linker are
generally re-located by their nature, which means to say, the
starting location of these codes is not determined, which means
they can be anywhere in the computer memory, Thus the basic
task of loaders to find/calculate the exact address of these
memory locations.
 Relocatable Machine Code: It can be loaded at any point and can be
run. The address within the program will be in such a way that it will
cooperate with the program movement.
 Loader/Linker: converts the relocatable code into absolute code
and tries to run the program resulting in a running program or an
error message (or sometimes both can happen). Linker loads a
variety of object files into a single file to make it executable. Then
loader loads it in memory and executes it.
 Debuggers
A computer program used to test and debug other programs (target
program)
 Text Editors
Program that edits plain text

Language Processors: Assembler, Compiler and Interpreter


A language processor, or language translator, is a computer program that
convert source code from one programming language to another language or
human readable language. They also find errors during translation.

Why Language Processors?


It is a tedious task to write a computer program directly in machine code. The
programs are written mostly in high-level languages like Java, C++, Python etc.
and are called source code. These source code cannot be executed directly by the
computer and must be converted into machine language to be executed. Hence,
a special translator system software is used to translate the program written in
a high-level language into machine code is called Language Processor and the
program after translated into machine code (object program/object code).
Types of Language Processors
1. Compiler
 The language processor that reads the complete source program written
in high-level language as a whole in one go and translates it into an
equivalent program in machine language is called a Compiler.
Example: C, C++, C#.
 In a compiler, the source code is translated to object code successfully if
it is free of errors.
 The compiler specifies the errors at the end of the compilation with line
numbers when there are any errors in the source code. The errors must
be removed before the compiler can successfully recompile the source
code again the object program can be executed number of times without
translating it again.

2. Assembler
 The Assembler is used to translate the program written in Assembly
language into machine code.
 The source program is an input of an assembler that contains assembly
language instructions.
 The output generated by the assembler is the object code or machine
code understandable by the computer.
 code written in assembly language is some sort of
mnemonics(instructions) like ADD, MUL, MUX, SUB, DIV, MOV and
so on.

3. Interpreter
 The translation of a single statement of the source program into machine
code is done by a language processor and executes immediately before
moving on to the next line is called an interpreter.
 If there is an error in the statement, the interpreter terminates its
translating process at that statement and displays an error message.
 The interpreter moves on to the next line for execution only after the
removal of the error.
 An Interpreter directly executes instructions written in a programming
or scripting language without previously converting them to an object
code or machine code.
 An interpreter translates one line at a time and then executes it.
 Advantages:

o Modification of the user program can be easily made and implements as


execution proceeds
o Type of object that denotes a variable may change dynamically
o Debugging a program and finding errors is a simplified task
o Makes the language, machine independent

 Disadvantages:

o Execution of the program is slower


o Memory consumption is more

Example: Perl, Python and Matlab.


Comparison of Compilers and Interpreters

You might also like