programming language

18
Programming Programming Language Language . . อออออออ อออออออ อออออออ อออออออ อออออออออออออออออออ อออ อออออออออออออออออออ อออ อออออออออออ อออออออออออ ออออออออออออออออออ ออออออออออออออออออ

Upload: jaxon

Post on 13-Jan-2016

38 views

Category:

Documents


4 download

DESCRIPTION

Programming Language. อ.รัชดาพร คณาวงษ์ วิทยาการคอมพิวเตอร์ คณะวิทยาศาสตร์ มหาวิทยาลัยศิลปากร. What are PLs?. A tool for instructing machine A way for communicating A notation of algorithms How to expressing concepts A mean for controlling computerized devices. Over View. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Programming Language

Programming LanguageProgramming Language

ออ..รั�ชดาพรั คณาวงษ์�รั�ชดาพรั คณาวงษ์�ว�ทยาการัคอมพ�วเตอรั� คณะว�ทยาการัคอมพ�วเตอรั� คณะ

ว�ทยาศาสตรั�ว�ทยาศาสตรั�มหาว�ทยาลั�ยศ�ลัปากรัมหาว�ทยาลั�ยศ�ลัปากรั

Page 2: Programming Language

What are PLs?What are PLs?

A tool for instructing machineA tool for instructing machine

A way for communicatingA way for communicating

A notation of algorithmsA notation of algorithms

How to expressing conceptsHow to expressing concepts

A mean for controlling computerized devicesA mean for controlling computerized devices

Page 3: Programming Language

Over ViewOver View

Machine language is unintelligibleMachine language is unintelligibleAssembly Language is low levelAssembly Language is low levelBenefits of Higher-level LanguageBenefits of Higher-level LanguageA Role for Programming LanguagesA Role for Programming LanguagesProgramming ParadigmsProgramming Paradigms Imperative ProgrammingImperative Programming Object-Oriented ProgrammingObject-Oriented Programming Logic ProgrammingLogic Programming Functional ProgrammingFunctional Programming

Page 4: Programming Language

Machine LauguageMachine Lauguage

Native language of a computerNative language of a computer

Hard to understand for humanHard to understand for human

Example 1.1 A code fragment of von Neumann machine is 00000010101111001010

0000001011111100100000000011001110101000

Its meaning is adding theh numbers in location 10 and 11 and stores the result in location 12.

Page 5: Programming Language

Assembly LanguageAssembly Language

A variant of Machine Language in which A variant of Machine Language in which names and symbols take the place of the names and symbols take the place of the actual codes for machine operations, actual codes for machine operations, values, and storage locations, making values, and storage locations, making individual instructions more readable.individual instructions more readable.See Example 1.2See Example 1.2 Reads a sequence of integers like Reads a sequence of integers like

1 1 2 2 2 3 1 4 41 1 2 2 2 3 1 4 4 Remove the same value adjacent and write outRemove the same value adjacent and write out

1 2 3 1 41 2 3 1 4

Page 6: Programming Language

A A random-access machinerandom-access machine

RAM:RAM:random-access machinerandom-access machine

It is consisted of 4 main componentsIt is consisted of 4 main components A memory : sequence of locations 0,1,2A memory : sequence of locations 0,1,2 A program : sequence of instructionsA program : sequence of instructions An input file : a sequence of values consumed An input file : a sequence of values consumed

at a time by read instructionsat a time by read instructions An output file : a sequence of values An output file : a sequence of values

consumed at a time by write instructionsconsumed at a time by write instructions

Page 7: Programming Language

Example of RAMExample of RAM

memorymemory 1: M[0] := 0 2: read(M[1]) 3: If M[1] ≥ 0 then goto 5 4: goto 7 5: M[3] := M[0] – M[1] 6: if M[3] ≥ 0 then goto 16 7: writeln(M[1]) 8: read(M[2]) 9: M[3] := M[2] – M[1]10: if M[3] ≥ 0 then goto 1211: goto 1412: M[3] := M[1] – M[2]13: if M[3] ≥ 0 then goto 814: M[1] := M[2] + M[0]15: goto 316: halt

0

27

0

1

2

3

n

-27

INPUT

OUTPUT

Page 8: Programming Language

Instruction set of a RAMInstruction set of a RAM

