CMSC 3301. 2 CMSC 330: Organization of Programming Languages Instructor: Michael Lam (lam at cs)‏ TA: Aleks Aris (aris at cs)‏ Introduction.

Slides:



Advertisements
Similar presentations
Introduction to Programming Languages Nai-Wei Lin Department of Computer Science and Information Engineering National Chung Cheng University.
Advertisements

Programming Languages Language Design Issues Why study programming languages Language development Software architectures Design goals Attributes of a good.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 1 Overview A good programming language is.
Chapter3: Language Translation issues
Reasons to study concepts of PL
ISBN Chapter 1 Preliminaries. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.1-2 Chapter 1 Topics Motivation Programming Domains.
Computers: Tools for an Information Age
January 12, Compiler Design Hongwei Xi Comp. Sci. Dept. Boston University.
CMSC330 Summer 2009 Kinga Dobolyi
CS 330 Programming Languages 09 / 06 / 2007 Instructor: Michael Eckmann.
Programming Languages Structure
ISBN Lecture 01 Preliminaries. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.1-2 Lecture 01 Topics Motivation Programming.
PZ01BX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ01BX - Standardization, Internationalization Programming.
Introduction to a Programming Environment
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Summer 02-03Programming Language Concepts1 Programming Language Concepts (CS 360) Lecture 1: Overview, Grammars, and Little Languages Jeremy R. Johnson.
ISBN Chapter 1 Topics Motivation Programming Domains Language Evaluation Criteria Influences on Language Design Language Categories Language.
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
Programming Language Concepts
1 Programming Languages Marjan Sirjani 2 1- The Study of Programming Languages The purpose of language is simply that it must convey meaning. (Confucius)
CS190/295 Programming in Python for Life Sciences: Lecture 1 Instructor: Xiaohui Xie University of California, Irvine.
PROGRAMMING LANGUAGES The Study of Programming Languages.
Overview. Copyright © 2006 The McGraw-Hill Companies, Inc. Chapter 1 Overview A good programming language is a conceptual universe for thinking about.
PZ01A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ01A -- Introduction Programming Language Design and.
CS 355 – Programming Languages
CMSC CMSC 330: Organization of Programming Languages Instructor: Michael Lam (lam at cs) TA: Richard Johnson (rbjohns8 at cs) Introduction.
Chapter 8 High-Level Programming Languages (modified by Erin Chambers)
CS 326 Programming Languages, Concepts and Implementation
(1.1) COEN 171 Programming Languages Winter 2000 Ron Danielson.
High level & Low level language High level programming languages are more structured, are closer to spoken language and are more intuitive than low level.
Chapter 1. Introduction.
CS 363 Comparative Programming Languages
CS 330 Programming Languages 09 / 04 / 2008 Instructor: Michael Eckmann.
Programming Languages Summer
1 Programming Languages Marjan Sirjani Course web site:
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 2.
1 Introduction Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages.
Copyright © 2007 Addison-Wesley. All rights reserved.1-1 Reasons for Studying Concepts of Programming Languages Increased ability to express ideas Improved.
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
Fundamental Programming: Fundamental Programming K.Chinnasarn, Ph.D.
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
Module 4 Part 2 Introduction To Software Development : Programming & Languages Introduction To Software Development : Programming & Languages.
Topic #1: Introduction EE 456 – Compiling Techniques Prof. Carl Sable Fall 2003.
Engr. Isabelo Jun D. Paat, ME-CoE Lecturer 1 Programming Languages.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 1 Overview A good programming language is.
Programming Language Concepts (CIS 635) Elsa L Gunter 4303 GITC NJIT,
Chapter 1: Preliminaries Lecture # 2. Chapter 1: Preliminaries Reasons for Studying Concepts of Programming Languages Programming Domains Language Evaluation.
Programming Language Theory 2014, 1 Chapter 1 :: Introduction Origin : Michael L. Scott School of Computer & Information Engineering,
Software Engineering Algorithms, Compilers, & Lifecycle.
1 Standardization, Internationalization Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section.
Chapter 1. Introduction.
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Component 1.6.
Introduction to programming languages, Algorithms & flowcharts
Concepts of Programming Languages
Why study programming languages?
Introduction to programming languages, Algorithms & flowcharts
PROGRAMMING LANGUAGES
CS 326 Programming Languages, Concepts and Implementation
CSCI-235 Micro-Computer Applications
Information Science and Engineering
课程名 编译原理 Compiling Techniques
Introduction to programming languages, Algorithms & flowcharts
Course supervisor: Lubna Siddiqui
Programming Languages 2nd edition Tucker and Noonan
High Level Programming Languages
Principles of Programming Languages
강의 내용 및 방법 접근방법 리포트 시험 Lambda Calculus, Proof of Correctness
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Presentation transcript:

CMSC 3301

2 CMSC 330: Organization of Programming Languages Instructor: Michael Lam (lam at cs)‏ TA: Aleks Aris (aris at cs)‏ Introduction

CMSC 3303 Course Website Syllabus Office hours Schedule Project assignments Resource links Web forum Submit server

