Programming Languages, Summary CSC419; Odelia Schwartz

Similar documents
Chapter 5 Names, Binding, Type Checking and Scopes

Chapter 5 Names, Bindings, Type Checking, and Scopes

Chapter 5. Names, Bindings, and Scopes

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

Chapter 1. Preliminaries

INSTITUTE OF AERONAUTICAL ENGINEERING

St. MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad

Chapter 1 Preliminaries

Concepts of Programming Languages

Concepts of Programming Languages

Chapter 1. Preliminaries

CS 3360 Design and Implementation of Programming Languages. Exam 1

Principles of Programming Languages. Lecture Outline

Type Bindings. Static Type Binding

Programming Languages Third Edition. Chapter 7 Basic Semantics

Imperative Programming

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

Introduction. A. Bellaachia Page: 1

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

Programming Languages 2nd edition Tucker and Noonan"

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

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

NOTE: Answer ANY FOUR of the following 6 sections:

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

CSC 533: Organization of Programming Languages. Spring 2005

Answer: Early binding generally leads to greater efficiency (compilation approach) Late binding general leads to greater flexibility

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

CSE 307: Principles of Programming Languages

Programmiersprachen (Programming Languages)

Chapter 7. Expressions and Assignment Statements

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

COMP 201: Principles of Programming

Binding and Variables

Software II: Principles of Programming Languages. Why Expressions?

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

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

Chapter 7. Expressions and Assignment Statements ISBN

Programming Languages Third Edition. Chapter 10 Control II Procedures and Environments

Final-Term Papers Solved MCQS with Reference

Question No: 1 ( Marks: 1 ) - Please choose one One difference LISP and PROLOG is. AI Puzzle Game All f the given

Concepts of Programming Languages

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

Organization of Programming Languages CS320/520N. Lecture 06. Razvan C. Bunescu School of Electrical Engineering and Computer Science

11. a b c d e. 12. a b c d e. 13. a b c d e. 14. a b c d e. 15. a b c d e

Names, Bindings, Scopes

CMPS Programming Languages. Dr. Chengwei Lei CEECS California State University, Bakersfield

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

Chapter 6. Data Types ISBN

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

CS 3360 Design and Implementation of Programming Languages. Exam 1

6. Discuss how producer-consumer problem and Dining philosophers problem are solved using concurrency in ADA. [16]

Organization of Programming Languages CS3200 / 5200N. Lecture 06

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

Lecture 4 Memory Management

MIDTERM EXAM (Solutions)

G COURSE PLAN ASSISTANT PROFESSOR Regulation: R13 FACULTY DETAILS: Department::

Types. What is a type?

COSC252: Programming Languages: Basic Semantics: Data Types. Jeremy Bolton, PhD Asst Teaching Professor

Chapter 3. Describing Syntax and Semantics

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

G Programming Languages - Fall 2012

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

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

Informatica 3 Syntax and Semantics

Chapter 3. Describing Syntax and Semantics ISBN

What is a programming language?

Expressions & Assignment Statements

MIDTERM EXAMINATION - CS130 - Spring 2005

Introduction to Scientific Computing Languages

Concepts in Programming Languages

Introduction to Scientific Computing Languages

SOFTWARE ARCHITECTURE 6. LISP

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

Introduction. Primitive Data Types: Integer. Primitive Data Types. ICOM 4036 Programming Languages

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


Chapter 7 Expressions and Assignment statements

Chapter 3. Describing Syntax and Semantics

Attributes, Bindings, and Semantic Functions Declarations, Blocks, Scope, and the Symbol Table Name Resolution and Overloading Allocation, Lifetimes,

Chapter 4. Syntax - the form or structure of the expressions, statements, and program units

Chapter 7. Expressions and Assignment Statements (updated edition 11) ISBN

Chapter 6 part 1. Data Types. (updated based on 11th edition) ISBN

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

Syntax. In Text: Chapter 3

HANDLING NONLOCAL REFERENCES

Chapter 7. Expressions and Assignment Statements

CPSC 3740 Programming Languages University of Lethbridge. Data Types

Com S 541. Programming Languages I

UNIT 3

TYPES, VALUES AND DECLARATIONS

CS 415 Midterm Exam Spring 2002

LECTURE 18. Control Flow

LECTURE 1. Overview and History

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

Chapter 9 Subprograms

Topic IV. Parameters. Chapter 5 of Programming languages: Concepts & constructs by R. Sethi (2ND EDITION). Addison-Wesley, 1996.

Chapter 3. Syntax - the form or structure of the expressions, statements, and program units

CMSC 331 Final Exam Section 0201 December 18, 2000

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

Chapter 10 Implementing Subprograms

Transcription:

Programming Languages, Summary CSC419; Odelia Schwartz

Chapter 1 Topics Reasons for Studying Concepts of Programming Languages Programming Domains Language Evaluation Criteria Influences on Language Design Language Categories Language Design Trade-Offs Implementation Methods Programming Environments 3

