Concepts of Programming Languages

Similar documents
Programming Languages 2nd edition Tucker and Noonan"

Chapter 1. Preliminaries

Chapter 1 Preliminaries

CS383 PROGRAMMING LANGUAGES. Kenny Q. Zhu Dept. of Computer Science Shanghai Jiao Tong University

Chapter 1. Preliminaries

Chapter 1. Preview. Reason for Studying OPL. Language Evaluation Criteria. Programming Domains

Programming Languages, Summary CSC419; Odelia Schwartz

Concepts of Programming Languages

Principles of Programming Languages. Lecture Outline

What is a programming language?

Chapter 5. Names, Bindings, and Scopes

Why study Programming Language Concepts? Chapter One. Language Evaluation Criteria. Programming Domains. Readability Writability Reliability Cost

Early computers (1940s) cost millions of dollars and were programmed in machine language. less error-prone method needed

8/27/17. CS-3304 Introduction. What will you learn? Semester Outline. Websites INTRODUCTION TO PROGRAMMING LANGUAGES

EI326 ENGINEERING PRACTICE & TECHNICAL INNOVATION (III-G) Kenny Q. Zhu Dept. of Computer Science Shanghai Jiao Tong University

INSTITUTE OF AERONAUTICAL ENGINEERING

Programmiersprachen (Programming Languages)

Concepts of Programming Languages

General Concepts. Abstraction Computational Paradigms Implementation Application Domains Influence on Success Influences on Design

Introduction. A. Bellaachia Page: 1

! Broaden your language horizons! Different programming languages! Different language features and tradeoffs. ! Study how languages are implemented

Why are there so many programming languages? Why do we have programming languages? What is a language for? What makes a language successful?

COP4020 Programming Languages. Compilers and Interpreters Robert van Engelen & Chris Lacher

CS 565: Programming Languages. Spring 2008 Tu, Th: 16:30-17:45 Room LWSN 1106

Compiling and Interpreting Programming. Overview of Compilers and Interpreters

CS 242. Fundamentals. Reading: See last slide

Chapter 2 Preview. Preview. History of Programming Languages. History of Programming Languages. History of Programming Languages

St. MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad

CS 3360 Design and Implementation of Programming Languages. Exam 1

Com S 541. Programming Languages I

1. true / false By a compiler we mean a program that translates to code that will run natively on some machine.

Programming Languages Third Edition. Chapter 7 Basic Semantics

Design & Implementation Overview

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

9/7/17. Outline. Name, Scope and Binding. Names. Introduction. Names (continued) Names (continued) In Text: Chapter 5

Outline. Programming Languages 1/16/18 PROGRAMMING LANGUAGE FOUNDATIONS AND HISTORY. Current

Seminar in Programming Languages

Programming Paradigms

Concepts in Programming Languages

CSC 533: Organization of Programming Languages. Spring 2005

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler Front-End

Organization of Programming Languages (CSE452) Why are there so many programming languages? What makes a language successful?

COP 3402 Systems Software. Lecture 4: Compilers. Interpreters

Imperative Programming

Chapter 5 Names, Bindings, Type Checking, and Scopes

Compilers. Prerequisites

! Broaden your language horizons. ! Study how languages are implemented. ! Study how languages are described / specified

G Programming Languages - Fall 2012

IA010: Principles of Programming Languages

Programming Languages, Introduction CSC419; Odelia Schwartz

The role of semantic analysis in a compiler

Compilation I. Hwansoo Han

CST-402(T): Language Processors

Introduction to Scientific Computing Languages

Introduction to Scientific Computing Languages

Chapter 5 Names, Binding, Type Checking and Scopes

Why are there so many programming languages?

Informal Semantics of Data. semantic specification names (identifiers) attributes binding declarations scope rules visibility

Topic I. Introduction and motivation References: Chapter 1 of Concepts in programming languages by J. C. Mitchell. CUP, 2003.

CS 3360 Design and Implementation of Programming Languages. Exam 1

Concepts of Programming Languages

Working of the Compilers

CSCI 3136 Principles of Programming Languages

SKILL AREA 304: Review Programming Language Concept. Computer Programming (YPG)

G Programming Languages - Fall 2012

