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

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

CMSC 330: Organization of Programming Languages. Administrivia

CMSC 330: Organization of Programming Languages

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

CMSC 330: Organization of Programming Languages. Administrivia

Concepts of Programming Languages

Programming Languages 2nd edition Tucker and Noonan"

Programming Languages, Summary CSC419; Odelia Schwartz

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

Com S 541. Programming Languages I

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

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

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

Concepts in Programming Languages

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

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

CMSC 330: Organization of Programming Languages

CSCI 3136 Principles of Programming Languages

CSc 372 Comparative Programming Languages

Principles of Programming Languages. Lecture Outline

Introduction. A. Bellaachia Page: 1

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

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

What is a programming language?

IA010: Principles of Programming Languages

Tail Calls. CMSC 330: Organization of Programming Languages. Tail Recursion. Tail Recursion (cont d) Names and Binding. Tail Recursion (cont d)

INSTITUTE OF AERONAUTICAL ENGINEERING

Chapter 1. Preliminaries

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

CS 314 Principles of Programming Languages

G Programming Languages - Fall 2012

Topics Covered Thus Far. CMSC 330: Organization of Programming Languages. Language Features Covered Thus Far. Programming Languages Revisited

Compiler Construction D7011E

MIDTERM EXAM (Solutions)

CS 242. Fundamentals. Reading: See last slide

G Programming Languages - Fall 2012

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

Lecture 1. Introduction to course, Welcome to Engineering, What is Programming and Why is this the first thing being covered in Engineering?

CMSC 330: Organization of Programming Languages. Operational Semantics

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

Simply-Typed Lambda Calculus

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

LECTURE 1. Overview and History

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

St. MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad

SOFTWARE ARCHITECTURE 6. LISP

NOTE: Answer ANY FOUR of the following 6 sections:

Chapter 1. Preliminaries

Semantic Analysis. Lecture 9. February 7, 2018

MIDTERM EXAMINATION - CS130 - Spring 2005

CSc 520. Course Outline (Subject to change) Course Outline (Subject to change)... Principles of Programming Languages. Christian Collberg

Chapter 1 Preliminaries

CS 3304 Comparative Languages. Lecture 1: Introduction

The role of semantic analysis in a compiler

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

Seminar in Programming Languages

CS101 Introduction to Programming Languages and Compilers

Programming Paradigms

CSCI-GA Scripting Languages

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

CS 50 Introduction to Computer Science I