M[M[ll] := ] := nn Put integerPut integer n n into locationinto location l. l.M[M[ll] := M[] := M[jj] + M[] + M[kk]] Put sum of values locations Put sum of values locations jj & & kk into location into location llM[M[ll] := M[] := M[jj] - M[] - M[kk]] Put the difference of the values in Put the difference of the values in jj and and kk into into llM[M[ll] := M[M[] := M[M[jj]]]] Let Let kk = value in location = value in location jj, In effect, M[, In effect, M[ll]=M[]=M[kk]]M[M[M[M[jj]] := M[]] := M[kk]] Let Let ll = value in location = value in location ii. In effect, M[. In effect, M[ll]=M[]=M[kk]]ReadRead(M[(M[ll])]) Get next input value and put it into location Get next input value and put it into location ll..WritelnWriteln(M[(M[jj])]) Produce value in location j as next output valueProduce value in location j as next output valueGoto Goto II Next, execute instruction in location Next, execute instruction in location ii if [ if [jj]≥0]≥0If M[If M[jj] ≥ 0 then goto ] ≥ 0 then goto ii Next, execute instruction in location Next, execute instruction in location ii if M[ if M[jj]≥0]≥0HaltHalt Stop executionStop execution

Page 9: Programming Language

Benefits of Higher-Level LanguageBenefits of Higher-Level Language

Readable familiar notationsReadable familiar notations

Machine independenceMachine independence

Availability of program librariesAvailability of program libraries

Consistency checks during implementation Consistency checks during implementation that can detect errorsthat can detect errors

Page 10: Programming Language

Example of High-Level ProgramExample of High-Level Program

New users and programs: many contributors do New users and programs: many contributors do not know, and do not wish to learn, the not know, and do not wish to learn, the instruction set of the machineinstruction set of the machineReadability: more easily understood, repaired Readability: more easily understood, repaired and modify.and modify.Portability: runs on several machines and whose Portability: runs on several machines and whose expression in source code is except for a few expression in source code is except for a few modules, identical on each machine.modules, identical on each machine.

In 1973,The Unix operating system kernel was rewritten in the programming language C.

Page 11: Programming Language

Problems of ScaleProblems of Scale

Programming Language can help in 2 ways.Programming Language can help in 2 ways.

ReadableReadable

Compact notation reduce the errorsCompact notation reduce the errors

Human Error FactorExample: Due to a programming error, the rocket carrying Mariner I, an unmanned probe to the planet Venus, has to be destroyed 290 seconds after launch on July 22,1962.

if not (in radar contact with the rocket) thendo not correct its flight path

Page 12: Programming Language

An evolutionary of earlier languagesAn evolutionary of earlier languages

Page 13: Programming Language

Programmming ParadigmsProgrammming Paradigms

Imperative ProgrammingImperative Programming

Functional ProgrammingFunctional Programming

Object-Oriented ProgrammingObject-Oriented Programming

Logic ProgrammingLogic Programming

Page 14: Programming Language

Imperative ProgrammingImperative Programming

Action orientedAction oriented

As a sequence of actionsAs a sequence of actions

Original Language is FortranOriginal Language is Fortran

Pascal and C are general-purpose Pascal and C are general-purpose imperative programming languageimperative programming language

Page 15: Programming Language

Functional ProgrammingFunctional Programming

Originated with Lisp, a language designed Originated with Lisp, a language designed in 1958 for applications in AIin 1958 for applications in AI

McCarthy et al [1965] explained Lisp asMcCarthy et al [1965] explained Lisp as

LISP is designed primitively for symbolic data LISP is designed primitively for symbolic data processing. It has been used for symbolic processing. It has been used for symbolic calculations in differential and integral calculus, calculations in differential and integral calculus, electrical circuit theory, mathematical logic, pame electrical circuit theory, mathematical logic, pame playing and other fields of AIplaying and other fields of AI

Page 16: Programming Language

Object-Oriented ProgrammingObject-Oriented Programming

Simula’s origins in simulation.Simula’s origins in simulation.

Kristen Nygaard and Ole-Johan Dahl [1961]Kristen Nygaard and Ole-Johan Dahl [1961]

Key concept is a class of objectsKey concept is a class of objects

C++ SmalltalkC++ Smalltalk

Page 17: Programming Language

Logic ProgrammingLogic Programming

Developed in 1972 for natural language Developed in 1972 for natural language processing in French by Alain Colmerauer processing in French by Alain Colmerauer and Philippe Rousseland Philippe Roussel

A specialized form of logical reasoning to A specialized form of logical reasoning to answer such queriesanswer such queries

Page 18: Programming Language

Language ImplementationLanguage Implementation

CompilerCompiler Once translation is complete:target code run Once translation is complete:target code run

later time called runtime.later time called runtime.

Interpreter:Interpreter: directly run programdirectly run program

(a) COMPILE (b) INTERPRET

Application Level……….

Language Level…………

Machine Level…………..

Source Program Program

Target Code

MachineMachine

Interperter