280 likes | 481 Views
159.331 Programming Languages & Algorithms. Lecture 3 Aspects of Programming Languages - Part 2. Programming Paradigms. “ Paradigm ” - unfortunately word has become a bit abused From Greek: “ para ” - side by side and “ deigma ” - that which is shown
E N D
159.331 Programming Languages & Algorithms Lecture 3 Aspects of Programming Languages - Part 2 Prog Lang & Alg
Programming 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) Prog Lang & Alg
Defining 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 & Grune’s Programming paradigms structure… Prog Lang & Alg
Prominent Programming Paradigms • Imperative Paradigm • Object-oriented Paradigm • Functional Paradigm • Logic Paradigm • Parallel and Distributed Paradigm Be aware others do exist and are (constantly) being proposed and argued for/against See the programming literature… Prog Lang & Alg
Programming 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! Prog Lang & Alg
Bal’s & Grune’s way of thinking about a “programming paradigm” Prog Lang & Alg
Some MoreStandard 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 Prog Lang & Alg
Language Generations Procedural is sometimes called imperative. Prog Lang & Alg
Generational 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 in a platform/vendor independent way Prog Lang & Alg
5th & 6thGeneration Languages • 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. Prog Lang & Alg
Other Language Classifications Can emphasise what is to be done 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” Prog Lang & Alg
Language Levels Language level: • Low • High • Very High Not terribly meaningful but good at distinguishing between assembly at the Low level, through Fortran, C, Pascal and friends at High and those using an abstract machine layer at the Very High Level. Prog Lang & Alg
Language Levels Prog Lang & Alg
Program 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… Prog Lang & Alg
Lexical 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. Prog Lang & Alg
Syntactic 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 if…then…else construct Prog Lang & Alg
Contextual 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 Prog Lang & Alg
Semantics Layer • The “meaning” • In programming languages the semantic level describes what the permissible actions mean • Logic and Functional (declarative tending) languages have less distinction between contextual and semantics layers. • These languages are less “instruction-oriented” (operational tending). Prog Lang & Alg
Structure Levels Prog Lang & Alg
Lexical Structure Lexical symbols, lexical units, tokens: • Identifiers - (our) chosen variable names - myName • Keywords - the language’s special words - for • Operators - the language’s special symbols - * • Separators - more special symbols - ; • Literals - hard wired constants - 123, “ABC” • Comments - ignored by the compiler • Layout and White Space - allows break up into tokens Prog Lang & Alg
Syntactic 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 Prog Lang & Alg
::= means “is defined as” | means “or” < > 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 Prog Lang & Alg
The 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. Prog Lang & Alg
We break up the program piece by piece - rule by rule Computer programs are in fact very good at following rules! Prog Lang & Alg
Context • 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) Prog Lang & Alg
Semantics • 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. Prog Lang & Alg
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 Prog Lang & Alg
“Aspects” 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 Prog Lang & Alg