CSCI 3136 Principles of Programming Languages



Similar documents
n Introduction n Art of programming language design n Programming language spectrum n Why study programming languages? n Overview of compilation

Lecture 1: Introduction

Chapter 1. Dr. Chris Irwin Davis Phone: (972) Office: ECSS CS-4337 Organization of Programming Languages

Programming Languages

CSE 307: Principles of Programming Languages

Language Evaluation Criteria. Evaluation Criteria: Readability. Evaluation Criteria: Writability. ICOM 4036 Programming Languages

Introduction. Compiler Design CSE 504. Overview. Programming problems are easier to solve in high-level languages

1/20/2016 INTRODUCTION

Compilers. Introduction to Compilers. Lecture 1. Spring term. Mick O Donnell: michael.odonnell@uam.es Alfonso Ortega: alfonso.ortega@uam.

Compiler Construction

Programming Languages

High-Level Programming Languages. Nell Dale & John Lewis (adaptation by Michael Goldwasser)

CSC Software II: Principles of Programming Languages

Language Processing Systems

Semester Review. CSC 301, Fall 2015

Announcements FORTRAN ALGOL COBOL. Simula & Smalltalk. Programming Languages

Scoping (Readings 7.1,7.4,7.6) Parameter passing methods (7.5) Building symbol tables (7.6)

CSE 130 Programming Language Principles & Paradigms

Lecture 9. Semantic Analysis Scoping and Symbol Table

1.1 WHAT IS A PROGRAMMING LANGUAGE?

Chapter 13 Computer Programs and Programming Languages. Discovering Computers Your Interactive Guide to the Digital World

Programming Languages CIS 443

Computer Programming. Course Details An Introduction to Computational Tools. Prof. Mauro Gaspari:

How to make the computer understand? Lecture 15: Putting it all together. Example (Output assembly code) Example (input program) Anatomy of a Computer

What is a programming language?

McGraw-Hill The McGraw-Hill Companies, Inc.,

Image credits:

Principles of Programming Languages Topic: Introduction Professor Louis Steinberg

Semantic Analysis: Types and Type Checking

COS 301 Programming Languages

Chapter 5 Names, Bindings, Type Checking, and Scopes

Functional Programming

Evolution of the Major Programming Languages

03 - Lexical Analysis

Compiler Construction

1 Introduction. 2 An Interpreter. 2.1 Handling Source Code

Advanced compiler construction. General course information. Teacher & assistant. Course goals. Evaluation. Grading scheme. Michel Schinz

Programming Language Pragmatics

Course Goal CMSC 330: Organization of Programming Languages. Studying Programming Languages. All Languages Are (Kind of) Equivalent.

CS 106 Introduction to Computer Science I

Static vs. Dynamic. Lecture 10: Static Semantics Overview 1. Typical Semantic Errors: Java, C++ Typical Tasks of the Semantic Analyzer

Compiler I: Syntax Analysis Human Thought

COURSE CODE: CSC 411 Organization of Programming Languages

Chapter 6: Programming Languages

Lexical Analysis and Scanning. Honors Compilers Feb 5 th 2001 Robert Dewar

Lexical analysis FORMAL LANGUAGES AND COMPILERS. Floriano Scioscia. Formal Languages and Compilers A.Y. 2015/2016

Programming Languages

Ed. v1.0 PROGRAMMING LANGUAGES WORKING PAPER DRAFT PROGRAMMING LANGUAGES. Ed. v1.0

CA Compiler Construction

Fundamentals of Programming Languages

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives

Programming Languages and Compilers

Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science

Asogwa Tochukwu Chijindu Department of Computer Engineering, Enugu State University of Science and Technology(ESUT), Enugu, Nigeria.

Master of Sciences in Informatics Engineering Programming Paradigms 2005/2006. Final Examination. January 24 th, 2006

Levels of Programming Languages. Gerald Penn CSC 324

Introduction to Software Paradigms & Procedural Programming Paradigm

