Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Languages
Nai-Wei Lin
Department of Computer Science and
Information Engineering
National Chung Cheng University
Chapter 1
Introduction
Outline
3
What Is a Programming Language
4
How we communicate
influences how we think,
and vice versa.
5
A programming language is
a notation
for describing computation
in computer-readable and
human-readable form
6
Computation
7
Turing Completeness
8
Levels of Programming Languages
Machine languages
Assembly languages
High-level languages
9
Definition of Programming Languages
10
Syntax
11
Semantics
12
Formal Definition of Programming
Languages
The Syntax of a programming language is
usually formally defined by context-free
grammars
The Semantics of a programming
language is usually informally defined by
human languages. It can be partially
defined in a formal language using
operational semantics, denotational
semantics, or axiomatic semantics
13
Implementation of Programming
Languages
A compiler is a program that can translate
programs written in a language into
programs written in another language
An interpreter is a program that can
understand a language and execute
programs written in that language
14
Compilers
Source Target
Compiler
program program
Target
Input Output
program
15
Interpreters
Input
Source Output
Interpreter
program
16
Virtual Machines
An interpreter can be viewed as a virtual
machine that can directly execute a high level
programming language
Compilers and interpreters are relative
concepts. Many programming languages
have both a compiler and an interpreter
Java has a compiler that translates the Java
programs into Java byte codes. The Java
virtual machine is an interpreter that can
directly execute Java byte codes
17
Abstractions in Programming Languages
18
Abstract 抽象 摘要
19
Abstractions
The set of
operations The sequence of
associated operations to be
with each processed
data object
Data Control
Operations
20
Abstractions
21
Data Abstractions
Basic abstractions: basic data types such
as integers, floating point numbers, and
characters
Structured abstractions: structured data
types such as arrays and records
Unit abstractions: abstract data types such
as stacks, queues, trees, and graphs
22
Control Abstractions
23
Abstraction of Operations
24
Abstraction of Operations
High-Level Languages
Abstract Operations
Machine Operations
Machine Languages
25
Paradigms of Programming Languages
Imperative programming – a series of
commands: Fortran, Pascal, C, Ada
Object-oriented programming – a class of
objects: Simula, Smalltalk, C++, Java
Functional programming – a collection of
mathematical function definitions: Scheme, ML,
Haskell
Logic programming – a collection of logical
predicates: Prolog, Godel
26
Imperative Programming
u , if v = 0;
gcd(u, v) =
gcd (v, u % v), otherwise.
gcd u v = if v == 0 then u
else gcd(v (u ‘mod’ v))
What
29
Logic Programming
V = 0
gcd(U, V) = U
V 0, Y = U %V, gcd(V, Y) = X
gcd(U, V) = X
gcd(U, V, U) :- V = 0.
gcd(U, V, X) :- not (V = 0),
Y is U mod V,
What gcd(V, Y, X).
30
Language Design Criteria ?
31
Efficiency
Efficiency of compiler construction:
implementability
Efficiency of compiler execution: simplicity,
reliability
Efficiency of program construction: writability,
expressiveness
Efficiency of program execution: optimizability
Efficiency of program modification: readability,
maintainability
32
Regularity
33
Generality
Do constructs have as few restrictions as
possible?
Functions
In Pascal, functions can be passed as parameters,
but there are no function variables.
C lacks nested functions.
Scheme and ML have completely general
functions
Fortran can pass variable-length array
parameters, but cannot define variable-length
array variables
34
Orthogonality
35
Uniformity
36
Other Criteria
37
Other Criteria
Security: programs cannot do unexpected
damage. (Pascal, Java)
Preciseness: having a definition that can
answer programmers and implementers
questions. (Most languages today, but only
one has a mathematical definition: ML)
Machine-independence: should run the
same on any machine. (Java)
38
Other Criteria
39
C++: A Case Study
Thanks to Bjarne Stroustrup, C++ is not
only a great success story, but also the
best-documented language development
effort in history:
1997: The C++ Programming Language,
3rd Edition (Addison-Wesley).
1994: The Design and Evolution of C++
(Addison-Wesley).
1993: A History of C++ 1979-1991,
SIGPLAN Notices 28(3).
40
Course Contents
Introduction Expressions
Syntax Statements
41