Upload
leslie-howard
View
218
Download
2
Tags:
Embed Size (px)
Citation preview
Theory of Programming Languages
Introduction
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
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
Definition
• A Programming Language is a notational system for describing computation in machine-readable and human-readable form
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.
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
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)
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
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)
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
Control Abstractions
• Basic Abstractions– Variable assignment– GOTO’s
• Structured Abstractions– Selection– Looping– Sub programs
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)
Other Abstractions
• Parallel processing mechanisms– Threads– Processes– Tasks (Ada)
Computational Paradigms
• Imperative (Procedural) Programming
• Object-Oriented Programming
• Functional Programming
• Logic Programming
• Event-driven Programming
• Concurrent Programming
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
Object-oriented Programming
• Three major topics of object-oriented programming– Polymorphism– Inheritance– Encapsulation
• Object– State– Behavior
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)
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
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
Concurrent Programming
• Synchronization – Threads, for example
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
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
Interpretation
sourcecode
input interpreter output
Compilation
executablecode
processorinput output
sourcecode
compile targetcode
furthertranslation
executablecode
Phases of translation
• Lexical analyzer (scanner)
• Syntax analyzer (parser)
• Semantic analyzer
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