Title: Introduction to Programming Languages
1Introduction to Programming Languages
- Nai-Wei Lin
- Department of Computer Science and Information
Engineering - National Chung Cheng University
2Introduction
3Programming Languages
- Natural languages are designed to facilitate the
communication between human - Programming languages are designed to facilitate
the communication between human and computers
4How we communicate influences how we think, and
vice versa.
5Study programming languages affects the way we
think about computers and computation.
6A programming language is a notation for
describing computation in computer-readable and
human-readable form
7Computation
- Computation is usually defined formally using the
mathematical concept of a Turing machine - Churchs thesis states that it is not possible to
build a machine that is inherently more powerful
than a Turing machine
8Levels of Programming Languages
- Machine languages
- Assembly languages
- High-level languages
9Computer-Readability
- An interpreter is a program that can understand a
language and execute programs written in that
language - A compiler is a program that can translate
programs written in a language into programs
written in another language
10Interpreters
Input
Source program
Output
Interpreter
11Compilers
Source program
Target program
Compiler
Target program
Output
Input
12Language Definitions
- The Syntax of a programming language specifies
the structure of programs An if-statement
consists of the word if followed by an
expression inside parentheses, followed by a
statement, followed by an optional else part
consisting of the word else and another
statement.
13Language Definitions
- The Semantics of a programming language specifies
the meaning of programs An if-statement is
executed by first evaluating its expression,
which must have arithmetic or pointer type,
including all side effects, and if it compares
unequal to 0, the statement following the
expression is executed. If there is an else part,
and the expression is 0, the statement following
the else is executed.
14Language Definitions
- 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
15Human-Readability
- A programming language provides abstractions of
the actions of computers that are easy to
understand, even by persons not familiar with the
underlying details of the machine
16Abstract
- Disassociated from any specific instance (??)
- A summary of points (??)
17Abstractions
Data
Control
Operations
18Abstractions
- Data abstractions abstract properties of data,
such as numbers, character strings, trees, which
are subjects of computation - Control abstractions abstract properties of the
transfer of control, that is, the modification of
the execution path of a program based on the
situation at hand. Examples are loops,
conditional statements, and procedure calls
19Data Abstractions
- Basic abstractions basic data types such as
integers, floating point numbers, characters - Structured abstractions structured data types
such as arrays and records - Unit abstractions abstract data types such as
stacks, queues, trees, graphs
20Control Abstractions
- Basic abstractions basic statements such as
assignment statement and goto statement - Structured abstractions structured statements
such as if-statement, while-statement, and
procedures - Unit abstractions abstract data types such as
stacks, queues, trees, graphs
21Abstraction of Operations
Basic data types
Basic statements
Structured data types
Structured statements
Abstract data types
22Abstraction of Operations
High-Level Languages
Abstract Operations
Machine Operations
Machine Languages
23Programming Paradigms
- Imperative programming a series of commands
Fortran, Pascal, C, Ada - Functional programming a collection of
mathematical functions Lisp, ML, Haskell - Logic programming a collection of logical
declarations Prolog, Godel - Object-oriented programming a collection of
objects Simula, Smalltalk, C, Java
24Imperative Programming
int gcd(int u, int v) int t while (v
! 0) t u v u v
v t return u
How
25Functional Programming
gcd u 0 u gcd u v gcd (v (u mod
v)) gcd u v if v 0
then u else gcd(v (u
mod v))
What
26Logic Programming
gcd(U, V, U) - V 0. gcd(U, V, X) - not
(V 0), Y is U mod V, gcd(V, Y, X).
What
27Object-Oriented Programming
public class IntWithGcd private int
value public IntWithGcd(int val) value
val public int intValue() return value
public int gcd(int v) int z
value int y v while (y ! 0)
int t u v z y y t
return z
How
28Turing Completeness
- A programming language is Turing complete if it
can be used to describe all the computation that
a Turing machine can perform - A programming language is Turing complete if it
has integer variables and arithmetic operators,
assignment statements, sequence statements,
selection statements, and iteration statements
29Contents
- History
- Language design principles
- Syntax
- Imperative programming
- Functional programming
- Logic programming
- Object-oriented programming