+ All Categories
Home > Documents > ICS 313 Fundamentals of Programming Languages Spring Semester 2004 - 2005 (042) King Fahd University...

ICS 313 Fundamentals of Programming Languages Spring Semester 2004 - 2005 (042) King Fahd University...

Date post: 20-Dec-2015
Category:
View: 217 times
Download: 2 times
Share this document with a friend
Popular Tags:
40
ICS 313 amentals of Programming Languag Spring Semester 2004 - 2005 (042) King Fahd University of Petroleum & Minerals Information & Computer Science Department
Transcript
Page 1: ICS 313 Fundamentals of Programming Languages Spring Semester 2004 - 2005 (042) King Fahd University of Petroleum & Minerals Information & Computer Science.

ICS 313Fundamentals of Programming Languages

Spring Semester 2004 - 2005 (042)

King Fahd University of Petroleum & Minerals

Information & Computer Science Department

Spring Semester 2004 - 2005 (042)

King Fahd University of Petroleum & Minerals

Information & Computer Science Department

Page 2: ICS 313 Fundamentals of Programming Languages Spring Semester 2004 - 2005 (042) King Fahd University of Petroleum & Minerals Information & Computer Science.

Section 04, 10:00-11:15am UT, 24:250

• Instructor: Dr. Wasfi Al-Khatib الخطيب وصفي• Office: 22: 133-1• Office Hours: UT: 9:00 - 9:50am and 2:30 – 3:30pm

M: 3:00 - 4:00pm Or by appointment

• Phone: 1715• email: [email protected]• WebCT Page: http://webcourses.kfupm.edu.sa

Page 3: ICS 313 Fundamentals of Programming Languages Spring Semester 2004 - 2005 (042) King Fahd University of Petroleum & Minerals Information & Computer Science.

Catalogue Description

• Concepts of Programming Languages: Syntax and semantics, Data types, Control structures, Subprograms, Exception handling, Run-time storage management. Programming paradigms: Imperative, functional, logical, object-oriented and concurrent programming

Page 4: ICS 313 Fundamentals of Programming Languages Spring Semester 2004 - 2005 (042) King Fahd University of Petroleum & Minerals Information & Computer Science.

Course Objectives

• Outline the history and describe the rationale of different programming languages.

• Describe grammar and syntax specifications and analyze their implementations.

• Describe, analyze and use the various mechanisms in procedural languages; e g. data types, scope, control structures subprograms, etc.

• Describe and use the major programming paradigms: Imperative, Functional, Logical and Object-Oriented.

• Explain and describe how concurrency and exception handling are used in programming Languages

Page 5: ICS 313 Fundamentals of Programming Languages Spring Semester 2004 - 2005 (042) King Fahd University of Petroleum & Minerals Information & Computer Science.

Text Book

• Concepts of Programming Languages, By. R. Sebesta, 6th Ed, Addison Wesley, 2004.

Page 6: ICS 313 Fundamentals of Programming Languages Spring Semester 2004 - 2005 (042) King Fahd University of Petroleum & Minerals Information & Computer Science.

Course Outline1. Preliminaries2. Evolution of the Major Programming languages3. Describing Syntax and Semantics4. Imperative Programming (Introduction to C)5. Functional Programming6. Logic Programming7. Names, Bindings, Type Checking and Scopes8. Data Types9. Expressions and the Assignment Statements10.Statement-Level Control Structure11.Subprograms12.Implementing Subprograms13.Abstract Data Types

Page 7: ICS 313 Fundamentals of Programming Languages Spring Semester 2004 - 2005 (042) King Fahd University of Petroleum & Minerals Information & Computer Science.

Grading Policy

[Programming] Assignments 20%

Pop Quizzes 10%

Major Exam #1 10%

Major Exam #2 15%

Major Exam #3 20%

Final Exam 25%

Page 8: ICS 313 Fundamentals of Programming Languages Spring Semester 2004 - 2005 (042) King Fahd University of Petroleum & Minerals Information & Computer Science.

Important DatesTask Date [and Time] Location Weight

Help Session I TBA TBA N/A

Major Exam I Saturday March 5, 2005 6:30 – 8:00pm TBA 10%

Help Session II TBA TBA N/A

Major Exam II Saturday March 26, 2005 6:30 – 8:00pm TBA 15%

Help Session III TBA TBA N/A