Reasons for studying concepts of PL Increased ability to express ideas Improved background for choosing appropriate languages (when you open your startup when solving particular problems) Increased ability to learn new languages Better understanding of significance of implementation Better use of languages that are already known Overall advancement of computing 4

Programming Domains Scientific applications Large numbers of floating point computations; use of arrays Fortran (more recently though not stressed in book: Matlab, Python) Business applications Produce reports, use decimal numbers and characters COBOL Artificial intelligence Symbols rather than numbers manipulated; use of linked lists LISP 5

Language Categories Imperative Central features are variables, assignment statements, and iteration Include languages that support object-oriented programming Include scripting languages Include the visual languages Examples: Ada, C, Java, Perl, JavaScript, Ruby, Visual BASIC.NET, C++, Python, Functional Main means of making computations is by applying functions to given parameters In pure languages, no side effects Examples: LISP, Scheme, ML, Haskell 6

Language Categories (2) Logic Rule-based (rules are specified in no particular order) Example: Prolog 7

Language Evaluation Criteria Readability: the ease with which programs can be read and understood Writability: the ease with which a language can be used to create programs Reliability: conformance to specifications (i.e., performs to its specifications) Cost: the ultimate total cost 8

Computer Architecture Influence Well-known computer architecture: Von Neumann Imperative languages, most dominant, because of von Neumann computers Data and programs stored in memory Memory is separate from CPU Instructions and data are piped from memory to CPU Basis for imperative languages Variables model memory cells Assignment statements model piping Iteration is efficient We discussed Von Neumann bottleneck 9

Implementation Methods Compilation Programs are translated into machine language Pure Interpretation Programs are interpreted by another program known as an interpreter Hybrid Implementation Systems A compromise between compilers and pure interpreters translate high-level programs to an intermediate language 10

Evolution of the Major Programming Languages (light version) 1956 1958 1960 1962 1964 1966 1968 1970 Lisp Algol 60 Fortran I COBOL PL/I Smalltalk Pascal Prolog 1972 1974 Scheme 1976 Fortran 77 ML 1978 C (K&R) 1980 Smalltalk 80 1982 Ada 83 1984 Common Lisp C++ SML 1986 Perl Eiffel Caml 1988 Tcl 1990 Python Fortran 90 1992 1994 Java JavaScript Perl 5 Ruby 1996 OCaml 1998 Scheme R5RS C++ (ISO) Haskell 98 2000 C# Python 2.0 2002 2004 Java 2 (v1.5 beta) C# 2.0 2006 2008 See also http://www.levenez.com/lang/ for a complete list.

Describing Syntax and Semantics BNF and context-free grammars are equivalent metalanguages Well-suited for describing the syntax of programming languages An attribute grammar is a descriptive formalism that can describe both the syntax and the semantics of a language Three primary methods of semantics description Operation, axiomatic, denotational 12

Example Grammar for small language <program> begin <stmt_list> end <stmt_list> <stmt> <stmt> ; <stmt_list> <stmt> <var> = <expression> <var> a b c <expression> <var> + <var> <var> - <var> <var> 13

Example derivation <program> => begin <stmt_list> end We ll derive A = B + C; B = C with this grammar A derivation is a repeated application of rules, starting with the start symbol (in this case program) => reads derives 14

Example derivation <program> => begin <stmt_list> end => begin <stmt> ; <stmt_list> end => begin <var> = <expression> ; <stmt_list> end => begin A = <expression> ; <stmt_list> end => begin A = <var> + <var> ; <stmt_list> end => begin A = B + <var> ; <stmt_list> end => begin A = B + C ; <stmt_list> end => begin A = B + C ; <stmt> end => begin A = B + C ; <var> = <expression> end => begin A = B + C ; B = <expression> end => begin A = B + C ; B = <var> end => begin A = B + C ; B = C end 15

Example derivation <program> => begin <stmt_list> end => begin <stmt> ; <stmt_list> end => begin <var> = <expression> ; <stmt_list> end => begin A = <expression> ; <stmt_list> end => begin A = <var> + <var> ; <stmt_list> end => begin A = B + <var> ; <stmt_list> end => begin A = B + C ; <stmt_list> end => begin A = B + C ; <stmt> end => begin A = B + C ; <var> = <expression> end => begin A = B + C ; B = <expression> end => begin A = B + C ; B = <var> end => begin A = B + C ; B = C end We derived leftmost; could have also done rightmost 16

Derivations Every string of symbols in a derivation is called a sentential form A sentence is a sentential form that has only terminal symbols A leftmost derivation is one in which the leftmost nonterminal in each sentential form is the one that is expanded; similarly, rightmost derivation. A derivation may be neither leftmost nor rightmost 17

Parse Tree A hierarchical representation of a derivation <program> <stmt_list> <stmt> <var> = <expression> a <var> + <var> B C 18