Chapter 14. Programming and Languages. McGraw-Hill/Irwin. Copyright 2008 by The McGraw-Hill Companies, Inc. All rights reserved.

Chapter 15 Functional Programming Languages

Compiler and Language Processing Tools

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

Object-Oriented Software Specification in Programming Language Design and Implementation

Implementing Programming Languages. Aarne Ranta

C Compiler Targeting the Java Virtual Machine

Parsing Technology and its role in Legacy Modernization. A Metaware White Paper

[Refer Slide Time: 05:10]

How To Understand Programming Languages And Programming Languages

Languages september 12, 2015 Éric Lévénez < FORTRAN III end-1958 FORTRAN II FORTRAN I october 1956

Moving from CS 61A Scheme to CS 61B Java

Lab Experience 17. Programming Language Translation

The C Programming Language course syllabus associate level

Scanning and parsing. Topics. Announcements Pick a partner by Monday Makeup lecture will be on Monday August 29th at 3pm

UNIT-I Preliminaries

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

Lesson 06: Basics of Software Development (W02D2

CS 40 Computing for the Web

Instructor Özgür ZEYDAN BEU Dept. of Enve. Eng. CIV 112 Computer Programming Lecture Notes (1)

Programming Languages

Intel Assembler. Project administration. Non-standard project. Project administration: Repository

The Evolution of Programming Languages

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 20: Stack Frames 7 March 08

Chapter 12 Programming Concepts and Languages

Software Paradigms (Lesson 1) Introduction & Procedural Programming Paradigm

Departamento de Investigación. LaST: Language Study Tool. Nº 143 Edgard Lindner y Enrique Molinari Coordinación: Graciela Matich

Textual Modeling Languages

The previous chapter provided a definition of the semantics of a programming

Software. Programming Language. Software. Instructor Özgür ZEYDAN. Bülent Ecevit University Department of Environmental Engineering

COMP 356 Programming Language Structures Notes for Chapter 4 of Concepts of Programming Languages Scanning and Parsing

An Introduction to Computer Science and Computer Organization Comp 150 Fall 2008

CSE 373: Data Structure & Algorithms Lecture 25: Programming Languages. Nicki Dell Spring 2014

Programming Languages & Tools

CS 6371: Advanced Programming Languages

Computer Science. Requirements for the Major (updated 11/13/03)

Chapter 13: Program Development and Programming Languages

Transcription:

CSCI 3136 Principles of Programming Languages Faculty of Computer Science Dalhousie University Winter 2013

CSCI 3136 Principles of Programming Languages Faculty of Computer Science Dalhousie University Winter 2013 Reading: Chapter 1

How to Talk to Your Computer A programmer s dream: (Just say what you want... in English) Computer, please compute the best route from Halifax to San Francisco and display it on your screen.

How to Talk to Your Computer A programmer s dream: (Just say what you want... in English) Computer, please compute the best route from Halifax to San Francisco and display it on your screen. CPU: (Assembly)... addl $1, -4(%rbp) movl %eax, %esi...

How to Talk to Your Computer A programmer s dream: (Just say what you want... in English) Computer, please compute the best route from Halifax to San Francisco and display it on your screen. Very expressive Low programming effort Sometimes ambiguous CPU: (Assembly)... addl $1, -4(%rbp) movl %eax, %esi... Very low-level Tedious Unambiguous

How to Talk to Your Computer A programmer s dream: (Just say what you want... in English) Computer, please compute the best route from Halifax to San Francisco and display it on your screen. Very expressive Low programming effort Sometimes ambiguous Bridging the gap: (Java, C++, Ruby, Haskell, Scheme,... ) class RouteFinder {... public static void main(string[] args) {... }... } CPU: (Assembly)... addl $1, -4(%rbp) movl %eax, %esi... Very low-level Tedious Unambiguous

How to Talk to Your Computer A programmer s dream: (Just say what you want... in English) Computer, please compute the best route from Halifax to San Francisco and display it on your screen. Very expressive Low programming effort Sometimes ambiguous Bridging the gap: (Java, C++, Ruby, Haskell, Scheme,... ) class RouteFinder {... public static void main(string[] args) {... }... } Unambiguous Fairly expressive Fairly efficient to implement in terms of low-level CPU instructions CPU: (Assembly)... addl $1, -4(%rbp) movl %eax, %esi... Very low-level Tedious Unambiguous

Part I: Program Semantics and Translation Ways to specify programming languages formally What is a syntactically correct program in this language? What does a syntactically correct program mean? What is the computation it specifies? Basics of compilation and interpretation How do we translate a syntactically correct program into (machine) code that carries out exactly the computation specified by the program?

Part II: Language Features and Their Implementation Programming paradigms Different high-level ways of thinking about computation. Each paradigm is suited best for certain classes of applications. Each programming language designed to express a certain subset of these paradigms more easily.

Why Is This Useful? Makes learning new languages and understanding obscure features easier. Helps choose the most appropriate language for the job, evaluate trade-offs. Learn to simulate useful features in languages that lack them. Learn to use features of a language most effectively.

History of Programming Languages Machine language, assembly language FORTRAN (1957) versions I IV,... 1995 ALGOL (1958) Pascal (1971) Ada (1983) LISP (1959) Scheme (1975), Common Lisp (1984) COBOL (1959), APL (1960), SNOBOL (1962) BASIC (1964) Visual Basic (1990) Simula (1967) Smalltalk (1980) C++ (1985) C (1972) C++ (1985), Perl (1987), Python (1990s), Java (1995), JavaScript (1995), PHP (1995), C# (2002) Prolog (1973)

Why So Many Programming Languages? Evolution Special purpose Personal preference What makes a programming language successful? Expressive power Easy to learn Easy to implement Open-source Good compilers (e.g., FORTRAN) Economics, patronage, inertia

Programming Paradigms Imperative programming Closest to von Neumann machine (assemblers, FORTRAN, BASIC, COBOL) Structured programming (ALGOL, Pascal, C) Object-oriented programming Smalltalk, C++, Java Functional programming Lisp, Scheme, ML, Haskell Logic programming Prolog, VisiCalc

Course Outline Program translation Lexical analysis, regular languages, and finite automata Parsing, context-free languages, and push-down automata Semantic analysis and atribute grammars Flow of control and information Names, scopes, and binding Control flow Building abstractions Subroutines and control abstractions Data types Object-oriented programming Functional programming

Textbooks and Course Material Required textbook: Michael L. Scott. Programming Language Pragmatics, 3rd edition. Slides (available from http://www.cs.dal.ca/~nzeh/teaching/3136). Hopcroft et al. to Automata Theory. Tucker and Noonan. Programming Languages. More relevant books listed on the course website. Some are available online. Other links can be found on the course website.

Evaluation and Plagiarism Policy Evaluation 40% assignments (weekly) 20% midterm exam 40% final exam Assignment groups You are allowed to form groups of up to 3 students working together on an assignment. Each group hands in one joint assignment. Thus, all members of the same group receive the same mark. The constitution of groups may change between assignments. Plagiarism policy Collaboration between groups is not allowed. Any use of reference material (book, web,... ) must be acknowledged. According to Faculty policy, any suspected case of plagiarism is referred to the Academic Integrity Officer and may be forwarded to the Senate Discipline Committee.

But I Know Only Java This courses uses Java, C, C++, Python, Ruby, Perl, Scheme, and Haskell to illustrate important programming concepts. Other languages may be mentioned in passing where appropriate. Search the web for tutorials on how to use these languages, tinker with them. Learning new languages is fun!

Overview of Program Translation CSCI 3136 Principles of Programming Languages Faculty of Computer Science Dalhousie University Winter 2013 Reading: Chapter 1

Compilation vs Interpretation Compilation Interpretation

Compilation vs Interpretation Compilation Source program Compiler Target program Input Target program Output Interpretation

Compilation vs Interpretation Compilation Source program Compiler Target program Input Target program Output Interpretation Source program Input Interpreter Output

Trade-Off Between Compilation and Interpretation

Trade-Off Between Compilation and Interpretation Advantages of compilation Standalone code Faster code Smaller code

Trade-Off Between Compilation and Interpretation Advantages of compilation Advantages of interpretation Standalone code Faster code Smaller code Faster development More flexibility and possibly more expressive power Late binding Dynamic features

Compilation-Interpretation Boundary

Compilation-Interpretation Boundary... is fuzzy: Just in time (JIT) compilation The Perl interpreter compiles program into intermediate code. The Java compiler compiles the program into byte code that is run by an interpreter.

Compilation-Interpretation Boundary... is fuzzy: Just in time (JIT) compilation The Perl interpreter compiles program into intermediate code. The Java compiler compiles the program into byte code that is run by an interpreter. Generally, we consider a translation program that translates source code into machine code or some intermediate code to be a compiler if it needs to perform a semantic analysis of the source code to produce the intermediate code: Java is compiled: the byte code is close to machine code and requires semantic analysis to produce. Perl is interpreted: the intermediate code is produced only when the program is run. BASIC is interpreted: early interpreters stored program in tokenized form. No semantic analysis is required to produce this.

Phases of Compilation Source program (character stream) Scanner (lexical analysis) Front end Parse tree Parser (syntactic analysis) Token stream Back end Modified intermediate form Modified target language Semantic analysis and code generation Machine-independent code improvement Target code generation Machine-specific code improvement Abstract syntax tree or other intermediate form Target language (e.g., assembly) Symbol table

Lexical Analysis and Parsing Lexical analysis Group input characters into tokens (e.g., identifiers, keywords, numbers,... ) Remove extraneous characters (e.g., spaces, tabs, newline characters) and comments Parsing Organize tokens into a parse tree according to a grammar describing the language Ensure the sequence of tokens conforms to the syntax defined by the language grammar

Semantic Analysis Generates symbol table and intermediate representation of program (e.g., syntax tree) from the parse tree. The symbol table maps each identifier to information known about it. The abstract syntax tree includes only important nodes of the parse tree but also stores annotations of these nodes (e.g., pointers from identifiers to symbol table entries). Enforces rules not captured by the context-free grammar (e.g., use identifier only after it has been declared). Generates code for run-time checks (e.g., array bounds).

A Sample Pascal Program { calculate greatest common divisor } program gcd( input, output ); var i, j : integer; begin read( i, j ); while i <> j do if i > j then i := i - j else j := j - i; writeln( i ); end.

Program After Tokenization (Scanning) { calculate greatest common divisor } program gcd ( input, output ) ; var i, j : integer ; begin read ( i, j ) ; while i <> j do if i > j then i := i - j else j := j - i ; writeln end. ( i ) ;

A Context-Free Grammar for the Language in the Example Rules Program program identifier ( identifier More_identifiers ) ; Block. More_identifiers ɛ Terminals program, var, integer, begin, end, while, do, if, then, else (, ),,, ;, :,., :=, <>, >, - identifier Non-terminals Block Labels Constants Types Variables Subroutines begin Statement More_statements end More_identifiers, identifier More_identifiers. Program, More_identifiers, Block, Labels, Constants, Types,...

The Parse Tree of the Program Program program identifier (gcd) ( identifier More_identifiers ). (input), identifier (output) More_identifiers ɛ Block Lbls Consts Types Variables Subs begin Stmt More_stmts end ɛ ɛ ɛ var... ɛ......

The Abstract Syntax Tree and the Symbol Table Program (5) read (3) (6) (3) read (7) while Predefined Userdefined Index Symbol Type 1 integer type 2 textfile type 3 input 2 4 output 2 5 gcd program 6 i 1 7 j 1 <> if write > := := (6) (7) (4) (6) writeln (6) (7) (6) - (7) - (4) (6) (7) (7) (6)