Principles of Programming Languages. Lecture Outline

Similar documents
Chapter 1. Preliminaries

Chapter 1. Preliminaries

Chapter 1 Preliminaries

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

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

Concepts of Programming Languages

Programming Languages, Summary CSC419; Odelia Schwartz

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

Concepts of Programming Languages

What is a programming language?

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

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

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

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

Introduction. A. Bellaachia Page: 1

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

NOTE: Answer ANY FOUR of the following 6 sections:

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

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

Programming Languages, Introduction CSC419; Odelia Schwartz

Design & Implementation Overview

COP 3402 Systems Software. Lecture 4: Compilers. Interpreters

Chapter 5. Names, Bindings, and Scopes

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

Crafting a Compiler with C (II) Compiler V. S. Interpreter

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

Software II: Principles of Programming Languages. Why Expressions?

Why are there so many programming languages?

1DL321: Kompilatorteknik I (Compiler Design 1) Introduction to Programming Language Design and to Compilation

1DL321: Kompilatorteknik I (Compiler Design 1)


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

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

Programming Languages 2nd edition Tucker and Noonan"

Programmiersprachen (Programming Languages)

CS 3360 Design and Implementation of Programming Languages. Exam 1

Chapter 7. Expressions and Assignment Statements ISBN

CS 3360 Design and Implementation of Programming Languages. Exam 1

Chapter 7. Expressions and Assignment Statements

1DL321: Kompilatorteknik I (Compiler Design 1) Introduction to Programming Language Design and to Compilation

INFS 214: Introduction to Computing

LECTURE 1. Overview and History

CS 415 Midterm Exam Spring 2002

Programming Languages

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

Introduction to Scientific Computing Languages

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

Compiler Design 1. Introduction to Programming Language Design and to Compilation

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

Introduction to Scientific Computing Languages

Introduction to Programming Languages and Compilers. CS164 11:00-12:30 TT 10 Evans. UPRM ICOM 4029 (Adapted from: Prof. Necula UCB CS 164)

Chapter 7. Expressions and Assignment Statements

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

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

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

CS 3304 Comparative Languages. Lecture 1: Introduction

CSE 452: Programming Languages. Outline of Today s Lecture. Expressions. Expressions and Control Flow

Grade Weights. Language Design and Overview of COOL. CS143 Lecture 2. Programming Language Economics 101. Lecture Outline

Computer Software: Introduction

INSTITUTE OF AERONAUTICAL ENGINEERING

Expressions & Assignment Statements

PLAGIARISM. Administrivia. Course home page: Introduction to Programming Languages and Compilers

Introduction to Programming Languages and Compilers. CS164 11:00-12:00 MWF 306 Soda

Compilers. Prerequisites

Imperative Programming

CS101 Introduction to Programming Languages and Compilers

Com S 541. Programming Languages I

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

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

Compilation I. Hwansoo Han

CS 415 Midterm Exam Fall 2003

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

G Programming Languages - Fall 2012

Programming Languages Third Edition. Chapter 7 Basic Semantics

Expressions and Assignment Statements

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

Chapter 5 Names, Binding, Type Checking and Scopes

Program Abstractions, Language Paradigms. CS152. Chris Pollett. Aug. 27, 2008.

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

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

PROGRAMMING LANGUAGE PARADIGMS & THE MAIN PRINCIPLES OF OBJECT-ORIENTED PROGRAMMING

Programming Paradigms

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

Final-Term Papers Solved MCQS with Reference

Introduction to Programming: Variables and Objects. HORT Lecture 7 Instructor: Kranthi Varala

Concepts in Programming Languages

St. MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad

Compiling and Interpreting Programming. Overview of Compilers and Interpreters

Programs are: CMPSCI 105/119/120: Programming, Flowchar<ng, and Running Program Flowcharts

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

Iterative Statements. Iterative Statements: Examples. Counter-Controlled Loops. ICOM 4036 Programming Languages Statement-Level Control Structure

Compilers and Interpreters

CS321 Languages and Compiler Design I. Winter 2012 Lecture 1

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

Chapter 5 Names, Bindings, Type Checking, and Scopes

Types and Type Inference

CSC 533: Organization of Programming Languages. Spring 2005

G Programming Languages - Fall 2012

Names, Bindings, Scopes

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

Transcription:

Principles of Programming Languages CS 492 Lecture 1 Based on Notes by William Albritton 1 Lecture Outline Reasons for studying concepts of programming languages Programming domains Language evaluation criteria Influences on language design Language categories Design trade-offs Implementation methods Administrative Stuff 2 1

Reasons for Studying Increased capacity to express ideas Learning new data structures, algorithms, and other language features will allow a programmer to create more efficient programs Example: after learning object-oriented programming in Java, a C programmer could simulate objects using structures and functions 3 Reasons for Studying Improved background for choosing appropriate languages Without having studied several different languages, programmers will tend to stick with the first language they learned Example: A C programmer might implement a binary tree with arrays, instead of using the objectoriented capabilities of Java 4 2