CSE 307: Principles of Programming Languages

Programming Languages

CS 415 Midterm Exam Spring 2002

HANDLING NONLOCAL REFERENCES

G Programming Languages Spring 2010 Lecture 4. Robert Grimm, New York University

Chapter 3:: Names, Scopes, and Bindings (cont.)

Informatica 3 Syntax and Semantics

Chapter 3:: Names, Scopes, and Bindings (cont.)

Lecture 09. Ada to Software Engineering. Mr. Mubashir Ali Lecturer (Dept. of Computer Science)

Language Translation, History. CS152. Chris Pollett. Sep. 3, 2008.

CS 330 Lecture 18. Symbol table. C scope rules. Declarations. Chapter 5 Louden Outline

SE352b: Roadmap. SE352b Software Engineering Design Tools. W3: Programming Paradigms

Lecture 13: Object orientation. Object oriented programming. Introduction. Object oriented programming. OO and ADT:s. Introduction

Names, Bindings, Scopes

CSc 372. Comparative Programming Languages. 2 : Functional Programming. Department of Computer Science University of Arizona

LECTURE 1. Overview and History

NOTE: Answer ANY FOUR of the following 6 sections:

Chapter 5. Variables. Topics. Imperative Paradigm. Von Neumann Architecture

9/5/17. The Design and Implementation of Programming Languages. Compilation. Interpretation. Compilation vs. Interpretation. Hybrid Implementation

R13 SET Discuss how producer-consumer problem and Dining philosopher s problem are solved using concurrency in ADA.

CS 3304 Comparative Languages. Lecture 1: Introduction

CMSC 330: Organization of Programming Languages. Administrivia

Scripted Components: Problem. Scripted Components. Problems with Components. Single-Language Assumption. Dr. James A. Bednar

Scripted Components Dr. James A. Bednar


Dynamically-typed Languages. David Miller

Lecture 1: Course Introduction

COSC 2P90 Programming Languages & Object-Orientation

Language Translation. Compilation vs. interpretation. Compilation diagram. Step 1: compile. Step 2: run. compiler. Compiled program. program.

CS508-Modern Programming Solved MCQ(S) From Midterm Papers (1 TO 22 Lectures) BY Arslan

What Is Computer Science? The Scientific Study of Computation. Expressing or Describing

CMSC 330: Organization of Programming Languages

Data Types. Every program uses data, either explicitly or implicitly to arrive at a result.

names names identifiers variables subroutines constants

CS 314 Principles of Programming Languages

Transcription:

Concepts of Programming Languages Lecture 1 - Introduction Patrick Donnelly Montana State University Spring 2014 Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014 1 / 46

Textbook Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014 2 / 46

Administrivia Website: http://nisl.cs.montana.edu/~pdonnelly/csci305/ Reading: Chapter 1 Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014 3 / 46

A good programming language is a conceptual universe for thinking about programming. A. Perlis Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014 4 / 46

Reasons for Studying Programming Languages Increased ability to express ideas Improved background for choosing appropriate languages Increased ability to learn new languages Better understanding of significance of implementation Better use of languages that are already known Overall advancement of computing Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014 5 / 46

Principles Programming languages have four properties: Syntax Names Types Semantics For any language: Its designers must define these properties Its programmers must master these properties Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014 6 / 46

Syntax Definition The syntax of a programming language is a precise description of all its grammatically correct programs. When studying syntax, we ask questions like: What is the grammar for the language? What is the basic vocabulary? How are syntax errors detected? Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014 7 / 46

Names Various kinds of entities in a program have names: variables types functions parameters classes objects Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014 8 / 46

Names Various kinds of entities in a program have names: variables types functions parameters classes objects Named entities are bound in a running program to: Scope Visibility Type Lifetime Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014 8 / 46

Types Definition A type is a collection of values and a collection of operations on those values. Simple types: numbers characters booleans,... etc. Structured types Strings, lists, trees, hash tables,... etc.. Definition A language s type system can help to: Determine legal operations Detect type errors Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014 9 / 46

Semantics Definition The meaning of a program is called its semantics. In studying semantics, we ask questions like: When a program is running, what happens to the values of the variables? What does each statement mean? What underlying model governs run-time behavior, such as function call? How are objects allocated to memory at run-time? Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014 10 / 46