Ambiguity in Grammars A grammar is ambiguous if and only if it generates a sentential form that has two or more distinct parse trees Problematic for compilers since parse tree, and therefore meaning of the structure, cannot be determined uniquely 19

Chapter 5: Names, Bindings, Type Checking, and Scopes Case sensitivity and the relationship of names to special words represent design issues of names Variables are characterized by the sextuples: name, address, value, type, lifetime, scope Binding is the association of attributes with program entities Scalar variables are categorized as: static, stack dynamic, explicit heap dynamic, implicit heap dynamic Strong typing means detecting all type errors 20

Static and Dynamic Binding A binding is static if it first occurs before run time and remains unchanged throughout program execution. A binding is dynamic if it first occurs during execution or can change during execution of the program 21

Categories of Variables by Lifetimes Static--bound to memory cells before execution begins and remains bound to the same memory cell throughout execution, e.g., C and C++ static variables 22

Categories of Variables by Lifetimes Stack-dynamic--Storage bindings are created for variables when their declaration statements are elaborated. (A declaration is elaborated when the executable code associated with it is executed) local variables in C subprograms and Java methods 23

Categories of Variables by Lifetimes Explicit heap-dynamic -- Allocated and deallocated by explicit directives, specified by the programmer, which take effect during execution Referenced only through pointers or references, e.g. dynamic objects in C++ (via new and delete), all objects in Java 24

Categories of Variables by Lifetimes Implicit heap-dynamic--allocation and deallocation caused by assignment statements Ex: JavaScript and PHP; Python 25

Type Checking Generalize the concept of operands and operators to include subprograms and assignments Type checking is the activity of ensuring that the operands of an operator are of compatible types A compatible type is one that is either legal for the operator, or is allowed under language rules to be implicitly converted, by compiler- generated code, to a legal type This automatic conversion is called a coercion. A type error is the application of an operator to an operand of an inappropriate type 26

Type Checking (continued) If all type bindings are static, nearly all type checking can be static If type bindings are dynamic, type checking must be dynamic A programming language is strongly typed if type errors are always detected Advantage of strong typing: allows the detection of the misuses of variables that result in type errors 27

Strong Typing (continued) Coercion rules strongly affect strong typing--they can weaken it considerably Although Java has just half the assignment coercions of C++, its strong typing is still far less effective than that of Ada Languages with a lot of coercion (C/C++), are less reliable than those with little coercion (Ada), and those with no coercion (ML). 28

Variable Attributes: Scope The scope of a variable is the range of statements over which it is visible The nonlocal variables of a program unit are those that are visible but not declared there The scope rules of a language determine how references to names are associated with variables Static and dynamic scope 29

Referencing Environments The referencing environment of a statement is the collection of all names that are visible in the statement In a static-scoped language, it is the local variables plus all of the visible variables in all of the enclosing scopes A subprogram is active if its execution has begun but has not yet terminated In a dynamic-scoped language, the referencing environment is the local variables plus all visible variables in all active subprograms 30

Chapter 6 Topics Introduction Primitive Data Types Character String Types User-Defined Ordinal Types Array Types Associative Arrays Record Types Union Types Pointer and Reference Types Note comparisons across languages 2

Chapter 7 Topics Introduction Arithmetic Expressions Overloaded Operators Type Conversions Relational and Boolean Expressions Short-Circuit Evaluation Assignment Statements Mixed-Mode Assignment 32

Arithmetic Expressions: Design Issues Design issues for arithmetic expressions Operator precedence rules? Operator associativity rules? Order of operand evaluation? Operand evaluation side effects? Operator overloading? Type mixing in expressions? 33

Chapter 15 Functional Programming Languages Functional programming languages use function application, conditional expressions, recursion, and functional forms to control program execution instead of imperative features such as variables and assignments Pure functional languages have no side effects LISP began as a purely functional language and later included imperative features Scheme is a relatively simple dialect of LISP that uses static scoping exclusively We also talked about increasing interest of functional in imperative, and some functional capabilities in imperative languages (such as in Python) 34

Functional Programming Languages ML is a static-scoped and strongly typed functional language which includes type inference, strong typing, and no type coercions; includes lists and list operations. Haskell is a lazy functional language supporting infinite lists; it is purely functional, unlike ML. Purely functional languages have advantages over imperative alternatives, but their lower efficiency on existing machine architectures has prevented them from enjoying widespread use We focused on some programming examples in Scheme (and also showed main concepts of ML/ Haskell) 35

Chapter 16: Logic Programming Languages Symbolic logic provides basis for logic programming Logic programs should be nonprocedural Prolog statements are facts, rules, or goals Resolution is the primary activity of a Prolog interpreter Although there are a number of drawbacks with the current state of logic programming it has been used in a number of areas We focused on some programming in Prolog 36

List processing capabilities We saw this in functional languages (e.g., Scheme, ML, Haskell) We also saw this in logical languages (Prolog) Comparison of similarities and differences in list processing capabilities 37