50

FIT-Unit3 chapter2- Computer Languages

Embed Size (px)

Citation preview

Page 1: FIT-Unit3 chapter2- Computer Languages
Page 2: FIT-Unit3 chapter2- Computer Languages

Contents

Types of Programming Languages

Generations of Programming Languages

Features of good Programming Languages

Page 3: FIT-Unit3 chapter2- Computer Languages

Types of programming

languages Computers understand only one language that

is binary language or the language of 0s and1s.

In the initial years, instructions were given inbinary from only.

Although these programs were easilyunderstood by the computers but it was toodifficult for a normal person to understand.

Human beings came up with assembly andHigh level languages to communicate with thecomputers. They are classified into threecategories:

Page 4: FIT-Unit3 chapter2- Computer Languages

Machine language It is the native language of the computers

It is usually only 0s and 1s to represent data andinstructions

Assembly language Has symbolic instructions and executable machine

codes

Letters were used instead of 0s and 1s

High level language Written using set of words, have rules for them

The program written in HLL is called as source program

These are converted into machine readable using acompiler or interpreter.

Page 5: FIT-Unit3 chapter2- Computer Languages

Generations of programming

languages

First generation: machine language

Second generation: assembly language

Third generation : High level language

Fourth generation

Fifth generation: very high level languages

Page 6: FIT-Unit3 chapter2- Computer Languages

First generation: machine

language First language was binary, hence known as

machine language.

Machines have only two states, ON (1) andOFF (0)

Machine language is also known as nativelanguage as the codes is directlyunderstood by the computer.

There are two parts in the instructions OPCODE

OPERAND

Page 7: FIT-Unit3 chapter2- Computer Languages

Advantages of machine

languages

Translation free

Machine language is the only language that

computers can directly execute without the need

for conversion.

High speed

No conversion is needed, the applications

developed using machine language is extremely

fast.

Used for applications of nuclear reactors and

chemical processing.

Page 8: FIT-Unit3 chapter2- Computer Languages

Disadvantages of machine

languages

Machine dependent

Application developed for a particular type of

machine, may not run on another machine.

Costly and difficult for the organizations.

Complex language

Machine language is complex , difficult to read

or write.

Programmer has to be an hardware expert to

understand the machine language perfectly.

Page 9: FIT-Unit3 chapter2- Computer Languages

Error prone

Since programmer has to remember all the

opcode and memory locations

Requires lot of effort to keep track of logic of the

problem.

Tedious

Problems arises when modifications of the

existing code has to be done.

Very tedious task and time consuming.

Page 10: FIT-Unit3 chapter2- Computer Languages

Second generation : assembly

language Assembly language allows the programmer to

interact directly with the hardware.

This language assigns a mnemonic code to each

machine language instruction to make it easier to

remember to write.

Allows a better human readable method of writing

programs as compared to writing in binary bit

patterns.

Each processor family has its own assembly

language.

Mnemonic is usually three letter long

corresponding to each machine instruction.

Page 11: FIT-Unit3 chapter2- Computer Languages

The letters are usually abbreviated indicating whatthe instruction does.

Since each type of the computer uses a differentnative instruction set, assembly languages cannotbe standardized from one machine to another andinstructions from one computer cannot beexpected to work on another.

It allows the use of symbols and set of rules thatcan be combined to form a line of code.

Each line of code has four columns called asfields.

The general format is[label] <opcode> <operands> [; comments]

Page 12: FIT-Unit3 chapter2- Computer Languages

[ … ] indicate that enclosed specification may

or may not appear in the statement.

If a label is specified , it is associated as a

symbolic name with machine words generated

for the assembly statement.

If multiple operands are used, each of them is

separated by a comma.

Comments are optional , they facilitate

documentation.

Eg: BEGIN ADD A,B ; add B to A

Page 13: FIT-Unit3 chapter2- Computer Languages

assembler

No matter how close assembly language is to machinecode, the computer still cannot understand it.

The assembly language program must be translatedinto machine code by separate program called anassembler.

The assembler program recognizes the characterstrings that make up the symbolic names of the variousoperations and substitutes the required code for eachinstruction.

In short assembler converts the assembly codes intobinary codes and then it assembles the machineunderstandable code into the main memory of thecomputer, making it ready for execution.

Page 14: FIT-Unit3 chapter2- Computer Languages

Working of an assembler

Page 15: FIT-Unit3 chapter2- Computer Languages

Functions of assembler

It translates mnemonic operation codes tomachine code and corresponding registeraddress to system address.

It checks the syntax of the assembly programand generates diagnostic messages on syntaxerrors.

It assembles all the instructions in the mainmemory for execution.

In case of large assembly programs, it alsoprovides linking facility among subroutines.

It facilitates the generation of output on therequired output medium.

Page 16: FIT-Unit3 chapter2- Computer Languages

Advantages of assembly

language Easy to understand and use:

It uses mnemonics instead of numerical opcodes andmemory locations used in machine language.