Paradigms Definition A programming paradigm is a pattern of problem-solving thought that underlies a particular genre of programs and languages. There are four main programming paradigms: Imperative Object-oriented Functional Logic Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014 11 / 46

Imperative Paradigm Follows the classic von Neumann-Eckert model: Program and data are indistinguishable in memory Program = a sequence of commands State = values of all variables when program runs Large programs use procedural abstraction Example imperative languages: Cobol Fortran C Ada Perl Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014 12 / 46

The von Neumann-Eckert Model Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014 13 / 46

Object-oriented (OO) Paradigm An OO Program is a collection of objects that interact by passing messages that transform the state. When studying OO, we learn about: Sending Messages Inheritance Polymorphism Example OO languages: Smalltalk Java C++ C# Python Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014 14 / 46

Functional Paradigm Functional programming models a computation as a collection of mathematical functions. Input = domain Output = range Functional languages are characterized by: Functional composition Recursion Example functional languages: Lisp Scheme ML Haskell Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014 15 / 46

Logic Paradigm Logic programming declares what outcome the program should accomplish, rather than how it should be accomplished. When studying logic programming we see: Programs as sets of constraints on a problem Programs that achieve all possible solutions Programs that are nondeterministic Example logic programming languages: Datalog Prolog Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014 16 / 46

Special Topics Concurrency: e.g., Client-server programs Correctness: How can we prove that a program does what it is supposed to do under all circumstances? Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014 17 / 46

On Language Design Design Constraints: Computer architecture Technical setting Standards Legacy systems Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014 18 / 46

On Language Design Design Constraints: Computer architecture Technical setting Standards Legacy systems Outcomes and Goals: 1 How does a programming language emerge and become successful? 2 What key characteristics make an ideal programming language? Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014 18 / 46

Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014 19 / 46

Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014 20 / 46

Language Design Trade-Offs Reliability vs. cost of execution Example: Java demands all references to array elements be checked for proper indexing, which leads to increased execution costs Readability vs. writability Example: APL provides many powerful operators (and a large number of new symbols), allowing complex computations to be written in a compact program but at the cost of poor readability Writability (flexibility) vs. reliability Example: C++ pointers are powerful and very flexible but are unreliable Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014 21 / 46

Compilation Compiler translate high-level program (source language) into machine code (machine language) Programs are translated into machine language; includes JIT systems Slow translation, fast execution Use: Large commercial applications Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014 22 / 46

Compilation Compiler translate high-level program (source language) into machine code (machine language) Programs are translated into machine language; includes JIT systems Slow translation, fast execution Use: Large commercial applications Example compiled languages: Fortran, Cobol, C, C++ Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014 22 / 46

Compilation Compilation process has several phases: lexical analysis: converts characters in the source program into lexical units syntax analysis: transforms lexical units into parse trees which represent the syntactic structure of program semantics analysis: generate intermediate code code generation: machine code is generated Load module (executable image): the user and system code together Linking and loading: the process of collecting system program units and linking them to a user program Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014 23 / 46

Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014 24 / 46

Von Neumann Bottleneck Connection speed between a computer s memory and its processor determines the speed of a computer Program instructions often can be executed much faster than the speed of the connection; the connection speed thus results in a bottleneck Known as the von Neumann bottleneck; it is the primary limiting factor in the speed of computers Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014 25 / 46

Pure Interpretation Interpreter executes instructions on a virtual machine Programs are interpreted by another program known as an interpreter No translation Easier implementation of programs (run-time errors can easily and immediately be displayed) Slower execution (10 to 100 times slower than compiled programs) Often requires more space Now rare for traditional high-level languages but recent comeback with some Web scripting languages (e.g., JavaScript, PHP) Use: Small programs or when efficiency is not an issue Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014 26 / 46

Pure Interpretation Interpreter executes instructions on a virtual machine Programs are interpreted by another program known as an interpreter No translation Easier implementation of programs (run-time errors can easily and immediately be displayed) Slower execution (10 to 100 times slower than compiled programs) Often requires more space Now rare for traditional high-level languages but recent comeback with some Web scripting languages (e.g., JavaScript, PHP) Use: Small programs or when efficiency is not an issue Example interpreted languages: Scheme, Haskell, Python Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014 26 / 46

