0% found this document useful (0 votes)
8 views

programming languages

The document provides an overview of programming languages, distinguishing between low-level and high-level languages, and explaining their characteristics. It discusses the roles of source code, object code, and language processors such as compilers and interpreters. Additionally, it highlights common programming languages and the types of errors that can occur during programming.

Uploaded by

aaimasaqlain
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

programming languages

The document provides an overview of programming languages, distinguishing between low-level and high-level languages, and explaining their characteristics. It discusses the roles of source code, object code, and language processors such as compilers and interpreters. Additionally, it highlights common programming languages and the types of errors that can occur during programming.

Uploaded by

aaimasaqlain
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

COMPUTER SCIENCE

Introduction of Programming Languages

Copyright @ IT Series www.itseries.com.pk


Topics

• Program and Programming languages


• Characteristics of High-Level Programming Languages
• Differentiate between Low-Level and High-Level Languages
• Source Code and Object Code
• Language Processors or Translators

Copyright @ IT Series www.itseries.com.pk


 A well defined set of instructions given to the computer
A person who develops
• All tasks performed by a computer are controlled by computer program program is called
programmer.
• Written in programming languages

Examples of Programs:

• Microsoft Word

• Adobe Photoshop

• Skype

Copyright @ IT Series www.itseries.com.pk


Hi..

• A set of words and symbols used to write a computer program


• Provides way of communication between user and computer
• A computer program is written in a programming language
• Provides set of rules for writing the computer Programs called syntax
• The instructions must be written according to syntax of the language
• A large number of programming languages are available for writing programs
• Programmer selects a programming language according to the type of the program

scanf
printf
(), {}, “ “ ;

Copyright @ IT Series www.itseries.com.pk


Low Level Language
• Near to computer hardware and far from human languages
• Divided into two main categories
• Machine Language
• Assembly Language
Machine Language
• Instructions are written in binary form or code
• Directly understood by the computer
• Native language of computer
• Fast program execution
• No need of translator
• Machine dependent
Low Level
• Difficult to understand and learn Languages
• Very time consuming for writing and modifying program

Copyright @ IT Series www.itseries.com.pk


Assembly Language
• Also a low level language
• One step higher than machine language
• English like words are used instead of binary code
• English like words are known as mnemonics
• mnemonic is an abbreviation for an operation
• Examples of mnemonics:
• ADD
• MOV
• MUL
• Easier than machine language
• Mostly used to write system software
• The program written in assembly language cannot be executed directly on the computer
• Requires a translator named assembler

Copyright @ IT Series www.itseries.com.pk


High Level Languages
• Close to human languages
• Instructions are similar to English language such as input and print etc.
• Easy to understand
• Every High level language has its own set of rules
• Set of rules is called syntax
• Each instruction must follow syntax of the language
• Needs translator
• Separate translator for each language
• Translator indicates errors in instructions
• A program must be error free to be converted into machine code

Copyright @ IT Series www.itseries.com.pk


Examples of High Level Languages
• C/C++ : System & Application Software
• Java: Provides strong features for Networking Programming

• Pascal: Used for Scientific and Business Applications


• FORTRAN FORmula TRANslation, very powerful Mathematical Capabilities
• BASIC: Beginners All Purpose Symbolic Instructions, mainly for students for solving simple problems

• COBOL: Common Business Oriented Language. Designed for business applications

Copyright @ IT Series www.itseries.com.pk


• Closer to human languages and far from machine language
Easy to Learn • English like languages and are easier to learn

• Easy to read and modify


Easy Error Detection • Easy to find errors in programs written in high level languages

• Syntax of High level langauges are standardized


• These languages describe well defined way of writing programs
Standardized Syntax • Different organizations determine standard syntax of these languagues
• ANSI(American National Standard Institute) is popular organization

• These languages do not require deep knowledge of hardware


Deep Hardware • A programmer can write efficient programs without a deep knowledge
of hardware
Knowledge not Required • He can concentrate on solving problems rather than concerning
hardware architecture

Copyright @ IT Series www.itseries.com.pk


• High Level Languages provide machine independence
• It means that the programs written in high level language can be
Machine Independence executed on different type of computer
• Example- Program written in C language program can be executed
on Intel & Motorola processors

