Dr. Muhammed Al-Mulhem 1ICS ICS 535 Design and Implementation of Programming Languages Part 1 Introduction (Chapter 1)
Dr. Muhammed Al-Mulhem 2ICS Programming Languages What is a programming language? What is a programming language? 1. A programming language is the medium of expression in the art of computer programming. [Mitchell] 2. Any notation for the description of algorithms and data structures may be termed as a programming language. [Pratt.]
Dr. Muhammed Al-Mulhem 3ICS Programming Languages (Cont.) What is a programming language? What is a programming language? No general consensus on the precise definition of programming language. Important aspects include function, target, constructs, and expressive power. Function: A programming language is a language used to write computer programs, which instruct a computer to perform some kind of computation and/or organize the flow of control between mechanical devices.computer programscomputation
Dr. Muhammed Al-Mulhem 4ICS Programming Languages (Cont.) Target: Programming languages differ from natural languages in that natural languages are only used for interaction between people, while programming languages also allow humans to communicate instructions to machines. natural languages
Dr. Muhammed Al-Mulhem 5ICS Programming Languages (Cont.) Constructs: Programming languages may contain constructs for defining and manipulating data structures or for controlling the flow of execution.data structuresflow of execution Expressive power: The theory of computation classifies languages by the computations they can express.theory of computation
Dr. Muhammed Al-Mulhem 6ICS Taxonomy of Programming Languages Hundreds of programming languages have been devloped. Hundreds of programming languages have been devloped. No single overall classification scheme for programming languages. No single overall classification scheme for programming languages. One classification is the domain of use. One classification is the domain of use. Another classification by purpose like general purpose, system programming, scripting, and concurrent. Another classification by purpose like general purpose, system programming, scripting, and concurrent. Some languages have multiple characteristics like Java: Object-oriented and concurrent. Some languages have multiple characteristics like Java: Object-oriented and concurrent.
Dr. Muhammed Al-Mulhem 7ICS Taxonomy of Programming Languages Commonly, PLs are divided into programming paradigms (procedural/imperative, object-oriented, functional, and logic). Commonly, PLs are divided into programming paradigms (procedural/imperative, object-oriented, functional, and logic).
Dr. Muhammed Al-Mulhem 8ICS Programming Languages Diversity One of the things that makes programming languages so fascinating is their diversity. One of the things that makes programming languages so fascinating is their diversity. Imperative Languages Imperative Languages int fact (int n) { int sofar = 1; while ( n > 0 ) sofar *= n--; return sofar; } Functional Languages Functional Languages (defun fact (x) (if ( <= x 0 ) 1 (* x (fact ( - x 1)))))
Dr. Muhammed Al-Mulhem 9ICS Programming Languages Diversity Logic Programming Languages Logic Programming Languages fact(1, 1). fact(N, M) :- X is N – 1, fact(X, Y), M is N * Y.
Dr. Muhammed Al-Mulhem 10ICS Programming Languages Diversity Object-Oriented Languages Object-Oriented Languages public class MyInt { private int value; public MyInt (int value) { this.value = value; this.value = value;} public int getValue() { return value; return value;} public MyInt getFact() { return new MyInt (fact(value)); return new MyInt (fact(value));} private int fact(int n) { int sofar = 1; int sofar = 1; while (n > 1) sofar *= n--; return sofar; }}
Dr. Muhammed Al-Mulhem 11ICS Criteria for a good programming language An ideal programming language will make it easy for programmers to write programs concisely and clearly. An ideal programming language will make it easy for programmers to write programs concisely and clearly. A good programming language will help others read programs and understand how they work. A good programming language will help others read programs and understand how they work. A good language for large-scale programming will help programmers manage the interaction among software components effectively. A good language for large-scale programming will help programmers manage the interaction among software components effectively.
Dr. Muhammed Al-Mulhem 12ICS Trade-offs in Programming Language Design Some language features make it easy for us to write programs quickly, but may make it harder for us to design testing tools or methods. Some language features make it easy for us to write programs quickly, but may make it harder for us to design testing tools or methods. Some language constructs make it easier for a compiler to optimize programs, but may make programming cumbersome. Some language constructs make it easier for a compiler to optimize programs, but may make programming cumbersome. Different computing environments and applications require different program characteristics, different programming language designers have chosen different trade-offs. Different computing environments and applications require different program characteristics, different programming language designers have chosen different trade-offs. One reason for discussing historical languages is that this gives us a realistic way to understand programming language design trade-offs. One reason for discussing historical languages is that this gives us a realistic way to understand programming language design trade-offs.
Dr. Muhammed Al-Mulhem 13ICS Trade-offs Example APL (named after the book A Programming Language)[5] is an interactive array-oriented language APL (named after the book A Programming Language)[5] is an interactive array-oriented language[5]interactivearray-oriented language[5]interactivearray-oriented language It is concise, using symbols rather than words and applying functions to entire arrays without using explicit loops. It is concise, using symbols rather than words and applying functions to entire arrays without using explicit loops.arrays An expression to find all prime numbers from 1 to R. An expression to find all prime numbers from 1 to R.prime numbersprime numbers (~R ∊ R ∘.×R)/R←1↓ ⍳ R
Dr. Muhammed Al-Mulhem 14ICS (~R ∊ R ∘.×R)/R←1↓ ⍳ R Executed from right to left, this means: Executed from right to left, this means: ιR creates a vector containing integers from 1 to R (if R = 6 at the beginning of the program, ιR is ) ιR creates a vector containing integers from 1 to R (if R = 6 at the beginning of the program, ιR is )integers Drop first element of this vector (↓ function), i.e. 1. So 1↓ιR is Drop first element of this vector (↓ function), i.e. 1. So 1↓ιR is Set R to the new vector (←, assignment primitive), i.e Set R to the new vector (←, assignment primitive), i.e Generate outer product of R multiplied by R, i.e. a matrix which is the multiplication table of R by R (°.× function), i.e. Generate outer product of R multiplied by R, i.e. a matrix which is the multiplication table of R by R (°.× function), i.e.outer productmultiplication tableouter productmultiplication table Build a vector the same length as R with 1 in each place where the corresponding number in R is in the outer product matrix (ε, set inclusion function), i.e Build a vector the same length as R with 1 in each place where the corresponding number in R is in the outer product matrix (ε, set inclusion function), i.e Logically negate the values in the vector (~, negation function), i.e Logically negate the values in the vector (~, negation function), i.e Select the items in R for which the corresponding element is 1 (/ function), i.e Select the items in R for which the corresponding element is 1 (/ function), i.e
Dr. Muhammed Al-Mulhem 15ICS PLs Histroy 1950s Algol, Cobol, Fortran, Lisp 1950s Algol, Cobol, Fortran, Lisp 1980sObject-orientation 1980sObject-orientation 1990sNetwork-centered computing 1990sNetwork-centered computing 2000sDiversity of computing devices, wireless and cellular computing. 2000sDiversity of computing devices, wireless and cellular computing.
Dr. Muhammed Al-Mulhem 16ICS A Summary of Concepts and Languages ThreadsObjectsExceptionsFunctionsExpressionsLanguage LISP C Pascal Smalltalk C++ ML Java
Dr. Muhammed Al-Mulhem 17ICS Programming Languages Development Two main aspects: Design and Implementation Two main aspects: Design and Implementation Design: Two specifications Design: Two specifications Syntax Syntax Semantics Semantics Implementation: Two approaches: Implementation: Two approaches: Interpretation Interpretation Compilation Compilation