Programming Language Concepts
Programming Language Concepts
Concepts
Tatjana Petkovi
[email protected]
1
Programming Language
Pragmatics
Michael Scott
http://www.cs.rochester.edu/u/
scott/pragmatics/
2
Contents
1 Introduction
2 Programming Language Syntax
2.1 Specifying Syntax
2.2 Recognizing Syntax
2.3* Theoretical Foundations
4 Semantic Analysis
5 Assembly-Level Computer Architecture
6 Control Flow
6.1 Expression Evaluation
6.2 Structured and Unstructured Flow
6.3 Sequencing
6.4 Selection
6.5 Iteration
6.6 Recursion
5
7 Data Types
7.1 Type Systems
7.2 Type Checking
7.3 Records (Structures) and Variants
(Unions)
7.4 Arrays
7.5 Strings
7.6 Sets
7.7 Pointers and Recursive Types
7.8 Lists
6
Introduction
Computing devices:
Mechanical:
Fingers, abacus
Blaise Pascal 1642 +Gottfried Wilhelm von Leibnitz +-*/
Charles Babbage 1832 programmable
Electronical:
COLOSSUS 1943
ENIAC (Electronic Numerical Integrator and Computer)
1946
9
Machine language
binary system - John Von Neumann
GCD for MIPS R4000
10
11
Assembly languages
assembler
GCD
12
Assembler
translator from symbolic language to machine
language (one-to-one mapping)
tool to assemble the symbolic program in the
machine
Advantages
relocatable & reusable (copy) programs
macro expansion
first step towards higher-level programming
larger programs (like operating systems)
possible
13
But,
each kind of computer has its own
programmers must learn to think like
computers
maintenance of larger programs is difficult
Higher-level languages
portability
natural notation (for anything)
support to software development
14
Fortran 1956
Cobol 1959
Algol 1958, 1960
...
compilers
15
16
17
18
Instruction Code)
1961
popular in the eighties
Visul Basic, Visual Basic for Application
19
Algol 68
the same idea of universality
too complex
Pascal
N. Wirth
late sixties
simple to learn, easy to use, ...
introduces subrange and enumeration types,
unified structures, unions
Pascal-like notion
Turbo Pascal
free availability
Modula
21
ADA
1983
new attempt for the universal language
US DOD
too big expectations never fulfilled
theoreticaly significant, data types, moduls,
abstraction, concurrency, exception handling
22
C
1970
UNIX, system software programming
1978 D. M. Ritchi and B. W. Kernighan
1983 ANSI C
close to assembly languages
not reliable, weak type checking, no dynamic
semantic checks
C++
23
object-oriented languages
data abstraction
objects, classes
inheritance, polimorphism
roots in Simula 67
Smalltalk 80, Eiffel, Omega, Oberon, C++,
Delta, Java
visul environment, interactive,
events driven programming: Visual Basic,
Delphi
24
Language classification
imperative
how the computer should solve the problem
first do this, then repeat that, then branch there...
procedural languages (Pascal, C, Basic, ...)
computing via side-effects
Von Neumann architecture (1946)
object-oriented
25
declarative languages
program = description of the problem
a formal statement of what is the problem
closer to humans than computers
functional languages
Lisp, 1958
-calculus, Church 1930
computing without variables
logic programming
predicate logic, Fredge 1871
Prolog, seventies
computing with relations
26
27
sequential
concurrent
in conjuction with sequential (Fortran, C,...)
explicite (Java, Ada, Modula-3)
28
special purposes
symbolic data Lisp
character strings Snobol, Icon
low-level programming C
numeric data Fortran
logic programming - Prolog
personal preference
iteration : recursion
pointers : implicit dereferencing
29
ease of implementation
excellent compilers
Fortran
30
Language characteristics
formally defined syntax
(grammars, syntax diagrams)
data types
(predefined, others)
data structures
(array, record, file, set)
control
(if, case, for, while)
subroutines
31
modules
abstract data types
data + procedures + functions
closed
concurrency
parallelism
low-level mechanisms
to access registers, memory, format data
exception handling mechanisms
I/O procedures
32
Evaluating languages
readability
33
readability (still...)
orthogonality
small number of concepts and ways to combine
them
control flow
structural languages
data structures
records more clear than arrays
syntax
begin .. end, if .. fi (end if)
34
easy of use
depends on the application
simplicity and orthogonality
programmers accept limitted number of new concepts
small numbers of concepts and constructs
abstraction support
emphasses global characteristics
subroutines, modules, classes
expressivity
num = num + 1 or num++
while or for
35
reliability
to decrese number of run-time errors
early binding
data types
explicitly defined
operators types determined
casting
exceptions handling
run-time errors caused by the program or system
aliasing
mutual references to the same memory location
Fortran: equivalence
Pascal: pointers
may cause errors
36
effectivity
of a program
important for real-time systems
of the compiler
important for often modified programs
overall
important for widely used software
37
C, Pascal
no modules use naming & discipline
command shells
programmable editors
programmable applications
42
Interpretation
greater flexibility
better diagnostics
excellent source-level debugger
cope with variables sizes, types, names
write and execute on fly program pieces
(Prolog, Lisp)
Compilation
better performance
saves time, memory
43
a mixture of both
compilation or interpretation?
44
compilation
thorough analysis and nontrivial
transformation
45
examples
Basic, pure interpreted
Fortran, pure compiled
format interpreter
46
preprocessor
removes comments, expands macros, conditional compilation
47
C++
early AT&T compiler
48
Pascal
early compilers:
- a Pascal compiler written in Pascal
the same compiler in P-code
- a P-code interpreter written in Pascal
1. translate (by hand) the P-code interpreter into a
local language
49
Programming environments
Assemblers, debuggers, preprocessors,
linkers, editors, configuration management
tools
Overview of compiling
phases
front end
figure out the meaning of the source program
back end
construct target program
52
53
passes
54
55
scanner
lexical analysis
tokens: program, gcd, (, i, ,, j, ), ;, ... , end, .
removes comments, tags tokens with line and
column numbers
parser
syntactic analysis
parse tree
CFG (context-free grammar)
56
57
58
Semantic Analysis
Intermediate code generation
meaning
recognizes multiple occurances of an
identifier, tracks types of identifiers and
expressions
symbol table
identifier, type, internal structure, scope
59
60
checks that
64
65
Code improvements
more efficient
quicker and/or less memory
two phases:
machine independent, on intermediate form
target program improvement, register
distribution, reordering instructions
66