The Interpreting Process Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014 27 / 46

Hybrid Implementation Systems A compromise between compilers and pure interpreters A high-level language program is translated to an intermediate language that allows easy interpretation Faster than pure interpretation Use: Small and medium systems when efficiency is not the first concern Example Hybrid compilation/interpretation The Java Virtual Machine (JVM) Perl programs are partially compiled to detect errors before interpretation Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014 28 / 46

Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014 29 / 46

Just-in-Time Implementation Systems Initially translate programs to an intermediate language Then compile the intermediate language of the subprograms into machine code when they are called Machine code version is kept for subsequent calls JIT systems are widely used for Java programs.net languages are implemented with a JIT system In essence, JIT systems are delayed compilers Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014 30 / 46

Preprocessors Preprocessor macros (instructions) are commonly used to specify that code from another file is to be included A preprocessor processes a program immediately before the program is compiled to expand embedded preprocessor macros A well-known example: C preprocessor expands #include, #define, and similar macros Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014 31 / 46

Characteristics of a Successful Language Simplicity and readability Clarity about binding Reliability Support Abstraction Orthogonality Efficient implementation Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014 32 / 46

Characteristics of a Successful Language Simplicity and readability Clarity about binding Reliability Support Abstraction Orthogonality Efficient implementation Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014 33 / 46

Simplicity and Readability Small instruction set: e.g., Java vs Scheme Simple syntax: e.g., C/C++/Java vs Python Benefits: Ease of learning Ease of programming Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014 34 / 46

Characteristics of a Successful Language Simplicity and readability Clarity about binding Reliability Support Abstraction Orthogonality Efficient implementation Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014 35 / 46

Clarity about Binding A language element is bound to a property at the time that property is defined for it. Definition A binding is the association between an object and a property of that object. Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014 36 / 46

Clarity about Binding A language element is bound to a property at the time that property is defined for it. Definition A binding is the association between an object and a property of that object. Examples a variable and its type a variable and its value Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014 36 / 46

Clarity about Binding A language element is bound to a property at the time that property is defined for it. Definition A binding is the association between an object and a property of that object. Examples a variable and its type a variable and its value Early binding takes place at compile-time. Late binding takes place at run time Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014 36 / 46

Characteristics of a Successful Language Simplicity and readability Clarity about binding Reliability Support Abstraction Orthogonality Efficient implementation Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014 37 / 46

Reliability A language is reliable if: Program behavior is the same on different platforms e.g., early versions of Fortran Type errors are detected e.g., C vs Haskell Semantic errors are properly trapped e.g., C vs C++ Memory leaks are prevented e.g., C vs Java Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014 38 / 46

Characteristics of a Successful Language Simplicity and readability Clarity about binding Reliability Support Abstraction Orthogonality Efficient implementation Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014 39 / 46

Language Support Accessible (public domain) compilers/interpreters Good texts and tutorials Wide community of users Integrated with development environments (IDEs) Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014 40 / 46

Characteristics of a Successful Language Simplicity and readability Clarity about binding Reliability Support Abstraction Orthogonality Efficient implementation Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014 41 / 46

Abstraction in Programming Data: Programmer-defined types/classes Class libraries Procedural: Programmer-defined functions Standard function libraries Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014 42 / 46

Characteristics of a Successful Language Simplicity and readability Clarity about binding Reliability Support Abstraction Orthogonality Efficient implementation Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014 43 / 46

Orthogonality Definition A language is orthogonal if its features are built upon a small, mutually independent set of primitive operations. Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014 44 / 46

Orthogonality Definition A language is orthogonal if its features are built upon a small, mutually independent set of primitive operations. Fewer exceptional rules = conceptual simplicity Example restricting types of arguments to a function Tradeoffs with efficiency Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014 44 / 46

Characteristics of a Successful Language Simplicity and readability Clarity about binding Reliability Support Abstraction Orthogonality Efficient implementation Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014 45 / 46

Efficient Implementation Embedded systems Real-time responsiveness (e.g., navigation) Failures of early Ada implementations Web applications Responsiveness to users (e.g., Google search) Corporate database applications Efficient search and updating AI applications Modeling human behaviors Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014 46 / 46