Dialects of ML. CMSC 330: Organization of Programming Languages. Dialects of ML (cont.) Features of ML. Functional Languages. Features of ML (cont.

Functional Programming Principles in Scala. Martin Odersky

Concepts of Programming Languages

Computer Science Seminar. Whats the next big thing? Ruby? Python? Neither?

CS A331 Programming Language Concepts

CMSC 330: Organization of Programming Languages. Functional Programming with OCaml

Compilers. Prerequisites

CS558 Programming Languages

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

Hi! My name is Sorin. Programming Languages. Why study PL? (discussion) Why study PL? Course Goals. CSE : Fall 2017

Hi! My name is Sorin. Programming Languages. Why study PL? (discussion) Why study PL? Course Goals. CSE 130 : Fall 2013

What is a compiler? Xiaokang Qiu Purdue University. August 21, 2017 ECE 573

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

CS 3360 Design and Implementation of Programming Languages. Exam 1

Programming Languages

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

Thanks! Review. Course Goals. General Themes in this Course. There are many programming languages. Teaching Assistants. John Mitchell.

Closures. Mooly Sagiv. Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming

1DL321: Kompilatorteknik I (Compiler Design 1)

CS 3360 Design and Implementation of Programming Languages. Exam 1

Closures. Mooly Sagiv. Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming

G Programming Languages - Fall 2018

Topics Covered Thus Far CMSC 330: Organization of Programming Languages

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

CS Exam #1-100 points Spring 2011

Administration Computers Software Algorithms Programming Languages

Midterm 1. CMSC 430 Introduction to Compilers Spring Instructions Total 100. Name: March 14, 2012

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

CMSC 330: Organization of Programming Languages. OCaml Imperative Programming

CS 3813/718 Fall Python Programming. Professor Liang Huang.

What is a compiler? var a var b mov 3 a mov 4 r1 cmpi a r1 jge l_e mov 2 b jmp l_d l_e: mov 3 b l_d: ;done

So what does studying PL buy me?

Principles in Programming: Orientation & Lecture 1. SWE2004: Principles in Programming Spring 2014 Euiseong Seo

Why are there so many programming languages?

CST-402(T): Language Processors

Course Syllabus. Programming Language Paradigms. Spring - DIS Copenhagen. Semester & Location: Elective Course - 3 credits.

Key components of a lang. Deconstructing OCaml. In OCaml. Units of computation. In Java/Python. In OCaml. Units of computation.

Programming Languages

Programmiersprachen (Programming Languages)

Transcription:

Course Goal CMSC 330: Organization of Programming Languages Introduction Instructors: Mike Hicks, Chau-Wen Tseng TAs: Srividya Ramaswamy, Eylul Dogruel, Khoa Doan Learn how programming languages work! Broaden your language horizons Different programming languages Different language features and tradeoffs! Study how languages are implemented What really happens when I write x.foo( )?! Study how languages are described / specified Mathematical formalisms CMSC 330 2 All Languages Are Equivalent! A language is Turing complete if it can compute any function computable by a Turing Machine! Essentially all general-purpose programming languages are Turing complete I.e., any program can be written in any programming language Why Study Programming Languages?! To allow you to choose between languages Using the right programming language for a problem may make programming Easier, faster, less error-prone Programming is a human activity Features of a language make it easier or harder to program for a specific application! Therefore this course is useless?! Learn only 1 programming language, always use it CMSC 330 3 CMSC 330 4 Why Study Programming Languages?! To make you better at learning new languages You may need to add code to a legacy system E.g., FORTRAN (1954), COBOL (1959), You may need to write code in a new language Your boss says, From now on, all software will be written in {C++/Java/C#/Python } You may think Java is the ultimate language But if you are still programming or managing programmers in 20 years, they probably won t be programming in Java! Why Study Programming Languages?! To make you better at using languages you think you already know Many design patterns in Java are functional programming techniques Understanding what a language is good for will help you know when it is appropriate to use CMSC 330 5 CMSC 330 6 1

Course Subgoals! Learn some fundamental CS concepts Regular expressions Context free grammars Automata theory Compilers & parsing Parallelism & synchronization! Improve programming skills Learn how to learn new programming languages Learn how to program in a new programming style CMSC 330 7 Calar / Course Overview! Tests 4-5 quizzes, 2 midterms, final exam! Projects Project 1 Maze solver in Ruby Project 2 Finite automata in Ruby Project 3 Puzzle solver in OCaml Project 4 Parser + interpreter in OCaml Project 5 Multithreading Project 6 Advanced multithreading! Programming languages Ruby, OCaml, Java CMSC 330 8 Rules and Reminders! Use lecture notes as your text To be supplemented by readings, internet! Keep ahead of your work Get help as soon as you need it Office hours, CS forum, email! Don t disturb other students in class Keep cell phones quiet Use laptops only for school work Academic Integrity! All written work (including projects) must be done on your own Do not copy code from other students Do not copy code from the web! Work together on high-level project questions Do not look at/describe another student s code If unsure, ask instructor!! Can work together on practice questions for the exams CMSC 330 9 CMSC 330 10 Syllabus! Scripting languages (Ruby)! Regular expressions and finite automata! Functional programming (OCaml)! Context-free grammars! Formal semantics! Environments, scoping, and binding! Object-oriented programming (Java)! Concurrency! Advanced topics Changing Language Goals! 1950s-60s Compile programs to execute efficiently Language features based on hardware concepts Integers, reals, goto statements Programmers cheap; machines expensive Keep the machine busy CMSC 330 11 CMSC 330 12 2

Changing Language Goals! Today Language features based on design concepts Encapsulation, records, inheritance, functionality, assertions Processing power and memory very cheap; programmers expensive Ease the programming process To wit: scripting languages are very slow, and yet very popular Language Attributes to Consider! Syntax What a program looks like! Semantics What a program means (mathematically)! Implementation How a program executes (on a real machine) CMSC 330 13 CMSC 330 14 Imperative Languages! Also called procedural or von Neumann! Building blocks are functions and statements Programs that write to memory are the norm int x = 0; while (x < y) x = x + 1; Functional Languages! Also called applicative languages! No or few writes to memory Functions are higher-order let rec map f = function [] -> [] x::l -> (f x)::(map f l) FORTRAN (1954) Pascal (1970) C (1971) CMSC 330 15 LISP (1958) ML (1973) Scheme (1975) Haskell (1987) OCaml (1987) CMSC 330 16 Logical Languages! Also called rule-based or constraint-based! Program consists of a set of rules A :- B If B holds, then A holds app([], L2, L2). app([x Xs],Ys,[X Zs]) :- app(xs,ys,zs). PROLOG (1970) Various expert systems Object-Oriented Languages! Programs are built from objects Objects combine functions and data Often have classes and inheritance Base may be either imperative or functional class C { int x; int getx() {return x;} } class D exts C { } Smalltalk (1969) C++ (1986) OCaml (1987) Java (1995) CMSC 330 17 CMSC 330 18 3

Scripting Languages! Rapid prototyping languages for little tasks Typically with rich text processing abilities Generally very easy to use Base may be imperative or functional; may be OO #!/usr/bin/perl for ($j = 0; $j < 2*$lc; $j++) { $a = int(rand($lc)); sh (1971) perl (1987) Python (1991) Ruby (1993) CMSC 330 19 Other Languages! There are lots of other languages w/ various features COBOL (1959) Business applications Imperative, rich file structure BASIC (1964) MS Visual Basic widely used Originally an extremely simple language Now a single word oxymoron Logo (1968) Introduction to programming Forth (1969) Mac Open Firmware Extremely simple stack-based language for PDP-8 Ada (1979) The DoD language Real-time Postscript (1982) Printers- Based on Forth CMSC 330 20 Ruby! An imperative, object-oriented scripting language Created in 1993 by Yukihiro Matsumoto Core of Ruby on Rails web programming framework (the key to its popularity) Similar in flavor to many other scripting languages (e.g., perl, python) Much cleaner than perl Full object-orientation (even primitives are objects!) A Small Ruby Example intro.rb: def greet(s) print("hello, ) print(s) print("!\n ) % irb # you ll usually use ruby instead irb(main):001:0> require "intro.rb" => true irb(main):002:0> greet("world") Hello, world! => nil CMSC 330 21 CMSC 330 22 OCaml! A mostly-functional language Has objects, but won t discuss (much) Developed in 1987 at INRIA in France Dialect of ML (1973)! Natural support for pattern matching Generalizes switch/if-then-else very elegant! Has full featured module system Much richer than interfaces in Java or headers in C! Includes type inference Ensures compile-time type safety, no annotations A Small OCaml Example intro.ml: let greet s = begin print_string "Hello, "; print_string s; print_string "!\n" $ ocaml Objective Caml version 3.08.3 # #use "intro.ml";; val greet : string -> unit = <fun> # greet "world";; Hello, world! - : unit = () CMSC 330 23 CMSC 330 24 4

Attributes of a Good Language 1. Clarity, simplicity, and unity Provides both a framework for thinking about algorithms and a means of expressing those algorithms 2. Orthogonality Every combination of features is meaningful Features work indepently 5. Naturalness for the application Program structure reflects the logical structure of algorithm Attributes of a Good Language 4. Support for abstraction Program data reflects problem being solved 5. Ease of program verification Verifying that program correctly performs its required function 8. Programming environment External support for the language CMSC 330 25 CMSC 330 26 Attributes of a Good Language 7. Portability of programs Can develop programs on one computer system and run it on a different computer system 8. Cost of use Program execution (run time), program translation, program creation, and program maintenance 9. Security & safety Should be very hard to write unsafe program Executing Languages! Suppose we have a program P written in a high-level language (i.e., not machine code)! There are two main ways to run P 1. Compilation 2. Interpretation CMSC 330 27 CMSC 330 28 Compilation or Translation Interpretation def greet(s) print("hello, ) print(s) print("!\n ) 11230452 23230456 01200312 def greet(s) print("hello, ) print(s) print("!\n ) Hello, world! world world Hello, world!! Source program translated to another language Traditionally: machine code, which can be directly executed! Interpreter executes each instruction in source program one step at a time No separate executable CMSC 330 29 CMSC 330 30 5

Translation phases! Both compilers and interpreters translate textual source code into an easy-to-work-with format Traditionally involved multiple steps: lexing and parsing! The parsed format may undergo several transformations before the final result is produced In a sense, a compiler simply stops before the phase where it could execute the program, while an interpreter goes all the way Compiler or Intepreter?! gcc Compiler C code translated to object code, executed directly on hardware (as a separate step)! javac Compiler Java source code translated to Java byte code! DOS/sh/csh/tcsh/bash Interpreter commands executed by shell program! java Interpreter Java byte code executed by virtual machine CMSC 330 31 CMSC 330 32 Decision Less Simple Today! Previously Build program to use hardware efficiently Often use of machine language for efficiency! Today No longer write directly in machine language Use of layers of software Concept of virtual machines Each layer is a machine that provides functions for the next layer (e.g., javac/java distinction) This is an example of abstraction, a basic building block in computer science Formal (Mathematical) Semantics! What do my programs mean? let rec fact n = if n = 0 then 1 else n * (fact n-1) let fact n = let rec aux i j = if i = 0 then j else aux (i-1) (j*i) in aux n 1! Both Ocaml functions implement the fibonacci numbers. How do I know this? Can I prove it? Key ingredient: need a mathematical way of specifying what programs do, i.e., their semantics Doing so deps on the semantics of the language CMSC 330 33 CMSC 330 34 Semantic styles! A formal semantics is basically a mathematical implementation. Two flavors Denotational semantics (compiler): meaning defined in terms of another language If we know what C means, then we can define Ruby by translation to C Operational semantics (interpreter): meaning defined as rules that simulate program execution Show what Ruby programs do directly, using an abstract machine, more high-level than real hardware! Contrast with textual language definitions, which are incomplete and ambiguous Summary! Many types of programming languages Imperative, functional, logical, OO, scripting! Many programming language attributes Clear, orthogonal, natural! Programming language implementation Compiled, interpreted! Programming language semantics Knowing your program is right CMSC 330 35 CMSC 330 36 6