34
1 Introduction CO3225 Programming Language: Theory and Practice Low Aim is a Crime, but not high Low Aim is a Crime, but not high ambition ambition

1 Introduction CO3225 Programming Language: Theory and Practice Low Aim is a Crime, but not high ambition

Embed Size (px)

Citation preview

Page 1: 1 Introduction CO3225 Programming Language: Theory and Practice Low Aim is a Crime, but not high ambition

1

Introduction

CO3225

Programming Language: Theory and Practice

Low Aim is a Crime, but not high ambitionLow Aim is a Crime, but not high ambition

Page 2: 1 Introduction CO3225 Programming Language: Theory and Practice Low Aim is a Crime, but not high ambition

2

Introduction

• Motivation

• Language Design Principles

• Application Domains

• Language Evaluation Criteria

• Influences on Language Design

• Different Paradigms in Programming

• Stages in Translation

• Programming Languages Summary

Coverage

Page 3: 1 Introduction CO3225 Programming Language: Theory and Practice Low Aim is a Crime, but not high ambition

3

Introduction

• Learning programming language with appropriate paradigm

and logic, guides users in learning different languages

• Knowing the breadth of the stream • Choosing a specific language is easier, once the developer

is aware of many languages• Avoid reinvent something that already exists

• Knowing to expand his spectrum • Learning or adopting to new languages wont be an uphill

task anymore

• Better perspective on the implementation • Knowing the background processing helps in debugging

• Utilizing the language to the limit • Maximum usage of the given language

Motivation

Page 4: 1 Introduction CO3225 Programming Language: Theory and Practice Low Aim is a Crime, but not high ambition

4

Introduction

• Software development process−Requirements analysis and planning−Analysing various design possibilities−Coding the program−Testing the effectiveness of the program−Maintenance of the software

• Language design concepts−Syntax and Grammar

• Validate a program based on the given language specifications

−Type Systems and Semantics • Variable types with appropriate meanings

Motivation

Page 5: 1 Introduction CO3225 Programming Language: Theory and Practice Low Aim is a Crime, but not high ambition

5

Introduction

• Language design concepts− Memory Management

• Use of stack, heap, static and dynamic memory • Stack is an area of memory where storage is done only

by Last In First Out (LIFO) order. Data could be added or removed from the stack only from the top of the stack.

• Heap is an area of memory where allocation and freeing of memory is done arbitrarily. Heap is mainly used to store data during runtime.

− Exception Handling • How to handle exceptions?• OVERFLOW (the resultant value is larger than the

maximum allowed value for the specified type)• UNDERFLOW (the resultant value is smaller than the

minimum allowed value for the specified type)• DIVIDE BY ZERO, …

Motivation

Page 6: 1 Introduction CO3225 Programming Language: Theory and Practice Low Aim is a Crime, but not high ambition

6

Introduction

• Scientific Applications− Handle large number of floating point computations− FORTRAN, ALGOL-60, …

• Business or Management Information Systems− Process numerous decimal numbers and generate results− COBOL, …

• Artificial Intelligence− Manipulations of symbols instead of numbers− LISP, PROLOG, …

• Systems Programming− Interact with hardware devices− Able to write device drivers, compilers, etc.− C language, …

Application Domains

Page 7: 1 Introduction CO3225 Programming Language: Theory and Practice Low Aim is a Crime, but not high ambition

7

Introduction

• Scripting Languages− Process according to the instructions provided in the file− Awl, Perl, …

• Web-Centric− Internet based applications− JavaScript, PHP, …

• Special-purpose languages− Meant for specific applications− VHDL, SQL, …

Application Domains

Page 8: 1 Introduction CO3225 Programming Language: Theory and Practice Low Aim is a Crime, but not high ambition

8

Introduction

• Readability− Usability: Simple and clear to understand− Not too many ways to implement the same thing− Meaning should depend on the context− Affected by: complex syntax, presence of many ways to do a

single task, overloading of operators + methods, branching statements like goto

− Orthogonality: • Simpler constructs and be able to combine them• Presence of different parameter passing methods based on

different data types cause lack of orthogonality• Functional languages support orthogonality

• Writability− Expressing clearly and concisely− Abstracting the unnecessary details from the programmer

might help (Ex. Use a sort method without knowing how it works)

Language Evaluation Criteria

Page 9: 1 Introduction CO3225 Programming Language: Theory and Practice Low Aim is a Crime, but not high ambition

9

Introduction

• Binding− Early and late binding should be supported

• Reliability− Unexpected actions should not happen during program

execution− Provide this feature using: type checking, exception handling,

