Presentation is loading. Please wait.

Presentation is loading. Please wait.

CIS 317 Concepts of Programming languages Ismail Hmeidi

Similar presentations


Presentation on theme: "CIS 317 Concepts of Programming languages Ismail Hmeidi"— Presentation transcript:

1 CIS 317 Concepts of Programming languages Ismail Hmeidi hmeidi@just
CIS 317 Concepts of Programming languages Ismail Hmeidi Chapter 1 7/8/2019

2 Reasons to study concepts of PLs
List of potential benefits of studying language concepts :- 1. Increased capacity to express programming concepts 2. Improved background for choosing appropriate languages 3. Increased ability to learn new languages 4. Understanding the significance of implementation 5. Increased ability to design new languages 6. Overall advancement of computing 7/8/2019

3 The most popular language is not necessary the best one
7/8/2019

4 FORTRAN AND ALGOL60. ALGOL60 failed although it is better than FORTRAN. ALGOL60 description is difficult. Block structure, has recursion, and well-structured control statements 7/8/2019

5 Programming Domains In this section, we briefly discuss a few of the areas of computer applications and their associated Languages : 1. Scientific applications 2. Business applications 3. Artificial intelligence 4. Systems programming 5. Scripting languages 6. Special purpose languages 7/8/2019

6 Scientific applications needs
data structure ( arrays, matrices,…) and control structures( counting loops, selection,…..) 7/8/2019

7 Business applications
COBOL : appeared 60’s standardized in 85 Spreadsheet DB 7/8/2019

8 Artificial Intelligence (AI)
Use of symbolic rather than numeric computations - LISP : appeared in 59 - Prolog - Scheme : ( a dialect of LISP ). 7/8/2019

9 Artificial Intelligence
Use symbolic rather than numeric computation. Symbolic computation means that symbols, consisting of names rather than numbers, are manipulated 7/8/2019

10 System Programming The (OS) and all of the programming support tools of a computer System are collectively known as its system software Unix OS is written in C. Some consider it flexible. Some consider it dangerous. 7/8/2019

11 Scripting languages A scripting language is used by putting a list of commands, called a script, in a file to be executed The first language was: sh (For shell) sh began as a small collection of commands that were interpreted as calls to system subprograms that performed utility functions 7/8/2019

12 Scripting languages ksh : one of the most powerful and widely known of these is ksh (bolsky and korn,1995),which was developed by david korn at bell laboratories awk : report generator then more general purpose language Tcl : is an extensible scripting language developed by Johan ousterhout at the university of California at berkeley now is combined with (tk) a language that provides a method of building X Windows applications Perl: was a combination of sh and awk. 7/8/2019

13 Scripting languages Perl is popular because it is ideal language for Common Gateway interface (CGI). Scripting languages contributed a little to the development of programming languages 7/8/2019

14 Special-Purpose Languages
A host of special-purpose languages have appeared over the past 40 years. RPG : Report Generation APT : Used for instructing programmable machine tools GPSS: Simulation 7/8/2019

15 Language Evaluation Criteria
The purpose of this book is to examine carefully the underlying concepts of the various constructs and capabilities of programming languages . we will also evaluate these features , focusing on their impact on development (Including maintenance) process. 1. Readability : one of the most important criteria for judging language is the ease with which programs can be read and Understood - The most important criterium - Factors: characteristics that contribute to the readability of a programming language 7/8/2019

16 Language Evaluation Criteria
- Overall simplicity - Too many features is bad - Multiplicity of features is bad Ex. In C m a user can increment a simple integer variable in four different ways: 1. count = count count++ 3. count += count - Orthogonality - Makes the language easy to learn and read - Meaning is context independent - Control statements : use of goto statements severely reduces program readability - Data type and structures - Syntax considerations 7/8/2019

17 Language Evaluation Criteria
2. Writability - Factors: - Simplicity and orthogonality - Support for abstraction - Expressivity 3. Reliability - Type checking - Exception handling - Aliasing - Readability and writability 7/8/2019

18 Evaluation criteria (continued)
4. Cost - Categories - Programmer training - Software creation - Compilation - Execution - Compiler cost - Poor reliability - Maintenance 5. Others: portability, generality, well-definedness 7/8/2019

19 Orthogonality Orthogonality in a programming language means that a relative small set of primitive constructs can be combined in a relatively small number of ways to build the control and data structures of the languages. Every possible combination of primitives is legal and meaningful. Ex. Consider data types , suppose a language has four primitive data types , integer , float , double , and character , and two type operators , array and pointer. if the two type operators can be applied to themselves and the four primitive data types , a large number of data structure can be defined , however , if pointers were not allowed to point to arrays , many of these possibilities would be eliminated The lack of orthogonality leads to exception to the rules of the language 7/8/2019

