F28PL1 Programming Languages Lecture 20: Summary.

Slides:



Advertisements
Similar presentations
Programming Languages and Paradigms
Advertisements

Programming Languages and Paradigms The C Programming Language.
Names and Bindings.
The Assembly Language Level
Programming Languages Marjan Sirjani 2 2. Language Design Issues Design to Run efficiently : early languages Easy to write correctly : new languages.
Chapter 7: User-Defined Functions II
CS ExCo Advanced in Topics Object-Oriented Programming.
F28PL1 Programming Languages Lecture 5: Assembly Language 4.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 18.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 5 Types Types are the leaven of computer programming;
Functional Design and Programming Lecture 1: Functional modeling, design and programming.
1 Names, Scopes and Bindings. 2 Names Kinds of names Kinds of names Variables, functions, classes, types, labels, blocks, operators, tasks, etc. Variables,
Run time vs. Compile time
ISBN Lecture 01 Preliminaries. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.1-2 Lecture 01 Topics Motivation Programming.
CSE S. Tanimoto Syntax and Types 1 Representation, Syntax, Paradigms, Types Representation Formal Syntax Paradigms Data Types Type Inference.
VB in Context Michael B. Spring Department of Information Science and Telecommunications University of Pittsburgh Pittsburgh, Pa 15260
1 Run time vs. Compile time The compiler must generate code to handle issues that arise at run time Representation of various data types Procedure linkage.
1 Type Type system for a programming language = –set of types AND – rules that specify how a typed program is allowed to behave Why? –to generate better.
Describing Syntax and Semantics
Abstract Data Types and Encapsulation Concepts
1 Chapter 5: Names, Bindings and Scopes Lionel Williams Jr. and Victoria Yan CSci 210, Advanced Software Paradigms September 26, 2010.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009.
Imperative Programming
F28PL1 Programming Languages Lecture 10: Programming in C 5.
CS 403: Programming Languages Lecture 2 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
CSC3315 (Spring 2009)1 CSC 3315 Programming Languages Hamid Harroud School of Science and Engineering, Akhawayn University
Names Variables Type Checking Strong Typing Type Compatibility 1.
C Programming language
F28PL1 Programming Languages Lecture 15: Standard ML 5.
Programming Language C++ Xulong Peng CSC415 Programming Languages.
Names and Scope. Scope Suppose that a name is used many times for different entities in text of the program, or in the course of execution. When the name.
Dynamic Memory Allocation Conventional array and other data declarations An incorrect attempt to size memory dynamically Requirement for dynamic allocation.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition, Fifth Edition Chapter 7: User-Defined Functions II.
JAVA 0. HAFTA Algorithms FOURTH EDITION Robert Sedgewick and Kevin Wayne Princeton University.
Basic Semantics Associating meaning with language entities.
CSE 425: Data Types I Data and Data Types Data may be more abstract than their representation –E.g., integer (unbounded) vs. 64-bit int (bounded) A language.
Programming Languages and Paradigms Imperative Programming.
COP4020 Programming Languages Names, Scopes, and Bindings Prof. Xin Yuan.
CS 2130 Lecture 5 Storage Classes Scope. C Programming C is not just another programming language C was designed for systems programming like writing.
Copyright © Curt Hill Structured Data What this course is about.
COMP3190: Principle of Programming Languages
Types(1). Lecture 52 Type(1)  A type is a collection of values and operations on those values. Integer type  values..., -2, -1, 0, 1, 2,...  operations.
How to execute Program structure Variables name, keywords, binding, scope, lifetime Data types – type system – primitives, strings, arrays, hashes – pointers/references.
Variables reference, coding, visibility. Rules for making names  permitted character set  maximum length, significant length  case sensitivity  special.
1 Structure of Compilers Lexical Analyzer (scanner) Modified Source Program Parser Tokens Semantic Analysis Syntactic Structure Optimizer Code Generator.
CPS120: Introduction to Computer Science Variables and Constants.
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
CS 330 Programming Languages 10 / 23 / 2007 Instructor: Michael Eckmann.
F28HS2 Hardware-Software Interface Lecture 12: Assembly Language 6 & Summary.
Names, Scope, and Bindings Programming Languages and Paradigms.
Overview of Compilation Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 2.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Operational Semantics (Slides mainly.
Review A program is… a set of instructions that tell a computer what to do. Programs can also be called… software. Hardware refers to… the physical components.
1 jcmt Summer 2003Programming Languages CSE3302 Programming Languages Summer 2003 Dr. Carter Tiernan.
1 The user’s view  A user is a person employing the computer to do useful work  Examples of useful work include spreadsheets word processing developing.
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Functional Programming
Chapter 7: User-Defined Functions II
Names and Attributes Names are a key programming language feature
Type Checking Generalizes the concept of operands and operators to include subprograms and assignments Type checking is the activity of ensuring that the.
CS 326 Programming Languages, Concepts and Implementation
Representation, Syntax, Paradigms, Types
课程名 编译原理 Compiling Techniques
Representation, Syntax, Paradigms, Types
Representation, Syntax, Paradigms, Types
Representation, Syntax, Paradigms, Types
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Chapter 15 Functional Programming 6/1/2019.
Presentation transcript:

F28PL1 Programming Languages Lecture 20: Summary

Overview started by characterising a computer as a memory machine considered programming languages as abstractions from: – memory as address/byte associations – instructions as sequences of changes to address/byte associations

Overview layers of abstraction hierarchy of expressiveness tension between: – expressive power/ease of use – ease of implementation/ performance CPU memory I/O machine code assembly system high level declarative “distance” from CPU

Overview greater distance from CPU  – increased expressiveness/ succinctness – increased implementation effort – decreased performance more memory less speed CPU memory I/O “distance” from CPU machine code assembly system high level declarative

Summarising language characteristics how does a language abstract away from underlying byte machines? – types – data abstraction – control abstraction what are pragmatic consequences of language characteristics? – i.e. how do characteristics affect use?

Types values & operations what are base types? – e.g. Java: int, float, char etc what are structured types? – e.g. Java: object, array, String etc

Types how do types constrain language? weak v strong typing – i.e. whether type associated with entity can change (weak) or can’t change (strong) – e.g. Java: strong typing static v dynamic typing – i.e. whether types checked at compile time (static) or run time (dynamic) – e.g. Java: static typing

Polymorphism type abstraction – can types be generalised? – polymorphism == many shapes ad-hoc v parametric polymorphism – ad-hoc == “for this” i.e. language/context specific – parametric == controlled by parameters

Polymorphism e.g. Java – ad-hoc polymorphism operator overloading i.e. can use some operators with different types e.g. arithmetic – parametric polymorphism i.e. generic types with type variables

Assembler summary: types no types – everything is a byte representations for: – numbers, characters etc no type checking – representation are conventional – can apply any operation to any byte sequence regardless of representation – i.e. ad-hoc polymorphism

C summary: types strong, static types – but... can override types with casts & address manipulation base types – int, short, long, char, float, double structured types – array, struct, pointer, union, function ad-hoc polymorphism – operator overloading & cast

SML summary: types strong, static types base types – int, real, char, bool structured types – tuple, list, user defined ad-hoc polymorphism – operator overloading parametric polymorphism – functions, lists, user defined types

Prolog summary: types weak, dynamic types base types – integer, atom structured types – structure, list ad-hoc polymorphism – arbitrary types can appear in structures

Data abstraction memory abstraction variable as name/value abstraction from address/contents – e.g. Java: variables where may variables be introduced? – e.g. Java: class fields, method formal parameters, block/method bodies, iteration control

Data abstraction how may variables be bound to values? e.g Java: – initialising declaration – assignment – parameter passing

Data abstraction scope – i.e. where is something visible? – lexical v dynamic scope – i.e. constrained or not by site of definition/declaration extent – i.e. how long does something exist?

Data abstraction e.g. Java: lexical scope – class field/method names visible via object – variables in block/ method body visible in block unless redefined – method formal parameter visible in method body only e.g. Java: block extent – variables only exist in defining block/method body

Assembler summary: data abstraction names R0-R15, PC, LR, SP etc abstract from CPU registers labels abstract from memory addresses names and labels used as variables i.e. use name as operand to access/change register/memory no data structures – must craft explicitly from byte sequences

Assembler summary: data abstraction registers: – scope/extent - whole program labels: – scope whole file + where imported – extent – whole program

C summary: data abstraction variable – name/value association – abstracts address/contents can still expose low level memory: – & and * – can request that variable be bound to register

C summary: data abstraction variable introduction – declaration at start of program – declaration at start of block – formal parameters scope – lexical extent – block

SML summary: data abstraction variable – name/value association – cannot be changed address/memory not visible

SML summary: data abstraction variable introduction – global definition – local definition – formal parameter scope – lexical extent – local definition, function body,

Prolog summary: data abstraction variable – name/value association – changed by backtracking – variable sharing memory not visible

Prolog summary: data abstraction variable introduction – term scope – lexical extent – goal of which term is part

Control abstraction structured operations as commands how are calculations performed? – e.g. Java: expression how is memory accessed? – e.g. Java: use variable name in expression context how is memory changed? – e.g. Java: assignment to variable

Control abstraction how are commands structured? e.g. Java: – sequence block, nested method calls – choice if, switch – repetition while, for, iterators, recursion

Control abstraction e.g. Java – control flow method call, return & break – procedural void method i.e. from control sequences – functional method with return type i.e. from expressions – call by reference parameter passing

Program abstraction encapsulation – abstract over data & control e.g. Java – classes/objects

Assembler summary: control abstraction operators abstract from machine code must craft structured constructs from operator sequences no universal standards or conventions – but compilers/operating will define standards – e.g. for parameter passing

C summary: control abstraction expressions – abstract from arithmetic/logic sequences commands – abstract from: memory/register manipulation sequences flag test, branch & address

C summary: control abstraction commands – assignment – sequence block & function body – choice if & switch – repetition for & while – flow of control function call, return, break & goto

C summary: control abstraction functions – functional abstraction with return type – procedural abstraction no return type – call by value & by reference parameter passing

SML summary: control abstraction expressions – abstract from arithmetic/logic/flow of control sequences conditional expression pattern matching – abstracts from constant matching functions – call by value parameter passing recursion

Prolog summary: control abstraction term – abstracts from arithmetic/logic/flow of control sequences DB – disjunction of facts/rules rule body/question – conjunction of terms pattern matching – abstracts from constant matching

Prolog summary: control abstraction question/goal/sub-goal – analogous to function call – binds variables to terms recursion backtracking – reverses variable bindings

Pragmatics what is mapping to byte machine? how implemented? how easy to read/write/debug? performance? use? etc...

Assembler summary: pragmatics direct machine code abstraction 1 to 1 mapping from assembly language to machine code easier to program than machine code must be assembled to machine code very fast – same as machine code

Assembler summary: pragmatics hard to read/write/debug CPU specific – not portable – 1950s attempts at universal machine code (UNCOL) failed used for mission/system critical software – e.g. device drivers, BIOS, small embedded systems

C summary: pragmatics in-between assembler & high-level many to one mapping from command to machine code must be compiled to machine code (or interpreted) easier to read/write/debug than assembler can manipulate low level byte machine weak typing  errors from pointers & casts must manage memory explicitly – e.g. allocate free memory for dynamic structures

C summary: pragmatics not as fast as assembler CPU independent – ISO standard – mostly portable – but size of type depends on implementation used for system level programming, real- time/embedded control rapidly replacing assembler for lower-level programming

SML summary: pragmatics higher level than imperative programs many to one mapping from expression to machine code must be compiled to machine code (or interpreted) very succinct strong typing  reduces run-time errors good correspondence between program structure & data structure automatic memory management – garbage collection

SML summary: pragmatics not as fast as some imperative languages – garbage collection overhead CPU independent – formal definition – highly portable used for: – rapid prototyping – reasoning about programs – designing parallel frameworks e.g. Google map- reduce

Prolog: pragmatics higher level than imperative programs many to one mapping from expression to machine code must be compiled to machine code (or interpreted) very succinct good correspondence between program structure & data structure automatic memory management – garbage collection

Prolog: pragmatics weak types/static typing/ad-hoc polymorphism – space overhead: must have explicit representation on type in memory – time overhead: must check types for typed operation backtracking – space overhead: must keep track of execution history garbage collection overhead

Prolog: pragmatics very different model to imperative/functional languages – long way from von Neumann model – key concepts drawn from logic claims to be entirely implementation independent but need to understand: – variable sharing – backtracking

Prolog: pragmatics CPU independent – ISO standard – highly portable used for: – rapid prototyping – AI

Language choice formally, programming language choice is arbitrary Church-Turing thesis – all formal models of computability are equivalent thesis, not a theorem – can’t be proved as unknown number of models simplest way is to demonstrate Turing completeness – show model can be used to implement an arbitrary Turing Machine – Alan Turing’s 1936 model for computability

Language choice all models of computability so far have been shown to satisfy Church-Turing thesis including: – lambda calculus – recursive function theory – generalised von Neumann computers – programming languages with arbitrarily large values/structures so, in principle, can do anything in any programming language but...

Technical constraints on language choice language may not support key constructs – e.g. lower level system/platform manipulation/control – e.g. high level control abstractions suitable for parallelism language may not be supported on mandated platform implementation may not be able to deliver required performance implementation may not have particular: – functionality – libraries could fix these but adds time/effort/cost to project

Social constraints on language choice may prefer one language over another – why do you prefer the language? – not necessarily a good basis for choice... language may be mandated by: – employer – customer – either may have: substantial investment in specific language technology requirement for specific system/platform/external interoperability

Socio-technical constraints on language choice need to be future proof language should be: – stable – widely used – widely supported by different platform/language tool manufacturers