Reasons for Studying Increased ability to learn new language Knowing the basic concepts of programming languages allows one to learn a new language easier Example: C++ or Ada programmers, who already understand the concept of object-oriented programming, will have an easier time of learning Java then programmers have never used these concepts 5 Reasons for Studying Better understanding of the significance of implementation Knowledge of the basic concepts of programming languages enables the programmer to make more efficient choices with implementation and to find bugs easier in a program Example: A C programmer who understands pointers can create the binary tree using structures and pointers, instead of with arrays, and will have an easier time debugging programs that use pointers 6 3

Reasons for Studying Overall advancement of computing Knowing the advantages & disadvantages of different languages helps those in charge to choose better languages over poorer ones Example: In the early 1960s, Fortran was used much more than ALGOL 60, even though ALGOL 60 had much better control statements than Fortran 7 Programming Domains Scientific applications The first computers (1940s) created for scientific applications Used mostly arrays, matrices, counting loops, and selections Most efficient language for this is Fortran (1959) Also ALGOL 60 (1960) and its descendants designed mainly for this purpose 8 4

Programming Domains Business applications Began to be used for business in 1950s First language for this was COBOL (1960) Used to create reports, storing decimal numbers & character data, and calculation decimal operations More recently, microcomputers are used for spreadsheet systems & database systems 9 Programming Domains Artificial intelligence Uses symbolic rather than numeric computations Uses linked lists of names The functional language LISP was developed for AI applications in 1959 In 1970s, logic programming using Prolog appeared 10 5

Programming Domains Systems programming Operating system + supporting tools = systems software Must be efficient & interface with external drivers In 1960s & 1970s, PL/S, BLISS, & Extended ALGOL were first used for this Currently, the UNIX operating system is written mostly in the C language 11 Programming Domains Scripting languages Early scripting languages were simply a list of commands (called a script) in a file to be executed Scripting languages grew to include variables, control flow statements, functions, etc. Perl is a primitive programming language used for Common Gateway Interface (CGI) programming for the World Wide Web JavaScript & PHP are embedded in HTML documents for use on Web server systems 12 6

Language Evaluation Criteria 1. Readability 2. Writability 3. Realiability 4. Cost (Costability?) 13 Language Evaluation Criteria Readability Ease at which a program can be read & understood Factors that affect readability Overall simplicity Orthogonality Control statements Data types & structures Syntax considerations 14 7

Overall Simplicity A large number of features is difficult to learn So programmers might learn two different subsets of features Feature multiplicity (having more than one way to publish a particular operation) is not good For example, in C++ or Java you can decrement a variable in four different ways: x = x - 1; x-=1; x--; --x Operator overloading (a single operator symbol has more than one meeting) potentially can be bad Some languages, such as assembly language, can be too simple 15 Orthogonality A relatively small set of primitive constructs can be combined in the relatively small number of ways to build the control and data structures of the language For example, if the language has three primitive data types, an integer, double, and character, and two type operators, array and pointer, then a large number of data structures can be defined Lack of orthogonality leads to exceptions to rules Too much orthogonality can also be bad, such as if you had the ability to add a pointer to another pointer in C 16 8

Control Statements In the 1970s, the use of goto statements was replaced by structured programming, which could be read from top to bottom Most programming languages now contain sufficient control statements if (x < y) x++; if (x < y) goto L1; else y++; y++; goto L2; L1: x++; L2: 17 Data Types & Structures Adequate data types and data structures also aids readability A language with Boolean type is easier to read than one without indicatorflag = 0 is more difficult to read than indicatorflag = false 18 9

Syntax Considerations Syntax = the way in which linguistic elements (as words) are put together to form constituents (as phrases or clauses) Identifier forms If too short, reduces readibility Special words Ada uses end if & end loop, while Java just uses } In Fortran 95, Do & End can also be variable names Form & meaning In C, static changes meaning depending on position 19 Language Evaluation Criteria Writability Ease at which a language can be used to create programs for a specific problem domain Factors that affect writability Simplicity & orthogonality Support for abstraction Expressivity 20 10

Simplicity & Orthogonality It is best to have a smaller number of primitive constructs and a consistent set of rules for combining them Having a few constructs with few exceptions is easier to learn for a beginner programmer On the other hand, a language can also be too orthogonal, so the inexperienced programmer could add two pointers together 21 Support for Abstraction Abstraction = the ability to define and then use complicated structures or operations in ways that allow many of the details to be ignored Using the same function several times in the program To implement a binary tree in Fortran 77 requires arrays, while C++ uses nodes with two pointers and an integer 22 11