reliability and writability− Presence of aliasing (giving more than one name for a single

memory location) might affect reliability

• Cost− Training, maintenance− Transition from old to new version of the concerned application

• Uniformity− Similar appearance means similar meaning

• Generality− Language should be generic in nature and not specific

Language Evaluation Criteria

Page 10: 1 Introduction CO3225 Programming Language: Theory and Practice Low Aim is a Crime, but not high ambition

10

Introduction

• Extensibility− Users should be able to add new constructs to the language

• Standardability− Program should heterogeneous support− Write once and use at many places

• Support for Internationalization− Various formats of time, currency, etc should be supported

• Well-definedness (how detailed the official document is),

applicability, compilation time, implementability, debugging

(facilities to trace for errors and use break points), ability to

handle exceptions, regularity (which includes orthogonality,

generality, uniformity), coherence (understand only a single

level of abstraction), support for code verification

Language Evaluation Criteria

Page 11: 1 Introduction CO3225 Programming Language: Theory and Practice Low Aim is a Crime, but not high ambition

11

Introduction

• A computer is made up of Central Processing Unit (CPU),

memory, and Input/Output devices. − These components are connected using a set of connectors

wired in parallel, called as bus.

• CPU also contains a set of special memory locations called as

registers.

• Computer architecture is based on Von Neumann architecture

and it has its own specific limitations

• Execution of instructions are done using fetch-execute cycle or

instruction cycle

• Programs reside in memory and are executed by the CPU.

• Each instruction is moved from memory to the processor and

the address of the next instruction to be executed is stored in

the register called as program counter.

Influences on Language Design

Page 12: 1 Introduction CO3225 Programming Language: Theory and Practice Low Aim is a Crime, but not high ambition

12

Introduction

• In fetch-execute cycle, the instruction pointed by the program

counter is fetched from the memory to the instruction

register (present in CPU) and the program counter value is

incremented. Then, the actual instruction is decoded and

executed

• Restrictions due to Von Neumann architecture− Storage of both data (in the data store) and programs (in

the program store) are done in the same memory.− We need to pass the instructions and data from the memory

to CPU as memory and CPU are separate from one another.− Iterations, assignment statement and variables become the

basis for any imperative language

Influences on Language Design

Page 13: 1 Introduction CO3225 Programming Language: Theory and Practice Low Aim is a Crime, but not high ambition

13

Introduction

• Direct Memory Access (DMA) is used to steal

memory cycles from the CPU, during which data

transfer is handled directly between I/O devices and

memory

Von Neumann Architecture

CENTRAL PROCESSING UNIT

ARITHMETIC AND LOGIC UNIT (ALU)

CONTROL UNIT

MEMORY

Instructions and Data

Results of Processing

Connection to I/O devices

Page 14: 1 Introduction CO3225 Programming Language: Theory and Practice Low Aim is a Crime, but not high ambition

14

Introduction

• Virtual Machine: − Implement a machine or computer as a software− Execute programs as if programs are executed on a

physical machine

• Two types of virtual machine− System virtual machine (hardware virtual machine)

• Provides a platform over which a complete operating system could be executed

• Multiple OS can be run on a single physical computer• Ex. VMWare, VirtualBox, Sun xVM, …

− Process virtual machine (application virtual machine)• Uses existing OS and runs a process over it• Ex. Java Virtual Machine (JVM)

Virtual Machine

Page 15: 1 Introduction CO3225 Programming Language: Theory and Practice Low Aim is a Crime, but not high ambition

15

Introduction

• Impact of virtual machine on language design− Data structures (like storage management, sequencing of

operations, etc) and various algorithms form the basics of computer (virtual computer)

− Virtual computer structures are specific not only to programming language but also to operating systems, firmware, etc.

− You will find that certain operating systems and firmware run only on certain specific hardware architectures.

• Impact of computer architecture on language design− Instruction set required to execute the instruction is not infinite

• The set of instructions is determined by Reduced Instruction Set Computers (RISC) or Complex Instructions Set Computers (CISC)

− Different in speed between CPU performance and Memory access time

− Von Neumann bottleneck: instructions to be executed sequentially

Impact on language design

Page 16: 1 Introduction CO3225 Programming Language: Theory and Practice Low Aim is a Crime, but not high ambition

16

Introduction

• Impact of computer architecture on language design− Functional languages use functions and avoids

variables/assignment statements/iterations; Some feel that imperative languages are popular due to the impact of Von Neumann architecture

− Issues due to the current day application requirements of graphical user interfaces, embedded systems, web based applications, etc.

Impact on language design

