Lecture content. Course goals. Course Introduction. TDDA69 Data and Program Structure Introduction

Size: px
Start display at page:

Download "Lecture content. Course goals. Course Introduction. TDDA69 Data and Program Structure Introduction"

Transcription

1 Lecture content TDDA69 Data and Program Structure Introduction Cyrille Berger Course Introduction Introduction to the different Programming Paradigm The different programming paradigms Why different paradigms? Introduction to Functional Programming Expressions Functions Control Recursion Advantages and inconvenients of functional programming 2 / 73 Course goals Course Introduction Describe aspects of evaluation and execution in different language models Explain and demonstrate how design choices affect the expressiveness and efficacy of a programming language Analyze and value programming languages based on their evaluation and compilation strategies Implement programming languages in the form of an interpreter and a compiler 4

2 Why do you need to know how program are interpreted? It will help you understand why programming language works a certain way and what are the limits New programming languages and interpreters are constantly being developed Existing interpreters are constantly being developed to improve performance, security, add new features... Programming languages General purposes: C, C++, Java, Python... Special purposes: Prolog, Matlab, R, Agent0... Scripting: JavaScript, VBA... Historical: Fortran, Lisp Evolution of programming languages How is a program interpreted? Source code Parser Parser Abstract Syntax Tree Tree visitor Generator Source code... Bytecode Virtual Machine Assembler Assembly Operating System CPU 7 8

3 Facebook's work on the PHP intepreter Why did Facebook need to develop their own PHP interpreter? Facebook started with PHP in 2004 Back at the time, PHP was the gold standard for website programming and prototyping But this is causing problems and for practical reasons they cannot change programming language start 9 10 What did Facebook do? The standard PHP interpreter is using a virtual machine (Zend) They developed a tool to convert PHP to C++ Then they developed a new interpreter that do Just-In-Time (JIT) compilation, called HHVM They introduced Hack, a variant of PHP with a typing system And other examples... Google with Java, Dalvik, Python with CPython vs Qt's JavaScript, switching from AST Interpretation to JIT and to a mix of JIT and AST Interpretation

