Title: 159'331 Programming Languages
1159.331 Programming Languages Algorithms
- Lecture 03 - Aspects of Programming Languages -
Part 2
2Programming Paradigms
- Paradigm - unfortunately word has become a bit
abused - From Greek
- para - side by side and
- deigma - that which is shown
- In (Computer) Science a paradigm is usually
- A coherent set of methods that have been found to
be (more or less) effective in handling a
particular type of problem (problem domain)
3Defining Paradigms
- Usually a paradigm can be described by a simple
core guiding principle - Beware however that not all groupings or models
that are declared to be paradigms are equally
coherent - Sometimes paradigms in science only become
apparent post hoc (afterwards when the fuss has
died down) - We will follow Bal Grunes Programming
paradigms structure
4Prominent Programming Paradigms
- Imperative Paradigm
- Object-oriented Paradigm
- Functional Paradigm
- Logic Paradigm
- Parallel and Distributed Paradigm
- Be aware others do exists and are (constantly)
being proposed and argued for/against - See the programming literature
5Programming Models
- Paradigm will be our major sort key
- We will follow Bal Grune and use Model as
our next subdivision - A Programming Model therefore is a way of
dividing up a paradigm for sub problems or areas - For example we will discuss the message-passing
and data-parallel programming models that could
be said to be approaches to the parallel and
distributed programming paradigm. - Remember this is only a convention for
discussing the field - useful if we try to be
consistent!
6Bals Grunes way of thinking about a
programming paradigm
7Some More Standard Jargon
- Generations in computer languages
- Nice idea but lots of controversy about exactly
what belongs in which category - Roughly sequential idea
- 1st generation is lowest level, earliest
generation - Higher generations or layers are more
advanced/sophisticated
8procedural sometimes called imperative
9Generational Language Development
- We have discussed the first three generations -
which seem mostly agreed upon - Fourth Generation Languages (4GL) have
- Strong data structure support with persistence
- Support for application/problem-specific ideas
- SQL is a good example - Structured Query
language - a programming language for managing
databases ina platform/vendor independent way
105th and 6th Generations
- 5GL are intended to allow non-specialists to use
Artificial Intelligence (AI) ideas - many based
on logical Inference - Prolog is a classic example - it provides a
logic inference engine with a command line
interface and language syntax - 6GLs are a bit less well defined - typically
based on neural network engines with an
appropriate syntax - mostly still experimental.
11Other Language Classifications
- Can emphasise what is to be achieved rather than
how it is to be done. - Languages that emphasise the what are termed
definitional or declarative - The functional and logic languages tend towards
declarative - Languages emphasising the how called
operational or non-declarative - The imperative (or procedural) and OO languages
tend towards operational
12Language Levels
- Low, High and Very High Level (see table)
- Not terribly meaningful but good at
distinguishing between assembly etc at the
lowest level, through Fortran, C, Pascal and
friends at High and those using an abstract
machine layer at the Very High Level.
13SETL is a Set oriented language with good logic
support
14Program Structure
- Reminder of some terminology.
- In a natural language we usually think in terms
of lexical, syntactic and semantic levels. - Lexical level - concerns the vocabulary (set) of
words - Syntax says how the words are allowed to be
strung together to make sentences - Semantics level addresses what it means
- This does not quite work for programming
languages
15Lexical Structure
- Usually this level is pretty obvious to the
human reader - Nouns and verbs etc in natural languages
- Special reserved keywords like BEGIN, END, FOR
in programming languages even is a word of
sorts - Program identifiers - typically allowed to
start with a letter, and be of some max length
containing any mix of letters and numbers
and upper lower case.
16Syntactic Level
- The rules specify what words are allowed to
appear where - eg reserved keywords symbols and identifiers in
a typical programming language - Often these syntax rules are designed to be
close to natural language constructs - eg ifthenelse construct
17Contextual Layer
- Programming languages generally have an extra
layer we can call the contextual layer between
syntax and semantics - Think of it as a way of breaking down the
concept of semantics into a form more easily
explained in a program - Need this as bits of syntax mean different things
in different contexts - This level is concerned with the feasibility of
instructions and indicates what actions can be
performed on a given object
18Semantics Layer
- The meaning
- In programming languages the semantic level
describes what the permissable actions mean - Logic and Functional (declarative tending)
languages have less distinction between
contextual and semantics layers. - These languages are less instruction-oriented
(operational tending).
19(No Transcript)
20Lexical Structure
- Lexical symbols, lexical units, tokens
- Identifiers - (our) chosen variable names eg
myName - Keywords - the languages special words - eg for
- Operators - the languages special symbols eg
- Separators - more special symbols eg
- Literals - hard wired constants eg 123, ABC
- Comments - ignored by the compiler
- Layout and White Space - allows break up into
tokens
21Syntactic Structure
- A context-free grammar - Extended Backus-Naur
Form (EBNF) - Program parsing
- Can use a grammar to produce a sequence of
lexical symbols which is a program (ie we can
write programs) - We can parse a program into meaningful units
according to a grammar
22 means is defined as means or lt gt
denotes notion names
Note - this is not a very exciting language!
superscript is used to indicate repetition 1
or more times superscript used for zero or
more times
23The EBNF grammar tells out what we are allowed
to write In this program language.
The grammar also specifies what a compiler or
interpreter can do to make sense of the program
text.
24We break up the program piece by piece - rule by
rule
Computer programs are in fact very good at
following rules!
25Context
- Context conditions extra conditions in the
language definition concerning entities - Our language might forbid some things
- in an expression both values must be integers
so 1 a is illegal - if a value is an identifier it must have a
value so program n n 1 end is illegal - We would like the compiler to check these
conditions (not always done or not always
possible)
26Semantics
- What do language notions mean ?
- For example - what will happen when the value of
an expression is calculated? - This is the semantics of the expression
- Semantics of each notion combine to define the
semantics of the whole language - Semantics can be described formally - but much
harder than context-free grammars used to
describe syntax - well beyond our scope for this
paper.
27Aspects Part 2 - Summary
- Programming Paradigms
- Programming Models
- Programming Generations
- Programming Levels
- Lexical Layer
- Syntax Layer - context-free grammars and EBNF
- Contextual Layer
- Semantics Layer
- See the EBNF links on the web site.
- Chaper 1 of Bal Grune, Chapter 3-4 of Sebesta
- Next - Programming Language Media and Program
Construction