Page 17: 1 Introduction CO3225 Programming Language: Theory and Practice Low Aim is a Crime, but not high ambition

17

Introduction

• Paradigms (programming paradigms) indicate various styles of

formulating solutions for the given problem, programmatically

• Different paradigms required different methodology to be used

to solve a given problem− In object-oriented paradigm, the problem is solved using

objects and interactions among them;− In functional paradigm, the problem is solved using stateless

functions; − In procedural paradigm, the problem is solved using a

sequence of procedures

• Imperative or Procedural languages− Depends on variables, assignment statements and iteration − Processing is done step-by-step− Ex. C, Pascal, Cobol, Fortran, Basic, C++ − Note: Certain languages support multiple paradigms

Different Paradigms

Page 18: 1 Introduction CO3225 Programming Language: Theory and Practice Low Aim is a Crime, but not high ambition

18

Introduction

• Functional or applicative languages− Uses functions with specified parameters to accomplish the

task− Includes functional composition, conditionals, recursions,

etc− Ex. LISP, Scheme, Haskell, ML, SML− Pure functional language does not include any variable

declaration, so infers the variable type from the assigned value.

• Logic or declarative languages− Concentrate on what is the expected outcome for the

program instead of how the outcome is accomplished − Logic programs infers or deduces from facts, using rules− Used to write Expert Systems and other Artificial

Intelligence applications− Ex. PROLOG (PROgramming in LOGic)

Different Paradigms

Page 19: 1 Introduction CO3225 Programming Language: Theory and Practice Low Aim is a Crime, but not high ambition

19

Introduction

• Object-Oriented Languages− Uses classes and objects− A class includes various subtasks associated with it. − Objects being an instance of the class could perform those

subtasks− Supports inheritance, dynamic type binding, …− Uses divide and conquer on both data and appropriate

methods− Ex. C++, Java, Smalltalk, Eiffel, Ruby, Python, …− Procedural languages don't have something in between

local and global variables; OOP supports it.

• Event-based languages− Based on user activities like mouse click and other events− Ex. Visual Basic, Java

Different Paradigms

Page 20: 1 Introduction CO3225 Programming Language: Theory and Practice Low Aim is a Crime, but not high ambition

20

Introduction

• Concurrent or Parallel languages− Executes the processes in distributed manner. − Some languages are specifically for distributed processing;

Some general purpose languages also supports distributed application development.

− Ex. SR, Linda, High Performance Fortran, OCCAM, and PVM

• Special Purpose Languages− Meant for specialized tasks− Ex. SQL, Perl, HTML, VHDL, …

• Aspect Oriented Languages− Separate not highly related activities so as to reuse the

codes effectively.− AspectJ, AspectC#, Aspect .Net

Different Paradigms

Page 21: 1 Introduction CO3225 Programming Language: Theory and Practice Low Aim is a Crime, but not high ambition

21

Introduction

• Pure Interpretation− Interprets the program in sequence of one statement after

the other.− Ex. Interpretation of HTML code by the client browser

• Compilation Process− Two step process; convert to assembly language and then

to object program− Assembler: Generates object or machine code from

assembly language− Compiler: Generates object or machine from high-level

language− Loader and Linker:

• Linkers are called as Link Editors• Program loading is done by loader; Resolution is handled

by linker; and relocation is handled by both linker and loader

Stages in Translation

Page 22: 1 Introduction CO3225 Programming Language: Theory and Practice Low Aim is a Crime, but not high ambition

22

Introduction

• Compilation Process− Loader and Linker:

• Program Loading:−Copy program code from hard disk to main memory−Requires allocating and mapping of address space

• Relocation:−Initially programs are based on base address as zero−Changing of addresses based on the position at which

the program is loaded onto the memory• Resolution:

−Linking of appropriate libraries −Referencing symbols needed by the program

• Preprocessor or macroprocessor−Extended features for the high-level programming

language

Stages in Translation

Page 23: 1 Introduction CO3225 Programming Language: Theory and Practice Low Aim is a Crime, but not high ambition

23

Introduction

Stages in Translation

Source File (.c or .cpp or others)

Preprocessed Code(.i file)

Preprocessor

Assembly Code(.s file)

Compiler

Object Code(.o file)

Assembler

Executable Code(.exe file)

Linker Library FilesOther Object

Codes

Relocation Information

Load the Program into Memory

Loader Runtime LibraryRuntime Objects

1st Source File 2nd Source File nth Source File

1st Object File

Assembler

2nd Object File

Assembler

nth Object File

Assembler

Executable Code(.exe file)

