god1 - มหาวิทยาลัยศิลปากร

Download Report

Transcript god1 - มหาวิทยาลัยศิลปากร

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
Machine language is unintelligible
Assembly Language is low level
Benefits of Higher-level Language
A Role for Programming Languages
Programming Paradigms




Imperative Programming
Object-Oriented Programming
Logic Programming
Functional Programming
Machine Lauguage
Native language of a computer
Hard to understand for human
Example 1.1 A code fragment of von Neumann
machine is
00000010101111001010
00000010111111001000
00000011001110101000
Its meaning is adding theh numbers in location
10 and 11 and stores the result in location 12.
Assembly Language
A variant of Machine Language in which
names and symbols take the place of the
actual codes for machine operations,
values, and storage locations, making
individual instructions more readable.
See Example 1.2


Reads a sequence of integers like
112223144
Remove the same value adjacent and write out
12314
A random-access machine
RAM:random-access machine
It is consisted of 4 main components




A memory : sequence of locations 0,1,2
A program : sequence of instructions
An input file : a sequence of values consumed
at a time by read instructions
An output file : a sequence of values
consumed at a time by write instructions
Example of RAM
memory
0
0
1 27
2
3 -27
n
INPUT
OUTPUT
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
M[0] := 0
read(M[1])
If M[1] ≥ 0 then goto
goto 7
M[3] := M[0] – M[1]
if M[3] ≥ 0 then goto
writeln(M[1])
read(M[2])
M[3] := M[2] – M[1]
if M[3] ≥ 0 then goto
goto 14
M[3] := M[1] – M[2]
if M[3] ≥ 0 then goto
M[1] := M[2] + M[0]
goto 3
halt
5
16
12
8
Instruction set of a RAM
M[l] := n
Put integer n into location l.
M[l] := M[j] + M[k] Put sum of values locations j & k into location l
M[l] := M[j] - M[k] Put the difference of the values in j and k into l
M[l] := M[M[j]]
Let k = value in location j, In effect, M[l]=M[k]
M[M[j]] := M[k]
Let l = value in location i. In effect, M[l]=M[k]
Read(M[l])
Get next input value and put it into location l.
Writeln(M[j])
Produce value in location j as next output value
Goto I
Next, execute instruction in location i if [j]≥0
If M[j] ≥ 0 then goto i Next, execute instruction in location i if M[j]≥0
Halt
Stop execution
Benefits of Higher-Level Language
Readable familiar notations
Machine independence
Availability of program libraries
Consistency checks during implementation
that can detect errors
Example of High-Level Program
In 1973,The Unix operating system kernel was
rewritten in the programming language C.
New users and programs: many contributors do
not know, and do not wish to learn, the
instruction set of the machine
Readability: more easily understood, repaired
and modify.
Portability: runs on several machines and whose
expression in source code is except for a few
modules, identical on each machine.
Problems of Scale
Programming Language can help in 2 ways.
Readable
Compact notation reduce the errors
Human Error Factor
Example: 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) then
do not correct its flight path
An evolutionary of earlier languages
Programmming Paradigms
Imperative Programming
Functional Programming
Object-Oriented Programming
Logic Programming
Imperative Programming
Action oriented
As a sequence of actions
Original Language is Fortran
Pascal and C are general-purpose
imperative programming language
Functional Programming
Originated with Lisp, a language designed
in 1958 for applications in AI
McCarthy et al [1965] explained Lisp as
LISP is designed primitively for symbolic data
processing. It has been used for symbolic
calculations in differential and integral calculus,
electrical circuit theory, mathematical logic, pame
playing and other fields of AI
Object-Oriented Programming
Simula’s origins in simulation.
Kristen Nygaard and Ole-Johan Dahl [1961]
Key concept is a class of objects
C++ Smalltalk
Logic Programming
Developed in 1972 for natural language
processing in French by Alain Colmerauer
and Philippe Roussel
A specialized form of logical reasoning to
answer such queries
Language Implementation
Compiler

Once translation is complete:target code run
later time called runtime.
Interpreter: directly run program
(a) COMPILE
(b) INTERPRET
Application Level……….
Language Level…………
Source Program
Machine Level…………..
Target Code
Machine
Program
Interperter
Machine