CMSC 3304 Course Grading 5 projects (40%)‏ –Late submission penalty (see syllabus)‏ 2 midterms + final exam (15/15/25%)‏ Class participation (5%)‏ Homeworks will not be graded and solutions will be posted online Office Hours for 330

CMSC 3305 Classroom reminders Arrive on time Sit up front (easier to see console text)‏ Put cell phones on silenced/vibrate Laptops are fine, but be polite Interaction is good—ask questions! Attendance is neither mandatory nor directly rewarded –Lots of in-class examples Lectures will be available online

CMSC 3306 Project rules DO NOT SHARE PROJECT CODE! Re-using your own code is fine We will be using the submit server –Submit EARLY to ensure your setup works Most tests will be secret –Spend time writing your own test cases –Sharing test cases is fine Secret test results available after Friday discussion section Project late penalties –10% up to 24 hours late –25% between 24 hours and 9am Friday

CMSC 3307 Other notes Take advantage of the web forum No textbook - use the lecture notes The summer semester is highly compressed –Stay organized and ahead of your work Get help as soon as you need it –Office hours are posted online GLUE/GRACE accounts –glue.umd.edu/grace.umd.edu –UM directory ID+password –If you have a laptop, use it instead

CMSC 3308 Syllabus Scripting languages (Ruby)‏ Regular expressions and finite automata Context-free grammars Functional programming (OCaml)‏ Concurrency Object-oriented programming (Java)‏ Environments, scoping, and binding Advanced topics

CMSC 3309 Course Goal 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 –Mathematical formalisms

CMSC 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 So why is this course not useless?

CMSC Why Study Programming Languages? Using the right language for a problem may be easier, faster, and less error-prone –Programming is a human activity –Features of a language make it easier or harder to program for a specific application 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 {Ada/C++/Java/…}” 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!

CMSC 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 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 Today: –Language features based on design concepts Encapsulation, records, inheritance, functionality, assertions –Processing power and memory very cheap; programmers expensive Ease the programming process

CMSC Language Attributes to Consider Syntax -- What a program looks like Semantics -- What a program means Implementation -- How a program executes

CMSC Types of Languages Imperative/Procedural Declarative –Functional –Logical (rule-based)‏ Object-oriented Scripting Data-oriented/Query (not covered)‏

CMSC 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; –FORTRAN (1954)‏ –Pascal (1970)‏ –C (1971)‏

CMSC 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)‏ –LISP (1958)‏ –ML (1973)‏ –Scheme (1975)‏ –Haskell (1987)‏ –OCaml (1987)‏

CMSC Logical Languages Also called rule-based or constraint-based Program consists of a set of rules –“A :- B” – If B holds, then A holds append([], L2, L2). append([X|Xs],Ys,[X|Zs]) :- append(Xs,Ys,Zs). –PROLOG (1970)‏ –Various expert systems

CMSC 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 extends C { … } –Smalltalk (1969)‏ –C++ (1986)‏ –OCaml (1987)‏ –Java (1995)‏

CMSC 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 “Other” Languages There are lots of other languages around with 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 Realtime –Postscript (1982) – Printers- Based on Forth –…

CMSC 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 –Compilation –Interpretation

CMSC Compilation or Translation Source program translated to another language –Often machine code, which can be directly executed –Advantages? Disadvantages? def greet(s)‏ print("Hello, ”)‏ print(s)‏ print("!\n”)‏ end … “world”“Hello, world”

CMSC Steps of Compilation 1. Lexical Analysis (Scanning) – Break up source code into tokens such as numbers, identifiers, keywords, and operators FOR ID:i LESSTHAN NUM:6

CMSC Steps of Compilation 2. Parsing (Syntax Analysis) – Group tokens together into higher-level language constructs (conditionals, assignment statements, functions, …)‏ For loop

CMSC Steps of Compilation 3. Intermediate Code Generation – Verify that the source program is valid and translate it into an internal representation –May have more than one intermediate rep for 0:i:6 or Load 0 Load i Etc…

CMSC Steps of Compilation 4. Optimization (optional) – Improve the efficiency of the generated code –Eliminate dead code, redundant code, etc. –Change algorithm without changing functionality (e.g., X=Y+Y+Y+Y  X=4*Y  X = Y shift left 2)‏ [If interested in compilation, take CMSC 430]

CMSC Interpretation Interpreter executes each instruction in source program one step at a time –No separate executable –Advantages? Disadvantages? def greet(s)‏ print("Hello, ”)‏ print(s)‏ print("!\n”)‏ end “world”“Hello, world”

CMSC Compiler or Intepreter? gcc Compiler – C code translated to object code, executed directly on hardware javac Compiler – Java source code translated to Java byte code tcsh/bash Interpreter – commands executed by shell program java Interpreter – Java byte code executed by virtual machine

CMSC Compilation or Interpretation – Not so 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

CMSC Interactive Exercise Introduce yourself to your neighbor(s) in groups of 2-4 and together write down as many languages as you can think of, specifying the following attributes: Type: imperative, functional, or logical Properties: object-oriented, scripting, or query Execution: compiled, interpreted, or both