Library FilesLinker

• Convert several files

individually to object files using

assembler and then link them.

Page 24: 1 Introduction CO3225 Programming Language: Theory and Practice Low Aim is a Crime, but not high ambition

24

Introduction

• Hybrid Implementation− Cross compiler runs a program on one machine (host

machine) and returns the code for another machine (target machine)

• Compiler Vs Interpreter− Compiler is used when the program is complete (production

stage)− Interpreter is preferred when program is under testing stage

or debugging stage and execution period is not vital

Stages in Translation

Page 25: 1 Introduction CO3225 Programming Language: Theory and Practice Low Aim is a Crime, but not high ambition

25

Introduction

• Pseudocodes: − Better than machine code because machine code is very difficult

to read and modify. − Highly machine dependent. − Pseudocodes include various conditional branching, unconditional

branching, arithmetic and mathematical functions. • FORTRAN: FORmula TRANslation [IBM by John Backus in 1957]

− Versions: Fortran IV, Fortran 77, Fortran 90, Fortran 95, Fortran 2003, High Performance Fortran, …

− Aim: support numerical computations− Loops were used and manipulated using arrays − Fortran 90 has pointers and recursion − Fortran 2003 supports object-oriented programming,

interoperating with C language, …• COBOL: Common Business-Oriented Language

− Designed by Grace Hopper of US Navy during 1959-1960− Serve business needs like managing inventories and payrolls− Read file as inputs rather than input from keyboard− Code looks much like English language statements and is lengthy

and also includes various divisions in code

Programming Languages Summary

Page 26: 1 Introduction CO3225 Programming Language: Theory and Practice Low Aim is a Crime, but not high ambition

26

Introduction

