Imperative Programming Languages (IPL)

Similar documents
Design Issues. Subroutines and Control Abstraction. Subroutines and Control Abstraction. CSC 4101: Programming Languages 1. Textbook, Chapter 8

Chapter 7. - FORTRAN I control statements were based directly on IBM 704 hardware

Control Structures. Outline. In Text: Chapter 8. Control structures Selection. Iteration. Gotos Guarded statements. One-way Two-way Multi-way

UNIT 3

G Programming Languages - Fall 2012

Question No: 1 ( Marks: 1 ) - Please choose one One difference LISP and PROLOG is. AI Puzzle Game All f the given

LECTURE 18. Control Flow

Continuations provide a novel way to suspend and reexecute

Ch. 7: Control Structures

C++ (Non for C Programmer) (BT307) 40 Hours

SE352b: Roadmap. SE352b Software Engineering Design Tools. W3: Programming Paradigms

NOTE: Answer ANY FOUR of the following 6 sections:

Introduction Primitive Data Types Character String Types User-Defined Ordinal Types Array Types. Record Types. Pointer and Reference Types

Programmiersprachen (Programming Languages)

G Programming Languages - Fall 2012

Introduction. A. Bellaachia Page: 1

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING

Fundamentals of Programming Languages. Data Types Lecture 07 sl. dr. ing. Ciprian-Bogdan Chirila

Introduction to Programming Using Java (98-388)

Review of the C Programming Language

Programmin Languages/Variables and Storage

1. true / false By a compiler we mean a program that translates to code that will run natively on some machine.

Programming Languages 2nd edition Tucker and Noonan"

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

C-LANGUAGE CURRICULAM

Data Types. Outline. In Text: Chapter 6. What is a type? Primitives Strings Ordinals Arrays Records Sets Pointers 5-1. Chapter 6: Data Types 2

CSC 533: Organization of Programming Languages. Spring 2005

Run-time Environments - 2

Principles of Programming Languages. Lecture Outline

Aryan College. Fundamental of C Programming. Unit I: Q1. What will be the value of the following expression? (2017) A + 9

Topic IV. Parameters. Chapter 5 of Programming languages: Concepts & constructs by R. Sethi (2ND EDITION). Addison-Wesley, 1996.

General Concepts. Abstraction Computational Paradigms Implementation Application Domains Influence on Success Influences on Design

CS508-Modern Programming Solved MCQ(S) From Midterm Papers (1 TO 22 Lectures) BY Arslan

Statement level control structures

Com S 541. Programming Languages I

Chapter 5. Names, Bindings, and Scopes

Introduction to C++ Introduction. Structure of a C++ Program. Structure of a C++ Program. C++ widely-used general-purpose programming language

Comp 333: Concepts of Programming Languages Fall 2016

Module 27 Switch-case statements and Run-time storage management

The basic operations defined on a symbol table include: free to remove all entries and free the storage of a symbol table

Introduction to C++ with content from

Preview 9/20/2017. Object Oriented Programing with C++ Object Oriented Programing with C++ Object Oriented Programing with C++

Evolution of PL s. EECS 476, Prog. Lang. Design/ page 1

Types. What is a type?

Lecture Notes on Programming Languages

St. MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad

QUIZ on Ch.5. Why is it sometimes not a good idea to place the private part of the interface in a header file?

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find

CSE 307: Principles of Programming Languages

Programming Languages, Summary CSC419; Odelia Schwartz

Data Types In Text: Ch C apter 6 1

CSc 520 Principles of Programming Languages. 26 : Control Structures Introduction

Organization of Programming Languages (CSE452) Why are there so many programming languages? What makes a language successful?

2. Evolution of the Major Programming languages

Topic IV. Block-structured procedural languages Algol and Pascal. References:

Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS

G Programming Languages - Fall 2012

R13 SET Discuss how producer-consumer problem and Dining philosopher s problem are solved using concurrency in ADA.

10. Abstract Data Types

Programming Languages & Paradigms PROP HT Course Council. Subprograms. Meeting on friday! Subprograms, abstractions, encapsulation, ADT

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

Chapter 5 Names, Binding, Type Checking and Scopes

Imperative Programming

Fundamentals of Programming Languages

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

Lecture 13: Object orientation. Object oriented programming. Introduction. Object oriented programming. OO and ADT:s. Introduction

Iterative Statements. Iterative Statements: Examples. Counter-Controlled Loops. ICOM 4036 Programming Languages Statement-Level Control Structure