Programs written in assembly level language are much moreeasier to understand when compared to machine levellanguage

Less error prone: mnemonics and system addresses are used

Programmer need not keep track of address while coding,leads to less error prone program.

Efficiency: Can run much faster and use less memory and other

resources when compared to HLL programs.

More control on hardware: Gives direct access to key machine features essential for

implementing certain kinds of low level routines.

Page 17: FIT-Unit3 chapter2- Computer Languages

Disadvantages of assembly

language Machine dependent:

Different computer architectures have their own machine andassembly languages, programs are not portable to other systems.

Harder to learn The source code for assembly level language is cryptic and in a very

low machine specific form

Makes a programmer difficult to understand

Slow development time

Less efficient Assembly level language program has to be converted to machine

language

No standardization

No support for modern software engineering technology Provides less opportunity for reuse and no OOP support

Does not provide support for safety-critical systems.

Page 18: FIT-Unit3 chapter2- Computer Languages

Third generation: high level

language Languages such as COBOL, FORTON, BASIC

and C are examples

Similar to english language.

They are machine independent

A single HLL statement can substitute severalinstructions in machine or assembly levellanguage.

BASIC code snippetLET X=10

LET Y=20

LET SUM= X+ Y

PRINT SUM

Page 19: FIT-Unit3 chapter2- Computer Languages

Translating HLL into machine

level language

Achieved by language translators called as

compilers, interpreters etc which accepts

the statements in one language and

produce equivalent statements in other

language.

Page 20: FIT-Unit3 chapter2- Computer Languages

complier

It is defined as a translator that translates a programinto another program, known as target language.

Usually used to translate a high level language into amachine language.

The compiler replaces one HLL statements by severalmachine level language statements.

The compiler stores the entire program, scans it andtranslates the whole program into equivalent machinelanguage program.

During translation, the compiler checks for syntaxerrors, if any error it gives a error message

After compilation, after removal of all errors from thesource code, the resulting machine code is saved in anexecutable file.

Page 21: FIT-Unit3 chapter2- Computer Languages
Page 22: FIT-Unit3 chapter2- Computer Languages

interpreter

It translates a statements in a program and

executes that statement immediately,

before translating next line of statement

When an error occurs the execution of the

program is halted and error message is

displayed.

Page 23: FIT-Unit3 chapter2- Computer Languages
Page 24: FIT-Unit3 chapter2- Computer Languages

linker

An application contains 100 or 1000s lines ofcodes

The codes are divided into logical groups andstored in different modules so that thedebugging and maintenance of the codebecomes easier.

When the programs are divided into blocks ,they have to be linked together to create acomplete application, it is done by a linker.

a linker is a program that links several objectmodules and libraries to form a singleprogram.

Page 25: FIT-Unit3 chapter2- Computer Languages

loader

Loaders are part of operating system thatbrings an executable file residing on disk intomemory and starts its execution.

Its responsible for loading, linking andrelocation.

A loader is a program that performs thefunctions of a linker and then immediatelyschedules the executable code for execution,without necessarily creating an executable fileas an output.

Four 4 basic functions are performed:

Page 26: FIT-Unit3 chapter2- Computer Languages

Allocation It allocates memory space for the programs

Linking It combines two or more separate object programs

and supplies the information needed to allowreferences between them.

Relocation It prepares a program to execute properly from its

secondary storage area

Loading It places data and machine instructions into the

memory.

Page 27: FIT-Unit3 chapter2- Computer Languages

Types of loader

Absolute loader

○ It loads the file into memory at the location specified by

the beginning portion of the file and then passes control

to the program.

○ If the memory space specified by the header is

currently in use, execution cannot proceed and the user

must wait until the requested memory becomes free.

○ Performs only loading operations

○ It does not perform linking and program relocation.

Page 28: FIT-Unit3 chapter2- Computer Languages

Relocating loader

○ This loader loads the program in the memory, altering

the various address required to ensure correct

referencing.

○ The decision as to where in memory the program is

placed, is made by the operating system, not the file

headers.

○ The relocating loader can only relocate code that has

been produced by a linker capable of producing relative

code.

Page 29: FIT-Unit3 chapter2- Computer Languages

Advantages of high level

languages

Readability

Machine independent

Easy debugging

Easier to maintain

Low development cost

Easy documentation

Page 30: FIT-Unit3 chapter2- Computer Languages

Disadvantage of high level

language

Poor control on hardware

Less efficient

Page 31: FIT-Unit3 chapter2- Computer Languages

Four generation

Commonly used for database access.

Here computers are instructed what to and

not how to do.

It is easy to write but has less control over

how each task is actually performed.

Have minimum number of rules.

Saves time and allows programmer to code

a complex tasks.

Page 32: FIT-Unit3 chapter2- Computer Languages

Three categories: Query languages

○ Allow user to retrieve information from database byfollowing simple syntax rules.

Report generators○ To produce customized reports using data stored in a

database.

Application generators○ User writes programs to allow data to be entered into

the database.