• BASIC (Beginner's All-Purpose Symbolic Instruction Code): − Designed by John Kemeny and Thomas Kurts at Dartmouth in

1964− Meant to be pleasant and friendly − User time is considered vital than computer time− Most common dialect is Visual BASIC

• Pascal: − Designed in 1970 by Niklaus Wirth− Taught as a primary language in computer science majors− Most part of the compiler is also written in Pascal itself and thus

making it less dependant on platform− Compiler is written in Pascal, so bootstrapping is needed

• Compile the compiler by hand into its P-code. Tedious but not difficult

• P-code interpreter executes this hand-translated compiler• Optimizations are done later to improve the process• Use existing Pascal compiler to develop P-code on one

machine and use the P-code interpreter appropriate to the other machine.

Programming Languages Summary

Page 27: 1 Introduction CO3225 Programming Language: Theory and Practice Low Aim is a Crime, but not high ambition

27

Introduction

• C lanuguage: − Designed by Dennis Ritche of ATT Bell Laboratories in 1970− Based on BCPL (Basic Combined Programming Language

developed by Martin Richards in 1967) and B language (developed by Ken Thompson)

− Aim: systems programming and especially on UNIX platform− Supports Pointers, low-level coding like assembly language, …

• C++ language:− Designed by Bjarne Stroustup of ATT Bell Laboratories in

1980.− object oriented language with exception handling features− Inherited many features from C and Simula 67

− Supports both procedural and object oriented paradigms− Eiffel: designed to be simpler and smaller than C++ but with

good efficiency− Delphi: Borland is also of Object-Oriented paradigm which

includes certain features from Pascal

Programming Languages Summary

Page 28: 1 Introduction CO3225 Programming Language: Theory and Practice Low Aim is a Crime, but not high ambition

28

Introduction

• ADA: − Designed by Augusta Byron Lovelace of US armed services in

1979\− Object oriented language which supports multi-processing− Supports data abstraction in the form of Packages, elaborate

exception handling and concurrency.• Java:

− Designed by Sun Microsystems in 1991− First version was released in 1996− Object oriented which is significantly simplified compared to C++

• Java does not include struct, union, pointer arithmetic.• Pointers are not supported but are handled using references.

− Applets are an additional feature present in this language. • C#:

− Designed as part of the .NET development platform by Microsoft− Based on both C++ and Java− All .NET languages use the common class library known as

Common Type System (CTS).

Programming Languages Summary

Page 29: 1 Introduction CO3225 Programming Language: Theory and Practice Low Aim is a Crime, but not high ambition

29

Introduction

• LISP:

− LISt Processing language designed by McCarthy at MIT in 1959

− Syntax is based on lambda calculus

− Applied mainly to Artificial Intelligence research

− Supports processing on data as lists rather than arrays and handles symbolic computations

− Pioneer in functional programming, LISP does not support variables or assignment but has control via recursion and conditional expressions

− COMMON LISP and Scheme are contemporary dialects of LISP

• Scheme was developed by Gerald Sussman and Guy Steele at MIT

• ML (developed by Robin Miller at Edinburgh University in 1970s), Miranda and Haskell are related languages

• Haskell developed by Hudak and Fasel in 1992 is based on Miranda

Programming Languages Summary

Page 30: 1 Introduction CO3225 Programming Language: Theory and Practice Low Aim is a Crime, but not high ambition

30

Introduction

• ALGOL (Algorithmic Language): − Designed during the period of FORTRAN− Aim: Syntax close to mathematical notation and easier to

describe algorithms− Algol 60: Many features like recursive calls to procedures, pass

by name, pass by value, begin-end blocks, structured statements and stack-dynamic arrays were introduced

• Smalltalk: − Developed at Xerox PARC, initially by Alan Kay and later by Adele

Goldberg during the period 1972-80− Supports object-oriented paradigm concepts like data

abstraction, inheritance, and dynamic type binding− Pioneer for graphical user interface (GUI)

• PL/I (Programming Language I): − Designed by IBM and SHARE− Aimed to support both scientific as well as business computing− First to support exception, recursive subprograms, pointers, etc.

Programming Languages Summary

Page 31: 1 Introduction CO3225 Programming Language: Theory and Practice Low Aim is a Crime, but not high ambition

31

Introduction

• Simula:

− Designed by Kristen Nygaard and Ole-Johan Dahl at Norwegian Computing Centre (NCC) in Oslo between 1962 and 1967.

− Based on Algol 60 and meant for system simulation

− Features included: Co-routines, Classes, objects and inheritance

• Prolog (Programming in Logic):

− Developed: University of Aix-Marseille by Comerauer and Rousel in 1972. Assisted by Kowalski at University of Edinburgh

− Non-procedural language purely based on formal logic

• APL (A Programming Language):

− Designed (1962): hardware description language by Ken Iverson at IBM

− Has many operators for scalars and arrays of various dimensions

− Supports dynamic typing and dynamic storage allocation

Programming Languages Summary

Page 32: 1 Introduction CO3225 Programming Language: Theory and Practice Low Aim is a Crime, but not high ambition

32

Introduction

• SNOBOL (String-Oriented Symbolic Language): − Designed (1964) to handle string manipulation by David Farber,

Ralph Griswold and Ivan Polensky at Bell labs− Important feature: String pattern matching − Icon, a successor to SNOBOL was developed by Griswold

• SQL (Structured Query Language): − Designed by IBM in 1986− Uses relational model and used to handle databases− Data is stored in databases and manipulations are done using SQL

• Scripting Languages: − Scripting languages include Perl, sh, awk, tcl, JavaScript, …− Normally interpreted one command at a time− Practical Extraction and Report Language (PERL)

• Does sophisticated pattern-matching techniques • Initially based on scripting languages like sh and awk

− awk: Includes text and file processing + pattern matching techniques

− Other scripts can call Tcl which is accompanied with Tk (powerful windowing graphics library).

Programming Languages Summary

Page 33: 1 Introduction CO3225 Programming Language: Theory and Practice Low Aim is a Crime, but not high ambition

33

Introduction

• HTML: HyperText Markup Language (HTML) − Developed by Tim Berners-Lee in 1989 in Switzerland − Used to create web pages to be viewed using different browsers− eXtensible Markup Language (XML) format (called as XML data

document) is displayed according to the eXtensible Stylesheet Language Transformation (XSLT) document

− JavaScript interpreter present in Web browsers interpret JavaScript codes, a client side scripting language

− Server side scripts could be written using scripting languages like PHP or JSP or ASP or ASP.NET.

• Ruby and Python: − Two recent object-oriented languages− Ruby: released by Yukihiro Matsumoto in 1996

• Pure object-oriented language like Smalltalk• Supports dynamic typing and so need to declare variables

− Python: Initially designed by Guido van Rossum at Stichting Mathematisch Centrum in the Netherlands during early 1990s. • Supports various data structures like lists, immutable lists

and hashes• Posses pattern matching capabilities

Programming Languages Summary

Page 34: 1 Introduction CO3225 Programming Language: Theory and Practice Low Aim is a Crime, but not high ambition

34

Introduction

• Parallel Programming: − Needed to accomplish or perform various tasks in Parallel. − Apart from specific software there are libraries that could be

added to existing languages like C or C++ or Java or the like− Two most popular libraries: Parallel Virtual Machine (PVM) and

Message Passing Interface (MPI)

Programming Languages Summary