4 List of lectures 1Introduction and Functional Programming 2Imperative Programming and Data Structures 3Parsing 4Evaluation 5Object Oriented Programming and types system 6Macros and 7Virtual Machines and Bytecode 8Garbage Collection and Native Code 9Concurrent Computing 10Declarative Programming 11Logic 12Summary Book(s) Structure and Interpretation of Computer Programs in Python by Hal Abelson, Jerry Sussman, Julie Sussman and John Denero Structure and Interpretation of Computer Programs by Hal Abelson, Jerry Sussman and Julie Sussman List of labs 1Functional Programming 2Supporting class for an interpreter 3ECMAScript Interpreter 4Macros 5Bytecode 6Garbage collector 7SQpy Division of time 24h lectures (in 12 sessions) 40h labs (in 20 sessions) 8h tutorials (in 4 88h homework 15 16

5 Last year evaluation and improvments Too much boilerplatting, Labs and lectures are not well connected Two new labs Quizzes are nice but teacher wait for too long Introduce a timeout Teacher is shy, slides are mostly used by the teacher to know what to say Introduce more interractivity The exam is worth more than two credits Introduction to the different Programming Paradigm 17 The different programming paradigms 20

6 Programming Paradigm (2/2) Declarative declarative Symbolic functional Logic Imperative Object-Oriented Expresses logic of computation without control flow: What should be computed and not how it should be computed. Examples: XML/HTML, antlr4/yacc/ regular expressions, make/ants, SQL, Declarative - Examples <b>hello world!</b> SELECT name FROM student WHERE course eq 'TDDA69' grammar Hello; r : 'hello' ID; ID : [a-z]+ ; WS : [' '\t\r\n]+ -> skip ; Functional Computation are treated as mathematical function without changing any internal state Examples: Lisp, Scheme, 23 24

7 Functional - Examples (print "Hello World") (take 25 (squares-of -> ( ) Imperative Express how computation are executed Describes computation in term of statements that change the internal state Examples: C/C++, Pascal, Java, Python, JavaScript Imperative - Examples Object-Oriented for(var i = 1; i < 26; ++i) var sq = i*i; console.log(sq) #include <stdio.h> int main() char ch; printf("enter a character\n"); scanf("%c", &ch); if (ch == 'a' ch == 'A' ch == 'e' ch == 'E' ch == 'i' ch == 'I' ch =='o' ch=='o' ch == 'u' ch == 'U') printf("%c is a vowel.\n", ch); else printf("%c is not a vowel.\n", ch); return 0; Based on the concept of objects, which are data structures containing fields and methods Programs are designed by making objects interact with each others Examples: C++, Java, C#, Python, Ruby, JavaScript

8 Object-Oriented - Programming Others paradigm languages #include <iostream> class Character : public Symbol public: Character(char _c) : m_c(_c) bool isvowel() const return ch == 'a' ch == 'A' ch == 'e' ch == 'E' ch == 'i' ch == 'I' ch =='o' ch=='o' ch == 'u' ch == 'U'; private: char m_c; ; int main() char c; std::cout << "Enter a character:\n"; std::cin >> c; Character ch(c); if(ch.isvowel()) std::cout << c << " is a vowel.\n"; else std::cout << c << " is not a vowel.\n"; Logic Based on Formal logic: expressing facts and rules Symbolic A program can manipulate its own formulas and components as if they are data Example: prolog Logic programming Symbolic programming likes(mary,food). likes(mary,wine). likes(john,wine). likes(john,mary).?- likes(mary,food). yes.?- likes(john,wine). yes.?- likes(john,food). no. 31 d( X, X, 1 ):-!. /* d(x) w.r.t. X is 1 */ d( C, X, 0 ):- atomic(c). /* If C is a constant */ /* then d(c)/dx is 0 */ d( U+V, X, R ):- /* d(u+v)/dx = A+B where */ d( U, X, A ), /* A = d(u)/dx and */ d( V, X, B ), R = A + B.... d( sin(w), X, Z*cos(W) ):- /* d(sin(w))/dx = Z*cos(W) */ d( W, X, Z). /* where Z = d(w)/dx */ d( exp(w), X, Z*exp(W) ):- /* d(exp(w))/dx = Z*exp(W) */ d( W, X, Z). /* where Z = d(w)/dx */...?- d(cos(2*x+1), X, what = 2*sin(2*X 32

9 Can you do everything in imperative programming? Why different paradigms? start 34 Is there a paradigm to rule them all? In theory you can program everything in C/C++ and imperative programming, or functional programming... But is that And is that Functional vs Imperative Double all the numbers in an array var numbers = Imperative: var doubled = [] for(var i = 0; i < numbers.length; i++) var newnumber = numbers[i] * 2 doubled.push(newnumber) Functional: var doubled = numbers.map(function(n) return n * 2 ) 35 36

10 Declarative vs Imperative Functional vs Imperative Select all the dogs that belongs to a specific Declarative: SELECT * from dogs INNER JOIN owners WHERE dogs.owner_id = owners.id Imperative: var dogswithowners = [] var dog, owner for(var dog in dogs) for(var owner in owners) if (owner && dog.owner_id == owner.id) dogswithowners.push( dog: dog, owner: owner ) Imperative language (C/C++, Java...) Basic constructs are imperative statements Change existing values, states x = x + y = while(x>0)... Functional Basic constructs are declarative Declare new values function f(x) return x + 1; Computations are primarily done by evaluating expressions Pure if all constructs are declarative Introduction to Functional Programming Expressions

11 Expressions (1/2) Primitive expressions to capture the simplest elements we want to describe numbers, arithmetic expressions... 2 plus 'hello' number operator string Call expressions: max ( 2, 3 ) operator operand operand Expressions (2/2) Means of combining simple elements into coumpound ones max(min(pow(3, 5), -4), min(1, -2) * 2) Names Means of abstracting elements by naming and manipulating them 2 plus 'hello' name a plus b name name name max ( 2, 3 ) name Assignment Binds names to a := 2 Now a has the value 2 a plus 2 evaluates to

12 What is a function? Functions Assignment is a simple means of abstraction: binds names to values Function definition is a more powerful means of abstraction: binds names to expressions 46 Function definition A function definition contains: A signature which defines how many arguments a function takes A body which defines the computation performed when the function is called function <name> ( parameters list ) return <return expression> ; Pure and non-pure function Pure functions: just return values: Math.abs(-2) -> Math.pow(2, 100) -> Non-pure functions: have side effects: print(-2) -> But print '-2' in the A side effect is not a value, it is anything that happens as a consequence of calling a 47 48

13 What is a lambda? start Closure and lambda A lambda is a function with no name var doubled = numbers.map(function(n) return n * 2 ) A closure is a function with captured variables This seem simple, but this is actually rather powerful! function create_function_multiplication(number) return function(x) return x * number; var doubled = numbers.map(create_function_multiplication(2)) Closure in Python Python has limited support for lamdas: single statement: numbers.map(lambda v: v * 2) But support nested functions (and closure): def create_function_multiplication(number): def function_multiplication(x): return x * number return function_multiplication doubled = numbers.map(create_function_multiplication(2)) Control 51

14 Control flow (1/2) In imperative programming, a control flow statement execution result in a choice between two paths Exemple: if, while... In functional programming, it is done using a special function. For instance, in Lisp: (COND (condition1 result1 ) (condition2 result2 )... (T resultn ) ) Control flow (2/2) The functional way in imperative languages: In JavaScript, C++, Java, Ruby...: condition? result1 : result2; In Python: condition if result1 else result What about loops? Loop constructs is imperative How would you implement the equivalent of a loop in functional? function factorial(n) var r = 1; for(var i = 2; i <= n; ++i) r *= i; return r; Recursion 55

15 What is recursion? A function is called recursive if the body of that function calls itself, either directly or indirectly. Factorial: the classical example (1/2) Factorial in factorial :: Integral -> Integral factorial 0 = 1 factorial n = n * factorial (n-1) Factorial in Common LISP: (define (factorial n) (cond ((= n 0) 1) (t (* n (factorial (- n 1)))))) Factorial: the classical example (1/2) Recursion vs loops With a loop: function factorial(n) var r = 1; for(var i = 2; i <= n; ++i) r *= i; return r; With a recursive function factorial(n) return (n===0)? 1 : n * factorial(n-1) 59 while(expression) do_something(); function loop_something(args...) if(expression) return; else do_something(); loop_something(args...); (define (loop_something args...) (cond (expression) value) (t (do_something) (loop_something args...)) 60

16 When to use recursion rather than iteration? (1/4) When to use recursion rather than iteration? (2/4) def factorial(n): if(n == 0): return 1 else: return n * factorial(n-1) Lets try: factorial(10) factorial(1000) In most programming language, the number of function call is limited by the size of the stack sys.getrecursionlimit() sys.setrecursionlimit(1003) factorial(1000) Tail-call optimisation When to use recursion rather than iteration? (3/4) When to use recursion rather than iteration? (4/4) Calling a function is usually more expensive than a loop def factorial2(n): r = 1 for i in range(1, n + 1): r = r * i return r timeit.timeit("factorial(30)", "from main import factorial") timeit.timeit("factorial2(30)", "from main import factorial2") It is a matter of Recursion is a bit more general than loops When walking through a tree 63 64

17 No side-effects pure functional Advantages and inconvenients of functional programming In pure functional, calling a function only return a value The implication is that calling a function with the same arguments will always return the same value Is the withdraw function pure (define balance 100) (define (withdraw amount) (if (>= balance amount) (begin (set! balance (- balance amount)) balance) "Insufficient funds")) enter code start 66 Verification and proving To prove a program correct, we must consider everything a program depends on In pure functional programs, dependence on any data structure is explicit Proving properties in functional programming (define (power b n) (cond ((= n 0) 1) (t (* (power b (- n 1)))))) Claim: for any integer n 0 and any number b, (power b n) = bⁿ Proof: 1) Verify the base case: (power b 2) Assume that (power b (- n 1)) is correct 3) Verify that (power b n) is correct assuming that (power b (- n 1)) is correct 67 68

18 Proving properties in imperative programming function power(b, n) int result = 1; for(int i = 0; i < n; + +i) result *= b; return result; Devise a loop invariant: (n i) (result = bⁱ) Prove that it is true for the first loop iteration Prove that each loop iteration preserves it Assume that (n i) (result = bⁱ) Prove that (n j) (result = bʲ) with j = i + 69 Concurency Concurency is one of the current hot topic in programming The main challenge is data-race Imperative programs are very sensible to data-race because of states There is no data-race in pure functional languages all data is immutable all functions are pure, without side-effects 70 Summary on the upside of functional programming The downside of functional programming The main advantage is no sideeffects Verification and proving Concurency Productivity? Ericsson claims an increase in productivity between 9 and 25 times when using their home-grown version of Erlang In practice, there is very limited need for proving a program Mostly in critical applications: rocket control, hospital... And how do you prove hardware? Performance issues (remember function call are expensive) Very limited support Most programming tasks require states 71 72

19 My Key message about programming paradigms Be pragmatic, there is no one answer! 73

Lecture content. Course goals. Course Introduction. TDDA69 Data and Program Structure Introduction

Lecture content. Course goals. Course Introduction. TDDA69 Data and Program Structure Introduction Lecture content TDDA69 Data and Program Structure Introduction Cyrille Berger Course Introduction to the different Programming Paradigm The different programming paradigm Why different paradigms? Introduction

More information

Lecture content. Course goals. Course Introduction. TDDA69 Data and Program Structure Introduction Cyrille Berger

Lecture content. Course goals. Course Introduction. TDDA69 Data and Program Structure Introduction Cyrille Berger Lecture content TDDA69 Data and Program Structure Introduction Cyrille Berger Course Introduction Concepts and models of programming languages The different programming paradigms Why different paradigms?

More information

List of lectures. Lecture content. Imperative Programming. TDDA69 Data and Program Structure Imperative Programming and Data Structures

List of lectures. Lecture content. Imperative Programming. TDDA69 Data and Program Structure Imperative Programming and Data Structures List of lectures TDDA69 Data and Program Structure Imperative Programming and Data Structures Cyrille Berger 1Introduction and Functional Programming 2Imperative Programming and Data Structures 3Parsing

More information

CSE 413 Languages & Implementation. Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341)

CSE 413 Languages & Implementation. Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341) CSE 413 Languages & Implementation Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341) 1 Goals Representing programs as data Racket structs as a better way to represent