○ The program prompts the user to enter the needed data

○ Checks for validity.

Page 33: FIT-Unit3 chapter2- Computer Languages

Advantages of 4GL

The user can create an application in a

much shorter time for development and

debugging than with other languages.

The programmer is only interested in what

has to be done and that too at a very high

level.

Programmers do not provide any logic to

perform a task.

Lot of effort is saved.

Page 34: FIT-Unit3 chapter2- Computer Languages

Disadvantages of 4GL

They are quite lengthy programs,

Need more disk space

Programs are inflexible when compared to

other language programs.

Page 35: FIT-Unit3 chapter2- Computer Languages

Fifth generation: very HLL

Future of programming languages

Will be able to process natural languages.

The computers will be able to accept,interpret and execute the instructions innative language or language of end users.

The programmers may simple type or tellto computer, to instruct it what needs to bedone.

Closely linked to artificial intelligence andexpert systems.

Page 36: FIT-Unit3 chapter2- Computer Languages

Features of a good programming

language

Ease of use

Portability

Naturalness for the

application

Reliability

Safety

Performance

Cost

Promote structured

programming

Compact code

Maintainability

Reusability

Provides interface to other

language

Concurrency support

standardization

Page 37: FIT-Unit3 chapter2- Computer Languages

Ease of use

The language should be easy in writing codefor the programming and executing them.

The ease and clarity of a language dependsupon its syntax

It should be clear, simple and unified set ofconcepts.

The vocabulary of language shouldreassemble English.

Symbols, abbreviations and jargons should beavoided unless they are known by most of thepeople.

Page 38: FIT-Unit3 chapter2- Computer Languages

Portability

The code should be constructed such way

that it could be distributed across multiple

platforms

It should be independent of any particular

hardware or operating system

i.e. program written on one system should

be able to test in another system and

perform accurately.

Page 39: FIT-Unit3 chapter2- Computer Languages

Naturalness for the application

The language should have a syntax which

allows the program structure to show

underlying logical structure of algorithm.

It should provide conceptual framework for

thinking algorithm

Expressing algorithms in terms of flowchart

increases readability.

Page 40: FIT-Unit3 chapter2- Computer Languages

Reliability

The language should perform the intendedfunctions in satisfactory manner through out itslifetime.

Reliability is concerned with making systemfailure free.

Language should provide support forpreventing errors.

The language should also detect and reporterrors.

There should be mechanisms to handles theseerrors.

Page 41: FIT-Unit3 chapter2- Computer Languages

Safety

It is concerned with the extent to which the

language supports the construction of

safety critical systems, yielding systems

that are fault tolerant, fail safe or robust in

the face of systemic failure.

The system must do what is expected and

should be able to recover in any situation

that might lead to a mishap or actual

system hazard.

Page 42: FIT-Unit3 chapter2- Computer Languages

Performance

The language should not only be capable

of interacting with end users but also with

the hardware.

It should also interact with software

mechanisms and avoid poor politics and

support maintenance activities.

The hardware’s should be used in terms of

speed and memory.

Page 43: FIT-Unit3 chapter2- Computer Languages

cost

Primary concern before deploying

language at commercial level.

It include several costs such as

Program execution and translation cost

Program creation, testing and usage cost

Program maintenance cost

Page 44: FIT-Unit3 chapter2- Computer Languages

Promote structured

programming

A good language should be capable of

supporting structured programming.

A structured program also helps

programmers to visualize the problem

logical way, thereby reducing the

probability of errors in the code.

Page 45: FIT-Unit3 chapter2- Computer Languages

Compact code

A language should promote compact

coding.

Intended operations should be coded in

minimum number of lines.

Large codes require more testing and

developing time, thereby increasing the

cost of developing an application.

Page 46: FIT-Unit3 chapter2- Computer Languages

maintainability

Application has to be maintained regularly

so that it can meet changing requirements.

Maintainability is closely related to

structure of code.

If the original code is written in an

organized way then it would be easy to

modify or add new changes.

Page 47: FIT-Unit3 chapter2- Computer Languages

reusability

The language should facilitate the

adaptation of code for use in other

applications.

Code is reusable when it is independent of

other codes.

Stacks, queues and trees can be reused in

many programs.

Page 48: FIT-Unit3 chapter2- Computer Languages

Provides interface to other

language

Interface to other language refers to the

extent to which the selected language

supports the interfacing feature to other

languages.

This supports has an effect on reliability of

data which is exchanged between two

applications developed in different

languages.

Page 49: FIT-Unit3 chapter2- Computer Languages

Concurrency support

Refers to the extent to which inherent

language supports the construction of code

with multiple threads of control

Used in real time systems.

Also called as parallel processing

Page 50: FIT-Unit3 chapter2- Computer Languages

standardization

Means the extent to which the language

definition has been formally standardized

Extent to which it can be reasonably

expected that this standard will be followed

in a language translator.

Non standardized languages become

obsolete soon, produces inferior codes,

poor developers productivity, no reliability

of code