Introduction (Sections )

Slides:



Advertisements
Similar presentations
Intermediate Code Generation
Advertisements

Programming Languages and Paradigms
Adapted from Scott, Chapter 6:: Control Flow Programming Language Pragmatics Michael L. Scott.
Programming Paradigms Introduction. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1:
Programming Languages Marjan Sirjani 2 2. Language Design Issues Design to Run efficiently : early languages Easy to write correctly : new languages.
Machine-Level Programming III: Procedures Apr. 17, 2006 Topics IA32 stack discipline Register saving conventions Creating pointers to local variables CS213.
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 1: Introduction COMP 144 Programming Language Concepts Spring 2002 Felix Hernandez-Campos.
Programming Languages Structure
Stack Activation Records Topics IA32 stack discipline Register saving conventions Creating pointers to local variables February 6, 2003 CSCE 212H Computer.
CSE 425: Intro to Programming Languages and their Design A Few Key Ideas No particular language is a prerequisite for this course –However you should be.
Imperative Programming
High-Level Programming Languages: C++
Chapter 1. Introduction.
CS 363 Comparative Programming Languages
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
Chapter 1 - Introduction
By Neng-Fa Zhou1 Evolution of programming languages –Machine language –Assembly language –Sub-routines and loop (Fortran) –Procedures and recursion (Algol,
Fabián E. Bustamante, Spring 2007 Machine-Level Programming III - Procedures Today IA32 stack discipline Register saving conventions Creating pointers.
1 Lecture 1: Introduction (Sections ) CSCI 431 Programming Languages Fall 2002 A modification of slides developed by Felix Hernandez-Campos at UNC.
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
1 Programming Languages Fundamentals Cao Hoaøng Truï Khoa Coâng Ngheä Thoâng Tin Ñaïi Hoïc Baùch Khoa TP. HCM.
Programming Languages
Machine-level Programming III: Procedures Topics –IA32 stack discipline –Register saving conventions –Creating pointers to local variables.
Slide 1 WEEK 8 Imperative Programming Original by Vitaly Shmatikov.
Functions/Methods in Assembly
Copyright © 2009 Elsevier Chapter 6:: Control Flow Programming Language Pragmatics Michael L. Scott.
Chapter 1. Introduction.
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Programming Languages 2nd edition Tucker and Noonan
Introduction to programming languages, Algorithms & flowcharts
Why study programming languages?
Introduction to programming languages, Algorithms & flowcharts
PROGRAMMING LANGUAGES
Conditional Branch Example
Lecture 16: Introduction to Data Types
Lecture 14: Iteration and Recursion (Section 6.5 – 6.6)
CS4450: Principles of Programming Languages
Evolution of programming languages
Introduction to programming languages, Algorithms & flowcharts
Y86 Processor State Program Registers
Machine-Level Programming 4 Procedures
Chap. 6 :: Control Flow Michael L. Scott.
Expressions and Assignment Statements
Condition Codes Single Bit Registers
CSCE Fall 2013 Prof. Jennifer L. Welch.
Lecture 30 (based on slides by R. Bodik)
Machine-Level Programming 2 Control Flow
CSCE 121: Simple Computer Model Spring 2015
FP Foundations, Scheme In Text: Chapter 14.
Machine-Level Programming III: Procedures Sept 18, 2001
Chap. 6 :: Control Flow Michael L. Scott.
Programming Languages 2nd edition Tucker and Noonan
Final Review In Text: Chapters 1-3, 5-12,
High Level Programming Languages
Low Level Programming Languages
Statement-Level Control Structures
Expression and Asignment Statements
Language-based Security
CSCE Fall 2012 Prof. Jennifer L. Welch.
Final Review In Text: Chapters 1-3, 5-16.
Principles of Programming Languages
Machine-Level Programming II: Control Flow
Programming Languages and Paradigms
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Final Review In Text: Chapters 1-3, 5-16.
Chapter 7: Expressions and Assignment Statements Sangho Ha
A Tour of Language Implementation
Expressions and Assignment Statements
Presentation transcript:

Introduction (Sections 1.1-1.3) CSCI 431 Programming Languages Fall 2003 Introduction (Sections 1.1-1.3) A modification of slides developed by Felix Hernandez-Campos at UNC Chapel Hill

Programming Languages What is a programming language? Programming Language

Programming Languages A language used to express instructions to a computer. Definition of legal Programs (Syntax) Meaning of a Program (Semantics) Style of Programming (Pragmatics) Example, Consider the following statement: set x[i] to x[i] + 1 This is clearly intended to denote the increment of an array element. How would we translate this statement to a variety of different languages, and what would it mean?

In C (circa 1970), we would write this as x[i] = x[i] + 1; This performs a hardware lookup for the address of x and adds i to it. The addition is a hardware operation, so it is dependent upon the hardware in question. This resulting address is then referenced (if it's legal - which it might not be), 1 is added to the bit-string stored there (again, as a hardware addition, which can overflow), and the result is stored back to that location. However, no attempt has been made to determine that x is even a vector and that x[i] is a number.

In Scheme (1975), this would be transcribed as (vector-set! x i (+ (vector-ref x i) 1)) This does all the things the corresponding C operation does, but in addition it also (a) checks that the object named x is indeed an array, (b) makes sure it is within the bounds of the array, (c) ensures the dereferenced location contains a number, and (d) performs abstract arithmetic (so there will be no ``overflow'').

Finally, in Java (circa 1991), one might write x[i] = x[i] + 1; which looks identical to the C code. However, the actions performed are those performed by the Scheme code, with one major difference: the arithmetic is not as abstract. It is defined to be done as if the machine were a 32-bit machine, which means we can always determine the result of an operation, no matter which machine we execute the program on, but we cannot have our numbers grow arbitrarily large.

Programming Languages What is a programming language? Abstraction of virtual machine int sum(int[] x) { int sum = 0; n = 0; while (n < x.length) { sum += x[n]; } return sum; 00101010101010 10101011111010 11101010101110 ...

A simple algorithm for testing primality in Java: public static boolean isprime (int n) { int d; for (d = 2; d < n; d++) if (n % d == 0) return false; return true; }

In Intel X86 Assembler: .globl isprime isprime: pushl %ebp ; set up procedure entry movl %esp,%ebp pushl %esi pushl %ebx movl 8(%ebp),%ebx ; fetch arg n from stack movl $2,%esi ; set divisor d := 2 cmpl %ebx,%esi ; compare n,d jge true ; jump if d >= n loop: movl %ebx,%eax ; set n into .... cltd ; ... dividend register idivl %esi ; divide by d testl %edx,%edx ; remainder 0? … done: leal -8(%ebp),%esp ; clean up and exit popl %ebx popl %esi leave ret

Machine Code Characteristics: Explicit registers for values and intermediate results. Low-level machine instructions to implement operations. Control flow based on labels and conditional branches. Explicit memory management (e.g., stack management for procedures).

General Characteristics of HLLs: Complex Expressions (Arithmetic, Logical, ...) Structured Control Operators (Loops, Conditionals, Cases) Composite Types (Arrays, Records, etc.) Type Declarations and Type Checking Multiple storage classes (global/local/heap) Procedures/Functions, with private scope, maybe first-class Maybe abstract data types, modules, objects, etc. Maybe high-level control mechanisms (Exceptions, Back-tracking, etc.)

Programming Languages What is a programming language? Donald Knuth: Programming is the art of telling another human being what one wants the computer to do int sum(int[] x) { int sum = 0; n = 0; while (n < x.length) { sum += x[n]; } return sum; 00101010101010 10101011111010 11101010101110 ...

The Number of Programming Languages How many programming languages do you know? This is a sample list… http://dmoz.org/Computers/Programming/Languages Why is the number of programming languages so large? Evolution Special Purpose Personal Preference * Give me some examples * How many? (more than…)

The Number of Programming Languages How many programming languages do you know? This is a sample list… http://dmoz.org/Computers/Programming/Languages/ Why is the number of programming languages so large? Evolution Special Purpose Personal Preference

Evolution: Genealogy Prolog Scheme Python 91 (from Modula-3 and ABC 87?). Python 2 influenced by Perl and functional programming. From Sebesta’s Concepts of Programming Languages Java

The Number of Programming Languages How many programming languages do you know? This is a sample list… http://dmoz.org/Computers/Programming/Languages/ Why is the number of programming languages so large? Evolution Special Purpose Personal Preference

The Number of Programming Languages How many programming languages do you know? This is a sample list… http://dmoz.org/Computers/Programming/Languages/ Why is the number of programming languages so large? Evolution Special Purpose Personal Preference

The Number of Programming Languages How many programming languages do you know? This is a sample list… http://dmoz.org/Computers/Programming/Languages/ Why is the number of programming languages so large? Evolution Special Purpose Personal Preference A programming language is a way of thinking Different people think in a different way

A simple algorithm for testing primality In Java: public static boolean isprime (int n) { int d; for (d = 2; d < n; d++) if (n % d == 0) return false; return true; }

A simple algorithm for testing primality In Standard ML (using a recursive function): fun isprime (n:int) : bool = let fun no_divisor (d:int) : bool = (d >= n) orelse ((n mod d <> 0) andalso (no_divisor (d+1))) in no_divisor 2 end

Successful Programming Languages Are all languages equally successful? No! What makes a language successful? Expressive power Ease of use for the novice Ease of implementation Excellent compilers Economics, patronage, and inertia

Classification of Programming Languages Imperative languages Algorithms+data structures+assignment Von Neumann languages E.g. Fortran, Basic, C Object-oriented languages E.g. C++, Java

Classification of Programming Languages Declarative languages No assignment (well sorta) Functional languages Functions+lists E.g. Lisp, ML, and Haskell Dataflow languages Concurrent E.g. Id and Val Logic or constraint-based languages Propositions+predicates+logical deduction E.g. Prolog

Why study programming languages? Use the most appropriate programming language for your task E.g. Java is great for writing applications E.g. C is great for systems programming Make it easier to learn new languages Evolution => Similarities Make better use of language features Obscure features Cost of features Simulate useful features

Summary Programming languages: Set of abstractions => virtual machine A way of thinking