INSTITUTE OF AERONAUTICAL ENGINEERING

THE CONCEPT OF OBJECT

22c:111 Programming Language Concepts. Fall Types I

Lecture Overview. [Scott, chapter 7] [Sebesta, chapter 6]

Programming Languages

CMSC 4023 Chapter 9. Fundamentals of Subprograms Introduction

Chapter 8. Statement-Level Control Structures

Chapter 6. Structured Data Types. Topics. Structured Data Types. Vectors and Arrays. Vectors. Vectors: subscripts

References and pointers

CS558 Programming Languages

Concepts of Programming Languages

Outline. Programming Languages 1/16/18 PROGRAMMING LANGUAGE FOUNDATIONS AND HISTORY. Current

Compositional C++ Page 1 of 17

CS558 Programming Languages

Short Notes of CS201

CSE 452: Programming Languages. Outline of Today s Lecture. Expressions. Expressions and Control Flow

CS201 - Introduction to Programming Glossary By

Names, Scopes, and Bindings II. Hwansoo Han

Absolute C++ Walter Savitch

Programming Languages Third Edition. Chapter 9 Control I Expressions and Statements

Programming Languages Semantics

Chapter 9. Subprograms

8/27/17. CS-3304 Introduction. What will you learn? Semester Outline. Websites INTRODUCTION TO PROGRAMMING LANGUAGES

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

Final-Term Papers Solved MCQS with Reference

Run-time Environments - 3

On Orthogonality. by remembering only m + n things, we get m * n capabilities.

Static Semantics. Winter /3/ Hal Perkins & UW CSE I-1

1 Terminology. 2 Environments and Static Scoping. P. N. Hilfinger. Fall Static Analysis: Scope and Types

6. Names, Scopes, and Bindings

CS 330 Lecture 18. Symbol table. C scope rules. Declarations. Chapter 5 Louden Outline

Borland 105, 278, 361, 1135 Bounded array Branch instruction 7 break statement 170 BTree 873 Building a project 117 Built in data types 126

Lecture 6 Introduction to Objects and Classes

Transcription:

Imperative Programming Languages (IPL) Definitions: The imperative (or procedural) paradigm is the closest to the structure of actual computers. It is a model that is based on moving bits around and changing machine state Programming languages based on the imperative paradigm have the following characteristics: ΠThe basic unit of abstraction is the PROCEDURE, whose basic structure is a sequence of statements that are executed in succession, abstracting the way that the program counter is incremented so as to proceed through a series of machine instructions residing in sequential hardware memory cells. ΠThe sequential flow of execution can be modified by conditional and looping statements (as well as by the very low-level goto statement found in many imperative languages), which abstract the conditional and unconditional branch instructions found in the underlying machine instruction set.

ΠVariables play a key role, and serve as abstractions of hardware memory cells. Typically, a given variable may assume many different values of the course of the execution of a program, just as a hardware memory cell may contain many different values. Thus, the assignment statement is a very important and frequently used statement. Examples of imperative languages: FORTRAN, Algol, COBOL, Pascal, C (and to some extent C++), BASIC, Ada - and many more. PL/I PL/I (1963-5): was one of the few languages that attempted to be a general purpose language, rather than aiming at a particular category of programming. PL/I incorporated a blend of features from FORTRAN, ALGOL, and COBOL, plus allowed programmers to create concurrent tasks, handle run-time exceptions, use recursive procedures, and use pointers. The language development was closely tied to the development of the IBM/360, a line of "general use" computers. The main problems with the language were its large size and the interaction of so many complex features.

Simula 67: SIMULA 67: yet another descendant of ALGOL, SIMULA was the first language to support data abstraction, through the class concept. Pascal: PASCAL (1971): an extension of the ALGOL languages, it survived as a teaching language for structured programming, it still has widespread (though rapidly declining) use in the teaching community, but comparatively little commercial use. It has stronger type and error checking than Fortran or C and more restrictive syntax, hence enforces some fundamental programming concepts better than C (perhaps). C: C (1972): C presented relatively little that was new or remarkable in terms of programming language design, but used and combined established features in a very effective manner for programming. It was designed for systems programming, and initially spread through close ties with UNIX. C has numerous and powerful operators, and extensive libraries of supporting function.