Major Exam III Saturday April 30, 2005 6:30 – 8:00pm TBA 20%

Help Session IV TBA TBA N/A

Final Exam TBA TBA 25%

Page 9: ICS 313 Fundamentals of Programming Languages Spring Semester 2004 - 2005 (042) King Fahd University of Petroleum & Minerals Information & Computer Science.

Attendance Policy

• Attendance will be checked each class. • Unexcused Absences Policies:

– The first THREE absences are FREE of charge.– The fourth absence is worth – 3 points of your overall

score (out of 100). – Each subsequent absence, up to the sixth absence, is

worth -0.75 of your overall score.– The seventh absence will result in an automatic DN grade.– An unexcused absence can become an excused absence

ONLY by an official letter from the Dean of Student’s office.

Page 10: ICS 313 Fundamentals of Programming Languages Spring Semester 2004 - 2005 (042) King Fahd University of Petroleum & Minerals Information & Computer Science.

General Rules

• Students are expected to be courteous toward the instructor and their classmates throughout the duration of this course.

• All cell phones and pagers must be turned off during class and exams.

• Assignments are due at the beginning of class. No late assignment will be accepted. Discussing questions among your classmates is highly encouraged. Copying solutions from each other is NOT permitted and will be considered CHEATING and will be dealt with accordingly.

Page 11: ICS 313 Fundamentals of Programming Languages Spring Semester 2004 - 2005 (042) King Fahd University of Petroleum & Minerals Information & Computer Science.

Pop Quizzes

• 10 minute

• Each covers material given during the current lecture.

• They require you to be attentive during class time as you will be subject at any point in time to answer a pop-quiz.

Page 12: ICS 313 Fundamentals of Programming Languages Spring Semester 2004 - 2005 (042) King Fahd University of Petroleum & Minerals Information & Computer Science.

IMPORTANT RULE

• ZERO-TOLERANCE for CHEATING.

Page 13: ICS 313 Fundamentals of Programming Languages Spring Semester 2004 - 2005 (042) King Fahd University of Petroleum & Minerals Information & Computer Science.

Exam Policies

• 24-Hour Policy: One has 24 hours to object to the score of an assignment, a pop quiz, or a major exam from the end of the class time in which the graded assignment/quiz/exam papers have been distributed. If for some reason you cannot contact me in person within this period, send me an email requesting an appointment. The email should be sent within the 24-hour time period.

• Exams, assignments and pop-quizzes are generally CHALLENGING.

Page 14: ICS 313 Fundamentals of Programming Languages Spring Semester 2004 - 2005 (042) King Fahd University of Petroleum & Minerals Information & Computer Science.

1. Preliminaries

Page 15: ICS 313 Fundamentals of Programming Languages Spring Semester 2004 - 2005 (042) King Fahd University of Petroleum & Minerals Information & Computer Science.

Reasons to study concepts of PLs

• Increased capacity to express programming concepts

• Improved background for choosing appropriate languages

• Increased ability to learn new languages• Understanding the significance of

implementation• Increased ability to design new languages• Overall advancement of computing

Page 16: ICS 313 Fundamentals of Programming Languages Spring Semester 2004 - 2005 (042) King Fahd University of Petroleum & Minerals Information & Computer Science.

Programming Domains

• Scientific applications

• Business applications

• Artificial intelligence

• Systems programming

• Scripting languages

• Special purpose languages

Page 17: ICS 313 Fundamentals of Programming Languages Spring Semester 2004 - 2005 (042) King Fahd University of Petroleum & Minerals Information & Computer Science.

What is a Programming Language

• A programming language is

Page 18: ICS 313 Fundamentals of Programming Languages Spring Semester 2004 - 2005 (042) King Fahd University of Petroleum & Minerals Information & Computer Science.

Programming Language Definition

• Language Syntax– Grammar and punctuation.– Superset of legal languages.

• Language Semantics– What the syntax means.– Restricts syntactically correct programs.

Page 19: ICS 313 Fundamentals of Programming Languages Spring Semester 2004 - 2005 (042) King Fahd University of Petroleum & Minerals Information & Computer Science.

Computer Program Development

Algorithm

Syntax

Computer Program

Problem

Humanbrains

Semantics

Translation

Algorithm

Syntax

Page 20: ICS 313 Fundamentals of Programming Languages Spring Semester 2004 - 2005 (042) King Fahd University of Petroleum & Minerals Information & Computer Science.

