Theory of Programming Languages Introduction. What is a Programming Language? John von Neumann...
-
Upload
leslie-howard -
Category
Documents
-
view
219 -
download
2
Transcript of Theory of Programming Languages Introduction. What is a Programming Language? John von Neumann...
![Page 1: Theory of Programming Languages Introduction. What is a Programming Language? John von Neumann (1940’s) –Stored program concept –CPU actions determined.](https://reader035.fdocuments.net/reader035/viewer/2022062407/56649f445503460f94c65bc2/html5/thumbnails/1.jpg)
Theory of Programming Languages
Introduction
![Page 2: Theory of Programming Languages Introduction. What is a Programming Language? John von Neumann (1940’s) –Stored program concept –CPU actions determined.](https://reader035.fdocuments.net/reader035/viewer/2022062407/56649f445503460f94c65bc2/html5/thumbnails/2.jpg)
What is a Programming Language?
• John von Neumann (1940’s)– Stored program concept
– CPU actions determined by “codes” stored in memory
• Assembly Languages– Mnemonics for the Instruction Codes
– Low-level• One instruction per operation
– Machine-dependent
![Page 3: Theory of Programming Languages Introduction. What is a Programming Language? John von Neumann (1940’s) –Stored program concept –CPU actions determined.](https://reader035.fdocuments.net/reader035/viewer/2022062407/56649f445503460f94c65bc2/html5/thumbnails/3.jpg)
High-Level Languages
• Code abstractions allowed more readable and writeable programs– Assignments– Loops– Conditionals
• Machine – independent• Retains the processor-model of computation• Allows human to human communication
![Page 4: Theory of Programming Languages Introduction. What is a Programming Language? John von Neumann (1940’s) –Stored program concept –CPU actions determined.](https://reader035.fdocuments.net/reader035/viewer/2022062407/56649f445503460f94c65bc2/html5/thumbnails/4.jpg)
Definition
• A Programming Language is a notational system for describing computation in machine-readable and human-readable form
![Page 5: Theory of Programming Languages Introduction. What is a Programming Language? John von Neumann (1940’s) –Stored program concept –CPU actions determined.](https://reader035.fdocuments.net/reader035/viewer/2022062407/56649f445503460f94c65bc2/html5/thumbnails/5.jpg)
Computation
• Turing machine– Mathematical concept of a machine whose
operation is simple enough to be described with great precision
– Powerful enough to to perform any computation a computer can
– Church’s Theorem: It is impossible to build a machine that is inherently more powerful than a Turing machine.
![Page 6: Theory of Programming Languages Introduction. What is a Programming Language? John von Neumann (1940’s) –Stored program concept –CPU actions determined.](https://reader035.fdocuments.net/reader035/viewer/2022062407/56649f445503460f94c65bc2/html5/thumbnails/6.jpg)
Computation
• (For our purposes) Any process which can be carried out by a computer
• We will concentrate on general-purpose languages that are designed to be used in general processing
![Page 7: Theory of Programming Languages Introduction. What is a Programming Language? John von Neumann (1940’s) –Stored program concept –CPU actions determined.](https://reader035.fdocuments.net/reader035/viewer/2022062407/56649f445503460f94c65bc2/html5/thumbnails/7.jpg)
Machine Readablilty
• Simple enough to allow efficient translation– There must be an algorithm to translate the
language– This algorithm must not have too great a
complexity– This is usually ensured by restricting the
structure of the programming language to that of Context-free grammars (CFG’s)
![Page 8: Theory of Programming Languages Introduction. What is a Programming Language? John von Neumann (1940’s) –Stored program concept –CPU actions determined.](https://reader035.fdocuments.net/reader035/viewer/2022062407/56649f445503460f94c65bc2/html5/thumbnails/8.jpg)
Human Readability
• The language should allow abstractions of actions of the computer that are easy to understand– It should tend to resemble a natural language
(English for us)
• For large programs, there must be suitable mechanisms for reducing the amount of detail required to understand the program as a whole
![Page 9: Theory of Programming Languages Introduction. What is a Programming Language? John von Neumann (1940’s) –Stored program concept –CPU actions determined.](https://reader035.fdocuments.net/reader035/viewer/2022062407/56649f445503460f94c65bc2/html5/thumbnails/9.jpg)
Abstractions in Programming Languages
• Data Abstraction– Abstract properties of the data
• Strings
• Trees
• Control Abstraction– Abstract properties of the transfer of control
• Loops
• Procedure calls (sort, search)
![Page 10: Theory of Programming Languages Introduction. What is a Programming Language? John von Neumann (1940’s) –Stored program concept –CPU actions determined.](https://reader035.fdocuments.net/reader035/viewer/2022062407/56649f445503460f94c65bc2/html5/thumbnails/10.jpg)
Data Abstractions
• Basic Abstractions– Abstract the internal representation of data values
• Variables and data types
• Structured Abstractions– Arrays and Records
– Data Structures
• Unit Abstractions– Data encapsulation
– Information hiding
![Page 11: Theory of Programming Languages Introduction. What is a Programming Language? John von Neumann (1940’s) –Stored program concept –CPU actions determined.](https://reader035.fdocuments.net/reader035/viewer/2022062407/56649f445503460f94c65bc2/html5/thumbnails/11.jpg)
Control Abstractions
• Basic Abstractions– Variable assignment– GOTO’s
• Structured Abstractions– Selection– Looping– Sub programs
![Page 12: Theory of Programming Languages Introduction. What is a Programming Language? John von Neumann (1940’s) –Stored program concept –CPU actions determined.](https://reader035.fdocuments.net/reader035/viewer/2022062407/56649f445503460f94c65bc2/html5/thumbnails/12.jpg)
Unit Abstractions
• Grouping a collection of related procedures into a unit whose inner workings do not need to be understood to understand the program– Ex: all I/O procedures– Ex: all statistical procedures (mean, mode,
median, variance, etc)
![Page 13: Theory of Programming Languages Introduction. What is a Programming Language? John von Neumann (1940’s) –Stored program concept –CPU actions determined.](https://reader035.fdocuments.net/reader035/viewer/2022062407/56649f445503460f94c65bc2/html5/thumbnails/13.jpg)
Other Abstractions
• Parallel processing mechanisms– Threads– Processes– Tasks (Ada)
![Page 14: Theory of Programming Languages Introduction. What is a Programming Language? John von Neumann (1940’s) –Stored program concept –CPU actions determined.](https://reader035.fdocuments.net/reader035/viewer/2022062407/56649f445503460f94c65bc2/html5/thumbnails/14.jpg)
Computational Paradigms
• Imperative (Procedural) Programming
• Object-Oriented Programming
• Functional Programming
• Logic Programming
• Event-driven Programming
• Concurrent Programming
![Page 15: Theory of Programming Languages Introduction. What is a Programming Language? John von Neumann (1940’s) –Stored program concept –CPU actions determined.](https://reader035.fdocuments.net/reader035/viewer/2022062407/56649f445503460f94c65bc2/html5/thumbnails/15.jpg)
Imperative Programming
• Imperative programming is characterized by– Sequential execution of instructions– Use of variables representing memory locations– Use of assignment to change values of variables
![Page 16: Theory of Programming Languages Introduction. What is a Programming Language? John von Neumann (1940’s) –Stored program concept –CPU actions determined.](https://reader035.fdocuments.net/reader035/viewer/2022062407/56649f445503460f94c65bc2/html5/thumbnails/16.jpg)
Object-oriented Programming
• Three major topics of object-oriented programming– Polymorphism– Inheritance– Encapsulation
• Object– State– Behavior
![Page 17: Theory of Programming Languages Introduction. What is a Programming Language? John von Neumann (1940’s) –Stored program concept –CPU actions determined.](https://reader035.fdocuments.net/reader035/viewer/2022062407/56649f445503460f94c65bc2/html5/thumbnails/17.jpg)
Functional Programming
• Functional programming bases computation on evaluation of functions (or function applications)
• No notion of variables or assignment
• Repetitive operations are done by recursive functions (no notion of loops)
![Page 18: Theory of Programming Languages Introduction. What is a Programming Language? John von Neumann (1940’s) –Stored program concept –CPU actions determined.](https://reader035.fdocuments.net/reader035/viewer/2022062407/56649f445503460f94c65bc2/html5/thumbnails/18.jpg)
Logic Programming
• Logic programming is based on symbolic logic
• A logic program is a collection of declarations which are true about the desired result
• No notion of flow-of-control
![Page 19: Theory of Programming Languages Introduction. What is a Programming Language? John von Neumann (1940’s) –Stored program concept –CPU actions determined.](https://reader035.fdocuments.net/reader035/viewer/2022062407/56649f445503460f94c65bc2/html5/thumbnails/19.jpg)
Event-driven Programming
• Programming based on response to events
• The underlying system recognizes the events so there is no need for control-flow mechanisms except in response to events
![Page 20: Theory of Programming Languages Introduction. What is a Programming Language? John von Neumann (1940’s) –Stored program concept –CPU actions determined.](https://reader035.fdocuments.net/reader035/viewer/2022062407/56649f445503460f94c65bc2/html5/thumbnails/20.jpg)
Concurrent Programming
• Synchronization – Threads, for example
![Page 21: Theory of Programming Languages Introduction. What is a Programming Language? John von Neumann (1940’s) –Stored program concept –CPU actions determined.](https://reader035.fdocuments.net/reader035/viewer/2022062407/56649f445503460f94c65bc2/html5/thumbnails/21.jpg)
Language Definition
• Syntax– The structure of the language (grammar)– Notational systems for formal description
• BNF• Syntax diagrams
• Semantics– The meaning of the language constructs– Notational systems for formal description
• Operational semantics• Denotational semantics• Axiomatic semantics
![Page 22: Theory of Programming Languages Introduction. What is a Programming Language? John von Neumann (1940’s) –Stored program concept –CPU actions determined.](https://reader035.fdocuments.net/reader035/viewer/2022062407/56649f445503460f94c65bc2/html5/thumbnails/22.jpg)
Language Translation
• For a programming language to be useful, it needs a translator– Interpreter
• A translator that executes a program directly
– Compiler• A translator that produces an equivalent program in
a form suitable for execution
![Page 23: Theory of Programming Languages Introduction. What is a Programming Language? John von Neumann (1940’s) –Stored program concept –CPU actions determined.](https://reader035.fdocuments.net/reader035/viewer/2022062407/56649f445503460f94c65bc2/html5/thumbnails/23.jpg)
Interpretation
sourcecode
input interpreter output
![Page 24: Theory of Programming Languages Introduction. What is a Programming Language? John von Neumann (1940’s) –Stored program concept –CPU actions determined.](https://reader035.fdocuments.net/reader035/viewer/2022062407/56649f445503460f94c65bc2/html5/thumbnails/24.jpg)
Compilation
executablecode
processorinput output
sourcecode
compile targetcode
furthertranslation
executablecode
![Page 25: Theory of Programming Languages Introduction. What is a Programming Language? John von Neumann (1940’s) –Stored program concept –CPU actions determined.](https://reader035.fdocuments.net/reader035/viewer/2022062407/56649f445503460f94c65bc2/html5/thumbnails/25.jpg)
Phases of translation
• Lexical analyzer (scanner)
• Syntax analyzer (parser)
• Semantic analyzer
![Page 26: Theory of Programming Languages Introduction. What is a Programming Language? John von Neumann (1940’s) –Stored program concept –CPU actions determined.](https://reader035.fdocuments.net/reader035/viewer/2022062407/56649f445503460f94c65bc2/html5/thumbnails/26.jpg)
Language Design
• Machine and human readability are overriding requirements
• Facilities for the natural expression of the structure of data
• Goal of abstraction is complexity control