20 An Example As an example, the add instruction on IBM and VAX machine. Assembly languages IBM A reg1, memory_cell AR Reg1, Reg2; VAX ADDL operand_1, Operand2 7/8/2019

21 Give an example of lack of orthogonality in high-level languages ?
- In C, arrays and records ( struct ). The records can be returned from functions, but arrays can not. - An array element can be any data type except void. 7/8/2019

22 Lack or orthogonality or too much orthogonality can cause problems.
7/8/2019

23 The most orthogonal Programming language was Algol68.
For example, every language construct has a type, and there are no restriction on those types. 7/8/2019

24 Simplicity Simplicity in a language ,therefore, is at least in part the result of a combination of relatively small number of primitive constructs and a limited use of the concepts of orthogonality Some believe that functional languages offer a good combination of simplicity and orthogonality . A functional language ,such as lisp , is one in which computations are needed primarily by applying functions to given parameters. In contrast , in imperative languages such as C , C++ , and Java , Computations are usually specified with variables and assignment statements Functional languages offer potentially the greatest overall simplicity because thy can accomplish everything with a single construct , the function call , witch can be combined with other function calls in simple ways . 7/8/2019

25 Control Statements use of goto reduce the program readability
In FORTRAN 77, goto is necessary for while loop Some restrictions on goto a- They must precede their target. b- Their targets must never be too distinct c- Their numbers must be limited. 7/8/2019

26 BASIC and FORTRAN in early 19770s laced the control statements that allow strong restrictions on the use of goto 7/8/2019

27 Data types and structures
The presence of adequate facilities for defining data types and data structures in a language in another significant aid to readability. Which is more clear ?? flag = 1; // in language where there is no boolean or flag = true; // in language contain boolean 7/8/2019

28 Data types In FORTRAN 77 an array of employee
records might be stored in the following: CHARACTER ( LEN = 30) NAME( 100) INTEGER AGE(100), EMPLOYEE_NO( 100) REAL SALARY ( 100) Here we have 4 arrays with the same subscript value. This is not good. 7/8/2019

29 Syntax Consideration Restricting identifiers and special words form of a language, and designing statements so that their appearance indicates their purpose for more readable program The syntax, or form of the elements of a language has a significant effect on the readability of programs. Three things of syntax consideration. They are: a- identifier forms b- Special words c- Form and meaning 7/8/2019

30 Syntax Consideration A- identifier forms: restricting identifiers to very short lengths detracts (reduces) from readability. - The length of the variable. - In Fortran, it is 6 characters. - In original Basic. It is one letter followed by one or more digits. 7/8/2019

31 Syntax Consideration B- Special word : program appearance and thus program readability are strongly influenced by the forms of a language’s special words: (for example while, class ,and for statements) - C uses { and } . - Fortran 90 and Ada uses end if and end loop. In Fortran 90, some special words such as DO and END are legal variable names (can be very confusing ) 7/8/2019

32 Syntax Consideration C- Form and meaning : designing statements so that their appearance at least partially indicates their purpose is an obvious aid to readability - Semantics or meaning, should follow directly from syntax or form. - This is violated in some languages. For example, in C, the word static has two meaning ( variable that is created at compile time, or the variable is visible only in the file in which its definition appears). 7/8/2019

33 Syntax Consideration Another example: Unix commands (Shell commands of Unix) to copy we use cp to view a list of the files in a directory we use ls 7/8/2019

34 2 - Writability Writability is a measure of how easily a language can be used to create programs for chosen problem domain. Most of the languages charactaristcs that affect readability also affect writability COBOL is not good for creating two- dimensional arrays while APL is the opposite. 7/8/2019

35 2 - Writability The factors that affect writability are :
- Simplicity and orthogonality - Support of abstraction - Expressivity 7/8/2019

36 Support of Abstraction
Abstraction means the ability to define and then use complicated structures or operations in ways that allow many of the details to be ignored. - PL can support two kinds of abstraction: process and data. - An example of process abstraction is the subroutine. 7/8/2019

37 Support of Abstraction
An example of data abstraction is binary tree that stores integer data in its nodes. In Fortran 77, you need to do a 3-Dimensional array to define a binary tree, while in C++ and JAVA, you declare a tree node of two pointers and an integer. 7/8/2019

38 Expressivity Expressivity in a language can refer to several different characters. In a language like APL. It means that there are very powerful operators that allow a great deal of computation to be accomplished with a very small program. APL  A programming language that was developed by IBM in 1960 7/8/2019