• Programming in low level language is very difficult


More Programmer • But High level languages are easy to learn
• It encourages more people to learn these languages

• Programs written in high level languages are shorter than low level
languages
Shorter Programs • One instruction of high level language is equivalent to many
instructions of low level language

Copyright @ IT Series www.itseries.com.pk


Copyright @ IT Series www.itseries.com.pk
Source Code Translator(Compiler) Object Code

#include<stdio.h> 010101011010010110
#include<conio.h> 101010011101010101
void main() {
011101010101010010
printf(“I Love Pakistan”);
} 101110101010101101
010101010111011110

• High Level Language Instructions


• Also called source program • Machine Language Instructions
• Computer cannot understand source code • Also called object program or machine code
• Cannot be executed by the computer directly • Computer can understand it directly
• Need to be converted in object code

Copyright @ IT Series www.itseries.com.pk


• Type of system software that converts high level language or assembly language instructions
into machine language
• Types of language translator are:

Copyright @ IT Series www.itseries.com.pk


Compiler
• Program that converts the instruction of a high-level language into machine language as a whole
• Converts source code or program into machine or object code or program if it is free of errors
• Object program can be executed many times without translating it again
• A source code or program containing an error cannot be compiled
• The compiler generates error message to describe the cause of error
• All errors must be removed to successfully compile a source program
Examples
• C and C++ compilers Source Code Translator(Compiler) Object Code

#include<stdio.h> 010101011010010110
#include<conio.h> 101010011101010101
void main() {
011101010101010010
printf(“I Love Pakistan”);
} 101110101010101101
010101010111011110

Copyright @ IT Series www.itseries.com.pk


Interpreter
• Translate one statement of source code / program and executes it and then next statement is
translated and this goes on until end of the program

• If there is an error in the program statement, the interpreter stops working and displays the error
message

• Advantage over compiler is that an error is found immediately

• Does not execute the statement containing error

• Not very efficient

• It converts the instructions into machine program/code each time it is executed

• GWBASIC uses interpreter

Copyright @ IT Series www.itseries.com.pk


Assembler
• Program that translates the instructions of assembly language into machine language

Assembly Object Code


Assembler
Instructions

INC counter 0101010110100


MOV TOTAL, 48 1011010101001
ADD AH, BH 1110101110101
ADD MARKS, 10 0101011010101

Copyright @ IT Series www.itseries.com.pk


Compiler Interpreter
Convert the entire source code into machine code Converts one instruction into machine code at a time

Generates object code Does not generate object code

Convert high level program that can be executed Convert high level language program each time is
many times executed

Program execution is fast Program execution is slow

Displays syntax error after compiling the whole Display the syntax error on each instruction of the
program program

Copyright @ IT Series www.itseries.com.pk


 Syntax Errors
• A type of error that occurs when an invalid statement is written in the program
• Compiler detects syntax errors
• A program containing syntax errors cannot be compiled successfully
Syntax is a collection of
 Causes of Syntax Erros rules for writing programs
• The statement terminator is missing at the end of statement in any language
• A misspelled keyword is used in the program
• Any of the delimiters is missing
Example
Typing forr instead of for is an example
 Logical Errors
• A type of error that occurs due to poor logic of the programmer
• A statement with logical error may produce unexpected and wrong results in program
• Difficult to find because translator cannot detect
• It can only be detected by examining the program thoroughly
Example
• Using wrong conditions in program such as writing a<5 instead of a>5
• Using wrong formula as writing average=total *5 instead of average=total/5
Copyright @ IT Series www.itseries.com.pk
 Run Time Errors
• A type of error that occurs during the execution of program
• It occurs when a statement directs the computer to execute an illegal operation
• These are detected and displayed by the computer during execution
• Normally occur due to wrong input from the user
• Computer stops executing the program and displays error message if a run time error occurs
Example
• Dividing a number by zero
• User may enter wrong type of data
• User may ask the program to open a file does not exist

Copyright @ IT Series www.itseries.com.pk


It cannot be detected by the compiler

It does not crash the program

The user needs to review the whole program to find out logical error

It may take a lot of time for detecting logical error

Copyright @ IT Series www.itseries.com.pk


Copyright @ IT Series www.itseries.com.pk

You might also like