CMSC 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 Orthogonality Every combination of features is meaningful Features work independently What if, instead of working independently, adjusting the volume on your radio also changed the station? You would have to carefully change both simultaneously and it would become difficult to find the right station and keep it at the right volume. Your radio and tuning work orthogonally. And aren’t you glad they do!

CMSC Attributes of a Good Language 1.Naturalness for the application Program structure reflects the logical structure of algorithm 2.Support for abstraction Program data reflects problem being solved 3.Ease of program verification Verifying that program correctly performs its required function

CMSC Attributes of a Good Language 1.Programming environment External support for the language 2.Portability of programs Transportability of the resulting programs from the computer on which they are developed to other computer systems 3.Cost of use Program execution, program translation, program creation, and program maintenance

CMSC Who defines a language? Is: I = 1 && | 4; legal in C? –What is assigned to I if it is? –Who makes this determination? 3 ways typically to answer this: 1. Read language manual (Problem: Can you find one?)‏ 2. Read language standard (Problem: Have you ever seen it?)‏ 3. Write a program to see what happens. (Easy to do!)‏ Most programmers do 3

CMSC Creation of standards Language standards defined by national standards bodies: ISO - International Standards organization IEEE - Institute of Electrical and Electronics Engineers ANSI - American National Standards Institute All work in a similar way: 1. Working group of volunteers set up to define standard 2. Agree on features for new standard 3. Vote on standard 4. If approved by working group, submitted to parent organization for approval

CMSC Creation of standards Standards in the US are voluntary: –There is no federal standards-making organization. –NIST - National Institute for Standards and Technology develops standards that are only required on federal agencies, not for commercial organizations. Consensus is the key to standards making: –Contentious features often omitted to gain consensus –Only vendors have a vested interest in the results –Users don't care until standard approved, and then it is too late!

CMSC Standards conforming programs Standards define behavior for a standards conforming program - one that meets the rules of the language standard In general (except for Ada), behavior of non-conforming program is not specified, so any extensions to a standards conforming compiler may still be standards conforming, even though the program is not standards conforming. Standards supposed to be reviewed every 5 years –Examples: –FORTRAN 1966, 1977, 1990 –Ada 1983, 1995 Not quite 5 years, but at least periodically

CMSC When to standardize a language? Problem: When to standardize a language? –If too late - many incompatible versions FORTRAN in 1960s was already a de facto standard, but no two were the same LISP in 1994, about 35 years after developed. –If too early - no experience with language - Ada in 1983 had no running compilers –Just right - Probably Pascal in 1983, although it is now mostly a dead language Other languages: –C in 1988 –De facto standards: ML, SML, OCaml, Ruby –Smalltalk - none –Prolog - none

CMSC Internationalization Programming has become international –I18N issue - Internationalization - How to specify languages useful in a global economy? Character sets: –1950s1960s – 6 bit sufficient (upper case, digits, special symbols …)‏ –ASCII is a 7 bit 128 character code –Single 8-bit byte; usual format today character values. A lot in 1963, but insufficient today What about other languages? –Additional letters: German umlaut-ä, French accent-é, Scandanavian symbols-ö, –Russian, other alphabets (Greek, Arabic, Hebrew), ideographs (Chinese, Korean)? –Unicode - 16 bit code allows for 65K symbols. 8-bit byte is insufficient internationalization vs. internationalisation

CMSC Internationalization Some of the internationali*ation issues: –What character codes to use? –Collating sequences? - How do you alphabetize various languages? –Dates? – If I said your exam was on 10/12/07 when would you show up? Time? - How do you handle time zones, summer time in Europe, daylight savings time in US, Southern hemisphere is 6 months out of phase with northern hemisphere, Date to change from summer to standard time is not consistent. Some zones 30 minutes off. Currency? - How to handle dollars, pounds, euros, etc.

CMSC Summary Reasons to study PL Types of languages: –Imperative –Functional –Logical –Object-oriented Execution methods: –Compilation –Interpretation Desirable language properties Standardization

CMSC Ruby An imperative, object-oriented scripting language –Created in mid-1990s by Yukihiro Matsumoto –Similar in flavor to many other scripting languages (e.g., perl, python)‏ –Much cleaner than perl –Fully object-oriented (even primitives are objects!)‏

CMSC A Small Ruby Example def greet(s)‏ print("Hello, ”)‏ print(s)‏ print("!\n”)‏ end % irb # you’ll usually use “ruby” instead irb(main):001:0> require "intro.rb" => true irb(main):002:0> greet("world") Hello, world! => nil intro.rb:

CMSC 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 –Makes writing certain programs very elegant Has a really nice module system –Much richer than interfaces in Java or headers in C Includes type inference –Types checked at compile time, but no annotations

CMSC A Small OCaml Example let greet s = begin print_string "Hello, "; print_string s; print_string "!\n" end $ ocaml Objective Caml version # #use "intro.ml";; val greet : string -> unit = # greet "world";; Hello, world! - : unit = ()‏ intro.ml:

CMSC Homework Acquaint yourself with the website Review today's slides Check GLUE/GRACE and forum accounts Install Ruby (and OCaml if you have time)‏