39 Expressivity In C In Ada count ++ is easier than count = count + 1;
short circuit is good Also , the AND then Boolean operator in Ada is a convenient way of specifying short-circuit evaluation of a Boolean expression 7/8/2019

40 3 - Reliability A program is said to be reliable if it performs to its specifications under all conditions. 7/8/2019

41 3 - Reliability The following features have significant effect on reliability: a- Type checking b- Exception handling c- Aliasing d- Readability and Writability 7/8/2019

42 Type checking Type checking is simply testing for type of errors in a given program. run-time error type checking is expensive, thus compile-time error type checking is desirable. 7/8/2019

43 Type checking This reduce the errors.
Ada requires checks of the types of nearly all variables and expressions at compile time, except when the user explicitly states that type checking is to be suspended. 7/8/2019

44 Type checking In original C language, there is no checking for the formal parameter against the actual parameter. Another example of type checking is checking the range of the subscripts of the array. 7/8/2019

45 Exception Handling The ability of a program to intercept run-time errors, take corrective measures, and then continue. C++, JAVA, and Ada have it. C and FORTRAN dose not have it. 7/8/2019

46 Aliasing Having two or more distinct referencing methods or names, for same memory cell. - It is dangerous. - In C: Union members and pointers set to point to the same variable in C. 7/8/2019

47 Readability and Writability
Both readability and Writability influence reliability. The easier the program is to write, the more likely it is to be correct. Readability affects reliability in both the writing and maintenance phases of the life cycle. 7/8/2019

48 4 - Cost Cost : the ultimate total cost of a programming language is a function of many of its characteristics 1 - Training programmers. 2 - Writing programs 3 - Compiling programs 4 - Cost of execution programs written in a language is influenced by the language design ( many type checking prohibit fast execution). 7/8/2019

49 4 - Cost 5 - language implementation system (like free compiler).
6 - The cost of poor reliability ( fail in critical system ). 7 – Maintenance : includes both corrections and modifications to add new capabilities the cost of software maintenance depends on a number of language characteristics but primarily readability . Because maintenance is often done by individuals other than the original author of the software ,poor readability can make the task extremely challenging . Maintenance costs can be as high as to four times as much as development cost 7/8/2019

50 Primary influences on language design
1. Computer architecture - We use imperative languages, at least in part, because we use von Neumann machines 2. Programming methodologies - Late 1950s and early 1960s: Simple applications; worry about machine efficiency - Late 1960s: People efficiency became important; readability, better control structures - Late 1970s: Data abstraction - Middle 1980s: Object-oriented programming 7/8/2019

51 Computer Architecture
Most of the PL are designed around von Neumann architecture. In a von neumann computer both data and programs are stored in the same memory ,The (CPU) which actually executes instructions, is separate from the memory. These languages are called imperative languages. The central features of imperative languages are: variables, assignment, iterations. 7/8/2019

52 Computer Architecture
Programming can be done in functional languages without the kind of the variables that are used in the imperative languages In functional languages, by applying functions to given parameters. LISP is an example of functional languages LISP will not replace imperative languages until a non-von Neumann computer language is designed. 7/8/2019

53 Programming Methodologies
Smalltalk is OOP language ( not common ) OOP is part of most imperative languages, including Ada95, JAVA, and C++. Late 60’s and early 70’s Began in large part the structured programming movement of both the software development process and programming language design. An important reason for this research was the shift in the major cost of computing from hardware to software ,as hardware cost decreased and programmer costs increased. Increases in programmer productivity ware relatively small 7/8/2019

54 Language Categories 1. Imperative: specifies a sequence of actions, each of which may change the state of the computer system. FORTRAN, C, Pascal, etc. 2. Functional : specifies what is to be computed through a set of functions to be executed . LISP, SCHEME, ML, HASKEL for AI applications 7/8/2019

55 3. Logic : specifies a series of axioms or facts, rules of inference, and uses logic to answer queries or establish theorems. Prolog for natural language processing. Also applied in database queries, expert systems, etc. 4. Object-oriented (closely related to imperative) : for simulation of real-world happenings. specifies what is to be computed through interactions between objects Simula, Smalltalk, C++ 7/8/2019

56 Others: There are also other paradigms including visual languages, where programs are created by the manipulation of graphical objects rather than by the traditional production of code. Other paradigms can include interactive languages such as SQL and scripting languages such as python and Tcl. Concurrent Programming: specifies computation in terms of the operation of and interaction between concurrent sequential processes 7/8/2019

57 Difference with imperative languages
The OO languages software development use now UML Common with imperative languages The expressions, control statements, and assignment statements are closed ( in C and JAVA are nearly identical) 7/8/2019