Expressivity A language has relatively convenient, rather than cumbersome, ways for specifying computations For example, in C x++ is shorter & more convenient than x=x+1 23 Language Evaluation Criteria Reliability A reliable program performs to its specifications under all conditions Factors that affect reliability Type checking Exception handling Aliasing Readability & writability 24 12

Reliability Type checking Testing for type errors in a given program For example, can have errors if a function that is expecting an integer receives a float instead Exception handling Used in Ada C++ and Java, but not in C and Fortran For example, the try & catch blocks of C++ catch runtime errors, fix the problem, and then continue the program without an abnormal end 25 Reliability Aliasing Referencing the same memory cell with more than one name For example, in this C code both x & y can be used to the same memory cell int x = 5; int *y = &x; Readability & writability If a program is difficult to read or write, its easy to make mistakes and difficult to find them 26 13

Language Evaluation Criteria Cost The total cost of a programming language is based on many of its characteristics Factors that affect cost Training programmers Writing programs Compiling programs Executing programs Language implementation system Poor reliability Maintaining programs 27 Cost Most important contributors to language costs Program development Maintenance Reliability Most important evaluation criteria in respect to language costs Writability Readability 28 14

Other Evaluation Criteria Portability Ease with which programs can be moved from one implementation to another Influenced by a degree of standardization Time-consuming and difficult (C++ 10 yrs) BASIC not standardized Generality Applicability to a wide range of applications Well-definedness Completeness and precision of the language s official defining document 29 -----Class Discussion----- C vs. Java: Evaluate the C & Java languages using the criteria just described. What kind of problem-solving domain would C be useful for? What about Java? 1. Readability 2. Writability 3. Realiability 4. Costability 30 15

Influences on Language Design Computer architecture von Neumann ( von Noyman ) architecture Data & programs are stored in memory CPU executes instructions Instructions & data are piped between memory & CPU Imperative languages designed around this Variables model memory cells Assignment statements model piping operation Iterative form is most efficient form of iteration 31 Von Neumann Architecture Note: All diagrams in this lecture are from Robert W. Sebesta s Concepts of Programming Languages, 6 th Edition 32 16

Influences on Language Design von Neumann bottleneck Fetch-execution cycle Fetch the instruction pointed to by program counter Increment program counter Decode the instruction Execute the instruction Instructions can be executed faster than they can be moved to the CPU for execution 33 Influences on Language Design Programming methodologies Type checking & control statements were developed in early 1970s Used procedure-oriented programming Abstract data types were developed in late 1970s Object-oriented programming developed in the early 1980s 34 17

Language Categories 1. Imperative Uses variables, assignments statements, & iteration 2. Functional Uses functions, parameters, & recursion 3. Logic Uses facts & rules (written in no specific order) and a language system which produces the desired result 4. Object oriented Uses data abstraction, inheritance, & dynamic method binding 35 Language Design Trade-offs Some criteria conflict with one another For example, reliability & cost of execution In C, the index ranges of arrays are not checked So executes fast, but it not so reliable On the other hand, Java checks all references to array elements So executes slower, but is more reliable 36 18

Implementation Methods Compilation A compiler is a program that reads a program written in one language (the source language) and translates it into an equivalent program in another language (the target language). A part of this process is to report to its user the presence of errors in the source program. source program => compiler => target program error messages 37 8 Phases of a Compiler 6 main phases 1. Lexical analyzer (identify words, or tokens) 2. Syntax analyzer (identify sentences, use parsing) 3. Semantic analyzer (type checking) 4. Intermediate code generator 5. Code optimizer 6. Code generator Two more activities (interact with all 6 phases) 1. Symbol table manager 2. Error handler 38 19

Compilation Process 39 Post-Compiler Linking the program To create the executable (.exe file) program from the object (.obj) file, the linker (linkeditor) links: 1. The object files from the program modules, and 2. Any additional library files Usually this includes the use of relocatable addresses within the program Allows the program to run in different memory locations 40 20

Post-Compiler Loading the executable (.exe file) program Also called the load module or executable image The loader Identifies a memory location in which the program can be loaded, and Alters the relocatable machine code addresses to run in the designated memory location A program is loaded into memory each time it is run 41 Implementation Methods Pure interpretation High-level language statements are immediately decoded into machine code & executed Easy to debug Slow to decode (10 to 100 times slower) Requires more space for symbol table & source program 42 21

Pure Interpretation 43 Implementation Methods Hybrid implementation systems Cross between compilers & interpreters High-level language programs are translated to an intermediate language, which is easily interpreted Perl Partially compiled to detect errors, then interpreted Java Intermediate byte code is created from a program, then it is interpreted 44 22

Hybrid Implementation System 45 Administrative Issues Class Timings (mistake in quarter schedule) Course Website http://suraj.lums.edu.pk/~cs492 Office Hours (Today) Next Class (and reading) Handouts for Next Class 46 23