More information

CS 360 Programming Languages Interpreters

CS 360 Programming Languages Interpreters CS 360 Programming Languages Interpreters Implementing PLs Most of the course is learning fundamental concepts for using and understanding PLs. Syntax vs. semantics vs. idioms. Powerful constructs like

More information

CS 242. Fundamentals. Reading: See last slide

CS 242. Fundamentals. Reading: See last slide CS 242 Fundamentals Reading: See last slide Syntax and Semantics of Programs Syntax The symbols used to write a program Semantics The actions that occur when a program is executed Programming language

More information

CS 314 Principles of Programming Languages

CS 314 Principles of Programming Languages CS 314 Principles of Programming Languages Lecture 15: Review and Functional Programming Zheng (Eddy) Zhang Rutgers University March 19, 2018 Class Information Midterm exam forum open in Sakai. HW4 and

More information

CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures. Dan Grossman Autumn 2018

CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures. Dan Grossman Autumn 2018 CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures Dan Grossman Autumn 2018 Typical workflow concrete syntax (string) "(fn x => x + x) 4" Parsing Possible errors / warnings

More information

Computer Components. Software{ User Programs. Operating System. Hardware

Computer Components. Software{ User Programs. Operating System. Hardware Computer Components Software{ User Programs Operating System Hardware What are Programs? Programs provide instructions for computers Similar to giving directions to a person who is trying to get from point

More information

Seminar in Programming Languages

Seminar in Programming Languages Seminar in Programming Languages Shuly Wintner Fall 2010-11 Course web site: http://cs.haifa.ac.il/~shuly/teaching/10/plseminar/ Course Goals Programming Language Concepts A language is a conceptual universe

More information

Programming Languages, Summary CSC419; Odelia Schwartz

Programming Languages, Summary CSC419; Odelia Schwartz 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

More information

CSCI 3136 Principles of Programming Languages

CSCI 3136 Principles of Programming Languages CSCI 3136 Principles of Programming Languages Summer 2013 Faculty of Computer Science Dalhousie University 1 / 100 CSCI 3136 Principles of Programming Languages Summer 2013 Aminul Islam Faculty of Computer

More information

CS558 Programming Languages

CS558 Programming Languages CS558 Programming Languages Winter 2017 Lecture 7b Andrew Tolmach Portland State University 1994-2017 Values and Types We divide the universe of values according to types A type is a set of values and

More information

Com S 541. Programming Languages I

Com S 541. Programming Languages I Programming Languages I Lecturer: TA: Markus Lumpe Department of Computer Science 113 Atanasoff Hall http://www.cs.iastate.edu/~lumpe/coms541.html TR 12:40-2, W 5 Pramod Bhanu Rama Rao Office hours: TR

More information

61A Lecture 2. Wednesday, September 4, 2013

61A Lecture 2. Wednesday, September 4, 2013 61A Lecture 2 Wednesday, September 4, 2013 Names, Assignment, and User-Defined Functions (Demo) Types of Expressions Primitive expressions: 2 add 'hello' Number or Numeral Name String Call expressions:

More information

Concepts of Programming Languages

Concepts of Programming Languages Concepts of Programming Languages Lecture 1 - Introduction Patrick Donnelly Montana State University Spring 2014 Patrick Donnelly (Montana State University) Concepts of Programming Languages Spring 2014

More information

CS558 Programming Languages

CS558 Programming Languages CS558 Programming Languages Fall 2016 Lecture 7a Andrew Tolmach Portland State University 1994-2016 Values and Types We divide the universe of values according to types A type is a set of values and a

More information

CSCC24 Functional Programming Scheme Part 2

CSCC24 Functional Programming Scheme Part 2 CSCC24 Functional Programming Scheme Part 2 Carolyn MacLeod 1 winter 2012 1 Based on slides from Anya Tafliovich, and with many thanks to Gerald Penn and Prabhakar Ragde. 1 The Spirit of Lisp-like Languages

More information

Functional Programming and Haskell

Functional Programming and Haskell Functional Programming and Haskell Tim Dawborn University of Sydney, Australia School of Information Technologies Tim Dawborn Functional Programming and Haskell 1/22 What are Programming Paradigms? A programming

More information

Functional Programming Lecture 1: Introduction

Functional Programming Lecture 1: Introduction Functional Programming Lecture 1: Introduction Viliam Lisý Artificial Intelligence Center Department of Computer Science FEE, Czech Technical University in Prague viliam.lisy@fel.cvut.cz Acknowledgements

More information

CS 314 Principles of Programming Languages

CS 314 Principles of Programming Languages CS 314 Principles of Programming Languages Lecture 16: Functional Programming Zheng (Eddy Zhang Rutgers University April 2, 2018 Review: Computation Paradigms Functional: Composition of operations on data.

More information

Parsing Scheme (+ (* 2 3) 1) * 1

Parsing Scheme (+ (* 2 3) 1) * 1 Parsing Scheme + (+ (* 2 3) 1) * 1 2 3 Compiling Scheme frame + frame halt * 1 3 2 3 2 refer 1 apply * refer apply + Compiling Scheme make-return START make-test make-close make-assign make- pair? yes

More information

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

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler Front-End Outline Semantic Analysis The role of semantic analysis in a compiler A laundry list of tasks Scope Static vs. Dynamic scoping Implementation: symbol tables Types Static analyses that detect type errors

More information

Foundations. Yu Zhang. Acknowledgement: modified from Stanford CS242

Foundations. Yu Zhang. Acknowledgement: modified from Stanford CS242 Spring 2013 Foundations Yu Zhang Acknowledgement: modified from Stanford CS242 https://courseware.stanford.edu/pg/courses/317431/ Course web site: http://staff.ustc.edu.cn/~yuzhang/fpl Reading Concepts

More information

SOFTWARE ARCHITECTURE 6. LISP

SOFTWARE ARCHITECTURE 6. LISP 1 SOFTWARE ARCHITECTURE 6. LISP Tatsuya Hagino hagino@sfc.keio.ac.jp slides URL https://vu5.sfc.keio.ac.jp/sa/ 2 Compiler vs Interpreter Compiler Translate programs into machine languages Compilers are

More information

Functional Programming. Pure Functional Programming

Functional Programming. Pure Functional Programming Functional Programming Pure Functional Programming Computation is largely performed by applying functions to values. The value of an expression depends only on the values of its sub-expressions (if any).

More information

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

G Programming Languages Spring 2010 Lecture 4. Robert Grimm, New York University G22.2110-001 Programming Languages Spring 2010 Lecture 4 Robert Grimm, New York University 1 Review Last week Control Structures Selection Loops 2 Outline Subprograms Calling Sequences Parameter Passing

More information

61A Lecture 2. Friday, August 28, 2015

61A Lecture 2. Friday, August 28, 2015 61A Lecture 2 Friday, August 28, 2015 Names, Assignment, and User-Defined Functions (Demo) Types of Expressions Primitive expressions: 2 add 'hello' Number or Numeral Name String Call expressions: max

More information

An Introduction to Scheme

An Introduction to Scheme An Introduction to Scheme Stéphane Ducasse stephane.ducasse@inria.fr http://stephane.ducasse.free.fr/ Stéphane Ducasse 1 Scheme Minimal Statically scoped Functional Imperative Stack manipulation Specification

More information

CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages CMSC 330: Organization of Programming Languages Type Systems, Names and Binding CMSC 330 - Spring 2013 1 Topics Covered Thus Far! Programming languages Ruby OCaml! Syntax specification Regular expressions

More information

CSE413: Programming Languages and Implementation Racket structs Implementing languages with interpreters Implementing closures

CSE413: Programming Languages and Implementation Racket structs Implementing languages with interpreters Implementing closures CSE413: Programming Languages and Implementation Racket structs Implementing languages with interpreters Implementing closures Dan Grossman Fall 2014 Hi! I m not Hal J I love this stuff and have taught

More information

Programmiersprachen (Programming Languages)

Programmiersprachen (Programming Languages) 2016-05-13 Preface Programmiersprachen (Programming Languages) coordinates: lecturer: web: usable for: requirements: No. 185.208, VU, 3 ECTS Franz Puntigam http://www.complang.tuwien.ac.at/franz/ps.html

More information

Principles of Compiler Construction ( )

Principles of Compiler Construction ( ) Principles of Compiler Construction ( ) Dr Mayer Goldberg October 25, 2017 Contents 1 Course Objectives 1 2 Course Requirements 2 3 Detailed Syllabus 3 4 Computation of grade 6 5 References 6 Course number:

More information

CSCI 2041: Advanced Language Processing

CSCI 2041: Advanced Language Processing CSCI 2041: Advanced Language Processing Chris Kauffman Last Updated: Wed Nov 28 13:25:47 CST 2018 1 Logistics Reading OSM: Ch 17 The Debugger OSM: Ch 13 Lexer and Parser Generators (optional) Practical

More information

COMP 181. Agenda. Midterm topics. Today: type checking. Purpose of types. Type errors. Type checking

COMP 181. Agenda. Midterm topics. Today: type checking. Purpose of types. Type errors. Type checking Agenda COMP 181 Type checking October 21, 2009 Next week OOPSLA: Object-oriented Programming Systems Languages and Applications One of the top PL conferences Monday (Oct 26 th ) In-class midterm Review

More information

G Programming Languages - Fall 2012

G Programming Languages - Fall 2012 G22.2110-003 Programming Languages - Fall 2012 Lecture 3 Thomas Wies New York University Review Last week Names and Bindings Lifetimes and Allocation Garbage Collection Scope Outline Control Flow Sequencing

More information

Seminar on Languages for Scientific Computing Aachen, 6 Feb Navid Abbaszadeh.

Seminar on Languages for Scientific Computing Aachen, 6 Feb Navid Abbaszadeh. Scientific Computing Aachen, 6 Feb 2014 navid.abbaszadeh@rwth-aachen.de Overview Trends Introduction Paradigms, Data Structures, Syntax Compilation & Execution Concurrency Model Reference Types Performance

More information

Chapter 1. Fundamentals of Higher Order Programming

Chapter 1. Fundamentals of Higher Order Programming Chapter 1 Fundamentals of Higher Order Programming 1 The Elements of Programming Any powerful language features: so does Scheme primitive data procedures combinations abstraction We will see that Scheme

More information

MIDTERM EXAM (Solutions)

MIDTERM EXAM (Solutions) MIDTERM EXAM (Solutions) Total Score: 100, Max. Score: 83, Min. Score: 26, Avg. Score: 57.3 1. (10 pts.) List all major categories of programming languages, outline their definitive characteristics and

More information

Functional Languages. Hwansoo Han

Functional Languages. Hwansoo Han Functional Languages Hwansoo Han Historical Origins Imperative and functional models Alan Turing, Alonzo Church, Stephen Kleene, Emil Post, etc. ~1930s Different formalizations of the notion of an algorithm

More information

LECTURE 18. Control Flow

LECTURE 18. Control Flow LECTURE 18 Control Flow CONTROL FLOW Sequencing: the execution of statements and evaluation of expressions is usually in the order in which they appear in a program text. Selection (or alternation): a

More information

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

COP4020 Programming Languages. Compilers and Interpreters Robert van Engelen & Chris Lacher COP4020 ming Languages Compilers and Interpreters Robert van Engelen & Chris Lacher Overview Common compiler and interpreter configurations Virtual machines Integrated development environments Compiler

More information

The role of semantic analysis in a compiler

The role of semantic analysis in a compiler Semantic Analysis Outline The role of semantic analysis in a compiler A laundry list of tasks Scope Static vs. Dynamic scoping Implementation: symbol tables Types Static analyses that detect type errors

More information

Programming Paradigms and Languages Introduction. dr Robert Kowalczyk WMiI UŁ

Programming Paradigms and Languages Introduction. dr Robert Kowalczyk WMiI UŁ Programming Paradigms and Languages Introduction dr Robert Kowalczyk WMiI UŁ What is a programming paradigm? A programming paradigm is a fundamental style of computer programming, a way of building the

More information

Comp 333: Concepts of Programming Languages Fall 2016

Comp 333: Concepts of Programming Languages Fall 2016 Comp 333: Concepts of Programming Languages Fall 2016 Instructor: Professor Schwartz History Syntax and Semantics Compilers Language Constructs Names, Binding, Scoping, Data Types Expressions, Control

More information

Final-Term Papers Solved MCQS with Reference

Final-Term Papers Solved MCQS with Reference Solved MCQ(S) From FinalTerm Papers BY Arslan Jan 14, 2018 V-U For Updated Files Visit Our Site : Www.VirtualUstaad.blogspot.com Updated. Final-Term Papers Solved MCQS with Reference 1. The syntax of PHP

More information

Functional Programming Lecture 13: FP in the Real World

Functional Programming Lecture 13: FP in the Real World Functional Programming Lecture 13: FP in the Real World Viliam Lisý Artificial Intelligence Center Department of Computer Science FEE, Czech Technical University in Prague viliam.lisy@fel.cvut.cz 1 Mixed

More information

CSCI-GA Scripting Languages

CSCI-GA Scripting Languages CSCI-GA.3033.003 Scripting Languages 12/02/2013 OCaml 1 Acknowledgement The material on these slides is based on notes provided by Dexter Kozen. 2 About OCaml A functional programming language All computation

More information

Lecture 16: Static Semantics Overview 1

Lecture 16: Static Semantics Overview 1 Lecture 16: Static Semantics Overview 1 Lexical analysis Produces tokens Detects & eliminates illegal tokens Parsing Produces trees Detects & eliminates ill-formed parse trees Static semantic analysis

More information

Programming (Econometrics)

Programming (Econometrics) Programming (Econometrics) Lecture 1: Introduction Tommi Tervonen Econometric Institute, Erasmus University Rotterdam Course learning objectives After this course, you should be able to: Program econometrical

More information

Typical workflow. CSE341: Programming Languages. Lecture 17 Implementing Languages Including Closures. Reality more complicated

Typical workflow. CSE341: Programming Languages. Lecture 17 Implementing Languages Including Closures. Reality more complicated Typical workflow concrete synta (string) "(fn => + ) 4" Parsing CSE341: Programming Languages abstract synta (tree) Lecture 17 Implementing Languages Including Closures Function Constant + 4 Var Var Type

More information

CSE450. Translation of Programming Languages. Lecture 11: Semantic Analysis: Types & Type Checking

CSE450. Translation of Programming Languages. Lecture 11: Semantic Analysis: Types & Type Checking CSE450 Translation of Programming Languages Lecture 11: Semantic Analysis: Types & Type Checking Structure Project 1 - of a Project 2 - Compiler Today! Project 3 - Source Language Lexical Analyzer Syntax

More information

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

CS383 PROGRAMMING LANGUAGES. Kenny Q. Zhu Dept. of Computer Science Shanghai Jiao Tong University CS383 PROGRAMMING LANGUAGES Kenny Q. Zhu Dept. of Computer Science Shanghai Jiao Tong University KENNY Q. ZHU Research Interests: Programming Languages Probabilistic Programming Data Processing Concurrency

More information

CS101 Introduction to Programming Languages and Compilers

CS101 Introduction to Programming Languages and Compilers CS101 Introduction to Programming Languages and Compilers In this handout we ll examine different types of programming languages and take a brief look at compilers. We ll only hit the major highlights

More information

Semester Review CSC 301

Semester Review CSC 301 Semester Review CSC 301 Programming Language Classes There are many different programming language classes, but four classes or paradigms stand out: l l l l Imperative Languages l assignment and iteration

More information

G Programming Languages - Fall 2012

G Programming Languages - Fall 2012 G22.2110-003 Programming Languages - Fall 2012 Lecture 4 Thomas Wies New York University Review Last week Control Structures Selection Loops Adding Invariants Outline Subprograms Calling Sequences Parameter

More information

Principles of Compiler Construction ( )

Principles of Compiler Construction ( ) Principles of Compiler Construction ( ) Dr Mayer Goldberg September 5, 2016 Contents 1 Course Objectives 1 2 Course Requirements 2 3 Detailed Syllabus 3 4 References 6 Course number: 201-1-2061 Mandatory

More information

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

Topics Covered Thus Far. CMSC 330: Organization of Programming Languages. Language Features Covered Thus Far. Programming Languages Revisited CMSC 330: Organization of Programming Languages Type Systems, Names & Binding Topics Covered Thus Far Programming languages Syntax specification Regular expressions Context free grammars Implementation

More information

Functional programming in LISP

Functional programming in LISP Programming Languages Week 4 Functional programming in LISP College of Information Science and Engineering Ritsumeikan University review of part 3 enumeration of dictionaries you receive a sequence of

More information

INTRODUCTION PRINCIPLES OF PROGRAMMING LANGUAGES. Norbert Zeh Winter Dalhousie University 1/10

INTRODUCTION PRINCIPLES OF PROGRAMMING LANGUAGES. Norbert Zeh Winter Dalhousie University 1/10 INTRODUCTION PRINCIPLES OF PROGRAMMING LANGUAGES Norbert Zeh Winter 2018 Dalhousie University 1/10 GOAL OF THIS COURSE 2/10 GOAL OF THIS COURSE Encourage you to become better programmers 2/10 GOAL OF THIS

More information

CIS 194: Homework 3. Due Wednesday, February 11, Interpreters. Meet SImPL

CIS 194: Homework 3. Due Wednesday, February 11, Interpreters. Meet SImPL CIS 194: Homework 3 Due Wednesday, February 11, 2015 Interpreters An interpreter is a program that takes another program as an input and evaluates it. Many modern languages such as Java 1, Javascript,

More information

A Brief Introduction to Scheme (I)

A Brief Introduction to Scheme (I) A Brief Introduction to Scheme (I) Philip W. L. Fong pwlfong@cs.uregina.ca Department of Computer Science University of Regina Regina, Saskatchewan, Canada Scheme Scheme I p.1/44 Scheme: Feature Set A

More information

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

! Broaden your language horizons! Different programming languages! Different language features and tradeoffs. ! Study how languages are implemented Course Goal CMSC 330: Organization of Programming Languages Introduction Learn how programming languages work Broaden your language horizons! Different programming languages! Different language features

More information

Introduction to the course and basic programming concepts

Introduction to the course and basic programming concepts Introduction to the course and basic programming concepts Lecture 1 of TDA 540 Object-Oriented Programming Jesper Cockx Fall 2018 Chalmers University of Technology Gothenburg University About the course

More information

Introduction. A. Bellaachia Page: 1

Introduction. A. Bellaachia Page: 1 Introduction 1. Objectives... 2 2. Why are there so many programming languages?... 2 3. What makes a language successful?... 2 4. Programming Domains... 3 5. Language and Computer Architecture... 4 6.

More information

CS 415 Midterm Exam Spring 2002

CS 415 Midterm Exam Spring 2002 CS 415 Midterm Exam Spring 2002 Name KEY Email Address Student ID # Pledge: This exam is closed note, closed book. Good Luck! Score Fortran Algol 60 Compilation Names, Bindings, Scope Functional Programming

More information

Static Semantics. Lecture 15. (Notes by P. N. Hilfinger and R. Bodik) 2/29/08 Prof. Hilfinger, CS164 Lecture 15 1

Static Semantics. Lecture 15. (Notes by P. N. Hilfinger and R. Bodik) 2/29/08 Prof. Hilfinger, CS164 Lecture 15 1 Static Semantics Lecture 15 (Notes by P. N. Hilfinger and R. Bodik) 2/29/08 Prof. Hilfinger, CS164 Lecture 15 1 Current Status Lexical analysis Produces tokens Detects & eliminates illegal tokens Parsing

More information

CSCE 314 Programming Languages. Type System

CSCE 314 Programming Languages. Type System CSCE 314 Programming Languages Type System Dr. Hyunyoung Lee 1 Names Names refer to different kinds of entities in programs, such as variables, functions, classes, templates, modules,.... Names can be

More information

List of lectures. Lecture content. Symbolic Programming. TDDA69 Data and Program Structure Symbolic and Logic Programming Cyrille Berger

List of lectures. Lecture content. Symbolic Programming. TDDA69 Data and Program Structure Symbolic and Logic Programming Cyrille Berger List of lectures TDDA69 Data and Program Structure Symbolic and Logic Programming Cyrille Berger 1Introduction and Functional Programming 2Imperative Programming and Data Structures 3Parsing 4Evaluation

More information

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen COP4020 Programming Languages Functional Programming Prof. Robert van Engelen Overview What is functional programming? Historical origins of functional programming Functional programming today Concepts

More information

CS 3304 Comparative Languages. Lecture 1: Introduction

CS 3304 Comparative Languages. Lecture 1: Introduction CS 3304 Comparative Languages Lecture 1: Introduction 17 January 2012 2012 Denis Gracanin Course Overview 2 Welcome What this course is about? What this course is not about? What will you learn? How will

More information

Data Types. (with Examples In Haskell) COMP 524: Programming Languages Srinivas Krishnan March 22, 2011

Data Types. (with Examples In Haskell) COMP 524: Programming Languages Srinivas Krishnan March 22, 2011 Data Types (with Examples In Haskell) COMP 524: Programming Languages Srinivas Krishnan March 22, 2011 Based in part on slides and notes by Bjoern 1 Brandenburg, S. Olivier and A. Block. 1 Data Types Hardware-level:

More information

CMSC 330: Organization of Programming Languages. Administrivia

CMSC 330: Organization of Programming Languages. Administrivia CMSC 330: Organization of Programming Languages Administrivia 1 Course Goal Learn how programming languages work Broaden your language horizons Different programming languages Different language features

More information

Lecture 1: Introduction. 23. August, 2010

Lecture 1: Introduction. 23. August, 2010 Lecture 1: Introduction 23. August, 2010 Lecture Outline TDT4165 Administratrivia Programming Languages Introduction Illustration Hello World Programs Further Comments Summary TDT4165 Administratrivia

More information

INF 212 ANALYSIS OF PROG. LANGS FUNCTION COMPOSITION. Instructors: Crista Lopes Copyright Instructors.

INF 212 ANALYSIS OF PROG. LANGS FUNCTION COMPOSITION. Instructors: Crista Lopes Copyright Instructors. INF 212 ANALYSIS OF PROG. LANGS FUNCTION COMPOSITION Instructors: Crista Lopes Copyright Instructors. Topics Recursion Higher-order functions Continuation-Passing Style Monads (take 1) Identity Monad Maybe

More information

Denotational Semantics. Domain Theory

Denotational Semantics. Domain Theory Denotational Semantics and Domain Theory 1 / 51 Outline Denotational Semantics Basic Domain Theory Introduction and history Primitive and lifted domains Sum and product domains Function domains Meaning

More information

Type Inference Systems. Type Judgments. Deriving a Type Judgment. Deriving a Judgment. Hypothetical Type Judgments CS412/CS413

Type Inference Systems. Type Judgments. Deriving a Type Judgment. Deriving a Judgment. Hypothetical Type Judgments CS412/CS413 Type Inference Systems CS412/CS413 Introduction to Compilers Tim Teitelbaum Type inference systems define types for all legal programs in a language Type inference systems are to type-checking: As regular

More information

Organization of Programming Languages CS3200/5200N. Lecture 11

Organization of Programming Languages CS3200/5200N. Lecture 11 Organization of Programming Languages CS3200/5200N Razvan C. Bunescu School of Electrical Engineering and Computer Science bunescu@ohio.edu Functional vs. Imperative The design of the imperative languages

More information

6.184 Lecture 4. Interpretation. Tweaked by Ben Vandiver Compiled by Mike Phillips Original material by Eric Grimson

6.184 Lecture 4. Interpretation. Tweaked by Ben Vandiver Compiled by Mike Phillips Original material by Eric Grimson 6.184 Lecture 4 Interpretation Tweaked by Ben Vandiver Compiled by Mike Phillips Original material by Eric Grimson 1 Interpretation Parts of an interpreter Arithmetic calculator

More information

Chapter 7:: Data Types. Mid-Term Test. Mid-Term Test (cont.) Administrative Notes

Chapter 7:: Data Types. Mid-Term Test. Mid-Term Test (cont.) Administrative Notes Chapter 7:: Data Types Programming Language Pragmatics Michael L. Scott Administrative Notes Mid-Term Test Thursday, July 27 2006 at 11:30am No lecture before or after the mid-term test You are responsible

More information

Introduction to Engineering Using Robotics Experiments. Dr. Yinong Chen

Introduction to Engineering Using Robotics Experiments. Dr. Yinong Chen Introduction to Engineering Using Robotics Experiments Dr. Yinong Chen Outline Historical Perspective Programming Language Generations Programming Language Paradigms Imperative Programming Paradigm Writing

More information

NOTE: Answer ANY FOUR of the following 6 sections:

NOTE: Answer ANY FOUR of the following 6 sections: A-PDF MERGER DEMO Philadelphia University Lecturer: Dr. Nadia Y. Yousif Coordinator: Dr. Nadia Y. Yousif Internal Examiner: Dr. Raad Fadhel Examination Paper... Programming Languages Paradigms (750321)

More information

Welcome to Python! Ilhoe Jung. Graphics & Media Lab

Welcome to Python! Ilhoe Jung. Graphics & Media Lab Welcome to Python! 2013. 07. 23 Ilhoe Jung Graphics & Media Lab Course schedule [Lecture 1] Introduction & Basic Grammar [Lecture 2] Data type & Class [Lecture 3] External libraries for python Introducing

More information

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

! Broaden your language horizons. ! Study how languages are implemented. ! Study how languages are described / specified 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!

More information

Compilers. Type checking. Yannis Smaragdakis, U. Athens (original slides by Sam

Compilers. Type checking. Yannis Smaragdakis, U. Athens (original slides by Sam Compilers Type checking Yannis Smaragdakis, U. Athens (original slides by Sam Guyer@Tufts) Summary of parsing Parsing A solid foundation: context-free grammars A simple parser: LL(1) A more powerful parser:

More information

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

Tail Calls. CMSC 330: Organization of Programming Languages. Tail Recursion. Tail Recursion (cont d) Names and Binding. Tail Recursion (cont d) CMSC 330: Organization of Programming Languages Tail Calls A tail call is a function call that is the last thing a function does before it returns let add x y = x + y let f z = add z z (* tail call *)

More information

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

Lecture 1. Introduction to course, Welcome to Engineering, What is Programming and Why is this the first thing being covered in Engineering? Lecture 1 Introduction to course, Welcome to Engineering, What is Programming and Why is this the first thing being covered in Engineering? Welcome to ENGR 102 Syllabus review Your Time Expectations (in

More information

CS558 Programming Languages

CS558 Programming Languages CS558 Programming Languages Fall 2016 Lecture 3a Andrew Tolmach Portland State University 1994-2016 Formal Semantics Goal: rigorous and unambiguous definition in terms of a wellunderstood formalism (e.g.

More information

Introduction to Functional Programming. Slides by Koen Claessen and Emil Axelsson

Introduction to Functional Programming. Slides by Koen Claessen and Emil Axelsson Introduction to Functional Programming Slides by Koen Claessen and Emil Axelsson Goal of the Course Start from the basics Learn to write small-to-medium sized programs in Haskell Introduce basic concepts

More information

Computer Components. Software{ User Programs. Operating System. Hardware

Computer Components. Software{ User Programs. Operating System. Hardware Computer Components Software{ User Programs Operating System Hardware What are Programs? Programs provide instructions for computers Similar to giving directions to a person who is trying to get from point

More information

Why are there so many programming languages?

Why are there so many programming languages? Chapter 1 :: Introduction Programming Language Pragmatics, Fourth Edition Michael L. Scott Copyright 2016 Elsevier 1 Chapter01_ Introduction_4e - Tue November 21, 2017 Introduction Why are there so many

More information

Data Abstraction. An Abstraction for Inductive Data Types. Philip W. L. Fong.

Data Abstraction. An Abstraction for Inductive Data Types. Philip W. L. Fong. Data Abstraction An Abstraction for Inductive Data Types Philip W. L. Fong pwlfong@cs.uregina.ca Department of Computer Science University of Regina Regina, Saskatchewan, Canada Introduction This lecture

More information

Functional Programming. Big Picture. Design of Programming Languages

Functional Programming. Big Picture. Design of Programming Languages Functional Programming Big Picture What we ve learned so far: Imperative Programming Languages Variables, binding, scoping, reference environment, etc What s next: Functional Programming Languages Semantics

More information

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

Lecture 09. Ada to Software Engineering. Mr. Mubashir Ali Lecturer (Dept. of Computer Science) Lecture 09 Ada to Software Engineering Mr. Mubashir Ali Lecturer (Dept. of dr.mubashirali1@gmail.com 1 Summary of Previous Lecture 1. ALGOL 68 2. COBOL 60 3. PL/1 4. BASIC 5. Early Dynamic Languages 6.

More information

CSc 372. Comparative Programming Languages. 2 : Functional Programming. Department of Computer Science University of Arizona

CSc 372. Comparative Programming Languages. 2 : Functional Programming. Department of Computer Science University of Arizona 1/37 CSc 372 Comparative Programming Languages 2 : Functional Programming Department of Computer Science University of Arizona collberg@gmail.com Copyright c 2013 Christian Collberg 2/37 Programming Paradigms

More information

Pace University. Fundamental Concepts of CS121 1

Pace University. Fundamental Concepts of CS121 1 Pace University Fundamental Concepts of CS121 1 Dr. Lixin Tao http://csis.pace.edu/~lixin Computer Science Department Pace University October 12, 2005 This document complements my tutorial Introduction

More information

11/6/17. Functional programming. FP Foundations, Scheme (2) LISP Data Types. LISP Data Types. LISP Data Types. Scheme. LISP: John McCarthy 1958 MIT

11/6/17. Functional programming. FP Foundations, Scheme (2) LISP Data Types. LISP Data Types. LISP Data Types. Scheme. LISP: John McCarthy 1958 MIT Functional programming FP Foundations, Scheme (2 In Text: Chapter 15 LISP: John McCarthy 1958 MIT List Processing => Symbolic Manipulation First functional programming language Every version after the

More information

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

CSc 520. Course Outline (Subject to change) Course Outline (Subject to change)... Principles of Programming Languages. Christian Collberg Slide 0 2 Course Outline (Subject to change) This course will define, analyze and evaluate important concepts found in current programming languages. Its goals are to build an ability to evaluate and compare

More information

FP Foundations, Scheme

FP Foundations, Scheme FP Foundations, Scheme In Text: Chapter 15 1 Functional Programming -- Prelude We have been discussing imperative languages C/C++, Java, Fortran, Pascal etc. are imperative languages Imperative languages

More information

MIDTERM EXAMINATION - CS130 - Spring 2003

MIDTERM EXAMINATION - CS130 - Spring 2003 MIDTERM EXAMINATION - CS130 - Spring 2003 Your full name: Your UCSD ID number: This exam is closed book and closed notes Total number of points in this exam: 120 + 10 extra credit This exam counts for

More information