It has (comparatively) little in the way of type checking, which makes the language more flexible for the experienced user but more dangerous for the inexperienced. Ada Ada (1975-1983): Ada, like COBOL, had its development sponsored by the Department of Defense, and survived as a language largely because of mandated use by the DoD. In design, Ada s developers tried to incorporate everything known about software engineering to that time. It supports object oriented programming, concurrency, exception handling, etc. The design and implementation of the language suffered through being perhaps too ambitious.

IPL Characteristics: Variable and Storage Commands: á á á á á á á Assignments Procedure call Sequential commands Collateral commands Conditional commands Iterative commands Block commands Assignments Simple assignment: x = y +1; Multiple assignment: v1=v2=v3=v4=200; Simultaneous assignment: n1,n2,n3,n4 =m1,m2,m3,m4 Operator-assignment commands: m +=n

Procedure Calls The effect of a procedure call is to apply a procedure abstraction to some arguments The net effect of a procedure call is to update variables (local or global). Sequential commands Much of imperative languages are concerned with control flow, making sure that commands are executed in a specific order. A sequential command is a set of commands executed sequentially. In the sequential command: C1; C2; C2 is executed after C1 is finished.

Collateral commands A computation is deterministic if we can predict in advance exactly which sequence of steps will be followed. Otherwise the sequence is nondeterministic. A collateral command is a set of nondeterministic commands. In the command: C1; C2; C1 and C2 are executed in no particular order. Conditional commands A conditional command has a number of subcommands, from which exactly one is chosen to be executed. Example: the most elementary if command: if E then C1 else C2 end if;

Conditional commands can also be nondeterministic: If E1 then C1 E2 then C2 En then Cn end if; Nondeterministic conditional commands are available in concurrent programming languages (such as Ada). Another conditional command is the Case statement. Iterative commands An iterative command, also known as loop, has a set of commands that is to be executed repeatedly and some kind of phrases that determines when the iteration will stop. Control variable in the definite loops: o Predefined variable o The loop declares the variable o The initial value is atomic or comes an expression.

Two types of iterations: á Definite (For loop) á Undefinite (While loop) Side-effects in IPL In some IPL, the evaluation of expressions has the side effect of updating variables. /* A program in C-like syntax, with side-effects */ int i=1; main() { int y = 5; printf("%d\n",f(y)+g(y)); printf("%d\n",g(y)+f(y)); } int f(int x) { i = i*2; return i*x; } int g(int x) { return i*x; }

The two printf statements will not print the same answer. This means that, for this program f(y) + g(y) is different from g(y) + f(y) Is it bad programming? or side-effect of f on variable i? What is wrong with side-effects in sequential execution? Program is not readable: The result from a function depends on what happened during the execution of another function. Reusability: A program fragment depends on a global environment Correctness of a program becomes almost impossible Good programming: ensure that side-effects never occur. How can we enforce programmers to avoid side-effect?

How can side-effects be avoided? ΠThe problem is destructive assignment. ΠWhenever a statement like x = 8; is executed then the old value of x is destroyed and the new value, 8, substituted. To be safe this implies that the previous value of x cannot be needed again. ΠSo to avoid side-effects, abolish destructive assignment! Is there an alternative to imperative programming languages? Other programming paradigms.

Case Study - C History Kernighan and Ritche designers language designed to implement operating system (Unix) terse, compact, but can write really fast code free, ported with Unix types (minor difference with Pascal) static typing weak typing standard primitive types - but no booleans enumerated types (in ANSI C) composite types arrays records (structs) variant records (unions) no sets

expressions literals aggregate expressions ( a[] = {2, 3, 4} ) function calls (limited to returning primitive types, so composite values are not first-class) conditional expression ( (2 < 3)? 1 : 0 ) constants (in ANSI C) and variables storage classic run-time storage model selective and total updating of composite Variables static and dynamic arrays heap storage for values allocated by calling malloc() uncontrolled use of pointers, pointer craziness

Commands structured programming constructs (e.g., if-thenelse, for-loop) assignment is an expression multiple, composite assignment procedure (void functions) and function calls Bindings static scoping nested name spaces (can declare vars after a {) new-type and type declarations new-variable, but not variable declarations limited recursive declarations Abstractions user-defined function and procedure abstractions built-in selector abstractions only parameter passing call-by-value and call-bypointer eager evaluation of parameters

encapsulations no packages, objects, ADTs type systems built-in operator overloading/coercion type coercion via casting no user-defined overloading no polymorphic types no parameterised types sequencers gotos escapes via returns break escapes from containing block no exception handlers (setjmp, longjmp are in library)