Why Take This Course?

• In order to graduate1. True

2. False

3. Not necessarily

4. None of the above

• Learning a new language depends on how many languages you learn

1. True

2. False

3. Not necessarily

4. None of the above

Page 21: ICS 313 Fundamentals of Programming Languages Spring Semester 2004 - 2005 (042) King Fahd University of Petroleum & Minerals Information & Computer Science.

Programming Paradigms

• Imperative – Program = Algorithms + Data

• Functional– Program = Function o Function

• Object-Oriented– Program = Objects + Messages

• Logic– Program = Facts + Rules

• Special-purpose

Page 22: ICS 313 Fundamentals of Programming Languages Spring Semester 2004 - 2005 (042) King Fahd University of Petroleum & Minerals Information & Computer Science.

Imperative Programming

• Oldest style of Programming

• Algorithm is expressed as a sequence of instructions, e.g. assignment, looping, …

• For example, assembly, Fortran, Algol, Pascal, and C.

Page 23: ICS 313 Fundamentals of Programming Languages Spring Semester 2004 - 2005 (042) King Fahd University of Petroleum & Minerals Information & Computer Science.

Example in C

• Finding the greatest common divisor between two elements#include<stdio.h> void main() { int x,y; printf("enter any two numbers"); scanf("%d %d",&x,&y); if(x<0)x=-x; if(y<0)y=-y; while(x!=y) x>y?(x=x-y):(y=y-x); printf("gcd of the numbers is %d",x); }

Page 24: ICS 313 Fundamentals of Programming Languages Spring Semester 2004 - 2005 (042) King Fahd University of Petroleum & Minerals Information & Computer Science.

Functional Programming

• Comes from traditional Mathematics.• Description of computation is based on the

evaluation of functions or the application of functions to known values.

• No notion of variables or assignment to variables!

• Loops are replaced by recursion!• For example Lisp, Scheme, ML, Haskell.

Page 25: ICS 313 Fundamentals of Programming Languages Spring Semester 2004 - 2005 (042) King Fahd University of Petroleum & Minerals Information & Computer Science.

Example in Scheme

• Finding the greatest common divisor between two elements

(define (gcd u v) (if (= v 0) u (gcd v (remainder u v))))

Page 26: ICS 313 Fundamentals of Programming Languages Spring Semester 2004 - 2005 (042) King Fahd University of Petroleum & Minerals Information & Computer Science.

Object Oriented Programming

• Based on class and inheritance

• Instead of applying global functions to variables, “methods” associated with instances are invoked (message passing)

• For example, C++, Java, Smalltalk, …

Page 27: ICS 313 Fundamentals of Programming Languages Spring Semester 2004 - 2005 (042) King Fahd University of Petroleum & Minerals Information & Computer Science.

Example in C++

// gcd.cpp - long integer greatest common divisor class BadGcdArgumentsException{ };

long gcd(long a,long b) // Euclidean algorithm - returns 0 // if a and b are both 0.

