1 / 28

159.331 Programming Languages & Algorithms

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

allan
Download Presentation

159.331 Programming Languages & Algorithms

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 159.331 Programming Languages & Algorithms Lecture 3 Aspects of Programming Languages - Part 2 Prog Lang & Alg

  2. 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

  3. 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

  4. 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

  5. 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

  6. Bal’s & Grune’s way of thinking about a “programming paradigm” Prog Lang & Alg

  7. 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

  8. Language Generations Procedural is sometimes called imperative. Prog Lang & Alg

  9. 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

  10. 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

  11. 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

  12. 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

  13. Language Levels Prog Lang & Alg

  14. 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

  15. 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

  16. 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

  17. 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

  18. 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

  19. Structure Levels Prog Lang & Alg

  20. 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

  21. 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

  22. ::= 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

  23. 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

  24. We break up the program piece by piece - rule by rule Computer programs are in fact very good at following rules! Prog Lang & Alg

  25. 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

  26. 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

  27. 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

  28. “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

More Related