ITCS332:: Organization of Programming Languages
ITCS332:: Organization of Programming Languages
Chapter 1: Preliminaries
ISBN 0-321-33025-0
Chapter 1 Topics
Reasons for Studying Concepts of Programming Languages Programming Domains Language Evaluation Criteria Influences on Language Design Language Categories Language Design Trade-Offs Implementation Methods Programming Environments
1-2
1-5
Programming Domains
Computers are applied for different areas: from controlling nuclear plants to video games and mobile phones. Computer applications are classified into 5 categories: Scientific applications Scientific applications have simple data structures but require large number of floating point computations. The most common data structures are counting loops and selections Fortran Business applications Business applications require producing reports, use decimal numbers and characters COBOL With the advent of PCs: Spreadsheets and Databases Artificial intelligence AI applications are characterized by use of symbols rather than numbers Symbolic computation is better done with linked lists than arrays. The first widely used language for AI is LISP. An alternative language for AI applications was used in 1970s: Logic programming using Prolog and Scheme.
.ITCS332 by Dr. Abdel Fattah Salman 1-7
Programming Domains
Systems programming
System software involves OS and all programming support tools. System software is used continuous and needs to be efficient so it must have low-level features. Some computer manufacturers had developed special machine-oriented high-level languages for system software: PL/S from IBM, BLISS from Digital UNIX OS was written almost entirely in C
Web Software
The Web is supported by a collection of languages: markup (e.g., XHTML), scripting (e.g., PHP), general-purpose (e.g., Java). XHTML provides a way of embedding presentation instructions in the pages of information: text, images, sound, or animation. The dynamic web content requires embedding programming code in an XHTML document. Such code is in the form of a scripting language such as JavaScript or PHP. Alternatively, the XTHML document can request the execution of a separate program on the Web server to provide dynamic content.
.ITCS332 by Dr. Abdel Fattah Salman 1-8
To do this , we need a set of criteria: Readability: means the ease with which programs can be read and understood Writability: means the ease with which a language can be used to create programs Reliability: conformance to specifications (i.e., performs to its specifications under all conditions) Cost: the ultimate total cost of a programming language
.ITCS332 by Dr. Abdel Fattah Salman 1-9
Orthogonality
A relatively small set of primitive constructs can be combined in a relatively small number of ways Every possible combination is legal
Control statements
The presence of well-known control structures (e.g., while statement)
Syntax considerations
Identifier forms: flexible composition Special words and methods of forming compound statements Form and meaning: self-descriptive constructs, meaningful keywords
.ITCS332 by Dr. Abdel Fattah Salman 1-10
Overall simplicity
The first complicating feature is a large # of basic constructs is more difficult to learn than one with a small # of them. A manageable set of features and constructs. Programmers often learn and use a subset of the large language and ignore other features. Readability problems occur whenever the programs author used a different subset from that known to the reader. The second complicating feature is feature multiplicity: means having more than one way of doing the same operation. a=a+1; a+=1; a++; ++a. The third complicating feature is operator overloading: a single operator has more than one meaning. Some overloadings are useful and simplify the language by reducing the # of operators: Using + for both integer and real additions. Some overloadings are harmful and make the construct confusing: using + between 2 vector operands to mean their respective elements.
.ITCS332 by Dr. Abdel Fattah Salman 1-11
Suppose a L has 4 primitive data types: int, float, double, char and 2 type operators: array and pointer. If the type op can be applied to themselves and the 4 data types, then a large # of data structures can be defined.
The lack of orthogonality leads to the exceptions to the rules of the language. The use of orthogonality can be illustrated by comparing addition instruction of assembly on IBM mainframes and VAX superminicomputers: Adding 2 32-bit integers that reside in register/memory and replacing one of them with the sum: A reg1, mem ; on IBM AR reg1, reg2 ADDL op1, op2 ; on VAX The VAX instruction is orthogonal in that a single instruction can use either registers or memory as operands.
1-12
1-14
Expressivity
Expressivity means that a language has a set of relatively convenient ways of specifying operations. a++ is more convenient and shorter than a=a+1. Example: the inclusion of for statement in many modern languages makes writing counting loops easier than with the use of while
.ITCS332 by Dr. Abdel Fattah Salman 1-18
Exception handling
The ability of a program to intercept run-time errors, take corrective measures and continue is obvious to reliability. Ada, C++, and Java include extensive capabilities for exception handling, but Fortran not.
.ITCS332 by Dr. Abdel Fattah Salman 1-20
1-23
1-28
1-29
1-30
Language Categories
Imperative
Central features are variables, assignment statements, and iteration. An algorithm is specified in detail ,and the specific order of instructions must be included. Examples: C, Pascal
Functional
Main means of making computations is by applying functions to given parameters Examples: LISP, Scheme
Logic
Rule-based : rules are specified in no particular order and the language implementation system must choose an execution order the produces the desired results. Example: Prolog
Object-oriented
Data abstraction, inheritance, late binding Examples: Java, C++
.ITCS332 by Dr. Abdel Fattah Salman 1-31
Language Categories
Markup Not a programming language. It is used to specify the layout of information in Web documents Some programming capabilities has crept into some extensions to XHTML and XML such as Java Server Pages Standard Tag library (JSTL) and eXtensible Stylesheet Language Transformations (XSLT). New: used to specify the layout of information in Web documents Examples: XHTML, XML
1-32
1-33
In summary: The task of choosing constructs and features when designing a PL requires many compromises and trade-offs.
1-34
Implementation Methods
Machine language is the only language that most computers understand. A computer can be designed and built to use HLL as its machine language, but this will be very complex and expensive and highly inflexible because it would be difficult to use it with other HLLs. The more practical machine design choice implements in hardware a very low-level language that provides the most commonly needed primitive operations and requires system software to create an interface to programs in HLLs. In additional to the hardware and the language implementation system, computers need OS. PLs can be implemented by any of 3 methods: Compilation - Programs are translated into machine language Pure Interpretation Programs are interpreted by another program known as an interpreter Hybrid Implementation Systems A compromise between compilers and pure interpreters
.ITCS332 by Dr. Abdel Fattah Salman 1-35
1-36
Compilation
Translate high-level program (source language) into machine code (machine language), which can be executed directly on the computer. Slow translation, fast execution Compilation process has several phases: Lexical analysis (Scanning): converts characters in the source program into lexical units Syntax analysis (Parsing): transforms lexical units into parse trees which represent the syntactic structure of program Semantics analysis: generate intermediate code Code generation: machine code is generated
1-37
1-38
1-40
Pure Interpretation
Programs are interpreted by another program called interpreter with no translation. An interpreter acts as a software simulation of a machine whose fetchexecute cycle deals with HLL program statements rather than machine instructions. Easier implementation of programs (run-time errors can easily and immediately displayed) Slower execution (10 to 100 times slower than compiled programs). The primary source of slowness is the decoding of HLL statements, which are more complex that machine language instructions. Loop statements must be decoded in every iteration. Bottleneck: Statement decoding rather than CPU-MEM connection. Often requires more space Becoming rare on high-level languages Significant comeback with some Web scripting languages (e.g., JavaScript and PHP)
.ITCS332 by Dr. Abdel Fattah Salman 1-41
1-42
1-44
Preprocessors
A preprocessor is a program that processes a program immediately before it is compiled. Preprocessor instructions are embedded in programs. Preprocessor macros (instructions) are commonly used to specify that code from another file is to be included A preprocessor processes a program immediately before the program is compiled to expand embedded preprocessor macros A well-known example: C preprocessor expands #include, #define, and similar macros C example: #define max(A,B) ((A) > (B) ? (A) : (B)) The macro call: X = max(2*y, z/1.73); expands to X= ((2*y) > (z/1.73) ? (2*y):z/1.73));
.ITCS332 by Dr. Abdel Fattah Salman 1-46
Programming Environments
A programming environment is the collection of tools used in software development such as: file system, text editor, compiler, linker. Several programming environment are: UNIX An older operating system and tool collection Nowadays often used through a GUI (e.g., CDE, KDE, or GNOME) that run on top of UNIX Borland JBuilder Provides an integrated compiler, editor, debugger, and file system for Java development. Microsoft Visual Studio.NET A large, complex visual environment Used to program in 5 .NET languages: J#, Jscript , C#, managed C++, Visual BASIC.NET.
.ITCS332 by Dr. Abdel Fattah Salman 1-47
Summary
The study of programming languages is valuable for a number of reasons: Increase our capacity to use different constructs Enable us to choose languages more intelligently Makes learning new languages easier Most important criteria for evaluating programming languages include: Readability, writability, reliability, cost Major influences on language design have been machine architecture and software development methodologies The major methods of implementing programming languages are: compilation, pure interpretation, and hybrid implementation
.ITCS332 by Dr. Abdel Fattah Salman 1-48