{ long r; // First make sure everything is >= 0. if(a < 0) a = -a; if(b < 0) b = -b; // If both arguments are 0, throw an exception. if(a == 0 && b == 0) throw BadGcdArgumentsException(); // Otherwise the gcd of 0 and x is x. if(a == 0) return(b); if(b == 0) return(a); // Keep dividing until we get a zero remainder. The last // nonzero remainder is the gcd. while(b > 0) { r = a % b; a = b; b = r; } return(a); }

• Finding the greatest common divisor between two elements

Page 28: ICS 313 Fundamentals of Programming Languages Spring Semester 2004 - 2005 (042) King Fahd University of Petroleum & Minerals Information & Computer Science.

Logic Programming

• Like functional programming, but through formal logic.

• A program is a set of predicates, i.e. rules governing the problem.

• Either the truthfulness of a given formula or the deduction of new formulae results from running a logic program.

• For example, prolog.

Page 29: ICS 313 Fundamentals of Programming Languages Spring Semester 2004 - 2005 (042) King Fahd University of Petroleum & Minerals Information & Computer Science.

Example in Prolog

• Finding the greatest common divisor between two elements

gcd(U,V,U) :- V=0.gcd(U,V,X) :- V>0, Y is U mod V, gcd(V,Y,X).

Page 30: ICS 313 Fundamentals of Programming Languages Spring Semester 2004 - 2005 (042) King Fahd University of Petroleum & Minerals Information & Computer Science.

Special-Purpose Languages

• Shell, Awk, Perl, Python– System administration– Program configuration

• Postscript, Tex, RTF– Text and document setting

• HTML, XML– Markup Language

Page 31: ICS 313 Fundamentals of Programming Languages Spring Semester 2004 - 2005 (042) King Fahd University of Petroleum & Minerals Information & Computer Science.

Example in Perl• Make up one pdf file from separate postscript files.

# This script takes as input the desired output filename (without the extension) and the # number of input files. It is assumed that the input filenames are of the form 1.ps 2.ps ... # 99.ps and so on and so forth. It then combines all postscript files into one file with a .ps # extension. Finally, it will generate the pdf version of the postscript file.

$Docs_Dir = 'C:\\Program Files\\ScannerU\\';$OutputFile = $ARGV[0];$NumOfInputs = $ARGV[1];

$FileList = "";for ($i = 1; $i <= $NumOfInputs; $i = $i + 1) { $FileList = $FileList . $i . ".ps ";}chdir($Docs_Dir);system("gswin32c -dNOPAUSE -sDEVICE=pswrite -dBATCH -sOutputFile=" . $OutputFile . ".ps " . $FileList);system("ps2pdf -r720 " . $OutputFile . ".ps " . $OutputFile . ".pdf ");

Page 32: ICS 313 Fundamentals of Programming Languages Spring Semester 2004 - 2005 (042) King Fahd University of Petroleum & Minerals Information & Computer Science.

Language Evaluation Criteria• Readability

– The most important criteria– Factors

• Overall simplicity– Too many features is bad– Multiplicity of features is bad

• Orthogonality– Makes the language easy to learn and read– Meaning is context independent

• Control statements• Data type and structures• Syntax considerations

• Writability– Factors

• Simplicity and orthogonality• Support for abstraction• Expressivity

Page 33: ICS 313 Fundamentals of Programming Languages Spring Semester 2004 - 2005 (042) King Fahd University of Petroleum & Minerals Information & Computer Science.

Language Evaluation Criteria (cont.)• Reliability

– Factors• Type checking• Exception handling• Aliasing• Readability and writability

• Cost– Categories

• Programmer training• Software creation• Compilation• Execution• Compiler cost• Poor reliability• Maintenance

• Others: portability, generality, well-definedness

Page 34: ICS 313 Fundamentals of Programming Languages Spring Semester 2004 - 2005 (042) King Fahd University of Petroleum & Minerals Information & Computer Science.

Language Design Trade-offs

• Reliability versus cost of execution

• Writability versus readability

• Flexibility versus safety

Page 35: ICS 313 Fundamentals of Programming Languages Spring Semester 2004 - 2005 (042) King Fahd University of Petroleum & Minerals Information & Computer Science.

Layered View of a Computer

Page 36: ICS 313 Fundamentals of Programming Languages Spring Semester 2004 - 2005 (042) King Fahd University of Petroleum & Minerals Information & Computer Science.

Implementation Methods

• Compilation• Interpretation• Hybrid Implementation Systems

Page 37: ICS 313 Fundamentals of Programming Languages Spring Semester 2004 - 2005 (042) King Fahd University of Petroleum & Minerals Information & Computer Science.

Compilation

• Translate high-level program to machine code

• Slow translation• Fast execution

Page 38: ICS 313 Fundamentals of Programming Languages Spring Semester 2004 - 2005 (042) King Fahd University of Petroleum & Minerals Information & Computer Science.

Interpretation

• No translation• Slow execution• Usually found in

functional and logic-based programming languages.

Page 39: ICS 313 Fundamentals of Programming Languages Spring Semester 2004 - 2005 (042) King Fahd University of Petroleum & Minerals Information & Computer Science.

Hybrid Implementation Systems

• Small translation cost• Medium execution speed

Page 40: ICS 313 Fundamentals of Programming Languages Spring Semester 2004 - 2005 (042) King Fahd University of Petroleum & Minerals Information & Computer Science.

Programming Environments• The collection of tools used in software

development

• UNIX– An old operating system and tool collection

• Borland JBuilder– A PC environment for Java

• Smalltalk– A language processor/environment

• Microsoft Visual C++– A large, complex visual environment


Recommended