Top Banner
Theory of Programming Languages Introduction
26

Theory of Programming Languages Introduction. What is a Programming Language? John von Neumann (1940’s) –Stored program concept –CPU actions determined.

Dec 14, 2015

Download

Documents

Leslie Howard
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Theory of Programming Languages Introduction. What is a Programming Language? John von Neumann (1940’s) –Stored program concept –CPU actions determined.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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