Language Translators
Language Translators
BS FOUNDATION SEMESTER
1
Why Programming?
• Computer is just a dumb machine made up of different
electronic components. It is like a box which cannot do anything by
itself.
5
Why Programming?
• Programming is more about problem solving skills than writing
the code itself.
NOW DO THIS!
NOW DO
THIS! NOW
DO THIS!
NOW DO THIS!
NOW DO
THIS! 8
Program
• Program is a set (collection) of instruction to do a meaningful
task.
• Instructions 1-6 are used to solve a single task. This collection of instruction
is known as a program.
10
Programming Language
11
Programming Language
12
Programming Language
• Each language has a unique set of keywords (special words that it
understands) and a special syntax (format) for organizing program
instructions.
• There are many programming languages. For example:
13
Types of Programming Languages
• There are three types of programming languages:
14
Low-Level
Languages
LANGUAGE
16
Low-Level
Languages
• Two of the types of low level languages are:
17
Machine Language
• It is one of the low level language.
18
Machine Language
• Here all the instructions are written as code of binary sequence. For
example:
• In order to do addition, the code is: 10010001
• In order to decrement a number by one, the code is: 11011011
• In order to move data from one place to another, the code is:
10000111
19
Machine Language
• There are hundreds of instructions and each instruction has a binary code.
20
Machine Language
• Machine language program example:
10010010
11001010
01001010
11110101
00000101
00101000
11101010
10101010
21
Assembly Language
• Assembly language is same as machine language but uses English like words
to represent individual operations.
• For example: Instead of binary codes it uses : ADD, MOV, SUB, INC
• It is easier than the machine language but still it is very difficult to control a
larger program using assembly.
22
Assembly Language
23
Assembly Language
• Assembly language program example:
MVI A, 05h
MVI B, 9Ah
ADD B
INC
A
STA
24
High-Level
Languages
LANGUAGE
26
High-Level
Languages
• Like assembly language, it also uses English like words for the operations.
27
High-Level
Languages
• Some of the high level programming languages are:
• GW Basic • COBOL • J#
• C++ • Python • Ruby
• JAVA • C# • PHP
• Pascal • Visual Basic
28
High-Level
Languages
• High level language program example:
int main()
{
int a = 5;
int b =
6;
if(a > b)
cout<<“First number is greater.”;
else
cout<<“Second number is greater.”;
}
29
Middle-Level Languages
LANGUAGE
• A language that has the features of both low level and high level languages.
• More formally, a high level language that allows you to write low level
programs in it is called as middle level language.
31
Middle-Level Languages
• Some of the middle level programming languages are:
• C
• IBM PL/S (Programming Language/Systems)
• BCPL (Basic Combined Programming Language)
• BLISS (Bill's Language for Implementing System Software)
32
Source Code and Object
Code
Source Code Object Code
33
Source Code and Object
Code
Source Code Object Code
34
Language Translators
35
Language Translators
• Language translator is a program that converts the source code in to the
object code.
CONVERT
Source Code Translator Object Code
Language Translator
36
Why Language Translators?
• Computer only understands object code (machine code).
• There must be a program that converts source code in to the object code so
that the computer can understand it.
• The programmer writes the source code and then translator converts it in
machine readable format (object code).
37
Types of Language Translators
• There are three types of language translator:
38
Assembler
• Assembler is the language translator that converts assembly language code
in to the object code (machine code).
CONVERT
Assembly
Assembler Object Code
Source
Code
39
Compiler
• Compiler is the language translator that converts high level language code in
to the object code (machine code).
CONVERT
High-Level
Compiler Object Code
Source
Code
40
Compiler
1 2 3 4
CONVERT
High-Level
Interpreter Object Code
Source
Code
42
Interpreter
Program
Execute
1
43
Difference between Compiler and Interpreter
• Compiler • Interpreter
• It is faster. • It is slower.
• Errors are displayed after entire • Errors are displayed for every instruction
program is checked. • interpreted (if any).
45
Bu
g
• An error or defect occurred inside a computer program or hardware that
causes it to produce an incorrect or unexpected result, or to behave in
unintended ways is called as a bug.
• Most of the bugs arise from mistakes and errors made by programmer in
source code.
• The term bug was used by Grace Hopper in 1946.
• Hopper used to work on Mark II computer, there some error occurred in the
system. The cause of the error was a moth (bug) trapped in a relay creating
short circuit.
• That caused the term bug to be coined.
46
Debugging
47
Debugging
• It is the process of finding and fixing the bugs (errors) in the program.
48
Types of errors
49
Types of errors
50