58 Logic PL == rule based languages
rules are specified in no particular order. The language implementation system must choose an execution order that produces the desired results. 7/8/2019

59 Language Design Trade-offs
1. Reliability versus cost of execution 2. Writability versus readability 3. Flexibility versus safety 7/8/2019

60 Example of : Reliability versus cost of execution contradiction
Ada and C: In Ada all references to array elements be checked to ensure that the index is not out of range. This adds cost to the execution of Ada programs that contain large references to array elements. In C, this does not exist. ( Ada is more reliable than C) 7/8/2019

61 Example of : Writability vs readability
APL is a language designed for matrices. It has very powerful set of operators for array operands( high degree of expressivity ), as a results it has poor readability. 7/8/2019

62 Example of : Flexibility versus safety
PASCAL variant record allow memory cell to contain different type values at different times. For example, a cell may contain either a pointer or an integer. So a pointer value put in such a cell can be operated on as if it were an integer. This is dangerous. 7/8/2019

63 Implementation Methods
7/8/2019

64 7/8/2019

65 Implementation Methods
The Major Implementation Methods are : 1. Compilation 2- Pure Interpretation 3- Hybrid Implementation Systems 7/8/2019

66 Implementation Methods
1. Compilation Translate high-level program to machine code Slow translation Fast execution 7/8/2019

67 Implementation Methods
1. Compilation Examples: C, C++, Ada, COBOL Look at Figure 1.3 7/8/2019

68 Implementation Methods Compilation
The lexical analyzer gathers the characters of the source program into lexical units. The lexical units of a program are identifiers, special words, operators, and punctuation symbols. It ignores comments 7/8/2019

69 Implementation Methods Compilation
The syntax analyzer takes the lexical units from the lexical analyzer and uses them to construct hierarchical structure called pares tree. Optimization improve the programs by making them smaller or faster or both. 7/8/2019

70 Implementation Methods Compilation
The symbol table serves as a database for the compilation process. The primary contents of the symbol table are the type and attribute information of each user-defined name in the program 7/8/2019

71 Implementation Methods Compilation
The compiler builds calls to required system programs when they are needed by the user program. After that we need the linker and the loader. 7/8/2019

72 Implementation Methods Compilation
The linker connects the user program to the system programs by placing the addresses of the entry points of the system programs in the calls to them in the user program. 7/8/2019

73 Implementation Methods Compilation
The execution of a machine code program on von Neumann architecture computer occurs in a process called the fetch-execute cycle. The speed of the connection between a computer’s memory and its processor is the primary limiting factor in the speed of von Neumann architecture. 7/8/2019

74 2 . Pure interpretation 2 . Pure interpretation
No translation Slow execution Becoming rare At the opposite extreme of implementation methods, programs can be interpreted by another program called interpreter with no translation whatever . The interpreter program acts as a software simulation of a machine whose fetch-execute cycle deals with high-level language program statements rather than machine instructions . This software simulation obviously provides a virtual machine for the language . This technique ,called pure interpretation or simply interpretation . 7/8/2019

75 2 . Pure interpretation Advantage: easy implementation of many source-level debugging operations, because run time error messages can refer to source-level units. Disadvantage: slow ( times) require more space 7/8/2019

76 2 . Pure interpretation Examples:
GWBasic, some versions of APL and LISP. 7/8/2019

77 Hybrid Implementation Systems
Some language implementation systems are compromise between compilers and pure interpreters. They translate high-level language programs to an intermediate language designed to allow easy interpretation. This method is faster than pure interpretation because the source language statements are decoded only once. Such implementations are called hybrid implementing systems. 7/8/2019

78 Hybrid Implementation Systems (Continue)
Perl is implemented with a hybrid system. It evolved from the interpretive languages SH and AWK, but is partially compiled to detect errors before implementation interpretation and to simplify the interpreter. Initial implementations of Java were all hybrid. Its intermediate form, called byte code, provides portability to any machine that has a byte code interpreter and an associated run-time system. Together those are called the Java virtual machine. 7/8/2019

79 Programming Environments
The collection of tools used in software development This collection may consist of only a : File system A text editor A linker And a compiler Briefly describe several programming environments : 1. UNIX An old operating system and tool collection 2. Borland C++ it provides an integrated compiler ,editor ,debugger and file system ,where all four accessed through a graphical interface A PC environment for C and C++ 3. Smalltalk A language processor/environment 4. Microsoft Visual C++ A large, complex visual environment 7/8/2019


Download ppt "CIS 317 Concepts of Programming languages Ismail Hmeidi"

Similar presentations


Ads by Google